/* ==========================================================================
   Narrative landing page — scroll-driven chapters.
   Opens dark (space, cinema), resolves into the editorial light of "now".
   Mechanics: position:sticky for pinned media + IntersectionObserver reveals.
   ========================================================================== */

/* ---------- Chapter theming ---------- */
.story { position: relative; }

.chapter {
  position: relative;
  min-height: 100svh;
  display: grid;
  align-items: center;
  padding-block: clamp(5rem, 14vh, 9rem);
  transition: background-color .9s ease, color .9s ease;
}

/* Dark chapters — the origin half of the story. Transparent, so the fixed
   sky canvas (src/scripts/sky.js) shows through. */
.chapter[data-mode="dark"] {
  --local-ink:   #F2EFE9;
  --local-ink-2: #A9A399;
  --local-ink-3: #8A857C;
  --local-rule:  rgba(242, 239, 233, 0.14);
  background: transparent;
  color: var(--local-ink);
}
.chapter[data-mode="dark"] .chapter__line,
.chapter[data-mode="dark"] .chapter__num {
  text-shadow: 0 2px 28px rgba(6, 7, 10, .9);
}

.sky {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
.story > .chapter { z-index: 1; }

/* Scene markers read by sky.js; they sit mid-chapter unless told otherwise */
.mark {
  position: absolute;
  top: 50%;
  left: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* A tall chapter whose words stay put while the sky keeps changing */
.chapter--pinned {
  display: block;
  min-height: 260svh;
  padding-block: 0;
}

/* The "ways of seeing" chapter holds three scenes, so it scrolls longer */
.chapter--lens { min-height: 330svh; }
.chapter--lens .pin { position: sticky; }

/* Label beside the picture, naming the idea it shows */
.lens {
  position: absolute;
  top: clamp(5.5rem, 13svh, 8rem);
  left: 66%;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: 0.875rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #F2EFE9;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .5s ease;
  text-shadow: 0 2px 20px rgba(6, 7, 10, .9);
}
.lens.is-on { opacity: 1; }
.lens.is-swapping .lens__t { opacity: 0; transform: translateY(6px); }
.lens__n { color: #E8825C; }
.lens__t { transition: opacity .35s ease, transform .35s ease; }

/* A quiet aside that scrolls past with its chapter, under the picture */
.aside-quote {
  position: absolute;
  left: 66%;
  bottom: clamp(3rem, 12svh, 7rem);
  transform: translateX(-50%);
  width: min(30ch, 40vw);
  margin: 0;
  text-align: center;
  color: rgba(242, 239, 233, .42);
}
.aside-quote p {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 300;
  font-size: 0.9375rem;
  line-height: 1.5;
}
.aside-quote cite {
  display: block;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-style: normal;
  font-size: 0.625rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(242, 239, 233, .3);
}
.aside-quote.reveal.is-in { transform: translateX(-50%); }
.aside-quote.reveal { transform: translate(-50%, 22px); }

/* Light chapters — the present */
.chapter[data-mode="light"] {
  --local-ink:   var(--ink);
  --local-ink-2: var(--ink-2);
  --local-ink-3: var(--ink-3);
  --local-rule:  var(--rule);
  --local-bg:    var(--paper);
  background: var(--local-bg);
  color: var(--local-ink);
}

/* The hinge: the moment the story turns from origin to present */
.chapter--hinge {
  min-height: 80svh;
  background: linear-gradient(180deg, rgba(6,7,10,0) 0%, rgba(58,52,46,.9) 45%, #9C9186 72%, var(--paper) 100%);
}

/* ---------- Chapter internals ---------- */
.chapter__grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: clamp(1.5rem, 3vw, 2.5rem);
  align-items: center;
  width: 100%;
}

.chapter__num {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--local-ink-3);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.875rem;
}
.chapter__num::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--local-rule);
  max-width: 5rem;
}

.chapter__year {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  color: var(--local-ink-3);
}

.chapter__line {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 1.1rem + 3.4vw, 4rem);
  font-weight: 300;
  line-height: 1.16;
  letter-spacing: -0.028em;
  text-wrap: balance;
  margin-bottom: 1.25rem;
}
.chapter__line em {
  font-style: italic;
  color: var(--accent);
}
.chapter[data-mode="dark"] .chapter__line em { color: #E8825C; }

.chapter__body {
  font-size: clamp(0.9375rem, 0.9rem + 0.2vw, 1.0625rem);
  line-height: 1.68;
  color: var(--local-ink-2);
  max-width: 46ch;
}
.chapter__body + .chapter__body { margin-top: 1rem; }

/* Column placements */
.col-left   { grid-column: 1 / span 5; }
.col-right  { grid-column: 7 / span 6; }
.col-wide   { grid-column: 1 / span 8; }
.col-center { grid-column: 3 / span 8; text-align: center; }
.col-full   { grid-column: 1 / -1; }

/* ---------- Media frames inside chapters ---------- */
.plate {
  position: relative;
  overflow: hidden;
  border-radius: 2px;
}
.plate img { width: 100%; height: 100%; object-fit: cover; }
.plate--16x9 { aspect-ratio: 16 / 9; }
.plate--4x5  { aspect-ratio: 4 / 5; }
.plate--21x9 { aspect-ratio: 21 / 9; }
.plate--1x1  { aspect-ratio: 1 / 1; }

/* Placeholder treatment — deliberately handsome, so layout reads true before
   the real frames land. Replace .plate__ph with an <img>. */
.plate__ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1.5rem;
  background:
    radial-gradient(120% 90% at 30% 15%, rgba(255,255,255,.10), transparent 60%),
    linear-gradient(145deg, #2A2622 0%, #14161C 55%, #0A0A0E 100%);
  color: rgba(255,255,255,.42);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.7;
}
.plate__ph::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .16;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/></filter><rect width='120' height='120' filter='url(%23n)' opacity='.55'/></svg>");
}
.plate__ph span {
  position: relative;
  z-index: 1;
  display: block;
  max-width: 22ch;
}
.plate__ph b {
  display: block;
  color: rgba(255,255,255,.70);
  font-weight: 400;
  letter-spacing: 0.18em;
  margin-bottom: 0.5rem;
}
.chapter[data-mode="light"] .plate__ph {
  background:
    radial-gradient(120% 90% at 30% 15%, rgba(0,0,0,.04), transparent 60%),
    linear-gradient(145deg, #EDE9E1 0%, #DED8CC 100%);
  color: var(--ink-3);
}
.chapter[data-mode="light"] .plate__ph b { color: var(--ink-2); }

/* ---------- Sticky pinned sequence (used by the "now" chapter) ---------- */
.pin {
  position: sticky;
  top: 0;
  height: 100svh;
  display: grid;
  align-content: center;
}

/* Horizon glow under the opening title */
.glow {
  position: absolute;
  left: 50%;
  bottom: -38vh;
  width: 140vw;
  height: 70vh;
  transform: translateX(-50%);
  pointer-events: none;
  background: radial-gradient(50% 50% at 50% 50%, rgba(86, 122, 190, .30) 0%, rgba(86,122,190,0) 70%);
}

/* ---------- Scroll reveals ---------- */
.reveal {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity .9s cubic-bezier(.22,.7,.3,1), transform .9s cubic-bezier(.22,.7,.3,1);
}
.reveal.is-in { opacity: 1; transform: none; }
.reveal[data-delay="1"] { transition-delay: .10s; }
.reveal[data-delay="2"] { transition-delay: .20s; }
.reveal[data-delay="3"] { transition-delay: .32s; }
.reveal[data-delay="4"] { transition-delay: .44s; }

.plate.reveal { transform: translateY(30px) scale(.985); }
.plate.reveal.is-in { transform: none; }

/* ---------- Chapter rail (scroll position indicator) ---------- */
.rail {
  position: fixed;
  right: clamp(1rem, 2.5vw, 2rem);
  top: 50%;
  transform: translateY(-50%);
  z-index: 40;
  display: grid;
  gap: 0.875rem;
  mix-blend-mode: difference;
}
.rail a {
  display: block;
  width: 26px;
  height: 1px;
  background: rgba(255, 255, 255, .35);
  transition: background-color .3s ease, width .3s ease;
}
.rail a.is-active { background: #fff; width: 40px; }
.rail a span {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%);
}

/* ---------- Opening title ---------- */
.opening { position: relative; overflow: hidden; }
.opening__inner { position: relative; z-index: 2; text-align: center; }
.opening__kicker {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: rgba(242, 239, 233, .5);
  margin-bottom: clamp(1.75rem, 4vh, 3rem);
}
.opening__title {
  font-family: var(--font-display);
  font-weight: 200;
  font-size: clamp(2.25rem, 1rem + 5.4vw, 5.5rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
  color: #F5F2EC;
  margin-bottom: clamp(1.5rem, 3vh, 2.25rem);
  text-wrap: balance;
}
.opening__title em { font-style: italic; color: #E8825C; }
.opening__sub {
  font-size: clamp(0.9375rem, 0.9rem + 0.3vw, 1.125rem);
  color: rgba(242, 239, 233, .62);
  max-width: 44ch;
  margin-inline: auto;
  line-height: 1.6;
}

.scroll-cue {
  position: absolute;
  left: 50%;
  bottom: clamp(1.75rem, 5vh, 3rem);
  transform: translateX(-50%);
  z-index: 3;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: rgba(242, 239, 233, .45);
  display: grid;
  justify-items: center;
  gap: 0.75rem;
}
.scroll-cue::after {
  content: "";
  width: 1px;
  height: 2.75rem;
  background: linear-gradient(to bottom, rgba(242,239,233,.5), transparent);
  animation: cue 2.4s ease-in-out infinite;
}
@keyframes cue {
  0%, 100% { opacity: .25; transform: scaleY(.6); transform-origin: top; }
  50%      { opacity: 1;   transform: scaleY(1);  transform-origin: top; }
}

/* ---------- "Now" chapter: achievements ---------- */
.proof {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  border-top: 1px solid var(--local-rule);
  margin-top: clamp(2.5rem, 5vw, 4rem);
}
.proof__cell {
  padding: clamp(1.5rem, 3vw, 2.25rem) 1.5rem clamp(1.5rem, 3vw, 2.25rem) 0;
  border-bottom: 1px solid var(--local-rule);
}
.proof__fig {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3.4vw, 2.75rem);
  letter-spacing: -0.032em;
  line-height: 1;
  margin-bottom: 0.625rem;
}
.proof__fig em { font-style: normal; color: var(--accent); }
.proof__label {
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--local-ink-2);
  max-width: 26ch;
}
.proof__src {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  color: var(--local-ink-3);
  margin-top: 0.5rem;
  text-transform: uppercase;
}

/* ---------- Two-thread split (the Interstellar fork) ---------- */
.fork {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: clamp(1.5rem, 4vw, 3.5rem);
  align-items: center;
  margin-top: clamp(2.5rem, 5vw, 4rem);
}
.fork__side { display: grid; gap: 1rem; }
.fork__side h3 {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--local-ink-3);
  font-weight: 400;
}
.fork__side p {
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 0.9rem + 0.9vw, 1.6rem);
  line-height: 1.3;
  letter-spacing: -0.02em;
}
.fork__split {
  width: 1px;
  align-self: stretch;
  background: linear-gradient(to bottom, transparent, var(--local-rule) 20%, var(--local-rule) 80%, transparent);
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .col-left, .col-right, .col-wide, .col-center { grid-column: 1 / -1; }
  .col-center { text-align: left; }
  .chapter__grid { grid-template-columns: 1fr; gap: 2rem; }
  .chapter[data-mode="light"] { min-height: auto; padding-block: clamp(4rem, 12vh, 6rem); }
  .chapter[data-mode="dark"]:not(.opening) { align-items: end; padding-bottom: 12svh; }
  .chapter--pinned .pin { align-content: end; padding-bottom: 12svh; }
  .lens { left: 50%; top: 7.25rem; font-size: 0.6875rem; }
  .aside-quote { left: 50%; bottom: 5svh; width: calc(100% - 2 * var(--gutter)); }
  .chapter[data-mode="dark"]:has(.aside-quote) { padding-bottom: 24svh; }
  .fork { grid-template-columns: 1fr; }
  .fork__split { width: auto; height: 1px; background: var(--local-rule); }
  .rail { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; }
  .scroll-cue::after { animation: none; }
}
