/* ==========================================================================
   Base: reset, typography, layout primitives, utilities, motion primitives
   ========================================================================== */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }

  html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    scroll-padding-top: 5rem;
    hanging-punctuation: first last;
  }

  body {
    margin: 0;
    font-family: var(--font-body);
    font-size: var(--fs-md);
    line-height: var(--lh-body);
    color: var(--fg);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overflow-x: clip;
  }

  img, svg, video { display: block; max-width: 100%; height: auto; }
  img { font-style: italic; background-repeat: no-repeat; background-size: cover; }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-display);
    margin: 0 0 0.5em;
    text-wrap: balance;
  }
  h1 { font-size: var(--fs-4xl); font-weight: 800; }
  h2 { font-size: var(--fs-3xl); }
  h3 { font-size: var(--fs-xl); }
  h4 { font-size: var(--fs-lg); }

  p { margin: 0 0 1em; text-wrap: pretty; }
  p:last-child { margin-bottom: 0; }

  a { color: inherit; text-decoration-color: color-mix(in oklab, currentColor 40%, transparent); text-underline-offset: 0.18em; }
  a:hover { text-decoration-color: currentColor; }

  ul, ol { padding-inline-start: 1.25em; }

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

  :focus-visible { outline: 3px solid var(--ring); outline-offset: 3px; border-radius: var(--radius-sm); }

  ::selection { background: var(--accent); color: var(--accent-fg); }

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

  .section { padding-block: var(--section-y); background: var(--bg); color: var(--fg); position: relative; }
  .section--alt { background: var(--bg-alt); }
  .section--tight { padding-block: calc(var(--section-y) * 0.6); }

  .stack > * + * { margin-block-start: var(--stack, var(--sp-4)); }
  .cluster { display: flex; flex-wrap: wrap; gap: var(--cluster, var(--sp-3)); align-items: center; }
  .grid { display: grid; gap: var(--grid-gap, var(--sp-6)); grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--grid-min, 16rem)), 1fr)); }
  .split { display: grid; gap: var(--sp-10); align-items: center; grid-template-columns: 1fr; }
  @media (min-width: 56rem) { .split { grid-template-columns: 1fr 1fr; } .split--wide-media { grid-template-columns: 5fr 6fr; } }

  /* ---------- Typography helpers ---------- */
  .eyebrow {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    font-family: var(--font-display); font-weight: 600; font-size: var(--fs-sm);
    letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--accent);
    margin-bottom: var(--sp-3);
  }
  .eyebrow::before { content: ""; width: 1.75rem; height: 3px; background: currentColor; transform: skewX(var(--skew)); }
  .lead { font-size: var(--fs-lg); color: var(--fg-muted); max-width: 60ch; }
  .muted { color: var(--fg-muted); }
  .subtle { color: var(--fg-subtle); }
  .display { font-family: var(--font-display); }
  .mono { font-family: var(--font-mono); font-size: 0.92em; }
  .caps { font-family: var(--font-display); text-transform: uppercase; letter-spacing: var(--tracking-caps); font-weight: 600; font-size: var(--fs-xs); }
  .accent { color: var(--accent); }
  .measure { max-width: 65ch; }
  .center { text-align: center; }
  .center .lead, .center .measure { margin-inline: auto; }
  .visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

  /* Section heading block */
  .section-head { max-width: 60ch; margin-bottom: var(--sp-10); }
  .section-head--center { margin-inline: auto; text-align: center; }
  .section-head--center .eyebrow { justify-content: center; }
  .section-head h2 { margin-bottom: var(--sp-3); }

  /* ---------- Motion primitives ---------- */
  /* Reveal on scroll: scroll-driven when supported, IntersectionObserver fallback otherwise */
  .reveal {
    --reveal-y: 28px;
    opacity: 0;
    transform: translateY(var(--reveal-y));
    transition: opacity var(--dur-reveal) var(--ease-out), transform var(--dur-reveal) var(--ease-out);
    transition-delay: var(--delay, 0ms);
  }
  .reveal.is-inview { opacity: 1; transform: none; }

  @supports (animation-timeline: view()) {
    .reveal {
      opacity: 1; transform: none; transition: none;
      animation: reveal-up var(--dur-reveal) var(--ease-out) both;
      animation-timeline: view();
      animation-range: entry 0% entry 35%;
    }
    .reveal.is-inview { animation-play-state: running; }
  }
  @keyframes reveal-up {
    from { opacity: 0; transform: translateY(var(--reveal-y)); }
    to { opacity: 1; transform: none; }
  }

  /* Stagger children: set --i on each child */
  .stagger > * { --delay: calc(var(--i, 0) * 70ms); }

  /* Cross-document view transitions */
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation: vt-out 220ms var(--ease-in-out) both; }
  ::view-transition-new(root) { animation: vt-in 320ms var(--ease-out) both; }
  @keyframes vt-out { to { opacity: 0; transform: translateY(-6px); } }
  @keyframes vt-in { from { opacity: 0; transform: translateY(10px); } }
  site-header { view-transition-name: site-header; display: block; position: sticky; top: 0; z-index: var(--z-overlay); }
  site-footer { display: block; }
  ::view-transition-group(site-header) { animation-duration: 0ms; }

  @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; }
    .reveal { opacity: 1; transform: none; animation: none; }
    ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  }

  /* Scroll progress bar (scroll-driven) */
  .scroll-progress {
    position: fixed; inset: 0 0 auto 0; height: 3px; z-index: calc(var(--z-header) + 1);
    background: var(--accent); transform-origin: 0 50%; transform: scaleX(0);
    pointer-events: none;
  }
  @supports (animation-timeline: scroll()) {
    .scroll-progress { animation: grow-x linear both; animation-timeline: scroll(root); }
  }
  @keyframes grow-x { from { transform: scaleX(0); } to { transform: scaleX(1); } }
}

@layer base {
  /* Grid/flex children must be allowed to shrink below their content width */
  .grid > *, .split > *, .ds-layout > *, .wizard > *, .portal__grid > *, .location-card > *, .hero__content > * { min-width: 0; }
  /* Programmatic focus on headings (wizard steps) should not draw a ring */
  h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus, h3[tabindex="-1"]:focus { outline: none; }
}
