/* ==========================================================================
   MediGlow Showcase — Motion System
   Loads AFTER styles.css so it can override hero/section rules in later phases.
   Owns: scroll-reveal states  ·  [later] hero crossfade, stat band, sticky
   section, grain/glow  ·  the reduced-motion refinement.

   PROGRESSIVE ENHANCEMENT + A11Y (two independent safeguards):
     1. The hidden/animated states are gated on `html.js-motion`, a class
        motion.js adds ONLY when motion is allowed. No JS / no IntersectionObserver
        / reduced-motion  →  the class is never added  →  nothing is ever hidden.
     2. The reduced-motion media query below force-shows everything regardless.
   ========================================================================== */

/* ---- B1 · Scroll-reveal -------------------------------------------------- */
html.js-motion [data-reveal] {
  opacity: 0;
  transform: translateY(var(--rv-rise));                 /* vertical only → RTL-safe */
  transition: opacity var(--t-reveal), transform var(--t-reveal);
  transition-delay: calc(var(--rv-i, 0) * var(--rv-stagger));
  will-change: opacity, transform;                       /* promoted only while pending */
}
html.js-motion [data-reveal].is-in {
  opacity: 1;
  transform: none;
  will-change: auto;                                     /* drop the hint once revealed */
}

/* ---- B2 · Reduced-motion refinement (belt-and-suspenders with the JS guard) */
@media (prefers-reduced-motion: reduce) {
  [data-reveal] { opacity: 1 !important; transform: none !important; }
}

/* ---- B3 · Count-up stat band  (+ Phase-2 ambient glow folded in) --------- */
.statband { position: relative; overflow: hidden; }
.statband::before {                 /* soft brand glow = ambient depth on the navy band */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(58% 120% at 22% 0%,  var(--glow-aqua),   transparent 60%),
    radial-gradient(52% 120% at 86% 100%, var(--glow-powder), transparent 62%);
}
.statband .container { position: relative; z-index: 1; }

.statband__grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: clamp(1.5rem, 1rem + 3vw, 4rem); text-align: center;
}
.stat { position: relative; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.stat + .stat::before {              /* hairline divider sitting in the gap (logical → RTL-safe) */
  content: ""; position: absolute; inset-block-start: 50%; transform: translateY(-50%);
  inset-inline-start: calc(-1 * clamp(.75rem, .5rem + 1.5vw, 2rem));
  block-size: 56%; inline-size: 1px; background: rgba(255,255,255,.16);
}
.stat__num {
  font-family: var(--font-display); font-weight: var(--fw-light);
  font-size: clamp(2.5rem, 1.6rem + 3.6vw, 4.25rem); line-height: 1;
  color: var(--on-dark); letter-spacing: .01em;
}
.stat__label { font-size: var(--fs-sm); color: var(--on-dark-soft); max-inline-size: 22ch; }

@media (max-width: 640px) {
  .statband__grid { grid-template-columns: 1fr; gap: 0; }
  .stat + .stat::before { display: none; }
  .stat + .stat { margin-block-start: 1.8rem; padding-block-start: 1.8rem; border-top: 1px solid rgba(255,255,255,.13); }
}

/* ---- B4 · Cinematic hero — frame crossfade + grade + science cue ----------
   Frames are SCREENED over the navy bg (like the old single photo) so the white
   headline keeps its AA contrast and the styles.css vignette still caps brightness.
   motion.js toggles .is-active on a --hero-frame-dwell cadence. */
.hero__seq { position: absolute; inset: 0; z-index: -2; pointer-events: none; }
.hero__frame {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  opacity: 0; mix-blend-mode: screen;
  transition: opacity 1.4s var(--ease-cinematic);
}
.hero__frame.is-active { opacity: .42; }
/* slow Ken-Burns on whichever frame is active (transform/opacity → 60fps). Gated on
   js-motion so reduced-motion (sequencer never starts) simply holds frame 1 still. */
html.js-motion .hero__frame.is-active,
html.js-motion .hero__frame.is-leaving { animation: heroKen 8s ease-out both; }
@keyframes heroKen { from { transform: scale(1.015); } to { transform: scale(1.085); } }

/* one cool duotone grade unifies every frame as a single graded light */
.hero__grade {
  position: absolute; inset: 0; z-index: -2; pointer-events: none;
  mix-blend-mode: soft-light; opacity: .55;
  background: linear-gradient(152deg, var(--navy-deep) 0%, transparent 46%, var(--powder) 122%);
}

/* restrained "light-on-glass" science cue (replaces the repeating-gradient pool) */
.hero__science {
  position: absolute; inset: -12%; z-index: -1; pointer-events: none; opacity: .6;
  background:
    radial-gradient(38% 24% at 28% 30%, rgba(167,204,214,.20), transparent 62%),
    radial-gradient(32% 20% at 72% 58%, rgba(186,208,213,.15), transparent 62%),
    radial-gradient(26% 16% at 52% 80%, rgba(255,255,255,.08), transparent 62%);
  filter: blur(10px);
}
html.js-motion .hero__science { animation: heroDrift 26s ease-in-out infinite alternate; }
@keyframes heroDrift { from { transform: translate3d(0,0,0); } to { transform: translate3d(0,-2.4%,0); } }
/* a single specular sweep on load */
.hero__science::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(118deg, transparent 38%, rgba(255,255,255,.07) 50%, transparent 62%);
  opacity: 0;
}
html.js-motion .hero__science::after { animation: heroSweep 3s var(--ease-cinematic) .5s 1 both; }
@keyframes heroSweep {
  from { transform: translateX(-35%); opacity: 0; }
  30%, 70% { opacity: 1; }
  to { transform: translateX(35%); opacity: 0; }
}

/* hero entrance — pure CSS (fill:both → starts hidden at paint, no FOUC; no JS dep) */
.hero__inner > * { animation: heroLine .9s var(--ease-out) both; }
.hero__inner > *:nth-child(1) { animation-delay: .12s; }
.hero__inner > *:nth-child(2) { animation-delay: .26s; }
.hero__inner > *:nth-child(3) { animation-delay: .40s; }
.hero__inner > *:nth-child(4) { animation-delay: .54s; }
@keyframes heroLine { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .hero__inner > * { animation: none; }       /* content simply present */
  .hero__frame { transition: none; }
}

/* ---- B5 · Sticky-pinned science section (BioAge move) ---------------------
   .pinwrap__media is the (full-height) grid item; .pinwrap__sticky sticks within
   it while the tall .pinwrap__steps column scrolls past. Steps reveal via the B1
   engine; motion.js lights whichever is nearest viewport-centre. */
.pinwrap { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(1.5rem, 4vw, 4.5rem); }
.pinwrap__sticky {
  position: sticky; top: clamp(84px, 12vh, 120px); position: -webkit-sticky;
  border-radius: var(--r-card); overflow: hidden; isolation: isolate; box-shadow: var(--shadow-card);
}
.pinwrap__sticky img { display: block; width: 100%; height: clamp(360px, 56vh, 560px); object-fit: cover; }
.pinwrap__sticky.is-empty { background: linear-gradient(135deg, var(--navy), var(--navy-deep)); min-height: 360px; }
/* annotation dot — BioAge signature, recolored to brand aqua; gentle pulse */
.pinwrap__dot {
  position: absolute; inset-block-start: 1.1rem; inset-inline-start: 1.1rem; z-index: 2;
  width: 12px; height: 12px; border-radius: 50%; background: var(--aqua);
}
html.js-motion .pinwrap__dot { animation: pinPulse 2.6s ease-out infinite; }
@keyframes pinPulse {
  0%   { box-shadow: 0 0 0 0 rgba(167,204,214,.5); }
  70%,100% { box-shadow: 0 0 0 16px rgba(167,204,214,0); }
}

.pinwrap__steps { display: flex; flex-direction: column; }
.pin-intro { padding-block: clamp(1rem, 4vh, 3rem) 1rem; }
.pin-intro__lead { color: var(--slate); font-size: var(--fs-lead); max-width: 34ch; margin-top: .6rem; }
.pin-step {
  min-height: 56vh; display: flex; flex-direction: column; justify-content: center;
  padding-inline-start: 1.4rem; border-inline-start: 2px solid var(--line);
  transition: border-color .5s var(--ease-out);
}
.pin-step__n {
  font-family: var(--font-display); font-weight: var(--fw-light); font-size: 1rem;
  color: var(--sand); letter-spacing: .12em; transition: color .5s var(--ease-out);
}
.pin-step h3 { font-size: clamp(1.3rem, 1rem + 1.4vw, 1.9rem); color: var(--navy); margin-block: .5rem .7rem; font-weight: var(--fw-med); }
.pin-step p { color: var(--slate); max-width: 40ch; }
.pin-step .link-arrow { margin-top: 1.1rem; }
.pin-step.is-active { border-inline-start-color: var(--aqua); }
.pin-step.is-active .pin-step__n { color: var(--navy); }

@media (max-width: 760px) {
  .pinwrap { grid-template-columns: 1fr; gap: 1.4rem; }
  .pinwrap__sticky { position: static; top: auto; }       /* pin OFF on phones */
  .pinwrap__sticky img { height: clamp(220px, 42vh, 340px); }
  .pin-step { min-height: auto; padding-block: 1rem; }
}

/* ---- B6 · Parallax over-size: motion.js adds .is-parallax (desktop + motion only)
   so the vertical translate never reveals the band's edges. */
.imageband__img.is-parallax { top: -12%; height: 124%; will-change: transform; }

/* ---- Phase 2 · Film grain — static filmic texture on dark surfaces --------
   One tiny SVG fractal-noise tile, blended 'overlay' at --grain-opacity. Static
   (no motion cost), pointer-events:none, sits under content (z-index:-1 within an
   isolated stacking context). Premium depth without jank. */
.section--navy { position: relative; isolation: isolate; }
.hero::after,
.imageband::after,
.section--navy::after {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  opacity: var(--grain-opacity); mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 140px 140px;
}
