/* ============================================================
   PERIHELION — main stylesheet
   ============================================================ */
:root {
  --ink: #eaf0ff;
  --ink-dim: #9aa7c7;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --cond: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Barlow', 'Helvetica Neue', sans-serif;
  --hud-w: 76px;
  --gold: #ffb84d;
  --ember: #ff7a1a;
  --indigo: #070b1d;
  --panel: rgba(8, 12, 28, 0.62);
  --line: rgba(154, 167, 199, 0.28);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: auto; }
html, body { overscroll-behavior-y: none; }

body {
  background: #05070f;
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--gold); color: #140b06; }

/* thin custom scrollbar as mission timeline chrome */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: #05070f; }
::-webkit-scrollbar-thumb { background: linear-gradient(#7fb2e5, #101736 45%, #ffb84d); border-radius: 5px; }

/* ================= starfield ================= */
#stars {
  position: fixed; inset: 0;
  width: 100vw; height: 100vh;
  z-index: 0; pointer-events: none;
  opacity: 0;
}

/* ================= HUD ================= */
#hud {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--hud-w);
  z-index: 40;
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 0 calc(14px + env(safe-area-inset-bottom));
  gap: 18px;
  background: linear-gradient(90deg, rgba(4,6,14,0.82), rgba(4,6,14,0.55) 70%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-right: 1px solid rgba(154,167,199,0.14);
}

.hud-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hud-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 40% 38%, #fff3d6 0%, #ffb84d 45%, #ff7a1a 100%);
  box-shadow: 0 0 10px rgba(255,184,77,0.7);
}
.hud-name {
  font-family: var(--cond); font-weight: 600; font-size: 11px; letter-spacing: 0.32em;
  writing-mode: vertical-rl; color: var(--ink-dim);
}

.hud-nav { flex: 0 0 auto; }
#chapter-nav { list-style: none; display: flex; flex-direction: column; gap: 6px; }
#chapter-nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  width: 52px; min-height: 44px; padding: 6px 0;
  background: none; border: 1px solid transparent; border-radius: 6px;
  color: var(--ink-dim); cursor: pointer;
  font-family: var(--mono); font-size: 10px;
  transition: color .25s, border-color .25s, background .25s;
}
#chapter-nav button i { font-style: normal; font-size: 12px; letter-spacing: .1em; }
#chapter-nav button s {
  text-decoration: none; font-family: var(--cond); font-weight: 500;
  font-size: 8px; letter-spacing: .08em; text-transform: uppercase;
  opacity: .75; white-space: nowrap;
}
#chapter-nav button:hover, #chapter-nav button:focus-visible { color: var(--ink); border-color: var(--line); }
#chapter-nav button.active { color: var(--gold); background: rgba(255,184,77,0.08); border-color: rgba(255,184,77,0.35); }
#chapter-nav button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.hud-progress { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 120px; width: 100%; }
.hud-track {
  position: relative; flex: 1 1 auto; width: 3px;
  background: rgba(154,167,199,0.22); border-radius: 2px; overflow: visible;
}
.hud-fill {
  position: absolute; top: 0; left: 0; width: 100%; height: 0%;
  background: linear-gradient(#7fb2e5, #5f6edb 40%, #ffb84d 85%, #fff3d6);
  border-radius: 2px;
}
.hud-probe-dot {
  position: absolute; left: 50%; top: 0%;
  width: 9px; height: 9px; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: #fff3d6; box-shadow: 0 0 8px rgba(255,243,214,0.9);
}
.hud-pct { font-family: var(--mono); font-size: 9px; color: var(--ink-dim); letter-spacing: .08em; }

.hud-telemetry { display: flex; flex-direction: column; gap: 7px; width: 100%; padding: 0 6px; }
.hud-telemetry div { text-align: center; }
.hud-telemetry dt { font-family: var(--cond); font-weight: 500; font-size: 8px; letter-spacing: .22em; color: var(--ink-dim); }
.hud-telemetry dd { font-family: var(--mono); font-size: 9px; color: var(--ink); white-space: nowrap; }
.hud-telemetry dd.hot { color: var(--ember); }

/* ================= chapters / stages ================= */
#story { position: relative; z-index: 1; }

.chapter { position: relative; height: calc(var(--span, 1) * 100vh); }

.stage {
  position: sticky; top: 0;
  height: 100vh; height: 100svh;
  overflow: hidden;
}

.scene-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.scene-ui { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.scene-ui > * { pointer-events: auto; }

/* edge fades for eased inter-chapter transitions */
.fade { position: absolute; left: 0; right: 0; height: 22vh; z-index: 5; pointer-events: none; opacity: 0; }
.fade-in  { top: 0; }
.fade-out { bottom: 0; }

/* ================= scene typography ================= */
.kicker {
  font-family: var(--mono); font-size: 11px; letter-spacing: .28em;
  text-transform: uppercase; color: var(--ink-dim);
}
.scene-title {
  font-family: var(--cond); font-weight: 700;
  font-size: clamp(56px, 11vw, 148px);
  line-height: 0.92; letter-spacing: .045em; text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 2px 30px rgba(0,0,0,0.45);
}
.scene-sub { font-family: var(--mono); font-size: 12px; letter-spacing: .18em; color: var(--ink-dim); text-transform: uppercase; }
.scene-copy { max-width: 34em; font-size: clamp(15px, 1.6vw, 18px); color: var(--ink); opacity: .92; }

/* generic scrub-reveal state (JS-driven via --rp) */
.reveal { opacity: 0; transform: translateY(26px); will-change: opacity, transform; }

/* per-scene UI placement */
#ch-launch .scene-ui { display: flex; flex-direction: column; justify-content: flex-start; padding: 9vh 7vw 0 calc(var(--hud-w) + 6vw); }
#ch-launch .scene-title { color: var(--scene-ink, #0d2b52); text-shadow: none; transition: none; }
#ch-launch .kicker, #ch-launch .scene-sub { color: var(--scene-ink, #0d2b52); opacity: .8; }

.countdown { margin-top: 4vh; font-family: var(--mono); color: var(--scene-ink, #0d2b52); }
.countdown .cd-label { display: block; font-size: 11px; letter-spacing: .34em; opacity: .75; }
.countdown .cd-value { display: block; font-size: clamp(44px, 7vw, 96px); font-weight: 500; font-variant-numeric: tabular-nums; }

.quote {
  max-width: 30em; margin-top: auto; margin-bottom: 10vh;
  font-size: clamp(16px, 1.9vw, 21px); font-style: italic; line-height: 1.5;
  color: var(--ink);
}
#ch-launch .quote { color: var(--scene-ink, #0d2b52); }
.quote cite { display: block; margin-top: .6em; font-style: normal; font-family: var(--mono); font-size: 11px; letter-spacing: .14em; opacity: .8; }

.scroll-hint {
  position: absolute; bottom: 4vh; right: 5vw;
  display: flex; align-items: center; gap: 12px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .3em; color: var(--scene-ink, #0d2b52); opacity: .85;
}
.hint-line { width: 44px; height: 1px; background: currentColor; display: inline-block; animation: hintPulse 2.2s ease-in-out infinite; }
@keyframes hintPulse { 0%,100% { transform: scaleX(.4); opacity:.4 } 50% { transform: scaleX(1); opacity:1 } }

#ch-sail .scene-ui, #ch-slingshot .scene-ui, #ch-approach .scene-ui {
  padding: 10vh 7vw 0 calc(var(--hud-w) + 6vw);
  display: flex; flex-direction: column; gap: 2.2vh;
}
#ch-sail .scene-copy, #ch-slingshot .scene-copy, #ch-approach .scene-copy { max-width: 26em; }

.checklist { list-style: none; margin-top: 3vh; font-family: var(--mono); font-size: 12px; }
.checklist li {
  display: flex; gap: 14px; align-items: baseline;
  padding: 7px 0; border-bottom: 1px solid var(--line);
  max-width: 340px;
  opacity: .18; transform: translateX(-8px);
  transition: opacity .5s, transform .5s;
}
.checklist li.done { opacity: 1; transform: none; }
.checklist li b { font-weight: 400; letter-spacing: .1em; flex: 1; }
.checklist li s { text-decoration: none; color: #7dd8a8; font-size: 10px; letter-spacing: .2em; }
.checklist li.done s::before { content: "\25B8 "; }

.flyby-marker {
  margin-top: 4vh; font-family: var(--mono);
  display: flex; flex-direction: column; gap: 4px;
  border-left: 2px solid var(--gold); padding-left: 14px;
}
.flyby-marker span { font-size: 10px; letter-spacing: .3em; color: var(--ink-dim); text-shadow: 0 1px 8px rgba(0,0,0,0.7); }
.flyby-marker b { font-size: 26px; font-weight: 500; font-variant-numeric: tabular-nums; text-shadow: 0 1px 10px rgba(0,0,0,0.75); }

/* ================= cruise ================= */
.cruise-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  gap: 2vh 4vw;
  padding: 8vh 6vw 8vh calc(var(--hud-w) + 5vw);
}
.cruise-head { grid-column: 1 / -1; }
.cruise-head .scene-title { font-size: clamp(44px, 7.5vw, 110px); }

.log-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 20px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  align-self: start; max-height: 62vh; display: flex; flex-direction: column;
}
.log-panel h3 { font-family: var(--cond); font-weight: 600; font-size: 15px; letter-spacing: .24em; color: var(--ink-dim); margin-bottom: 10px; }
#log-list { list-style: none; overflow-y: auto; scrollbar-width: thin; }
#log-list li { border-bottom: 1px solid rgba(154,167,199,0.12); }
#log-list button {
  width: 100%; text-align: left; background: none; border: 0; cursor: pointer;
  padding: 10px 4px; display: grid; grid-template-columns: 74px 1fr; gap: 4px 10px;
  font-family: var(--mono); color: var(--ink);
  opacity: 0; transform: translateY(10px);
  transition: opacity .5s, transform .5s, background .2s;
}
#log-list li.on button { opacity: 1; transform: none; }
#log-list button:hover, #log-list button:focus-visible { background: rgba(255,184,77,0.07); }
#log-list button:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
#log-list .lt { font-size: 10px; color: var(--gold); letter-spacing: .06em; padding-top: 2px; }
#log-list .ls { font-size: 12px; line-height: 1.45; }
#log-list .lk { grid-column: 2; font-size: 9px; letter-spacing: .22em; color: var(--ink-dim); text-transform: uppercase; }
.log-note { margin-top: 10px; font-family: var(--mono); font-size: 9px; letter-spacing: .16em; color: var(--ink-dim); }

.inst-panel {
  align-self: start; display: flex; flex-direction: column; gap: 16px;
  font-family: var(--mono);
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 20px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.inst dt { font-size: 9px; letter-spacing: .28em; color: var(--ink-dim); margin-bottom: 4px; }
.inst dd { font-size: 17px; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 10px; }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 16px; }
.bars i { width: 4px; background: var(--gold); display: inline-block; height: 20%; transition: height .18s; border-radius: 1px; }

/* ================= approach ================= */
#ch-approach .scene-title { color: var(--scene-ink, #fff6e2); text-shadow: 0 0 44px rgba(255,150,50,0.35); }
#ch-approach .kicker, #ch-approach .scene-copy { color: var(--scene-ink, #ffe9c4); }

.warning-list { list-style: none; margin-top: 3vh; font-family: var(--mono); font-size: 12px; max-width: 420px; }
.warning-list li {
  padding: 8px 0 8px 22px; position: relative;
  border-bottom: 1px solid rgba(255,200,140,0.18);
  color: var(--scene-ink, #ffd9a8); letter-spacing: .06em;
  opacity: 0; transform: translateX(-10px);
  transition: opacity .5s, transform .5s;
}
.warning-list li.on { opacity: 1; transform: none; }
.warning-list li::before { content: "\25B2"; position: absolute; left: 0; color: var(--ember); font-size: 10px; top: 11px; }

.quote.light { color: var(--scene-ink, #fff3d6); }

/* ================= transmission ================= */
#ch-transmission .scene-ui { padding: 12vh 8vw 0 calc(var(--hud-w) + 7vw); display: flex; flex-direction: column; gap: 3vh; }
#ch-transmission .scene-title { color: #1a0e04; text-shadow: 0 0 30px rgba(255,255,255,0.35); }
#ch-transmission .kicker { color: rgba(26,14,4,0.75); }

.final-tx { max-width: 620px; }
.tx-label { font-family: var(--mono); font-size: 10px; letter-spacing: .3em; color: rgba(26,14,4,0.8); }
.tx-text {
  margin-top: 12px; font-family: var(--mono); font-size: clamp(14px, 1.7vw, 18px);
  line-height: 1.7; color: #1a0e04; white-space: pre-wrap; min-height: 9em;
}
.tx-text::after { content: "\2588"; animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0 } }

/* ================= epilogue ================= */
.epilogue { height: auto; }
.epilogue .stage { position: relative; height: auto; min-height: 100vh; overflow: visible; }
.epilogue-inner {
  max-width: 880px; margin: 0 auto;
  padding: 12vh 24px 14vh;
  display: flex; flex-direction: column; gap: 5vh;
}
.epilogue .scene-title { font-size: clamp(48px, 9vw, 120px); }
.epilogue-prose { max-width: 40em; display: flex; flex-direction: column; gap: 1.2em; font-size: clamp(15px, 1.7vw, 19px); color: var(--ink); opacity: .92; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.stats-grid div { background: #080c1a; padding: 20px 16px; display: flex; flex-direction: column; gap: 4px; }
.stats-grid b { font-family: var(--cond); font-weight: 600; font-size: 34px; color: var(--gold); line-height: 1; }
.stats-grid span { font-family: var(--mono); font-size: 9px; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-dim); }

.cast h3 { font-family: var(--cond); font-weight: 600; letter-spacing: .3em; font-size: 15px; color: var(--ink-dim); margin-bottom: 18px; }
.cast blockquote { border-left: 2px solid var(--line); padding-left: 18px; margin-bottom: 22px; font-style: italic; }
.cast cite { display: block; margin-top: 6px; font-style: normal; font-family: var(--mono); font-size: 10px; letter-spacing: .14em; color: var(--ink-dim); }

.credits { border-top: 1px solid var(--line); padding-top: 4vh; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.credits-title { font-family: var(--cond); font-weight: 700; font-size: 30px; letter-spacing: .4em; }
.credits p { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; color: var(--ink-dim); }
#replay {
  margin-top: 18px; padding: 14px 28px; min-height: 44px;
  font-family: var(--mono); font-size: 11px; letter-spacing: .26em;
  color: var(--gold); background: none; border: 1px solid rgba(255,184,77,0.45); border-radius: 4px;
  cursor: pointer; transition: background .25s, color .25s;
}
#replay:hover, #replay:focus-visible { background: var(--gold); color: #140b06; outline: none; }

/* ================= log modal ================= */
#log-modal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3,4,10,0.78); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: 20px;
}
#log-modal[hidden] { display: none; }
.modal-card {
  max-width: 560px; width: 100%; max-height: 80vh; overflow-y: auto;
  background: #0a0f22; border: 1px solid var(--line); border-radius: 10px;
  padding: 28px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
}
.modal-meta { font-family: var(--mono); font-size: 10px; letter-spacing: .22em; color: var(--gold); margin-bottom: 10px; }
.modal-card h3 { font-family: var(--cond); font-weight: 600; font-size: 26px; letter-spacing: .08em; margin-bottom: 14px; }
.modal-card p { font-family: var(--mono); font-size: 13px; line-height: 1.8; color: var(--ink); white-space: pre-wrap; }
#modal-close {
  margin-top: 22px; padding: 12px 22px; min-height: 44px;
  font-family: var(--mono); font-size: 10px; letter-spacing: .26em;
  color: var(--ink); background: none; border: 1px solid var(--line); border-radius: 4px; cursor: pointer;
}
#modal-close:hover, #modal-close:focus-visible { border-color: var(--gold); color: var(--gold); outline: none; }

/* ================= responsive: mobile staging ================= */
@media (max-width: 760px) {
  :root { --hud-w: 0px; }

  #hud {
    top: auto; bottom: 0; left: 0; right: 0;
    width: auto; height: auto;
    flex-direction: row; align-items: center;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    gap: 10px;
    background: linear-gradient(0deg, rgba(4,6,14,0.92), rgba(4,6,14,0.7) 75%, transparent);
    border-right: 0; border-top: 1px solid rgba(154,167,199,0.14);
  }
  .hud-brand { display: none; }
  .hud-nav { flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; }
  .hud-nav::-webkit-scrollbar { display: none; }
  #chapter-nav { flex-direction: row; gap: 4px; }
  #chapter-nav button { width: 44px; min-height: 44px; }
  #chapter-nav button s { display: none; }
  .hud-progress { flex: 0 0 64px; flex-direction: column; min-height: 0; justify-content: center; }
  .hud-track { width: 100%; height: 3px; flex: 0 0 3px; }
  .hud-fill { width: 0%; height: 100%; background: linear-gradient(90deg, #7fb2e5, #5f6edb 40%, #ffb84d 85%, #fff3d6); }
  .hud-probe-dot { top: 50%; left: 0%; transform: translate(-50%,-50%); }
  .hud-pct { font-size: 8px; }
  .hud-telemetry { flex: 0 0 auto; flex-direction: row; gap: 10px; width: auto; padding: 0; }
  .hud-telemetry div:nth-child(2), .hud-telemetry div:nth-child(4) { display: none; }
  .hud-telemetry dd { font-size: 9px; }

  .scene-ui { padding-bottom: 84px; } /* keep clear of bottom HUD */

  #ch-launch .scene-ui,
  #ch-sail .scene-ui,
  #ch-slingshot .scene-ui,
  #ch-approach .scene-ui,
  #ch-transmission .scene-ui {
    padding-left: 6vw; padding-right: 6vw; padding-top: 7vh;
  }
  .scene-title { font-size: clamp(44px, 15vw, 84px); }
  .quote { margin-bottom: 16vh; font-size: 16px; }

  .cruise-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    padding: 7vh 5vw 84px;
    gap: 2.5vh;
  }
  .log-panel { max-height: 38vh; }
  .inst-panel { flex-direction: row; flex-wrap: wrap; gap: 10px 18px; }
  .inst dd { font-size: 14px; }

  .scroll-hint { right: auto; left: 6vw; bottom: 21vh; }
  .checklist li { max-width: none; }
  .warning-list { max-width: none; }
}

@media (max-width: 380px) {
  .hud-telemetry div:nth-child(3) { display: none; }
}

/* ================= reduced motion: static composition ================= */
html.reduced .chapter { height: auto; }
html.reduced .stage { position: relative; height: 100vh; height: 100svh; }
html.reduced .epilogue .stage { height: auto; }
html.reduced .reveal { opacity: 1 !important; transform: none !important; }
html.reduced .fade { display: none; }
html.reduced .hint-line { animation: none; }
html.reduced .tx-text::after { animation: none; }
html.reduced .checklist li, html.reduced .warning-list li { opacity: 1; transform: none; transition: none; }
html.reduced #log-list button { opacity: 1; transform: none; transition: none; }
html.reduced .scene-ui > * { margin-bottom: 8px; }
