/* ===========================================================================
   motion.css — the scroll-motion system. Loaded last so it can override
   panels.css. Depends on tokens.css.

   ---------------------------------------------------------------------------
   THE IDEA

   The page is one continuous take through eight colour fields, and the
   artwork is the subject. Everything below serves that:

     text leads, media lands last and settles longest,
     so the eye is always delivered to the work.

   ---------------------------------------------------------------------------
   FOUR LAYERS, IN ORDER OF HOW MUCH THEY MATTER

   1. ENTRANCE CHOREOGRAPHY (JS-triggered transitions, IntersectionObserver)
      A section's parts arrive in reading order — eyebrow, heading words,
      body, media — with a real stagger between them. Distance and duration
      scale with the visual mass of the thing moving.

   2. CONTINUOUS DEPTH (CSS scroll-driven animations, no JS)
      Poster images drift inside their own frames as you scroll. This is the
      only thing on the page that moves while you are reading, and it is
      deliberately almost subliminal.

   3. SIGNATURE MOMENTS (two, and only two)
      The hero's departure, and the showreel's letterbox arrival.

   4. HOVER REFINEMENT
      Media responds to the pointer, not just the button on top of it.

   5. THE STATEMENT FIELD (css/statement-field.css + js/statement-field.js)
      The hero statement is split into two- and three-character clusters that
      lean toward the cursor while a fine pointer is in the hero. It is NOT in
      this file, because it is the one layer whose per-frame values are written
      by script rather than declared — but it owns a transform on the hero
      subtree, so it belongs in the table below. Desktop only, like layers 2
      and 3, and every pixel of its motion is caused by the pointer: with the
      cursor still, its loop is not merely idle, it is cancelled.

   ---------------------------------------------------------------------------
   WHY THE ENTRANCE LAYER IS TRANSITIONS AND THE DEPTH LAYER IS ANIMATIONS

   This project measured, in its own preview host, CSS `animation-timeline`
   never running while `CSS.supports('animation-timeline','view()')` returned
   true — the feature query lies there. So anything STRUCTURAL (does the
   reader ever see this content?) is IntersectionObserver, which is boring and
   works. Only DECORATIVE depth uses scroll-driven animation, where the cost
   of it silently not running is that the page is merely static — never
   broken, never blank. Layer 2 is a bonus, not a dependency.

   Every scroll-driven animation below therefore animates TOWARDS the
   element's natural resting state, never away from it.

   ---------------------------------------------------------------------------
   FAIL-VISIBLE — DO NOT INVERT THIS

   Every hidden state is behind `.js-reveal`, a class js/reveal.js adds to
   <html> ONLY after it has confirmed it can un-hide things. If that script
   404s, throws, or is blocked, nothing here ever hides and the page renders
   complete. See the header of js/reveal.js. Never hide in CSS and reveal in
   JS.

   ---------------------------------------------------------------------------
   TRANSFORM OWNERSHIP — THE ONE RULE THAT KEEPS THIS FROM BREAKING

   An animation beats a transition on the same property, silently. So no
   element may be both entrance-transitioned and scroll-animated on
   `transform`. The layers are kept on separate elements throughout:

     .video              entrance transform  (layer 1)
     .video__poster      scroll parallax     (layer 2)
     .video__poster img  hover scale         (layer 4)

     .h-duo / .statement NO transform — their .word children carry the
                         entrance, which is why the hero statement's parent
                         is free for the departure animation.

     .word               entrance rise + fade                (layer 1)
     .statement__cluster the field, written per frame by JS  (layer 5)

     Those last two are the hero statement read top to bottom: .panel__inner
     scrolls, .statement stays still, .word arrives, .statement__cluster leans.
     Four levels, one property each. The field could NOT simply live on .word,
     which is the whole reason a fourth level exists.

     .carousel__item     the wheel transform, written by js/carousel.js
     .carousel__img      hover scale         (layer 4)
     .selector__panel    the cross-fade, from css/selector.css

   The two widgets are why reveal.js lists `.selector` and `.carousel` as
   entrance targets rather than their inner items: an entrance transform on a
   panel would fight the wheel/stage transform its own script writes, and the
   animation would win silently.

   If you add a transform anywhere, check which layer already owns it.
   =========================================================================== */


/* ===========================================================================
   LAYER 1 — ENTRANCE CHOREOGRAPHY
   ===========================================================================
   Reduced motion: the whole layer is inside a no-preference query AND
   js/reveal.js returns early, so neither the class nor the styles apply. */

@media (prefers-reduced-motion: no-preference) {

  /* --- The resting (hidden) state, by role -------------------------------
     --s is the element's index within its section, set by js/reveal.js. It
     is what turns a section's independent fades into one ordered sentence. */

  .js-reveal .reveal {
    opacity: 0;
    transition-property: opacity, transform;
    transition-duration: var(--dur-enter-text);
    transition-timing-function: var(--ease-enter);
    transition-delay: calc(var(--s, 0) * var(--stagger));
    transform: translate3d(0, var(--rise-body), 0);
  }

  /* Eyebrows and micro-caps announce the section, so they move least and
     arrive first. */
  .js-reveal .reveal--micro {
    transition-duration: var(--dur-enter-micro);
    transform: translate3d(0, var(--rise-micro), 0);
  }

  /* Headings carry NO transform of their own — the word spans below do the
     work. Two nested transforms on a heading is how the previous build ended
     up moving some elements 60px and others 30px. Opacity only here, so the
     parent stays free for the hero departure animation. */
  .js-reveal .reveal--head {
    opacity: 1;
    transform: none;
    transition: none;
  }

  /* Media: the payoff. Furthest travel, longest settle, and a slight scale
     up into place so it arrives rather than appears. */
  .js-reveal .reveal--media {
    transition-duration: var(--dur-enter-media);
    transition-timing-function: var(--ease-media);
    transform: translate3d(0, var(--rise-media), 0) scale(var(--scale-media));
  }

  /* --- Arrived ----------------------------------------------------------- */
  .js-reveal .reveal.is-in {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }

  /* --- Words -------------------------------------------------------------
     --i is the word's index within its heading; --s is the heading's slot in
     the section. Adding them means a heading's words begin after whatever
     introduced the heading has landed — choreography nested two levels deep,
     which is the difference between "staggered" and "designed". */
  .js-reveal .word {
    display: inline-block;
    opacity: 0.001;
    transform: translate3d(0, var(--rise-word), 0);
    transition: opacity var(--dur-enter-text) var(--ease-enter),
                transform var(--dur-enter-text) var(--ease-enter);
    transition-delay: calc(
      var(--s, 0) * var(--stagger) + var(--i, 0) * var(--stagger-word)
    );
  }

  .js-reveal .is-in .word,
  .js-reveal .word.is-in {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }

  /* --- The section seam --------------------------------------------------
     A hairline drawn across the top of each section as it arrives. This is
     the section-to-section connective tissue: it uses the site's existing
     1.5px rule vocabulary (.ruled, .index-table) rather than inventing a new
     shape, and currentColor makes it legible on all five colour grounds
     without a per-ground override.

     panels.css sets .panel { position: static }. relative with no offsets is
     visually identical and gives the pseudo-element something to anchor to. */

  .panel { position: relative; }

  .panel::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 1.5px;
    z-index: 1;
    background: currentColor;
    opacity: 0.13;
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform 1.15s var(--ease-enter);
  }

  .panel.is-seam-in::before { transform: scaleX(1); }

  /* The hero is the top of the document — there is no seam above it. */
  .panel--hero::before { display: none; }
}


/* ===========================================================================
   LAYER 2 — CONTINUOUS DEPTH (scroll-driven, no JS)
   ===========================================================================
   Desktop only. On a phone this costs battery for an effect nobody sees at
   that size, and small screens are where scroll performance matters most.

   The poster image drifts inside its frame while the frame stays put. That is
   real foreground/background separation, and because it happens entirely
   inside an overflow:hidden box it cannot shift a single pixel of layout.
   --parallax-zoom is what makes the drift containable: at 1.08 there is ~4%
   of overscale on each edge and the drift is 3.5%, so an edge can never be
   exposed. Do not raise --parallax-media past that headroom. */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) and (min-width: 48rem) {

    .video__poster {
      animation: media-drift linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }

    @keyframes media-drift {
      from { transform: scale(var(--parallax-zoom)) translateY(calc(-1 * var(--parallax-media))); }
      to   { transform: scale(var(--parallax-zoom)) translateY(var(--parallax-media)); }
    }

    /* Text drifts the opposite way against its media sibling, at roughly a
       quarter of the distance.

       SCOPED TO THE TWO FILM SECTIONS ON PURPOSE. `.panel-split` is used in
       four places, and only these two pair a text column with a media column
       — which is the only arrangement where a differential reads as depth
       rather than as a misalignment:

         #exercises  first column is the CATCAT video grid, not text. Drifting
                     it would move media against a static caption block.
         #about      both columns are text (bio | "what's in the work").
                     Drifting one against the other just breaks their shared
                     baseline.

       If a third film section is ever added, add it to this list. */
    :is(#melancholy-love, #elemental-heroes) .panel-split > div:first-child {
      animation: text-drift linear both;
      animation-timeline: view();
      animation-range: cover 0% cover 100%;
    }

    @keyframes text-drift {
      from { transform: translateY(10px); }
      to   { transform: translateY(-10px); }
    }
  }
}


/* ===========================================================================
   LAYER 3 — THE TWO SIGNATURE MOMENTS
   =========================================================================== */

/* --- 3a. The hero departure ------------------------------------------------
   The statement drifts up and dims as the hero leaves while the mulberry
   ground stays put. Reads as a camera tilting off the wall rather than a div
   scrolling away, and it hands the reader off to the work instead of simply
   ending.

   Applied to .panel__inner, which owns no other transform; the hero's
   children carry their own entrance transforms and compose underneath it.
   Nothing here is position:sticky — the section keeps its natural height, so
   this does not reintroduce the pinned-panel model that was removed. */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) and (min-width: 48rem) {
    .panel--hero .panel__inner {
      animation: hero-depart linear both;
      animation-timeline: view();
      animation-range: exit 0% exit 100%;
    }

    @keyframes hero-depart {
      to { transform: translateY(-56px); opacity: 0.28; }
    }
  }
}

/* --- 3b. The showreel letterbox --------------------------------------------
   The showreel is the one thing a recruiter came for, so it gets the single
   genuinely cinematic arrival on the page: the frame opens from a closed
   letterbox rather than sliding in like everything else.

   clip-path, not height — height would reflow the page on every frame. The
   figure's default state is fully open, so if .js-reveal never lands the
   showreel is simply visible. */

@media (prefers-reduced-motion: no-preference) {
  .js-reveal #showreel .video {
    clip-path: inset(50% 0 50% 0);
    transition: clip-path 1.05s var(--ease-media),
                opacity var(--dur-enter-media) var(--ease-media),
                transform var(--dur-enter-media) var(--ease-media);
    transition-delay: calc(var(--s, 0) * var(--stagger));
  }

  .js-reveal #showreel .video.is-in { clip-path: inset(0 0 0 0); }
}


/* ===========================================================================
   LAYER 4 — HOVER REFINEMENT
   ===========================================================================
   Not inside a no-preference query: base.css already flattens every
   transition-duration to 0.01ms under reduced motion, so these become instant
   state changes rather than animations — which is the correct behaviour, not
   a missing one.

   Guarded by (hover: hover) so a touch device never gets a stuck hover state
   left behind after a tap. */

@media (hover: hover) {

  /* The poster itself responds, not just the play button floating on it.
     On .video__poster img — the <picture> above it owns the parallax
     transform, and the two must not collide. */
  /* 620ms -> 420ms, 2026-08-10. This is a HOVER — motion the reader caused,
     not motion the page performs at them. The entrance durations above stay
     long on purpose; input-driven response has to be quick or it reads as lag
     even when nothing is actually slow. */
  .video__poster img {
    transition: transform 420ms var(--ease-media);
  }

  .video__frame:hover .video__poster img,
  .video__frame:focus-visible .video__poster img {
    transform: scale(1.04);
  }

  /* The play button grows more slowly than it did, so it feels weighted
     rather than springy. */
  .video__play::before {
    transition: transform 420ms var(--ease-media);
  }

  .video__frame:hover .video__play::before { transform: scale(1.12); }

  /* Pills: the arrow leads the way out. */
  .pill__arrow {
    transition: transform 320ms var(--ease-enter);
  }

  /* The 0.04em Y-nudge is gone: the arrow is a masked .icon now and
     vertical-align sets its baseline. rotate() must be composed in or the
     north-east external-link arrows snap to east for the duration of the
     hover. One owner per transform. */
  .pill:hover .pill__arrow { transform: translateX(3px) rotate(var(--icon-rotate, 0deg)); }

  /* Nav and social underlines wipe in from the left instead of appearing all
     at once. border-bottom cannot be animated directionally, so these draw a
     pseudo-element rule instead. */
  .site-nav a,
  .social a { position: relative; }

  .site-nav a::after,
  .social a::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    /* --underline-inset is the link's own block padding, published by
       components.css. .social a gained 0.45rem of it on 2026-08-10 to reach a
       24px touch target; without reading it back here the rule would anchor to
       the bottom of the padded box and float 9px under the caps it belongs to.
       Links with no padding resolve the fallback and are unchanged. */
    bottom: calc(var(--underline-inset, 0px) - 1.5px);
    height: 1.5px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: 0 50%;
    transition: transform 340ms var(--ease-enter);
  }

  .site-nav a:hover::after,
  .site-nav a[aria-current]::after,
  .social a:hover::after { transform: scaleX(1); }

  /* These pseudo-rules replace the border-colour hovers in layout.css and
     components.css, which would otherwise both fire and read as a double
     line. */
  .site-nav a:hover,
  .site-nav a[aria-current] { border-bottom-color: transparent; }
  .social a:hover { border-bottom-color: transparent; }

  /* The CTA is the last thing on the page: let it open up slightly.

     NOT letter-spacing. Changed 2026-08-10. It used to transition
     `letter-spacing` over 420ms, which reflows the text on every single frame
     — the only place on the site animating anything but transform/opacity,
     and it sat on the page's final beat. `scale` reads as the same "opening
     up" gesture, runs on the compositor, and cannot push the surrounding
     layout around while it does.

     transform-origin is centre because .cta__panel is text-align: center;
     scaling from the default 50% 50% keeps the link optically anchored to the
     middle of the scalloped panel rather than creeping to one side. */
  .cta__link {
    transition: color var(--dur-fast) var(--ease-out),
                transform 320ms var(--ease-enter);
  }

  .cta__link:hover { transform: scale(1.045); }

  /* Carousel sheets answer the pointer the same way the video posters do, and
     at the same speed, so the two kinds of media feel like one system.

     On .carousel__img — NOT on .carousel__item, which owns the wheel
     transform. Putting a hover scale on the item would fight the
     translate/rotate that positions it on the wheel, and the animation would
     silently win. See the transform-ownership note at the top of this file. */
  /* 620ms -> 420ms, 2026-08-10, with the video poster above. Long enough to
     read as weighted, short enough to answer the pointer. */
  .carousel__img {
    transition: transform 420ms var(--ease-media);
  }

  /* data-focus, not data-hidden. carousel.js drives a continuous wheel
     position now, so the flag meaning "this is the panel in front" is keyed on
     ROUNDED distance and named for what it is. See the attribute contract note
     in css/carousel.css — these were the last two stale references. */
  .carousel__item[data-focus="true"] .carousel__figure:hover .carousel__img,
  .carousel__item[data-focus="true"] a:focus-visible .carousel__img {
    transform: scale(1.03);
  }
}


/* ===========================================================================
   MOBILE — SIMPLER AND LIGHTER, NOT JUST SMALLER
   ===========================================================================
   Layers 2 and 3a are already gated to >=48rem. This shortens the distances
   and tightens the stagger for what remains, so a phone gets the same
   choreography at roughly half the amplitude — enough to read as designed,
   not enough to make a long scroll feel busy. */

@media (max-width: 47.99rem) {
  :root {
    --rise-micro:  6px;
    --rise-word:   9px;
    --rise-body:  13px;
    --rise-media: 22px;
    --scale-media: 0.978;

    --stagger:      44ms;
    --stagger-word: 18ms;

    --dur-enter-media: 720ms;
  }
}
