/* ============================================================
   A.W.E.CO. · motion layer · Origin Labs
   Pinned scroll-scrubbed hero + scroll choreography polish.
   Loads AFTER styles.css. Companion script: motion.js
   (defer, after main.js).

   Architecture contract, do not break it:
   . Base state is static and complete. No selector here hides
     content unless html.anim is present.
   . The scrub track only grows once motion.js has confirmed the
     frame sequence exists (section#hero gains .scrub-live), so a
     missing render can never leave empty scroll.
   . Scrubbed properties are transform, opacity or canvas only,
     driven by CSS vars (--hp hero progress, --pp polaroid drift).
   ============================================================ */

:root {
  /* Client ruling (29 Jul): the film earns a longer watch; track doubled
     from the director's 200vh. CANALE 78 still owns the page's other pin. */
  --hero-track: 400vh;
}

/* ---------- Hero: static base (no JS, no .anim, frozen panes) ---------- */
/* The section keeps .hero, so the shipped gradient background remains the
   fallback wash if the poster asset is missing. */
.hero-track { position: relative; }
.hero-pin {
  position: relative;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  overflow: clip;
}
.hero-scrub .hero-inner {
  width: 100%;
  padding-block: clamp(7rem, 13vh, 9.5rem) clamp(4.5rem, 9vh, 6.5rem);
  z-index: 2;
}

/* Media stack: poster under canvas under scrim. Canvas exists only when
   armed; until its first frame lands it is transparent and the poster
   shows through, so there is never a blank hero. */
.hero-media { position: absolute; inset: 0; z-index: 0; }
.hero-poster {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: 62% 50%;  /* favour the toy tableau when narrow crops cut in */
}
.hero-canvas {
  display: none;
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}
/* Resting state keeps the 2688px poster: the canvas mounts but stays hidden
   until motion.js flags real progress (section gains .filming past ~1%).
   f_001 matches the poster framing, so the swap is invisible, and scrolling
   back to the top returns the sharp poster instead of an upscaled frame. */
.anim .scrub-live .hero-canvas { display: block; visibility: hidden; }
.anim .scrub-live.filming .hero-canvas { visibility: visible; }

/* Legibility scrim: the copy lives on the photo's dark left third and this
   guarantees it. Flat gradients on a real photograph, no glass.
   Stops are verified against the end-of-film frames (f_095 to f_120), where
   the dark third narrows and the yellow car reaches 43% of frame width:
   worst-case contrast including the 44px copy drift is 12.5:1 for the lead
   and 5.0:1 for the proof line (with the .9 alpha lift below), both past
   the 4.5:1 bar. The deeper floor gradient carries the proof line, which
   sits in the bottom fifth over straw and paint. */
.hero-scrim {
  position: absolute; inset: 0;
  background:
    linear-gradient(to right, rgba(10,37,23,.84) 0%, rgba(10,37,23,.58) 40%, rgba(10,37,23,.25) 60%, rgba(10,37,23,0) 76%),
    linear-gradient(to bottom, rgba(10,37,23,.5), rgba(10,37,23,0) 18%),
    linear-gradient(to top, rgba(10,37,23,.62), rgba(10,37,23,0) 42%);
}
/* The shipped .72 alpha proof was tuned for the flat gradient hero; over
   end-of-film straw and paint it cannot reach 4.5:1 at any sane scrim
   depth, so the film hero lifts it. Scoped to .hero-scrub only. */
.hero-scrub .hero-proof { color: rgba(255,255,255,.9); }

/* Dot grid: the shipped .hero::before would paint under the photo and be
   wasted. Rebuilt inside the pin at half presence, masked to the dark third
   so it never sits on the toys. */
.hero-scrub::before { content: none; }
.hero-pin::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.04) 1.5px, transparent 1.5px);
  background-size: 30px 30px;
  -webkit-mask-image: radial-gradient(52rem 40rem at 16% 42%, #000 0%, transparent 72%);
  mask-image: radial-gradient(52rem 40rem at 16% 42%, #000 0%, transparent 72%);
}

/* Scroll cue: static bar by default, gentle stretch only when armed. */
.hero-cue {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 3;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  color: rgba(255,255,255,.9);
  font-size: .8rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  transition: opacity .45s var(--ease);
}
.hero-cue i {
  width: 2.5px; height: 34px; border-radius: 2px;
  background: var(--sun-400);
}
.anim .hero-cue i {
  transform-origin: top;
  animation: cue-stretch 1.7s var(--ease) infinite alternate;
}
@keyframes cue-stretch {
  from { transform: scaleY(.3); }
  to   { transform: scaleY(1); }
}
/* .anim scoped: a watchdog un-arm after a scroll must not strand the cue
   invisible on the static hero (motion.js only toggles .hide while armed). */
.anim .hero-cue.hide { opacity: 0; }

/* ---------- Hero: armed scrub (html.anim + section.scrub-live) ---------- */
.anim .scrub-live .hero-track { height: var(--hero-track); }
.anim .scrub-live .hero-pin {
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  min-height: 0;
}
/* Media sized to the LARGE viewport so mobile URL-bar collapse never
   resizes (and therefore never blanks) the canvas mid-scrub. */
.anim .scrub-live .hero-media {
  inset: 0 0 auto 0;
  height: 100vh; height: 100lvh;
}
/* Copy drifts up a touch through the film for depth. Var-driven per frame,
   no transition, so there is nothing to settle and nothing to snap. */
.anim .scrub-live .hero-copy {
  translate: 0 calc(var(--hp, 0) * -44px);
}

/* ---------- Nav over the pinned film ---------- */
/* main.js flips .scrolled at 30px, which is tuned for a one-viewport hero.
   While the film holds the top of the page the nav keeps its dark dress;
   motion.js drops .on-hero the moment the pin releases. */
.anim .nav.on-hero.scrolled {
  background: rgba(10,37,23,.88);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.08);
}
.anim .nav.on-hero.scrolled .nav-links a::after { background: var(--sun-400); }

/* ---------- Choreography polish: section headings ---------- */
/* Scale-settle riding the existing .rv reveal system. Container case:
   .sec-head h2 scales inside the revealing head. Self case: h2.rv folds the
   scale into the reveal transform it already has. Static without .anim. */
.anim .sec-head.rv h2 {
  transform: scale(.965);
  transform-origin: 0 80%;
}
.anim .sec-head.rv.in h2 {
  transform: scale(1);
  transition: transform .95s var(--ease) .05s;
}
.anim .sec-head.rv.in.settle h2 { transition: none; }
.anim h2.rv { transform: translateY(26px) scale(.965); transform-origin: 0 80%; }
.anim h2.rv.in { transform: none; }

/* ---------- Choreography polish: story polaroids ---------- */
/* Two-speed drift while the story column passes. Uses the translate
   property so it composes with the shipped rotate transforms and never
   fights the hover (which transitions transform only). */
.anim .pola-1 { translate: 0 calc(var(--pp, 0) * -20px); }
.anim .pola-2 { translate: 0 calc(var(--pp, 0) * 14px); }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  :root { --hero-track: 320vh; }
  .hero-scrub .hero-inner { padding-block: 6.5rem 4rem; }
  .hero-cue { bottom: 16px; }
  .hero-cue i { height: 26px; }
}

/* ---------- Reduced motion: collapse to the static base ---------- */
/* main.js never arms .anim under reduced motion; these overrides also
   catch a mid-session preference flip. */
@media (prefers-reduced-motion: reduce) {
  .anim .scrub-live .hero-track { height: auto !important; }
  .anim .scrub-live .hero-pin {
    position: relative !important;
    height: auto !important;
    min-height: 100svh !important;
  }
  .hero-canvas { display: none !important; }
  .anim .scrub-live .hero-copy, .anim .pola-1, .anim .pola-2 { translate: none !important; }
  .anim .hero-cue i { animation: none !important; }
  .hero-cue.hide { opacity: 1 !important; }
  .anim .sec-head.rv h2, .anim h2.rv { transform: none !important; }
}
