/* ════════════════════════════════════════════════════════════════════
 * motion.css — scroll-driven parallax.
 *
 * ZERO parallax JavaScript. No scroll listener, no rAF loop.
 *
 * Why: progress here is a function of scroll OFFSET, not scroll EVENTS. There
 * is no event to coalesce, so iOS momentum scrolling is structurally
 * irrelevant rather than merely mitigated — and the lagging, snapping motion a
 * rAF scroll handler produces during a flick IS the cheap-parallax look we are
 * avoiding. The animation is handed to the compositor.
 *
 * The cost is honest: Firefox still ships this behind a flag, and iOS below 26
 * lacks it. Those users get a flat, correct, premium page. That is the right
 * degradation, because parallax is decoration, not content.
 *
 * Planes reuse figma-export/MOTION-VIDEO-PROMPT.md §6 / Device 05:
 *   background 0.3x · mid 0.6x · foreground 1.0x
 * A plane at rate r travels (1 - r) of the scroll, so the background moves most.
 *
 * HOSTS MUST BE `overflow: clip`, NEVER `hidden`. An overflow:hidden element is
 * a scroll container; view()/scroll(nearest) resolves to it, and because it
 * never scrolls the animation silently never advances. This is the single
 * easiest thing to get wrong here.
 * ════════════════════════════════════════════════════════════════════ */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {

    .plx { overflow: clip; }

    .plx--band {
      view-timeline-name: --plx;
      view-timeline-axis: block;
    }

    /* Scoped to a host on purpose. A .plx__* element outside one would otherwise
       pick up animation-name with no timeline, run on the document timeline,
       finish immediately and stay stuck at its end keyframe. */
    .plx--hero .plx__bg,
    .plx--hero .plx__mid,
    .plx--hero .plx__fg,
    .plx--band .plx__bg,
    .plx--band .plx__mid,
    .plx--band .plx__fg {
      animation-timing-function: linear; /* the default `ease` rubber-bands vs scroll */
      animation-fill-mode: both;
      animation-iteration-count: 1;
      animation-duration: auto;
      /* No will-change: a scroll-driven animation already promotes the element,
         and pinning a 1920px photo texture buys nothing. */
    }

    /* Bands ride their own view timeline.
     *
     * DESCENDANT, not direct-child. A plane is not always a direct child of its
     * host -- the download band's sits inside a .container and a grid wrapper.
     * With `>` that plane matched the .plx__mid base rule (so it got
     * `animation-name: plx-mid`) but never got a timeline, so it ran on the
     * document timeline, completed instantly, and sat permanently translated
     * 3.5% off. Silently broken AND visibly displaced, which is the worst of
     * both. Keep .plx--band hosts un-nested and this stays unambiguous. */
    .plx--band .plx__bg,
    .plx--band .plx__mid,
    .plx--band .plx__fg {
      animation-timeline: --plx;
      animation-range: cover 0% cover 100%;
    }

    /* The hero rides the document, 0 -> 100vh. Progress is 0 at load, which is
       what a hero needs; a view() timeline on an element flush with the document
       top loads already mid-range. */
    .plx--hero .plx__bg,
    .plx--hero .plx__mid,
    .plx--hero .plx__fg {
      animation-timeline: scroll(root block);
      animation-range: 0 100vh;
    }

    /* Oversized so the travel never exposes an edge.
     *
     * A plane carrying these MUST be absolutely positioned inside a clipping
     * host -- `top` is inert on a static box, and `height: 108%` on an in-flow
     * box with an aspect-ratio derives a WIDTH 8% too large. That is exactly
     * what the download band did: the class sat on the aspect-ratio'd grid item
     * rather than on its <img>, so the single `1fr` track resolved 22px wider
     * than the container at 320 and pushed the band's copy off-screen, while
     * the plane never actually moved. Put the class on .photo__img (absolute,
     * inset 0), never on the .photo box. */
    .plx--hero .plx__bg,  .plx--band .plx__bg  { height: 116%; top: -8%; animation-name: plx-bg; }
    .plx--hero .plx__mid, .plx--band .plx__mid { height: 108%; top: -4%; animation-name: plx-mid; }
    .plx--hero .plx__fg,  .plx--band .plx__fg  { animation-name: plx-fg; }

    /* `translate`, not `transform`: it composites identically but does NOT
       clobber an existing transform, so .hero__phone keeps its rotate(-2deg)
       and the universe device frames keep their scale(). */
    @keyframes plx-bg  { from { translate: 0 -7%;   } to { translate: 0 7%;   } }
    @keyframes plx-mid { from { translate: 0 -3.5%; } to { translate: 0 3.5%; } }
    @keyframes plx-fg  { from { translate: 0 1.5%;  } to { translate: 0 -1.5%; } }
  }
}

/* Reduced motion.
 *
 * base.css already kills animation globally — but that kill is DURATION-based
 * (animation-duration: 0.001ms) and a progress-based timeline ignores
 * animation-duration entirely. Worse, forcing a 0.001ms duration on a
 * scroll-driven animation can resolve it straight to its 100% keyframe, i.e.
 * fully translated away. So the timeline is killed explicitly and every plane
 * is pinned flat. The @supports block above is also wrapped in
 * `prefers-reduced-motion: no-preference`, so this is belt and braces. */
@media (prefers-reduced-motion: reduce) {
  .plx__bg,
  .plx__mid,
  .plx__fg {
    animation-timeline: none;
    animation-name: none;
    translate: none;
    height: 100%;
    top: 0;
  }
}

/* On narrow screens the photograph begins beneath the copy. Keep this
 * composition even when the scroll timeline is available or disabled. */
@media (max-width: 1023px) {
  .plx--hero .hero__media.plx__bg {
    inset: 46% 0 auto;
    height: 62%;
  }
}

/* Static hero image. Keep the photo in the markup for LCP and Firefox. */
.hero__slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--focal-sm, 50% 30%);
  opacity: 1;
}

@media (min-width: 1024px) {
  .hero__slide { object-position: var(--focal-lg, var(--focal-sm, 70% 40%)); }
}
