/* ========== theme tokens ========== */
:root {
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="dark"] {
  --bg: #02030a;
  --ink: #f1f4ff;
  --ink-soft: #b3bcdc;
  --ink-faint: #6b769c;
  --accent: #ff9a4d;
  --accent-2: #6fd2ff;
  --panel: rgba(16, 18, 34, 0.5);
  --panel-brd: rgba(170, 190, 255, 0.16);
  --panel-hi: rgba(255, 175, 110, 0.42);
  --quote: #ffd79a;
  --shadow: rgba(0, 0, 0, 0.55);
}

html[data-theme="light"] {
  --bg: #eef2fb;
  --ink: #15192a;
  --ink-soft: #3f4768;
  --ink-faint: #8a93b4;
  --accent: #c2440f;
  --accent-2: #1f5fd0;
  --panel: rgba(255, 255, 255, 0.64);
  --panel-brd: rgba(40, 70, 140, 0.16);
  --panel-hi: rgba(160, 60, 20, 0.34);
  --quote: #a8420a;
  --shadow: rgba(40, 60, 110, 0.18);
}

/* ========== base ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background 0.8s var(--ease), color 0.8s var(--ease);
}

#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; z-index: 0; display: block; }

.vignette {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(125% 105% at 50% 42%, transparent 52%, var(--bg) 128%);
  opacity: 0.78;
  transition: background 0.8s var(--ease);
}

main { position: relative; z-index: 2; }

/* ========== chapters ========== */
.chapter { position: relative; height: 215vh; }
.chapter--tall { height: 270vh; }
.chapter--hero { height: 180vh; }

.chapter__sticky {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; align-items: center;
  padding: clamp(1.4rem, 5vw, 6rem);
}
.chapter__content { max-width: 38rem; will-change: opacity, transform; position: relative; }
.chapter__content::before {
  content: ""; position: absolute; inset: -18% -14%; z-index: -1;
  background: radial-gradient(72% 64% at 50% 50%, var(--bg) 0%, var(--bg) 32%, transparent 80%);
  opacity: 0.82; filter: blur(34px); pointer-events: none;
}
.chapter[data-index="2"] .chapter__content,
.chapter[data-index="5"] .chapter__content,
.chapter[data-index="8"] .chapter__content,
.chapter[data-index="11"] .chapter__content,
.chapter[data-index="14"] .chapter__content { margin-left: auto; text-align: right; }
.chapter--hero .chapter__sticky { justify-content: center; text-align: center; }
.chapter--hero .chapter__content { text-align: center; }

/* ========== typography ========== */
.eyebrow, .body, .lede, .quote, .scroll-hint, .credit, .title {
  text-shadow: 0 0 14px var(--bg), 0 0 30px var(--bg), 0 1px 3px var(--bg);
}
.eyebrow {
  font-size: clamp(0.7rem, 1.4vw, 0.82rem);
  letter-spacing: 0.34em; text-transform: uppercase;
  color: var(--accent); font-weight: 500; margin-bottom: 1.1rem;
}
.title {
  font-family: var(--serif); font-weight: 380; line-height: 1.02; letter-spacing: -0.01em;
  font-size: clamp(2.6rem, 8vw, 5.6rem); margin-bottom: 1.3rem;
  text-shadow: 0 0 18px var(--bg), 0 0 44px var(--bg), 0 2px 40px var(--shadow);
}
.title--hero { font-size: clamp(3.2rem, 12vw, 8.4rem); letter-spacing: 0.05em; font-weight: 360; }

.lede {
  font-family: var(--serif); font-size: clamp(1.05rem, 2.6vw, 1.5rem); font-weight: 300;
  color: var(--ink-soft); line-height: 1.5; max-width: 30rem; margin: 0 auto 2rem;
}
.lede em { font-style: italic; color: var(--ink); }

.body { font-size: clamp(1rem, 2.2vw, 1.2rem); line-height: 1.72; color: var(--ink-soft); font-weight: 300; }
.body em { font-style: italic; color: var(--ink); font-weight: 400; }
.body strong { color: var(--ink); font-weight: 600; }

.cue {
  color: var(--accent); font-style: normal; font-weight: 500;
  border-bottom: 1px dashed currentColor; padding-bottom: 1px;
}
.cue::before { content: "✦ "; font-size: 0.85em; opacity: 0.85; }

.quote {
  font-family: var(--serif); font-style: italic;
  font-size: clamp(1.05rem, 2.7vw, 1.55rem); line-height: 1.5;
  color: var(--quote); max-width: 33rem; margin: 2rem auto 0;
}
.quote cite {
  display: block; margin-top: 1rem; font-size: 0.8rem; font-style: normal;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint);
}
.quote cite i { text-transform: none; letter-spacing: normal; }
.quote--long { font-size: clamp(0.95rem, 2.2vw, 1.32rem); line-height: 1.55; max-width: 40rem; }

.enter {
  margin-top: 2.4rem; font-family: var(--sans); font-size: clamp(0.95rem, 2.4vw, 1.1rem);
  font-weight: 500; letter-spacing: 0.08em; color: var(--ink);
  background: var(--panel); border: 1px solid var(--panel-hi);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 0.95rem 2.3rem; border-radius: 999px; cursor: pointer;
  animation: tapRing 2.4s ease-out infinite;
  transition: transform 0.3s var(--ease), border-color 0.3s var(--ease), opacity 0.6s var(--ease);
}
.enter:hover { transform: translateY(-2px); border-color: var(--accent); }
.enter__note { color: var(--accent); }
.enter.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }

.scroll-hint {
  margin-top: 1.6rem; display: flex; flex-direction: column; align-items: center; gap: 0.4rem;
  color: var(--ink-faint); font-size: 0.8rem; letter-spacing: 0.22em; text-transform: uppercase;
  transition: opacity 0.8s var(--ease);
}
.scroll-hint .chev { font-size: 1.4rem; animation: bob 1.8s var(--ease) infinite; }
.scroll-hint.hidden { opacity: 0; pointer-events: none; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(7px); } }
@keyframes pulse { 0%,100% { opacity: 0.35; } 50% { opacity: 0.85; } }

.replay {
  margin-top: 2.2rem; font-family: var(--sans); font-size: 0.85rem; letter-spacing: 0.12em;
  color: var(--ink); background: var(--panel); border: 1px solid var(--panel-hi);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 0.8rem 1.6rem; border-radius: 999px; cursor: pointer;
  transition: transform 0.3s var(--ease), border-color 0.3s var(--ease);
}
.replay:hover { transform: translateY(-2px); border-color: var(--accent); }
.credit { margin-top: 1.6rem; font-size: 0.72rem; letter-spacing: 0.14em; color: var(--ink-faint); }
.credit--dedication {
  margin-top: 1.6rem; font-size: clamp(0.82rem, 1.6vw, 0.98rem); letter-spacing: 0.05em; color: var(--ink-soft);
}
.credit--dedication strong { color: var(--accent); font-weight: 500; }
.credit--dedication + .credit { margin-top: 0.6rem; }

.chapter[data-index="15"] .chapter__sticky { align-items: flex-start; padding-top: clamp(1.6rem, 6vh, 4.5rem); }
.chapter[data-index="15"] .title { font-size: clamp(2.1rem, 6vw, 4.2rem); margin-bottom: 0.7rem; }

/* ========== UI chrome ========== */
.ui { position: fixed; z-index: 10; }
.ui--top {
  top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between;
  padding: clamp(1rem, 3vw, 1.8rem) clamp(1.2rem, 4vw, 2.4rem); pointer-events: none;
}
.ui--top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand__mark { color: var(--accent); font-size: 1.1rem; animation: spin 16s linear infinite; }
.brand__name { font-size: 0.78rem; letter-spacing: 0.34em; font-weight: 500; color: var(--ink-soft); }
@keyframes spin { to { transform: rotate(360deg); } }

.controls { display: flex; gap: 0.6rem; }
.ctrl {
  display: inline-flex; align-items: center; gap: 0.5rem; font-family: var(--sans);
  font-size: 0.74rem; letter-spacing: 0.1em; color: var(--ink-soft);
  background: var(--panel); border: 1px solid var(--panel-brd);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: 0.55rem 0.9rem; border-radius: 999px; cursor: pointer;
  transition: color 0.3s, border-color 0.3s, transform 0.3s var(--ease);
}
.ctrl:hover { color: var(--ink); border-color: var(--panel-hi); transform: translateY(-1px); }
.ctrl__icon { font-size: 0.95rem; line-height: 1; }
#soundBtn.is-on { color: var(--accent); border-color: var(--panel-hi); }
#soundBtn.is-on .ctrl__icon { animation: pulse 1.6s ease-in-out infinite; }
#soundBtn.is-pending { color: var(--accent); border-color: currentColor; animation: tapRing 1.8s ease-out infinite; }
#soundBtn.is-pending .ctrl__icon { animation: pulse 1.1s ease-in-out infinite; }
@keyframes tapRing {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 12px color-mix(in srgb, var(--accent) 0%, transparent); }
}

.ui--progress {
  bottom: 0; left: 0; right: 0; display: flex; align-items: center; gap: 0.9rem;
  padding: 0 clamp(1.2rem, 4vw, 2.4rem) clamp(0.9rem, 2.5vw, 1.4rem);
}
.progress__label {
  font-family: var(--serif); font-size: 0.8rem; letter-spacing: 0.2em;
  color: var(--ink-faint); min-width: 6.5rem; font-style: italic;
}
.progress__track { flex: 1; height: 2px; background: var(--panel-brd); border-radius: 2px; overflow: hidden; }
.progress__fill {
  height: 100%; width: 100%; transform-origin: left; transform: scaleX(0);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

html.is-dragging, html.is-dragging body {
  cursor: grabbing !important; user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}

@media (max-width: 640px) {
  /* top bar: shrink so the controls never clip off-screen */
  .ui--top { padding: 0.8rem 0.85rem; }
  .controls { gap: 0.4rem; }
  .ctrl__label { display: none; }
  .ctrl { padding: 0.5rem; }
  .ctrl__icon { font-size: 0.9rem; }
  .brand__mark { font-size: 0.95rem; }
  .brand__name { font-size: 0.62rem; letter-spacing: 0.2em; }

  /* tighter scroll lengths + padding */
  .chapter { height: 200vh; }
  .chapter--tall { height: 248vh; }
  .chapter--hero { height: 165vh; }
  .chapter__sticky { padding: 1.1rem; }
  .chapter__content::before { inset: -22% -16%; opacity: 0.9; }

  /* scale down typography so it fits a phone without overlapping */
  .eyebrow { font-size: 0.64rem; letter-spacing: 0.24em; margin-bottom: 0.75rem; }
  .title { font-size: clamp(1.85rem, 8.6vw, 2.5rem); margin-bottom: 0.85rem; }
  .title--hero { font-size: clamp(2.5rem, 13vw, 3.6rem); letter-spacing: 0.03em; }
  .lede { font-size: 1rem; line-height: 1.45; margin-bottom: 1.3rem; max-width: 100%; }
  .body { font-size: 0.95rem; line-height: 1.6; }
  .quote { font-size: 0.98rem; line-height: 1.42; margin-top: 1.2rem; max-width: 100%; }
  .quote cite { font-size: 0.66rem; margin-top: 0.6rem; }
  .quote--long { font-size: 0.9rem; line-height: 1.46; }
  .enter { margin-top: 1.5rem; padding: 0.78rem 1.7rem; font-size: 0.92rem; }
  .scroll-hint { margin-top: 1rem; font-size: 0.68rem; letter-spacing: 0.16em; }
  .replay { margin-top: 1.4rem; }
  .credit { margin-top: 1rem; }
  .credit--dedication { margin-top: 1.1rem; }

  /* discreet seek bar */
  .ui--progress { gap: 0.5rem; padding: 0 0.85rem calc(0.55rem + env(safe-area-inset-bottom)); }
  .progress__label { min-width: 0; font-size: 0.56rem; letter-spacing: 0.08em; white-space: nowrap; }
  .progress__track { height: 1.5px; }

  /* one column: all text left-aligned on phones */
  .chapter[data-index="2"] .chapter__content,
  .chapter[data-index="5"] .chapter__content,
  .chapter[data-index="8"] .chapter__content,
  .chapter[data-index="11"] .chapter__content,
  .chapter[data-index="14"] .chapter__content { text-align: left; margin-left: 0; }

  .chapter[data-index="15"] .title { font-size: clamp(1.7rem, 7vw, 2.3rem); }
}

/* very narrow: drop the wordmark so the toggles always fit */
@media (max-width: 430px) {
  .brand__name { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .chev, .brand__mark, #soundBtn.is-on .ctrl__icon { animation: none; }
}
