/* Jessco — brand tokens first; components use only these. */
:root {
  --void: #05070D;
  --ink: #111A2E;
  --star: #E8ECF4;
  --regolith: #98A2B3;
  --plasma: #6FB7FF;
  --gold: #F2C46D;
  --gold-hi: #F7D795;
  --void-rgb: 5, 7, 13;
  --ink-rgb: 17, 26, 46;
  --regolith-rgb: 152, 162, 179;
  --line: rgba(var(--regolith-rgb), 0.28);

  /* Newsreader loads as its fixed display cut (opsz 72, weight 400 + italic), so headlines stay at 400.
     The logo is drawn, not typeset (tools/make_logo.py), so it needs no font. */
  --f-display: "Newsreader", Georgia, "Times New Roman", serif;
  --f-body: "Instrument Sans", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --t-hero: clamp(3rem, 6.3vw, 5.9rem);
  --t-h2: clamp(2rem, 3.8vw, 3.4rem);
  --t-body: clamp(1rem, 0.35vw + 0.9rem, 1.15rem);
  --t-small: 0.8125rem;
  --t-mono: 0.75rem;
  --t-label: 0.6875rem;

  --s-1: 0.25rem; --s-2: 0.5rem; --s-3: 0.75rem; --s-4: 1rem; --s-5: 1.5rem; --s-6: 2rem; --s-7: 3rem;
  --gutter: clamp(1rem, 6vw, 6rem);
  --copy-top: 24vh;
  --copy-w: 31rem;

  --dur-ui: 200ms;
  --dur-pop: 250ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; background: var(--void); }
body {
  margin: 0;
  background: var(--void);
  color: var(--star);
  font-family: var(--f-body);
  font-size: var(--t-body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
:focus-visible { outline: 2px solid var(--plasma); outline-offset: 3px; }

.skip {
  position: fixed; left: var(--s-4); top: var(--s-4); z-index: 20;
  padding: var(--s-2) var(--s-4); background: var(--star); color: var(--void);
  font-family: var(--f-mono); font-size: var(--t-small);
  transform: translateY(-200%);
}
.skip:focus { transform: none; }

/* ---------- stage ---------- */
#space { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
.fallback { display: none; }
.no-webgl #space { display: none; }
.no-webgl .fallback {
  display: block; position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 50% 22% at 64% 48%, rgba(255, 214, 160, 0.35), transparent 70%),
    radial-gradient(ellipse 80% 40% at 64% 50%, rgba(111, 183, 255, 0.12), transparent 70%),
    var(--void);
}
.scrim {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: linear-gradient(90deg, rgba(var(--void-rgb), 0.86) 0%, rgba(var(--void-rgb), 0.6) 28%, rgba(var(--void-rgb), 0) 52%);
}
.labels { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-5) var(--gutter);
}
.wordmark { display: block; color: var(--star); text-decoration: none; }
.wordmark svg { display: block; height: 42px; width: auto; overflow: visible; }
.topbar-actions { display: flex; align-items: center; gap: var(--s-2); }
.topbar-cta {
  display: inline-flex; align-items: center; min-height: 40px;
  color: var(--star); text-decoration: none; font-size: var(--t-small); font-weight: 500;
  padding: 0 var(--s-4); border: 1px solid var(--line);
  background: rgba(var(--void-rgb), 0.4);
  transition: border-color var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out);
}
.topbar-cta:hover { border-color: var(--gold); color: var(--gold); }

.progress { display: none; }

/* ---------- chapter rail ---------- */
.rail {
  position: fixed; right: var(--s-5); top: 50%; z-index: 10;
  transform: translateY(-58%);
}
.rail ol { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-1); }
.rail a {
  display: flex; flex-direction: row-reverse; align-items: center; gap: var(--s-3);
  min-height: 24px; color: var(--regolith); text-decoration: none;
  font-family: var(--f-mono); font-size: var(--t-label);
}
.rail-dot {
  width: 7px; height: 7px; flex: none; border: 1px solid var(--regolith); border-radius: 50%;
  transition: background-color var(--dur-ui) var(--ease-out), border-color var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out);
}
.rail-label {
  opacity: 0; transform: translateX(4px); white-space: nowrap;
  padding: 1px 6px; background: rgba(var(--void-rgb), 0.78);
  transition: opacity var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out);
}
.rail a:hover .rail-label, .rail a:focus-visible .rail-label, .rail a[aria-current] .rail-label { opacity: 1; transform: none; }
.rail a:hover .rail-dot { border-color: var(--star); }
.rail a[aria-current] { color: var(--star); }
.rail a[aria-current] .rail-dot { background: var(--gold); border-color: var(--gold); transform: scale(1.3); }

/* ---------- telemetry HUD (signature) ---------- */
.hud {
  position: fixed; right: var(--s-6); bottom: var(--s-6); z-index: 9;
  width: 17.5rem; padding: var(--s-3) var(--s-4) var(--s-2);
  font-family: var(--f-mono); font-size: var(--t-mono); line-height: 1.5;
  background: rgba(var(--ink-rgb), 0.55);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--line);
}
.hud::before, .hud::after {
  content: ""; position: absolute; width: 10px; height: 10px; border-color: var(--gold); border-style: solid;
}
.hud::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; }
.hud::after { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }
.hud-head { display: flex; justify-content: space-between; gap: var(--s-4); color: var(--star); padding-bottom: var(--s-2); font-weight: 500; }
.hud-head span:last-child { color: var(--regolith); font-weight: 400; }
.hud-row {
  display: flex; justify-content: space-between; gap: var(--s-4);
  padding: 0.3rem 0; border-top: 1px dashed rgba(var(--regolith-rgb), 0.22);
}
.hud-row[hidden] { display: none; }
.hud-row .k { color: var(--regolith); }
.hud-row .v { color: var(--star); font-variant-numeric: tabular-nums; text-align: right; }
.hud-row .v.is-key { color: var(--gold); }

/* ---------- 3D labels ---------- */
/* .tag sits on its 3D anchor. updateLabels in main.js places the text around the dot and sets data-slot. */
.tag {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  opacity: 0; transition: opacity var(--dur-ui) var(--ease-out);
  font-family: var(--f-mono); font-size: var(--t-label); line-height: 1.35; white-space: nowrap;
  will-change: transform, opacity;
}
.tag-dot { position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--star); background: rgba(var(--void-rgb), 0.5); }
.tag-text {
  position: absolute; left: 0; top: 0; display: grid; padding: 1px 6px 2px;
  background: rgba(var(--void-rgb), 0.78);
}
.tag.is-placed .tag-text { transition: transform var(--dur-ui) var(--ease-out); }
.tag[data-slot="left"] .tag-text { text-align: right; }
.tag[data-slot="above"] .tag-text, .tag[data-slot="below"] .tag-text { text-align: center; }
.tag-text b { font-weight: 500; color: var(--star); font-size: 0.75rem; }
.tag-text span { color: var(--regolith); }
.tag--gold .tag-dot { border-color: var(--gold); background: var(--gold); }
.tag--gold .tag-text b { color: var(--gold); }
.tag--blue .tag-dot { border-color: var(--plasma); background: var(--plasma); }

/* ---------- arrival callout ---------- */
.arrival {
  position: fixed; left: 0; top: 0; z-index: 8; pointer-events: none;
  opacity: 0; transition: opacity var(--dur-pop) var(--ease-out);
}
.arrival-inner {
  padding: var(--s-4) var(--s-5);
  border-left: 2px solid var(--gold);
  background: linear-gradient(90deg, rgba(var(--void-rgb), 0.82), rgba(var(--void-rgb), 0.55));
  transform: translateY(6px) scale(0.97); transform-origin: left bottom;
  transition: transform var(--dur-pop) var(--ease-out);
}
.arrival.is-on { opacity: 1; }
.arrival.is-on .arrival-inner { transform: none; }
.arrival p { margin: 0; }
.arrival-kicker { font-family: var(--f-mono); font-size: var(--t-mono); color: var(--regolith); }
.arrival-time {
  font-family: var(--f-mono); font-weight: 500; color: var(--gold);
  font-size: clamp(2.75rem, 5vw, 4.25rem); line-height: 1.05; letter-spacing: -0.02em;
}
.arrival-time span { font-size: 0.4em; margin-left: 0.25em; letter-spacing: 0; }
.arrival-line { font-family: var(--f-display); font-weight: 400; font-size: clamp(1.25rem, 1.8vw, 1.6rem); letter-spacing: -0.01em; line-height: 1.2; color: var(--star); }

/* ---------- chapters ---------- */
main { position: relative; z-index: 3; }
.chapter {
  position: relative;
  height: calc(var(--h) * 1vh);
  padding: var(--copy-top) var(--gutter) 0;
}
.copy { position: sticky; top: var(--copy-top); max-width: var(--copy-w); }
.copy > p { margin: 0 0 var(--s-5); max-width: 29rem; text-shadow: 0 1px 12px rgba(var(--void-rgb), 0.8); }
h1, h2 { font-family: var(--f-display); font-weight: 400; letter-spacing: -0.022em; margin: 0 0 var(--s-5); text-wrap: balance; text-shadow: 0 1px 18px rgba(var(--void-rgb), 0.55); }
h1 { font-size: var(--t-hero); line-height: 1; }
h2 { font-size: var(--t-h2); line-height: 1.04; }
h1 em, h2 em { display: block; } /* the italic turn of a headline always starts its own line */
/* Mission-phase label above chapter headlines: blue = active, grey = locked, gold = final */
.copy > .phase {
  display: inline-flex; align-items: center; gap: var(--s-2); margin: 0 0 var(--s-4);
  font-family: var(--f-mono); font-size: var(--t-mono); font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--plasma);
}
.phase::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 10px currentColor; }
.copy > .phase--locked { color: var(--regolith); }
.phase--locked::before { background: none; box-shadow: none; border: 1px solid currentColor; }
.copy > .phase--final { color: var(--gold); }
.chapter--hero { --copy-top: 22vh; }
.chapter--hero .copy { --copy-w: 44rem; }

.cue {
  display: inline-flex; align-items: center; gap: var(--s-3);
  font-family: var(--f-mono); font-size: var(--t-mono); color: var(--regolith);
}
.cue::after {
  content: ""; width: 56px; height: 1px; transform-origin: left;
  background: linear-gradient(90deg, var(--plasma), transparent);
  animation: cue 2.4s var(--ease-out) infinite;
}
@keyframes cue { 0% { transform: scaleX(0.2); opacity: 0.4; } 60% { transform: scaleX(1); opacity: 1; } 100% { transform: scaleX(1); opacity: 0; } }

.stats {
  display: flex; flex-wrap: wrap; gap: var(--s-3) var(--s-6);
  margin: 0; padding-top: var(--s-4); border-top: 1px solid var(--line);
}
.stats div { display: grid; gap: 0.1rem; }
.stats dt { font-family: var(--f-mono); font-size: var(--t-mono); color: var(--regolith); }
.stats dd { margin: 0; font-family: var(--f-mono); font-weight: 500; font-size: 1.05rem; color: var(--gold); font-variant-numeric: tabular-nums; }

.chapter--contact {
  height: auto; min-height: 100vh;
  display: flex; flex-direction: column;
  padding-top: 26vh; padding-bottom: var(--s-6);
}
.chapter--contact .copy { position: static; }
.btn {
  display: inline-flex; align-items: center; gap: var(--s-3);
  padding: 0.85rem 1.4rem; background: var(--gold); color: var(--void); text-decoration: none;
  font-family: var(--f-body); font-weight: 600; font-size: 1.02rem;
  transition: background-color var(--dur-ui) var(--ease-out);
}
.btn span { transition: transform var(--dur-ui) var(--ease-out); }
.btn:hover { background: var(--gold-hi); }
.btn:hover span { transform: translateX(4px); }
.footer { margin-top: auto; padding-top: var(--s-7); }
.footer p { margin: 0; font-family: var(--f-mono); font-size: var(--t-mono); color: var(--regolith); }

/* ---------- tablet ---------- */
@media (max-width: 1100px) {
  .hud { width: 15.5rem; right: var(--s-4); bottom: var(--s-4); }
  .rail { display: none; }
}

/* ---------- phone ---------- */
@media (max-width: 760px) {
  :root { --copy-top: 50svh; --t-h2: 2.15rem; --t-hero: clamp(2.4rem, 11.8vw, 3rem); }
  .chapter { height: calc(var(--h) * 1svh); }
  .chapter--hero { --copy-top: 50svh; }
  .copy > p { font-size: 0.975rem; margin-bottom: var(--s-4); }
  h1, h2 { margin-bottom: var(--s-3); }
  .stats { gap: var(--s-2) var(--s-5); padding-top: var(--s-3); }
  .stats dd { font-size: 0.95rem; }
  .scrim { background: linear-gradient(0deg, rgba(var(--void-rgb), 0.92) 0%, rgba(var(--void-rgb), 0.78) 38%, rgba(var(--void-rgb), 0) 56%); }
  .topbar { padding: var(--s-4); }
  .wordmark svg { height: 34px; }
  .hud {
    top: 64px; left: var(--s-4); right: auto; bottom: auto; width: auto; min-width: 12.5rem;
    padding: var(--s-2) var(--s-3) var(--s-1); font-size: 0.6875rem;
  }
  .hud-row:nth-of-type(n + 5) { display: none; }
  .progress { display: block; position: fixed; left: 0; right: 0; top: 0; height: 2px; z-index: 11; background: rgba(var(--regolith-rgb), 0.15); }
  .progress span { display: block; height: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); }
  .arrival-inner { padding: var(--s-3) var(--s-4); }
  .chapter--contact { height: auto; min-height: 100svh; padding-top: 24svh; } /* grows past one screen on small phones, so the bottom padding still counts */
}

@media (max-width: 360px) { .wordmark svg { height: 30px; } }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cue::after { animation: none; transform: none; opacity: 1; }
  .arrival-inner { transition: none; }
  .tag.is-placed .tag-text { transition: none; }
}

/* keep copy that scrolls under the header from colliding with the wordmark */
.topbar::before {
  content: ""; position: absolute; inset: 0 0 -2.5rem; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg, rgba(var(--void-rgb), 0.92) 0%, rgba(var(--void-rgb), 0.6) 55%, rgba(var(--void-rgb), 0) 100%);
}

.contact-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3) var(--s-5); }
.contact-mail { margin: 0; font-family: var(--f-mono); font-size: var(--t-small); color: var(--regolith); }
.contact-mail span { color: var(--star); user-select: all; }

/* ---------- soundtrack toggle ---------- */
.sound {
  position: relative; /* anchors the idle pulse */
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-width: 40px; min-height: 40px; padding: 0 var(--s-4) 0 var(--s-3);
  color: var(--star); background: rgba(var(--void-rgb), 0.4);
  border: 1px solid var(--line); border-radius: 0;
  font-family: var(--f-mono); font-size: var(--t-mono); cursor: pointer;
  transition: border-color var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out);
}
/* Once playing or muted the icon says it all, and phones only ever show the icon. The words stay for screen readers. */
.sound[data-state="on"], .sound[data-state="muted"] { padding: 0 var(--s-3); }
.sound[data-state="on"] .sound-label, .sound[data-state="muted"] .sound-label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.sound:hover { border-color: var(--gold); color: var(--gold); }
.sound-icon { flex: none; overflow: visible; }
.sound-x { opacity: 0; }
.sound-wave { transition: opacity var(--dur-ui) var(--ease-out); }
.sound[data-state="muted"] .sound-wave, .sound[data-state="ended"] .sound-wave { opacity: 0; }
.sound[data-state="muted"] .sound-x { opacity: 1; }
.sound[data-state="muted"] { color: var(--regolith); }
.sound[data-state="on"] .sound-wave { animation: sound-wave 1.8s ease-in-out infinite; }
.sound[data-state="on"] .sound-wave--far { animation-delay: 0.3s; }
@keyframes sound-wave { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.sound[data-state="idle"]::after {
  content: ""; position: absolute; inset: -1px; border: 1px solid var(--gold); pointer-events: none;
  animation: sound-invite 2.6s var(--ease-out) infinite;
}
@keyframes sound-invite { 0% { opacity: 0.8; transform: scale(1); } 100% { opacity: 0; transform: scale(1.05, 1.3); } }
@media (max-width: 760px) {
  .sound { padding: 0 var(--s-3); }
  .sound .sound-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .chapter--contact { padding-bottom: calc(var(--s-6) + env(safe-area-inset-bottom, 0px)); }
}
@media (prefers-reduced-motion: reduce) {
  .sound[data-state="on"] .sound-wave, .sound[data-state="idle"]::after { animation: none; }
}

.footer { display: grid; gap: var(--s-2); }
.credits { max-width: 60rem; }
/* the telemetry box stays on screen, so the small print wraps to its left */
@media (min-width: 1101px) { .footer { max-width: calc(100vw - var(--gutter) - 17.5rem - var(--s-6) - var(--s-5)); } }
@media (min-width: 761px) and (max-width: 1100px) { .footer { max-width: calc(100vw - var(--gutter) - 15.5rem - var(--s-4) - var(--s-5)); } }
.credits a { color: var(--plasma); text-underline-offset: 2px; }
.credits a:hover { color: var(--star); }

/* ---------- loading ---------- */
.loader {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: var(--void); transition: opacity 700ms var(--ease-out);
}
.loader.is-done { opacity: 0; pointer-events: none; }
.loader[hidden] { display: none; }
.loader-inner { display: grid; justify-items: center; gap: var(--s-4); }
.loader-logo { width: min(520px, 84vw); margin-bottom: var(--s-1); }
.loader-logo svg { display: block; width: 100%; height: auto; overflow: visible; }
.loader-bar { width: min(280px, 70vw); height: 2px; background: rgba(var(--regolith-rgb), 0.2); overflow: hidden; }
.loader-bar span { display: block; height: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); transition: transform 300ms var(--ease-out); }
.loader-status {
  margin: 0; width: min(280px, 70vw); display: flex; justify-content: space-between; gap: var(--s-4);
  font-family: var(--f-mono); font-size: var(--t-mono); color: var(--regolith);
}
.loader-msg { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: opacity 160ms var(--ease-out); }
.loader-msg.is-swap { opacity: 0; }
.loader-pct { color: var(--gold); font-variant-numeric: tabular-nums; }

.loadbar { position: fixed; left: 0; right: 0; top: 0; height: 2px; z-index: 12; pointer-events: none; opacity: 0; transition: opacity 400ms var(--ease-out); }
.loadbar span { display: block; height: 100%; background: var(--plasma); transform-origin: left; transform: scaleX(0); transition: transform 300ms var(--ease-out); }
.is-loaded .loadbar:not(.is-done) { opacity: 0.85; }

.stage-wait {
  position: fixed; z-index: 7; left: 61%; top: 50%; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-4);
  font-family: var(--f-mono); font-size: var(--t-mono); color: var(--star);
  background: rgba(var(--ink-rgb), 0.7); border: 1px solid var(--line);
  opacity: 0; pointer-events: none; transition: opacity var(--dur-ui) var(--ease-out);
}
.stage-wait.is-on { opacity: 1; }
.stage-wait::before { content: ""; width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--plasma); animation: wait-pulse 1.2s ease-in-out infinite; }
@keyframes wait-pulse { 50% { opacity: 0.25; } }
@media (max-width: 900px) { .stage-wait { left: 50%; } }
@media (max-width: 760px) { .loadbar { top: 2px; } .stage-wait { top: 28%; } }
@media (prefers-reduced-motion: reduce) { .stage-wait::before { animation: none; } }
