/* ============================================================
   Prestigia Homes — Base layer
   Reset, document defaults, typography, layout primitives,
   and the scroll driven reveal system (pure CSS, no listeners).
   ============================================================ */

@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  * {
    margin: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* Anchor targets clear the fixed glass header */
    scroll-padding-top: 6rem;
    color-scheme: dark;
  }

  body {
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: var(--leading-body);
    letter-spacing: var(--track-body);
    color: var(--text-on-dark);
    background-color: var(--surface-ground);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100svh;
    /* Plane 0: the faint gold monogram field. Very low opacity,
       radial rather than a repeating pattern, so it reads as
       light in a room rather than as wallpaper. */
    background-image:
      radial-gradient(
        ellipse 120% 80% at 12% -10%,
        color-mix(in oklch, var(--gold) 9%, transparent),
        transparent 62%
      ),
      radial-gradient(
        ellipse 90% 70% at 92% 4%,
        color-mix(in oklch, var(--burgundy) 12%, transparent),
        transparent 58%
      );
    background-attachment: fixed;
  }

  img,
  picture,
  video,
  canvas,
  svg {
    display: block;
    max-width: 100%;
    height: auto;
  }

  input,
  button,
  textarea,
  select {
    font: inherit;
    color: inherit;
  }

  p,
  li,
  figcaption {
    text-wrap: pretty;
    max-width: var(--measure);
  }

  /* ---- Display typography -------------------------------- */
  h1,
  h2,
  h3,
  h4 {
    font-family: var(--font-display);
    font-weight: 400;
    letter-spacing: var(--track-display);
    line-height: var(--leading-tight);
    text-wrap: balance;
  }

  h1 {
    font-size: var(--step-5);
  }
  h2 {
    font-size: var(--step-4);
  }
  h3 {
    font-size: var(--step-2);
    line-height: var(--leading-snug);
  }
  h4 {
    font-size: var(--step-1);
    line-height: var(--leading-snug);
  }

  a {
    color: inherit;
    text-decoration-color: color-mix(in oklch, currentColor 40%, transparent);
    text-underline-offset: 0.22em;
    text-decoration-thickness: 1px;
    transition: color var(--dur-hover) var(--ease-out),
      text-decoration-color var(--dur-hover) var(--ease-out);
  }

  /* Chromium reports :visited as unvisited in getComputedStyle for privacy,
     so an undefined visited colour is invisible in code and obvious on
     screen. Define it explicitly and keep it on brand. */
  a:visited {
    color: inherit;
  }

  a:hover,
  a:visited:hover {
    color: var(--accent-hover);
    text-decoration-color: currentColor;
  }

  /* ---- Focus: visible and unmistakable ------------------- */
  :focus-visible {
    outline: 2px solid var(--gold-bright);
    outline-offset: 3px;
    border-radius: var(--radius-s);
  }

  ::selection {
    background: color-mix(in oklch, var(--gold) 40%, transparent);
    color: var(--ivory);
  }

  /* ---- Layout primitives --------------------------------- */
  .shell {
    width: min(100% - (var(--gutter) * 2), var(--shell));
    margin-inline: auto;
  }

  .shell-narrow {
    width: min(100% - (var(--gutter) * 2), var(--shell-narrow));
    margin-inline: auto;
  }

  .section {
    padding-block: var(--section-pad);
    background-color: var(--surface-section);
    position: relative;
  }

  .section--ground {
    background-color: transparent;
  }

  .stack > * + * {
    margin-block-start: var(--flow, var(--space-m));
  }

  .skip-link {
    position: absolute;
    inset-inline-start: var(--space-s);
    inset-block-start: -4rem;
    z-index: var(--z-overlay);
    background: var(--gold);
    color: var(--charcoal);
    padding: var(--space-2xs) var(--space-s);
    border-radius: var(--radius-m);
    font-weight: 600;
    transition: inset-block-start var(--dur-panel) var(--ease-out);
  }

  .skip-link:focus {
    inset-block-start: var(--space-s);
  }

  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  /* ---- Scroll driven reveal ------------------------------ *
   * Baseline in 2026 across Chrome, Firefox and Safari. No
   * IntersectionObserver, no scroll listeners, no library.
   * Degrades to fully visible where unsupported.              */
  @supports (animation-timeline: view()) {
    @media (prefers-reduced-motion: no-preference) {
      /* Plane 1 parallax: media drifts against its overlay */
      .parallax-media {
        animation: parallax-drift linear both;
        animation-timeline: view();
        animation-range: cover;
      }
    }
  }

  .reveal,
  .reveal-stagger > * {
    opacity: 1;
    transform: none;
  }

  body[data-motion="on"] .reveal:not(.is-revealed),
  body[data-motion="on"] .reveal-stagger > :not(.is-revealed) {
    opacity: 0;
    transform: translate3d(0, 22px, 0);
  }

  body[data-motion="on"] .reveal.is-revealed,
  body[data-motion="on"] .reveal-stagger > .is-revealed {
    opacity: 1;
    transform: none;
    transition: opacity 620ms var(--ease-out), transform 620ms var(--ease-out);
  }

  @keyframes reveal-in {
    from {
      opacity: 0;
      transform: translate3d(0, 22px, 0);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  @keyframes parallax-drift {
    from {
      transform: scale(1.14) translate3d(0, -3.5%, 0);
    }
    to {
      transform: scale(1.14) translate3d(0, 3.5%, 0);
    }
  }

  /* ---- View transitions across full page navigations ----- */
  @view-transition {
    navigation: auto;
  }

  @media (prefers-reduced-motion: no-preference) {
    ::view-transition-old(root) {
      animation: vt-out 180ms var(--ease-in-out) both;
    }
    ::view-transition-new(root) {
      animation: vt-in 260ms var(--ease-out) both;
    }
  }

  @keyframes vt-out {
    to {
      opacity: 0;
    }
  }
  @keyframes vt-in {
    from {
      opacity: 0;
    }
  }

  /* ---- Reduced motion: crossfade, never nothing ---------- */
  @media (prefers-reduced-motion: reduce) {
    html {
      scroll-behavior: auto;
    }
    *,
    *::before,
    *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }

  /* In page motion control, per WCAG 2.2 SC 2.3.3. Sits
     alongside the OS setting rather than replacing it. */
  body[data-motion="off"] *,
  body[data-motion="off"] *::before,
  body[data-motion="off"] *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
