:root {
  color-scheme: dark;
  --ink: #0b0909;
  --text: #f4efe6;
  --soft: rgba(248, 243, 234, 0.84);
  --faint: rgba(248, 243, 234, 0.62);
  --line: rgba(244, 239, 230, 0.28);
  --amber: #f5b841;
  --edge: max(6vw, 20px);
  --h1: clamp(60px, 11.5vw, 200px);
  --h2: clamp(28px, 3.3vw, 54px);
  --h3: clamp(26px, 2.8vw, 44px);
  --body: clamp(16px, 1.22vw, 20px);
  --num: clamp(86px, 10.5vw, 188px);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ink); color: var(--text); }
body { font: 400 var(--body)/1.55 Inter, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.028em; line-height: 1.04; margin: 0; text-wrap: balance; }
h1 { font-size: var(--h1); letter-spacing: -0.05em; line-height: 0.9; }
h2 { font-size: var(--h2); }
h3 { font-size: var(--h3); }
p { margin: 0; }
a { color: inherit; }

#gl { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; z-index: 0; }
.vignette { position: fixed; inset: 0; pointer-events: none; z-index: 1; background: radial-gradient(130% 100% at 50% 45%, transparent 60%, rgba(40, 22, 12, 0.32)); }
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 2; opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
@keyframes grain { 0% { transform: translate(0, 0); } 33% { transform: translate(-4%, 3%); } 66% { transform: translate(3%, -5%); } 100% { transform: translate(-2%, 2%); } }

#scroll { position: relative; z-index: -1; }

/* loader */
.loader { position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; gap: 18px; background: var(--ink); transition: opacity 1.2s var(--ease) 0.2s, visibility 0s linear 1.4s; }
.loader p { font-size: 15px; color: var(--soft); }
.loader span { height: 1px; width: 160px; justify-self: center; background: var(--line); position: relative; overflow: hidden; }
.loader span::after { content: ''; position: absolute; inset: 0; background: var(--text); transform-origin: left; animation: load 1.6s var(--ease) infinite; }
@keyframes load { 0% { transform: scaleX(0); } 70% { transform: scaleX(1); } 100% { transform: scaleX(1); opacity: 0; } }
.ready .loader { opacity: 0; visibility: hidden; }

/* chrome */
.bar { position: fixed; top: 0; left: 0; right: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; padding: 22px var(--edge); pointer-events: none; }
.mark { display: block; width: 34px; height: auto; filter: drop-shadow(0 1px 10px rgba(12, 8, 6, 0.5)); }
.bubble { display: inline-flex; align-items: center; gap: 9px; padding: 9px 16px 9px 12px; border-radius: 99px; font-size: 13px; font-weight: 400; background: rgba(40, 24, 14, 0.32); border: 1px solid rgba(255, 255, 255, 0.2); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.bubble i { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 12px var(--amber); }
#chap.swap { animation: swap 0.7s var(--ease); }
@keyframes swap { from { opacity: 0; transform: translateY(8px); filter: blur(4px); } }
.prog { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 21; background: var(--text); transform-origin: left; transform: scaleX(0); opacity: 0.8; }

.nav { position: fixed; right: 22px; top: 50%; transform: translateY(-50%); z-index: 20; display: flex; flex-direction: column; gap: 6px; }
.nav button { all: unset; cursor: pointer; display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 4px 0; font-size: 12px; font-weight: 400; color: var(--faint); transition: color 0.4s; }
.nav button em { font-style: normal; opacity: 0; transform: translateX(6px); transition: opacity 0.4s var(--ease), transform 0.4s var(--ease); white-space: nowrap; }
.nav button span::after { content: ''; display: inline-block; vertical-align: middle; margin-left: 8px; width: 14px; height: 1px; background: currentColor; transition: width 0.5s var(--ease); }
.nav button:hover em, .nav button:focus-visible em { opacity: 1; transform: none; }
.nav button.here { color: var(--text); }
.nav button.here span::after { width: 28px; }
.nav button:focus-visible { outline: 1px solid var(--amber); outline-offset: 4px; }
.nav { transition: opacity 0.6s var(--ease); }
.at-end .nav { opacity: 0; pointer-events: none; }

/* text over the scene */
.story { position: fixed; inset: 0; z-index: 10; pointer-events: none; text-shadow: 0 1px 2px rgba(30, 16, 8, 0.22), 0 2px 28px rgba(30, 16, 8, 0.38); }

/* one soft shade behind the text, full-screen so it never shows an edge */
#scrim { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#scrim i { position: absolute; inset: 0; opacity: 0; will-change: opacity; }
#scrim .s-l { background: linear-gradient(90deg, rgba(12, 8, 6, 0.86) 0%, rgba(12, 8, 6, 0.72) 28%, rgba(12, 8, 6, 0.42) 52%, rgba(12, 8, 6, 0.12) 72%, transparent 86%); }
#scrim .s-r { background: linear-gradient(270deg, rgba(12, 8, 6, 0.86) 0%, rgba(12, 8, 6, 0.72) 28%, rgba(12, 8, 6, 0.42) 52%, rgba(12, 8, 6, 0.12) 72%, transparent 86%); }
#scrim .s-b { background: linear-gradient(0deg, rgba(12, 8, 6, 0.84) 0%, rgba(12, 8, 6, 0.6) 26%, rgba(12, 8, 6, 0.22) 48%, transparent 64%); }
#scrim .s-t { background: linear-gradient(180deg, rgba(12, 8, 6, 0.7) 0%, rgba(12, 8, 6, 0.3) 24%, transparent 40%); }
#scrim .s-c { background: radial-gradient(80% 70% at 50% 50%, rgba(12, 8, 6, 0.78), rgba(12, 8, 6, 0.46) 55%, transparent 90%); }
#scrim .s-h { background: linear-gradient(0deg, rgba(12, 8, 6, 0.84) 0%, rgba(12, 8, 6, 0.56) 32%, rgba(12, 8, 6, 0.16) 58%, transparent 74%); }
#scrim .s-e { background: rgba(24, 14, 9, 0.8); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.beat { position: absolute; visibility: hidden; }
.beat.on { visibility: visible; }
.beat .ln { opacity: 0; will-change: transform, opacity; }
.beat p { color: var(--soft); margin-top: 18px; max-width: 34em; }

.hero { left: var(--edge); bottom: 11vh; right: var(--edge); }
.hero p { font-size: clamp(17px, 1.5vw, 24px); max-width: 30em; }
.cue { display: flex; align-items: center; gap: 12px; font-size: 15px !important; color: var(--faint) !important; margin-top: 40px !important; }
.cue span { width: 1px; height: 38px; background: linear-gradient(var(--text), transparent); animation: cue 2s var(--ease) infinite; transform-origin: top; }
@keyframes cue { 0% { transform: scaleY(0); } 60% { transform: scaleY(1); } 100% { transform: scaleY(1); opacity: 0; } }
.scrolled .cue { opacity: 0 !important; transition: opacity 0.5s; }

.pos-left { left: var(--edge); top: 50%; transform: translateY(-50%); width: min(38vw, 560px); }
.pos-right { right: calc(var(--edge) + 84px); top: 50%; transform: translateY(-50%); width: min(40vw, 580px); }
.pos-bottom { left: var(--edge); right: var(--edge); bottom: 10vh; }
.pos-top { left: 0; right: 0; top: 11vh; text-align: center; }
.pos-center { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(78vw, 1000px); text-align: center; }
.pos-center p { margin-left: auto; margin-right: auto; }

.src { left: var(--edge); right: calc(var(--edge) + 60px); bottom: 22px; font-size: 12px; color: var(--faint); }

.num { font-weight: 700; font-size: var(--num); line-height: 0.9; letter-spacing: -0.05em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num i { font-style: normal; font-weight: 700; font-size: 0.42em; letter-spacing: 0; margin-left: 0.04em; color: var(--soft); }
.stat p { font-size: clamp(18px, 1.5vw, 24px); color: var(--text); max-width: 20em; }

.story-beat h2 { margin-bottom: 26px; }
.story-beat .lit { color: var(--text); margin-top: 14px; opacity: 0.14; }

.born { width: min(42vw, 600px); }
.born h2 { font-size: clamp(28px, 3.2vw, 52px); }
.big2 { display: flex; gap: 40px; margin-top: 26px; }
.big2 .num { font-size: clamp(70px, 7vw, 120px); }
.big2 p { margin-top: 8px; font-size: 14px; max-width: 13em; }
.bars { margin-top: 22px; display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: 88px 1fr 28px; align-items: center; gap: 12px; font-size: 13px; color: var(--soft); }
.hbar b { height: 6px; background: rgba(255, 255, 255, 0.08); border-radius: 3px; overflow: hidden; display: block; }
.hbar i { display: block; height: 100%; background: var(--text); transform-origin: left; transform: scaleX(0); border-radius: 3px; }
.hbar em { font-style: normal; text-align: right; color: var(--text); }
.cap { font-size: 12px !important; color: var(--faint) !important; margin-top: 10px !important; }
.dreams { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 26px; font-size: 14px; color: var(--faint); }
.dreams strong { display: block; margin-top: 2px; font-size: clamp(17px, 1.5vw, 24px); font-weight: 700; color: var(--text); }

.note .who { color: var(--faint); margin: 0 0 12px; }
.person .where { color: var(--text); margin: 18px 0 0; }
.note h3 { font-size: clamp(36px, 4vw, 64px); }

.leads h2 { margin-bottom: 30px; }
.trio { display: grid; gap: 18px; }
.trio > div { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 18px; }
.trio .num { font-size: clamp(56px, 5.6vw, 96px); min-width: 3.2ch; }
.trio p { margin: 0; font-size: 15px; }
.ages { margin-top: 10px !important; font-weight: 700; color: var(--text) !important; font-size: clamp(28px, 2.8vw, 44px); line-height: 1; display: inline-block; margin-right: 18px; }
.ages small { display: inline-block; margin-left: 14px; font-weight: 400; font-size: 0.5em; color: var(--soft); }

.person { width: min(28vw, 400px); top: 56%; }
.person.pos-right { right: calc(var(--edge) + 84px); }
.person h3 { font-size: clamp(28px, 2.8vw, 46px); }
.person .where { margin: 10px 0 0; }
.person blockquote { margin: 0; font-size: clamp(32px, 3.2vw, 54px); font-weight: 700; line-height: 1.04; letter-spacing: -0.028em; text-wrap: balance; }
.person .tr { margin-top: 10px; }
.tl { list-style: none; padding: 0; margin: 22px 0 0; border-left: 1px solid var(--line); font-size: 15px; color: var(--soft); }
.tl li { position: relative; padding: 0 0 8px 18px; }
.tl li::before { content: ''; position: absolute; left: -4px; top: 0.55em; width: 7px; height: 7px; border-radius: 50%; background: var(--text); }
.tl li:last-child { color: var(--text); }

.how p, .final p { font-size: clamp(17px, 1.4vw, 22px); }
.final .facts { margin-top: 26px; color: var(--text) !important; }

.end { inset: 0; display: grid; grid-template-columns: 1.1fr 1fr; gap: 6vw; align-items: center; padding: 14vh var(--edge) 8vh; pointer-events: none; }
.end.on { pointer-events: auto; }
.end h2 { font-size: clamp(36px, 5vw, 84px); }
.btns { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 30px; }
.btn { display: inline-flex; align-items: center; gap: 10px; padding: 15px 24px; border-radius: 99px; background: var(--text); color: var(--ink); text-decoration: none; font-weight: 700; font-size: 15px; transition: transform 0.4s var(--ease), background 0.3s; }
.btn::after { content: '↗'; font-size: 14px; transition: transform 0.4s var(--ease); }
.btn:hover { transform: translateY(-2px); }
.btn:hover::after { transform: translate(2px, -2px); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
.sources { font-size: 13px; color: var(--soft); }
.sources .lbl { font-weight: 700; color: var(--text); margin: 0 0 10px; }
.sources ol { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.sources .fine { margin-top: 18px; font-size: 12px; color: var(--faint); }

/* phones and narrow windows: text sits low, the scene stays visible above */
@media (max-width: 760px) {
  .nav { display: none; }
  .pos-left, .pos-right, .born, .person { left: 20px; right: 20px; width: auto; top: auto; bottom: 9vh; transform: none; }
  .person { bottom: 7vh; }
  .person.pos-left { top: 19vh; bottom: auto; }
  #scrim .s-t { background: linear-gradient(180deg, rgba(12, 8, 6, 0.82) 0%, rgba(12, 8, 6, 0.58) 40%, rgba(12, 8, 6, 0.14) 62%, transparent 74%); }
  #scrim .s-b { background: linear-gradient(0deg, rgba(12, 8, 6, 0.86) 0%, rgba(12, 8, 6, 0.62) 40%, rgba(12, 8, 6, 0.14) 64%, transparent 76%); }
  .person.pos-right { right: 20px; }
  .born h2 { font-size: 26px; }
  .dreams { grid-template-columns: repeat(2, 1fr); }
  .end { grid-template-columns: 1fr; overflow-y: auto; align-content: start; padding-top: 12vh; }
  .src { right: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .grain, .cue span, .loader span::after { animation: none; }
}

/* no WebGL: the story as a plain page */
.nogl #gl, .nogl .grain, .nogl .nav, .nogl #scroll, .nogl #scrim { display: none; }
.nogl .loader { opacity: 0; visibility: hidden; }
.nogl .story { position: static; pointer-events: auto; padding: 100px var(--edge); display: grid; gap: 70px; }
.nogl .beat { position: static; visibility: visible; transform: none; width: auto; inset: auto; }
.nogl .beat .ln, .nogl .lit { opacity: 1 !important; }
.nogl .hbar i { transform: none; }
.nogl .end { display: grid; padding: 0; }
