/*
 * Stella scroll depth: parallax and scroll-reveal layer for the v4 landing.
 *
 * This sheet plus stella-scroll-depth.js own the whole effect. It drives
 * existing landing selectors through classes the JS adds at runtime
 * (sd-anim, sd-reveal, sd-drift-hero, sd-glow, sd-depth-near, sd-depth-mid), so no
 * other sheet changes.
 *
 * Constraints that must hold:
 * - Nothing here may touch #hs4-strip-track, .hs4-card, .hs4-band,
 *   .hs4-band-inner, .hs4-headline, or #hs4-slot. hero-section-v4.js writes
 *   the track transform every frame and measures the band text for the Find
 *   slot, so a transform, filter, or containment there would break it.
 * - Only transform and opacity animate. Every element keeps its final
 *   layout box at all times, so the page never shifts.
 * - Everything is gated on html[data-scroll-depth], which the JS sets. With
 *   JS off the page renders static and fully visible.
 * - Nothing outside <main> is transformed, so the sticky header and the
 *   search result modal keep their containing block.
 */

/* ── Keyframes ────────────────────────────────────────────── */

@keyframes sd-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sd-rise-18 {
  from { transform: translate3d(0, 18px, 0); }
  to { transform: translate3d(0, 0, 0); }
}

@keyframes sd-rise-16 {
  from { transform: translate3d(0, 16px, 0); }
  to { transform: translate3d(0, 0, 0); }
}

@keyframes sd-rise-14 {
  from { transform: translate3d(0, 14px, 0); }
  to { transform: translate3d(0, 0, 0); }
}

/*
 * Hero posters leave a little faster than the page while the hero exits.
 * Upward only: the cards overhang the green band by design, so a downward
 * drift would push them onto the headline.
 */
@keyframes sd-hero-drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(0, -32px, 0); }
}

/* Counter-drift for the taste card: trails on the way in, leads on the way out. */
@keyframes sd-card-drift {
  from { transform: translate3d(0, 40px, 0); }
  to { transform: translate3d(0, -40px, 0); }
}

/* Depth layers on top of the card's drift: the favourite pick's cover moves
   most, the shelf posters a little less, so the card reads in layers. */
@keyframes sd-depth-near {
  from { transform: translate3d(0, 22px, 0); }
  to { transform: translate3d(0, -22px, 0); }
}

@keyframes sd-depth-mid {
  from { transform: translate3d(0, 12px, 0); }
  to { transform: translate3d(0, -12px, 0); }
}

/* Vertical only. A horizontal drift could widen the document. */
@keyframes sd-glow-drift {
  from { transform: translate3d(0, 16px, 0); }
  to { transform: translate3d(0, -16px, 0); }
}

/* Fallback reveal. Fill is backwards only, so once it ends the element has
   no transform declaration left and hover transforms (chips) still work. */
@keyframes sd-reveal-in {
  from {
    opacity: 0;
    transform: translate3d(0, 16px, 0);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0);
  }
}

/* ── Native scroll-driven timelines ───────────────────────── */

@supports (animation-timeline: view()) {
  html[data-scroll-depth="native"] .sd-anim {
    animation-fill-mode: both;
    animation-timeline: view();
  }

  html[data-scroll-depth="native"] .sd-reveal {
    animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1);
  }

  /* (a) Hero poster strip. Applied to the marquee wrapper, never to the
     track or the cards. hero-section-v4.js hit-tests cards against
     marquee.getBoundingClientRect(), and both rects carry the same
     translation, so the geometry stays consistent. */
  html[data-scroll-depth="native"] .hs4-marquee.sd-drift-hero {
    animation-name: sd-hero-drift;
    animation-timing-function: linear;
    animation-range: exit 0% exit 100%;
  }

  /* (b) Section headings and body copy. */
  html[data-scroll-depth="native"] .sh-section-title.sd-reveal,
  html[data-scroll-depth="native"] .sh-waitlist-title.sd-reveal {
    animation-name: sd-fade-in, sd-rise-18;
    animation-range: entry 10% cover 22%;
  }

  html[data-scroll-depth="native"] .sh-section-body.sd-reveal,
  html[data-scroll-depth="native"] .sh-waitlist-body.sd-reveal {
    animation-name: sd-fade-in, sd-rise-18;
    animation-range: entry 18% cover 30%;
  }

  /* (c) Import chips. animation-composition adds the rise on top of the
     chip's own hover lift instead of replacing it, so the 3px hover
     translate survives the animation's permanent fill. Stagger comes from
     per-column ranges: animation-delay does not shift a progress timeline. */
  html[data-scroll-depth="native"] .sh-source-chip.sd-reveal {
    animation-name: sd-fade-in, sd-rise-14;
    animation-composition: replace, add;
    animation-range: entry 12% cover 26%;
  }

  html[data-scroll-depth="native"] .sh-source-chip.sd-reveal:nth-child(2n) {
    animation-range: entry 16% cover 30%;
  }

  html[data-scroll-depth="native"] .sh-source-chip.sd-reveal:nth-child(3n) {
    animation-range: entry 20% cover 34%;
  }

  /* (d) Media profile card. A transform here does not affect the
     @container query on .f13-card or the clientWidth / scrollWidth reads in
     stella-home.js, so the drift is safe. No containment is added. */
  html[data-scroll-depth="native"] .sh-taste-showcase.sd-reveal {
    animation-name: sd-fade-in, sd-card-drift;
    animation-timing-function: cubic-bezier(0.22, 0.61, 0.36, 1), linear;
    animation-range: entry 6% cover 24%, cover 0% cover 100%;
    will-change: transform;
  }

  /* (d2) Depth layers inside the card. The card clips its content
     (overflow: hidden makes it a scroll container), so a plain view() on
     these would track the card, which never scrolls. They follow a named
     timeline on the showcase instead, which tracks the page. "add" stacks
     the drift on any transform the element already has. */
  html[data-scroll-depth="native"] .sh-taste-showcase.sd-anim {
    view-timeline-name: --sd-card;
  }

  html[data-scroll-depth="native"] .sd-depth-near,
  html[data-scroll-depth="native"] .sd-depth-mid {
    animation-timeline: --sd-card;
    animation-timing-function: linear;
    animation-composition: add;
    animation-range: cover 0% cover 100%;
    will-change: transform;
  }

  html[data-scroll-depth="native"] .sd-depth-near {
    animation-name: sd-depth-near;
  }

  html[data-scroll-depth="native"] .sd-depth-mid {
    animation-name: sd-depth-mid;
  }

  /* (e) Trust items. */
  html[data-scroll-depth="native"] .sh-trust-item.sd-reveal {
    animation-name: sd-fade-in, sd-rise-16;
    animation-range: entry 12% cover 26%;
  }

  html[data-scroll-depth="native"] .sh-trust-item.sd-reveal:nth-child(2n) {
    animation-range: entry 16% cover 30%;
  }

  html[data-scroll-depth="native"] .sh-trust-item.sd-reveal:nth-child(3n) {
    animation-range: entry 20% cover 34%;
  }

  /* (f) Waitlist accent. isolation keeps the negative z-index pseudo above
     the section background and below its copy. The glow spans the whole
     section (an inner inset left a visible box edge where the gradients were
     cut off) and overshoots by the 16px drift top and bottom; overflow: clip
     contains it without creating a scroll container, so view() still tracks
     the page scroller and the document never widens. */
  html[data-scroll-depth="native"] .sh-waitlist.sd-glow {
    position: relative;
    isolation: isolate;
    overflow: clip;
  }

  html[data-scroll-depth="native"] .sh-waitlist.sd-glow::after {
    content: "";
    position: absolute;
    inset: -16px 0;
    z-index: -1;
    pointer-events: none;
    background:
      radial-gradient(
        58% 68% at 22% 30%,
        color-mix(in srgb, var(--hs4-pink) 14%, transparent),
        transparent 70%
      ),
      radial-gradient(
        54% 64% at 78% 70%,
        color-mix(in srgb, var(--hs4-yellow) 12%, transparent),
        transparent 72%
      );
    animation-name: sd-glow-drift;
    animation-timing-function: linear;
    animation-fill-mode: both;
    animation-timeline: view();
    animation-range: cover 0% cover 100%;
  }
}

/* ── IntersectionObserver fallback: reveal only, no drift ─── */

html[data-scroll-depth="fallback"] .sd-reveal {
  opacity: 0;
}

html[data-scroll-depth="fallback"] .sd-reveal.is-revealed {
  opacity: 1;
  animation: sd-reveal-in 620ms cubic-bezier(0.22, 0.61, 0.36, 1) backwards;
}

html[data-scroll-depth="fallback"] .sh-source-chip.sd-reveal.is-revealed:nth-child(2n),
html[data-scroll-depth="fallback"] .sh-trust-item.sd-reveal.is-revealed:nth-child(2n) {
  animation-delay: 60ms;
}

html[data-scroll-depth="fallback"] .sh-source-chip.sd-reveal.is-revealed:nth-child(3n),
html[data-scroll-depth="fallback"] .sh-trust-item.sd-reveal.is-revealed:nth-child(3n) {
  animation-delay: 110ms;
}

/* ── Reduced motion: fully static, final state ────────────── */

@media (prefers-reduced-motion: reduce) {
  html[data-scroll-depth] .sd-anim {
    animation-name: none !important;
    opacity: 1 !important;
  }

  html[data-scroll-depth] .sd-anim::after {
    animation-name: none !important;
    transform: none !important;
  }

  html[data-scroll-depth] .sd-drift-hero,
  html[data-scroll-depth] .sh-taste-showcase.sd-anim,
  html[data-scroll-depth] .sd-depth-near,
  html[data-scroll-depth] .sd-depth-mid {
    transform: none !important;
    will-change: auto !important;
  }
}

/* The hero's own motion toggle (body.hs4-is-reduced-motion) is honoured the
   same way, including when the visitor flips it at runtime. */
body.hs4-is-reduced-motion .sd-anim {
  animation-name: none !important;
  opacity: 1 !important;
}

body.hs4-is-reduced-motion .sd-anim::after {
  animation-name: none !important;
  transform: none !important;
}

body.hs4-is-reduced-motion .sd-drift-hero,
body.hs4-is-reduced-motion .sh-taste-showcase.sd-anim,
body.hs4-is-reduced-motion .sd-depth-near,
body.hs4-is-reduced-motion .sd-depth-mid {
  transform: none !important;
  will-change: auto !important;
}
