/* ————————————————————————————————————————
   Scroll-scrubbed storybook clips (scroll-scrub.js)
   Without the script: the first frame as a still with the lines stacked
   over it. With it (.is-live) each section is several screens tall and the picture sticks while
   scrolling plays the clip, one line at a time.
   ———————————————————————————————————————— */

.scroll-scrub {
  position: relative;
  background: var(--deep);
  color: var(--paper);
}

.scroll-scrub-stage {
  position: relative;
  min-height: max(30rem, 90svh);
  display: grid;
  align-items: end;
  overflow: hidden;
}

.scroll-scrub-stage img,
.scroll-scrub-stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Night-sky wash along the bottom so the lines read over a bright meadow. */
.scroll-scrub-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to top, rgba(22, 20, 48, 0.88), rgba(22, 20, 48, 0.3) 45%, rgba(22, 20, 48, 0) 70%);
}

.scroll-scrub-lines {
  position: relative;
  z-index: 2;
  width: 100%;
  padding-top: 6rem;
  padding-bottom: clamp(2.5rem, 8vh, 5rem);
  display: grid;
  gap: 1rem;
}

.scroll-scrub-line {
  margin: 0;
  max-width: 24ch;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3.4vw, 2.6rem);
  font-weight: 400;
  line-height: 1.15;
  color: var(--paper);
  text-shadow: 0 2px 18px rgba(22, 20, 48, 0.55);
}

.scroll-scrub-end {
  max-width: 16ch;
  font-size: clamp(2.3rem, 6.4vw, 4.6rem);
}

.scroll-scrub-end span,
.scroll-scrub-line [data-child-name] {
  color: var(--glow);
}

.scroll-scrub.is-live { height: 380vh; }

.scroll-scrub.is-live .scroll-scrub-stage {
  position: sticky;
  top: 0;
  height: 100svh;
  min-height: 0;
}

.scroll-scrub.is-live .scroll-scrub-lines > * {
  grid-area: 1 / 1;
  align-self: end;
  opacity: 0;
  transform: translateY(1.25rem);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.scroll-scrub.is-live .scroll-scrub-lines > .is-on {
  opacity: 1;
  transform: none;
}

/* The closing line gets the whole picture dimmed behind it, like the lights going down. */
.scroll-scrub.is-live .scroll-scrub-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: rgba(22, 20, 48, 0.5);
  opacity: 0;
  transition: opacity 0.7s ease;
}

.scroll-scrub.is-live:has(.scroll-scrub-end.is-on) .scroll-scrub-stage::before { opacity: 1; }

/* Phones: lift the lines clear of the sticky "Add your child's story" bar (sticky-cta.css, ~4.5rem tall). */
@media (max-width: 640px) {
  .scroll-scrub-lines { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px)); }
}
