/* ==========================================================================
   Noah Vice · motion
   Every animation lives in this file. The other stylesheets describe the
   finished page; this one describes how it gets there.

   On load      The hero plays its entrance once (CSS keyframes).

   On scroll    Elements with data-reveal start hidden (only when <html> has
                .js) and site.js adds .is-in as they come into view.
                  data-reveal           fade and rise
                  data-reveal="media"   image wipes up from the bottom and
                                        settles from a slight zoom
                  data-reveal="row"     hairline draws across, then the row rises
                  data-reveal="rule"    line draws left to right
                  data-reveal="pop"     scales up from nothing
                  data-split            text rises word by word, line by line
                                        (site.js wraps the words, adds .is-split)
                Stagger: site.js gives siblings an increasing --delay.

   Linked to    site.js writes CSS variables; the rules below turn them into
   scroll and   movement.
   the pointer    --hero      0 → 1 while the hero scrolls away
                  --q         −1 … 1, an element's position on screen (data-parallax)
                  --drift     −1 … 0 × data-drift: slides in, settles mid-screen
                  --mx, --my  −1 … 1, pointer position over the hero
                  --o         opacity of each word in the intro statement

   Off switch   With prefers-reduced-motion, and while editing in Canopy
                (html.epic-edit), everything sits in its final state.
   ========================================================================== */

@layer motion {
  /* ---------- Hero entrance ---------- */
  @keyframes hero-photo-in { from { opacity: 0; transform: scale(1.14); } }
  /* Rises out of an invisible mask at the word's own position: the clip moves
     up exactly as fast as the word moves down, so the edge stays still. */
  @keyframes rise-masked {
    from { transform: translateY(125%); clip-path: inset(-25% -8% 100% -8%); }
    to   { transform: none;             clip-path: inset(-25% -8% -25% -8%); }
  }
  @keyframes fade-up { from { opacity: 0; transform: translateY(18px); } }
  @keyframes fade-in { from { opacity: 0; } }

  .hero-photo { animation: hero-photo-in 2.2s var(--ease-out) backwards; }
  .hero-word { animation: rise-masked 1.4s var(--ease-out) backwards; }
  .hero-left .hero-word { animation-delay: 350ms; }
  .hero-right .hero-word { animation-delay: 470ms; }
  .hero-left .pill { animation: fade-up 1.1s var(--ease-out) 800ms backwards; }
  .hero-role > :first-child { animation: fade-up 1.1s var(--ease-out) 880ms backwards; }
  .hero-role > :last-child { animation: fade-up 1.1s var(--ease-out) 960ms backwards; }
  .hero .scroll-cue { animation: fade-up 1.1s var(--ease-out) 1100ms backwards; }
  .site-header { animation: fade-in 1.4s var(--ease) 900ms backwards; }

  /* ---------- Hero, linked to scroll and pointer ---------- */
  .hero-photo {
    translate: calc(var(--mx, 0) * -14px) calc(var(--hero, 0) * 22% + var(--my, 0) * -10px);
    scale: calc(1 + var(--hero, 0) * 0.08);
  }
  .hero-frame::after {                                   /* the hero darkens as it leaves */
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: var(--bg); opacity: calc(var(--hero, 0) * 0.85);
  }
  .hero .scroll-cue { opacity: calc(1 - var(--hero, 0) * 5); }
  @container hero (aspect-ratio >= 1.15) {
    /* The two halves of the name part as you scroll, and shift a little with the pointer */
    .hero-left  { translate: calc(var(--hero, 0) * -16cqw + var(--mx, 0) * 9px) calc(var(--my, 0) * 6px); }
    .hero-right { translate: calc(var(--hero, 0) *  16cqw + var(--mx, 0) * 9px) calc(var(--my, 0) * 6px); }
  }
  @container hero (aspect-ratio < 1.15) {
    .hero-name { translate: 0 calc(var(--hero, 0) * -14cqh); opacity: calc(1 - var(--hero, 0) * 1.6); }
  }

  /* ---------- Reveal on scroll ---------- */
  .js [data-reveal] {
    opacity: 0; transform: translateY(36px);
    transition: opacity var(--duration-reveal) var(--ease-out) var(--delay, 0ms),
                transform var(--duration-reveal) var(--ease-out) var(--delay, 0ms);
  }
  .js [data-reveal].is-in { opacity: 1; transform: none; }

  /* Split text: the block itself stays put; its words rise */
  .js [data-reveal].is-split { opacity: 1; transform: none; }
  .word { display: inline-block; overflow: clip; vertical-align: top; padding-block: 0.08em 0.14em; margin-block: -0.08em -0.14em; }
  .word-inner {
    display: inline-block; transform: translateY(115%);
    transition: transform 1.2s var(--ease-out) calc(var(--delay, 0ms) + var(--line, 0) * 90ms);
  }
  .is-in .word-inner { transform: none; }

  /* Media: wipe up and settle */
  .js [data-reveal="media"] {
    opacity: 1; transform: none;
    clip-path: inset(100% 0 0 0 round var(--radius-media));
    transition: clip-path 1.5s var(--ease-in-out) var(--delay, 0ms);
  }
  .js [data-reveal="media"].is-in { clip-path: inset(0 0 0 0 round var(--radius-media)); }
  .js [data-reveal="media"] > :first-child { scale: 1.25; transition: scale 2s var(--ease-out) var(--delay, 0ms); }
  .js [data-reveal="media"].is-in > :first-child { scale: 1; }

  /* Rows: hairline first, then content */
  .js [data-reveal="row"] { opacity: 1; transform: none; }
  .js [data-reveal="row"]::before { transform: scaleX(0); transition: transform 1.4s var(--ease-in-out) var(--delay, 0ms); }
  .js [data-reveal="row"] > * {
    opacity: 0; transform: translateY(28px);
    transition: opacity 1s var(--ease-out) calc(var(--delay, 0ms) + 250ms),
                transform 1s var(--ease-out) calc(var(--delay, 0ms) + 250ms),
                translate 600ms var(--ease-out), rotate 700ms var(--ease-out), color 500ms var(--ease), border-color 400ms var(--ease);
  }
  .js [data-reveal="row"].is-in::before { transform: none; }
  .js [data-reveal="row"].is-in > * { opacity: 1; transform: none; }
  .js .services-list.has-open [data-reveal="row"].is-in:not(.is-open) { opacity: 0.38; transition: opacity 500ms var(--ease); }

  /* Lines and the round button */
  .js [data-reveal="rule"] { opacity: 1; transform: scaleX(0); transition: transform 1.6s var(--ease-in-out) var(--delay, 0ms); }
  .js [data-reveal="rule"].is-in { transform: none; }
  .js [data-reveal="pop"] { opacity: 1; transform: none; scale: 0; transition: scale 1.1s var(--ease-spring) calc(var(--delay, 0ms) + 500ms); }
  .js [data-reveal="pop"].is-in { scale: 1; }

  /* ---------- Linked to scroll ---------- */
  [data-parallax] { translate: 0 calc(var(--q, 0) * -6%); }
  [data-drift] { display: block; translate: calc(var(--drift, 0) * 8vw) 0; }
  @media (max-width: 699px) { [data-drift] { translate: calc(var(--drift, 0) * 4vw) 0; } }
  .scrub-word { opacity: var(--o, 1); transition: opacity 200ms linear; }

  /* ---------- Cursor label replaces the hover pill on fine pointers ---------- */
  .has-cursor .project-cta { display: none; }
  .has-cursor [data-cursor], .has-cursor [data-cursor] * { cursor: none; }   /* the badge is the cursor here */
  .has-cursor .project-link:focus-visible .project-cta { display: inline-flex; }

  /* ---------- Smooth anchor jumps without JS smoothing ---------- */
  @media (prefers-reduced-motion: no-preference) { html:not(.has-smooth) { scroll-behavior: smooth; } }
  html { scrollbar-gutter: stable; }
  html.menu-open { overflow: hidden; }

  /* ---------- Off switch ---------- */
  .epic-edit :is(.hero-photo, .hero-word, .pill, .hero-role > *, .scroll-cue, .site-header) { animation: none; }
  .epic-edit :is(.hero-photo, .hero-left, .hero-right, .hero-name, [data-parallax], [data-drift]) { translate: none; scale: none; }
  .epic-edit .hero-frame::after { opacity: 0; }
  .epic-edit .hero .scroll-cue { opacity: 1; }
  .epic-edit :is([data-reveal], [data-reveal] > *, .word-inner) { opacity: 1; transform: none; clip-path: none; scale: none; transition: none; }
  .epic-edit [data-reveal]::before { transform: none; }
  .epic-edit .scrub-word { opacity: 1; }
  .epic-edit .service .service-body { grid-template-rows: 1fr; }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; transition-delay: 0s !important; }
    :is(.hero-photo, .hero-left, .hero-right, .hero-name, [data-parallax], [data-drift]) { translate: none; scale: none; }
    .hero-frame::after { opacity: 0; }
    .hero .scroll-cue { opacity: 1; }
    .js :is([data-reveal], [data-reveal] > *, .word-inner) { opacity: 1; transform: none; clip-path: none; scale: none; }
    .js [data-reveal]::before { transform: none; }
  }
}
