/* ==========================================================================
   Garden of Eden — STORY section
   Tokens inherited from projects/garden-of-eden/hero/styles.css (loaded
   first in index.html) — same measured palette, same motion tokens.
   Nothing here re-invents a colour or duration; it reuses :root.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Hero → Story transition veil
   A CSS gradient only — no new asset. story.js scrubs its opacity as the
   hero leaves view, synchronised with the story canopy un-zooming.
   -------------------------------------------------------------------------- */

.hero__transition-veil {
  z-index: 8; /* above --z-type, the topmost hero layer */
  opacity: 0;
  background: radial-gradient(ellipse at 50% 65%,
              rgb(20 23 10 / .2) 0%,
              rgb(20 23 10 / .92) 78%);
  will-change: opacity;
}

/* ==========================================================================
   Story shell
   ========================================================================== */

.story {
  position: relative;
  overflow-x: clip; /* clip, not hidden — preserves position:sticky inside */
  background: var(--ground);
  color: var(--text);
}

.story__canopy {
  position: sticky;
  top: 0;
  inset-inline: 0;
  block-size: 100vh;
  block-size: 100svh;
  z-index: 0;
  overflow: clip;
}

.story__canopy img {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  object-position: 50% 30%;
  /* the un-zoom scales THIS img, never the canopy box — a scaled box
     bled ~90px above the story section and painted a dark band over the
     hero's bottom edge (the "hero doesn't reach the fold" bug) */
  transform-origin: 50% 40%;
  will-change: transform;
}

/* canopy shade — composited stand-in for the old scrubbed brightness() */
.story__canopy-shade {
  position: absolute;
  inset: 0;
  background: var(--ground);
  opacity: 0; /* raised by story.js only when motion is allowed */
  pointer-events: none;
}

.story__canopy-scrim {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%,
              rgb(20 23 10 / .05) 0%,
              rgb(20 23 10 / .55) 100%);
  pointer-events: none;
}

/* ==========================================================================
   A beat — one pinned editorial scene. Full-bleed, no card chrome: every
   image is a vignette-matte cutout that fades to the same near-black as
   --ground, so nothing needs a background panel to sit on.
   ========================================================================== */

.beat {
  position: relative;
  z-index: 2;
  block-size: 100vh;
  block-size: 100svh;
  overflow: clip;
}

.beat__art {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.beat__img {
  position: absolute;
  inline-size: clamp(220px, 30vw, 460px);
  block-size: auto;
  aspect-ratio: 2 / 3; /* the cutouts' native ratio — reserves space pre-load */
  filter: drop-shadow(0 30px 60px rgb(0 0 0 / .5));
}

/* Optimized-media pass: these classes now sit on <picture> wrappers.
   Where the class is purely a container (canopy, wipe), display:contents
   keeps the inner img laid out exactly as before; where the class is
   positioned/animated (beat art), the picture stays a real box and the
   img fills its width at natural aspect — identical rendered size. */
.story__canopy picture,
.beat__wipe picture { display: contents; }

.beat__img img {
  display: block;
  inline-size: 100%;
  block-size: auto;
}

/* Absolute, not grid-placed: a grid item's column track can size to a
   child's max-content width regardless of max-inline-size on the item
   itself, which let large display type overflow a "22ch" box computed
   against the wrong (inherited, small) font context. Explicit position
   + a viewport-relative cap sidesteps that entirely and gives precise,
   editorial placement instead of centred grid alignment. */
.beat__content {
  position: absolute;
  z-index: 3;
  inset-block-start: 50%;
  translate: 0 -50%;
  max-inline-size: min(90vw, 620px);
  padding-inline: var(--sp-6);
  display: grid;
  gap: var(--sp-4);
}

.beat__content--left {
  inset-inline-start: clamp(1.5rem, 7vw, 6rem);
  text-align: left;
}

.beat__content--right {
  inset-inline-end: clamp(1.5rem, 7vw, 6rem);
  text-align: right;
}

.beat__content--center {
  inset-inline: 0;
  margin-inline: auto;
  text-align: center;
  max-inline-size: min(80vw, 680px);
}

.beat__kicker {
  margin: 0;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-style: italic;
  font-weight: 500;
  font-size: 1.25rem;
  color: var(--accent-gold);
  opacity: .9;
}

.beat__headline {
  margin: 0;
  font-weight: 300;
  line-height: 1.04;
  letter-spacing: -.01em;
  font-size: clamp(2.25rem, 5.4vw, 4.75rem);
  color: var(--text-strong);
  text-wrap: balance;
}

/* SplitText line-mask-rise — resting state is fully clipped and hidden.
   story.js only sets this once GSAP/SplitText are confirmed loaded; the
   fallback rule below guarantees visibility if either failed to run. */
.beat__headline .split-line { overflow: clip; }
.beat__headline .split-line > div { will-change: transform; }

.beat__lede {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
  opacity: .82;
  max-inline-size: 34ch;
}

/* --------------------------------------------------------------------------
   Beat III — the water reveal gets its own signature treatment (a clip
   wipe, per knowledge/animations/03-image-reveal/image-clip-wipe.md)
   instead of the floating-layer treatment used in beats I–II, so
   "stillness" reads as a different register from "abundance."
   -------------------------------------------------------------------------- */

.beat--iii .beat__art { display: grid; place-items: center; }

/* The water is the scene, not a framed panel: full-bleed environment,
   revealed by the same clip wipe. Legibility comes from environmental
   contrast — a soft radial calm behind the type — never a card. */
.beat__wipe {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  overflow: clip;
  clip-path: inset(0 100% 0 0); /* fully clipped resting state — story.js reveals it */
}

.beat__waterscrim {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: radial-gradient(ellipse 64% 58% at 50% 54%,
              rgb(20 23 10 / .68) 0%,
              rgb(20 23 10 / .30) 55%,
              rgb(20 23 10 / 0) 100%);
  pointer-events: none;
}

.beat__wipe img {
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  transform: scale(1.08);
}

.beat--iii .beat__img--a { inset-block-start: 6%;  inset-inline-start: 4%; z-index: 3; }
.beat--iii .beat__img--b { inset-block-end: 4%;    inset-inline-end: 5%;  z-index: 3; }

/* text centred in the calm of the vignette — a tall poetic column whose
   only line breaks are the four composed ones in the markup (the column
   is wide enough that nothing soft-wraps on top of them) */
.beat--iii .beat__content--center {
  max-inline-size: min(92vw, 46rem);
}
.beat--iii .beat__headline {
  font-size: clamp(2.1rem, 4.4vw, 4rem);
  line-height: 1.14;
}

/* ==========================================================================
   Beat IV — the cinematic close.

   "Feel integrated, not like an embedded player": no native `controls`
   attribute anywhere, full-bleed `object-fit: cover`, no player chrome,
   no border/frame around the video — it is composited exactly like the
   hero's atmosphere video, just full-bleed and foregrounded instead of a
   blended background layer.
   ========================================================================== */

.beat--cinema .cinema {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: clip;
  background: var(--ground); /* visible the instant the page loads, before the video/poster decodes */
}

.cinema__video {
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  object-fit: cover;
  object-position: 50% 35%;
  will-change: transform;
}

/* legibility + the entrance/exit darkening — story.js scrubs this
   opacity; the resting value here is what shows with JS disabled */
.cinema__scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top,
              rgb(20 23 10 / .82) 0%,
              rgb(20 23 10 / .38) 45%,
              rgb(20 23 10 / .18) 100%);
}

/* cinema shade — composited stand-in for the old animated brightness() */
.cinema__shade {
  position: absolute;
  inset: 0;
  background: var(--ground);
  opacity: 0; /* raised by story.js only when motion is allowed */
  pointer-events: none;
}

.beat--cinema .beat__content--center {
  z-index: 2;
  inset-block-end: 22%;
  translate: 0 0;
  inset-block-start: auto;
  max-inline-size: min(80vw, 620px);
}

.beat--cinema .beat__lede {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-style: italic;
  font-size: clamp(1.05rem, 1.6vw, 1.3rem);
  opacity: .9;
}

/* --------------------------------------------------------------------
   Accessible playback control — WCAG 2.2.2: any auto-playing motion
   lasting more than 5 seconds needs a mechanism to pause it. This is
   that mechanism, and it works with or without JS-driven autoplay.
   -------------------------------------------------------------------- */

.cinema__controls {
  position: absolute;
  z-index: 3;
  inset-block-end: var(--sp-6);
  inset-inline-end: var(--sp-6);
}

.cinema__toggle {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  min-block-size: 44px; /* responsive-strategy.md — measured touch-target failure elsewhere */
  padding: .6rem 1.1rem .6rem .9rem;
  border: 1px solid rgb(232 223 204 / .5);
  border-radius: var(--r-pill, 9999px);
  background: rgb(20 23 10 / .45);
  color: var(--text-strong);
  cursor: pointer;
  transition: background-color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.cinema__toggle:hover,
.cinema__toggle:focus-visible { background: var(--accent-gold); color: var(--ground); border-color: var(--accent-gold); }
.cinema__toggle:focus-visible { outline: 2px solid var(--accent-gold-bright); outline-offset: 3px; }

.cinema__toggle-label {
  font-family: system-ui, sans-serif;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.cinema__toggle-icon { position: relative; display: inline-block; inline-size: 14px; block-size: 14px; flex: none; }
.cinema__toggle-icon::before,
.cinema__toggle-icon::after { content: ''; position: absolute; background: currentColor; }

/* resting/paused state: a play triangle */
.cinema__toggle-icon::before {
  inset-block-start: 0; inset-inline-start: 1px;
  inline-size: 0; block-size: 0; background: transparent;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent currentColor;
}
.cinema__toggle-icon::after { display: none; }

/* playing state: two pause bars */
.cinema__toggle[aria-pressed="true"] .cinema__toggle-icon::before {
  inset-inline-start: 0; inline-size: 4px; block-size: 14px; border: 0; background: currentColor;
}
.cinema__toggle[aria-pressed="true"] .cinema__toggle-icon::after {
  display: block; inset-block-start: 0; inset-inline-start: 9px; inline-size: 4px; block-size: 14px;
}

/* ==========================================================================
   Per-beat art placement — irregular, editorial, not a grid. Positions
   are the "resting"/entered state; story.js offsets from here for the
   scrubbed parallax and reduced-motion simply uses these values as-is.
   ========================================================================== */

.beat--i .beat__img--a { inset-block-start: 8%;  inset-inline-end: 8%;   z-index: 2; rotate: -3deg; }
.beat--i .beat__img--b { inset-block-end: -4%;   inset-inline-end: 22%;  z-index: 4; inline-size: clamp(180px, 22vw, 340px); rotate: 2deg; }

.beat--ii .beat__img--a { inset-block-start: -6%; inset-inline-start: 6%;  z-index: 2; rotate: 2deg; }
.beat--ii .beat__img--b { inset-block-end: 4%;    inset-inline-start: 24%; z-index: 4; inline-size: clamp(180px, 20vw, 320px); rotate: -2deg; }
/* kept clear of the right-aligned text column (.beat__content--right) —
   low, tight to the corner, well below the vertically-centred headline */
.beat--ii .beat__img--c { inset-block-end: 2%;    inset-inline-end: 1%;   z-index: 1; inline-size: clamp(170px, 18vw, 280px); rotate: -1deg; opacity: .9; }

/* ScrollSmoother mode: the smoothed content wrapper is transformed, which
   disables position:sticky — story.js creates an equivalent ScrollTrigger
   pin instead, so the canopy just needs to be a normal flow box here. */
.smoother-on .story__canopy { position: relative; top: auto; }

/* ==========================================================================
   Responsive — beats keep pinning on mobile (a single full-screen scene
   at a time reads well on a phone); parallax layer count and drift are
   reduced per knowledge/animations/06-parallax mobile fallbacks.
   ========================================================================== */

@media (max-width: 767px) {
  .beat__content--left,
  .beat__content--right {
    justify-self: center;
    margin-inline: 0;
    text-align: center;
  }
  .beat__headline { font-size: clamp(2rem, 8vw, 2.75rem); }

  /* fewer, smaller, less scattered images per beat on a small screen */
  .beat--i .beat__img--b,
  .beat--ii .beat__img--c { display: none; }
  .beat__img { inline-size: clamp(160px, 46vw, 260px); }

  .beat--iii .beat__img--a, .beat--iii .beat__img--b { display: none; }

  /* mobile behaviour for the cinematic beat: no autoplay (story.js gates
     this on data-cost grounds, not just motion), so the resting poster
     is what most phone visitors see — keep it legible and give the
     control room without crowding a 390px width */
  .beat--cinema .beat__content--center { inset-block-end: 30%; max-inline-size: 88vw; }
  .cinema__controls { inset-block-end: var(--sp-4); inset-inline-end: var(--sp-4); }
  .cinema__toggle { padding-inline: .75rem; }
  /* icon-only on mobile — visually hidden, not display:none, so the
     label stays in the accessibility tree as the button's name */
  .cinema__toggle-label {
    position: absolute; inline-size: 1px; block-size: 1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}

/* ==========================================================================
   Reduced motion — every pin becomes normal flow, every reveal shows its
   resting state immediately. story.js additionally skips creating the
   ScrollTrigger instances entirely in this mode; this is the fallback if
   it somehow doesn't.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .beat { block-size: auto; min-block-size: 100svh; }
  .beat__headline .split-line > div { transform: none !important; }
  .beat__wipe { clip-path: inset(0 0 0 0) !important; }
  .beat__wipe img { transform: none !important; }

  /* the cinematic beat never auto-plays or auto-animates here — the
     poster (the <video>'s own `poster` attribute) is the resting
     visual, and the entrance/exit scale+brightness moves are skipped
     entirely rather than played instantly, since a sudden brightness
     jump is itself a motion effect worth avoiding. The Play control
     remains fully functional — reduced motion means no *automatic*
     motion, not "no motion the user explicitly asked for." */
  .cinema__video { transform: none !important; filter: none !important; }
  .cinema__scrim { opacity: .5 !important; }
  .story__canopy-shade, .cinema__shade, .hero__entrance-shade { opacity: 0 !important; }
  .story__canopy img { transform: none !important; }
}
