/*
 * Motion core, in the head on every page: the tokens, static rules that
 * change layout or paint at first render, enter, the first hero's layers,
 * smooth, transitions and the word spans' display. The rest of the motion
 * layer: motion-defer.css (not render-blocking), motion-marquee.css,
 * motion-tiers.css and about.css (head, only where their markup is), and
 * the body-linked home-map, study-cards, tiers and patterns files. Rules,
 * keys and which file holds each: docs/design/motion.md. Everything that
 * moves sits under "screen and prefers-reduced-motion: no-preference" and
 * under its key (html[data-fx~="key"], between "fx:key" comments).
 */

@layer motion {
  :root {
    --motion-fast: 180ms;
    --motion-base: 320ms;
    --motion-reveal: 640ms;
    --motion-enter: 560ms;
    --motion-stagger: 70ms;
    --motion-rise: 20px;
    --motion-marquee: 50s;
    --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
    --ease-pop: cubic-bezier(0.34, 1.4, 0.64, 1);
  }

  /* Static: the hero's glow layer (behind the text, no layout, no pointer).
     The section is its positioning and clipping parent, so the cursor glow
     covers the whole hero edge to edge, not the container box (.hero is
     display: contents; design review 2026-10-22, #4 #19 #35). No decorative
     circles in heroes (design system, 2026-10-25). "clip", not "hidden":
     it clips the same without making the section a scroll container, which
     would freeze a view timeline inside it (the tier drawings on phones);
     "hidden" stays first for a browser without "clip". */
  .block-hero {
    position: relative;
    overflow: hidden;
    overflow: clip;
  }

  .hero__body,
  .hero__media {
    position: relative;
    z-index: 1;
  }

  .hero__shapes {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
  }

  /* Static: the header shadow is a pseudo-element whose opacity changes */
  .site-header::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    box-shadow: 0 8px 24px -12px var(--color-shadow-header);
    opacity: 0;
    pointer-events: none;
  }

  .site-header.is-scrolled::after {
    opacity: 1;
  }

  /* Static: count-up figures reserve their width */
  [data-countup] {
    display: inline-block;
    font-variant-numeric: tabular-nums;
  }

  /* Static marquee rules: motion-marquee.css */

  @media screen and (prefers-reduced-motion: no-preference) {
    /* Interface feedback and fx:reveal: motion-defer.css */

    /* fx:enter ---- Entrance on load (pure CSS): the first hero, page headers and the case
       study hero rise in 90ms steps; the H1 and hero image only lift (never fade: they are
       the LCP candidates); the About collage badge pops in after them. */
    html[data-fx~="enter"] :is(.hero-enter, .page-header__inner) > * {
      animation: motion-rise var(--motion-enter) var(--ease-out) both;
    }

    html[data-fx~="enter"] :is(.hero-enter, .page-header__inner) > :nth-child(2) {
      animation-delay: 90ms;
    }

    html[data-fx~="enter"] :is(.hero-enter, .page-header__inner) > :nth-child(3) {
      animation-delay: 180ms;
    }

    html[data-fx~="enter"] :is(.hero-enter, .page-header__inner) > :nth-child(n + 4) {
      animation-delay: 270ms;
    }

    html[data-fx~="enter"] :is(.hero-enter > .hero__title, .page-header__inner > .page-header__title) {
      animation-name: motion-lift;
    }

    html[data-fx~="enter"] .hero-enter ~ .hero__media {
      animation: motion-lift 800ms var(--ease-out) both;
    }

    /* The About collage badge's entrance: about.css */
    /* /fx:enter */

    /* fx:layers ---- Decorative shapes: the About collage shapes
       and the closing band shapes float on their own loops ("transform"); where scroll-driven
       animations exist the collage shapes also drift at their own speed over the
       first viewport of scroll ("translate", so the two compose).
       The peach shapes keep their static "rotate". */
    html[data-fx~="layers"] :is(.collage__shape, .cta-shape) {
      animation: motion-float var(--float, 12s) ease-in-out var(--float-at, 0s) infinite var(--float-dir, normal);
    }

    .cta-shape--mint {
      --float: 13s;
    }

    .cta-shape--gold {
      --float: 7s;
      --float-at: -3s;
    }

    .cta-shape--ring {
      --float: 10s;
      --float-at: -6s;
      --float-dir: reverse;
    }

    html[data-fx~="layers"] .cta-shape--peach {
      animation: layers-turn 24s linear infinite;
    }

    @supports (animation-timeline: scroll()) {
      html[data-fx~="layers"] .collage__shape {
        animation-name: motion-float, layers-drift;
        animation-duration: var(--float, 12s), auto;
        animation-timing-function: ease-in-out, linear;
        animation-delay: var(--float-at, 0s), 0s;
        animation-iteration-count: infinite, 1;
        animation-direction: var(--float-dir, normal), normal;
        animation-fill-mode: none, both;
        animation-timeline: auto, scroll(root);
        animation-range: normal, 0 100vh;
      }
    }

    /* The About collage shapes and team rings: about.css */
    /* /fx:layers */

    /* fx:marquee: motion-marquee.css */

    /* fx:smooth ---- Smooth scrolling for in-page anchor links (the carousel's buttons check
       the same key in motion.js). */
    html[data-fx~="smooth"] {
      scroll-behavior: smooth;
    }
    /* /fx:smooth */

    /* fx:map ---- The home US map's motion is in public/assets/css/home-map.css (same layer,
       same key), linked by the locationmap block so only home loads it. */
    /* /fx:map */

    /* fx:glow: motion-defer.css */

    /* fx:transitions ---- Cross-document view transitions: a 200ms cross-fade, the header kept
       as its own group. The opt-in @view-transition rule is at the end of this file. */
    ::view-transition-old(root),
    ::view-transition-new(root) {
      animation-duration: 200ms;
    }

    html[data-fx~="transitions"] .site-header {
      view-transition-name: site-header;
    }

    ::view-transition-group(site-header) {
      animation-duration: 120ms;
    }
    /* /fx:transitions */

    /* fx:magnet: motion-defer.css */

    /* fx:lines ---- The word spans' display (layout at first render); the word reveal
       itself is in motion-defer.css. */
    html[data-fx~="lines"] :is(.section__title, .statement__title) > .w {
      display: inline-block;
    }
    /* /fx:lines */

    /* fx:icons, fx:tilt: motion-defer.css. fx:diagrams and the tier timeline:
       motion-tiers.css. The story timeline: about.css. */
  }

  @keyframes motion-rise {
    from {
      opacity: 0;
      transform: translateY(14px);
    }
  }

  @keyframes motion-lift {
    from {
      transform: translateY(12px);
    }
  }

  @keyframes motion-float {
    50% {
      transform: translate3d(0, -14px, 0);
    }
  }

  @keyframes layers-drift {
    to {
      translate: 0 var(--drift, -3rem);
    }
  }

  @keyframes layers-turn {
    50% {
      transform: translate3d(-1.5rem, 1rem, 0) rotate(180deg);
    }

    to {
      transform: rotate(360deg);
    }
  }

  @keyframes tl-fill-y {
    from {
      transform: scaleY(0);
    }
  }
}

/* fx:transitions */
/* The cross-document opt-in (outside the layer: @view-transition is a top-level
   rule). Motion-allowed visitors only; the fade timings are in the layer above. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
}
/* /fx:transitions */
