:root {
  color-scheme: dark;
  --bg: #020617;
  --panel: rgba(8, 15, 32, 0.95);
  --panel-solid: #081020;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.32);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #67e8f9;
  --accent-2: #fbbf24;
  --danger: #fb7185;
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input { font: inherit; }

button,
a,
summary,
input { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
summary:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 75%, white);
  outline-offset: 3px;
}

button { color: inherit; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--text);
  color: var(--bg);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.topbar {
  position: fixed;
  z-index: 20;
  inset: 0 0 auto;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(2, 6, 23, 0.86);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 43px;
  height: 43px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid color-mix(in srgb, var(--accent) 46%, transparent);
  border-radius: 50%;
  background: #071224;
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.04em;
  box-shadow: inset 0 0 24px color-mix(in srgb, var(--accent) 12%, transparent);
}

.brand strong,
.brand small {
  display: block;
  max-width: min(55vw, 620px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand strong { font-size: 15px; letter-spacing: -0.01em; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 10px; }

.top-status {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.1em;
}

.top-progress {
  width: 120px;
  height: 3px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--line);
}

.top-progress i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent);
  transition: width 300ms ease;
}

.experience { position: fixed; inset: 72px 0 82px; }

.scene {
  position: absolute;
  inset: 0 430px 0 0;
  overflow: hidden;
  background: #020617;
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset -40px 0 70px rgba(2, 6, 23, 0.7);
}

#sim-canvas { display: block; width: 100%; height: 100%; }

.scene-caption {
  position: absolute;
  z-index: 3;
  top: 20px;
  left: 22px;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: calc(100% - 330px);
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.72);
  color: var(--muted);
  font-size: 10px;
  backdrop-filter: blur(12px);
}

.scene-caption span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pulse {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 12%, transparent);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse { 50% { box-shadow: 0 0 0 9px transparent; } }

.scene-actions {
  position: absolute;
  z-index: 4;
  top: 20px;
  right: 22px;
  display: flex;
  gap: 7px;
}

.scene-actions button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.76);
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

.scene-actions button:hover,
.scene-actions button[aria-pressed="true"] {
  border-color: var(--line-strong);
  color: var(--text);
}

.scene-actions .perturb-button {
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: #fda4af;
}

.scene-actions .perturb-button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--danger) 13%, rgba(2, 6, 23, 0.8));
  color: #fecdd3;
}

.particle-legend {
  position: absolute;
  z-index: 3;
  left: 22px;
  bottom: 65px;
  display: flex;
  flex-wrap: wrap;
  gap: 13px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(2, 6, 23, 0.7);
  color: var(--muted);
  font-size: 9px;
  backdrop-filter: blur(10px);
}

.particle-legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.deuterium { background: #67e8f9; }
.dot.tritium { background: #fbbf24; }
.dot.alpha { background: #f472b6; }
.dot.neutron { background: #f8fafc; }

.guide {
  position: absolute;
  z-index: 6;
  inset: 0 0 0 auto;
  width: 430px;
  border-left: 1px solid var(--line);
  background: var(--panel);
  box-shadow: -24px 0 70px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(18px);
}

.guide-scroll {
  height: 100%;
  padding: 29px 31px 52px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.eyebrow {
  display: flex;
  justify-content: space-between;
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow span:last-child { color: var(--muted); }

.guide h1 {
  margin: 0;
  font-family: Iowan Old Style, Baskerville, Georgia, "Times New Roman", serif;
  font-size: clamp(31px, 3vw, 43px);
  font-weight: 500;
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.stage-short {
  margin: 15px 0 21px;
  color: #cbd5e1;
  font-size: 14px;
  line-height: 1.55;
}

.transition {
  display: grid;
  gap: 1px;
  overflow: hidden;
  margin: 0 0 21px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--line);
}

.transition > div {
  display: grid;
  grid-template-columns: 82px 1fr;
  align-items: baseline;
  gap: 8px;
  padding: 9px 11px;
  background: rgba(2, 6, 23, 0.78);
}

.transition span,
.section-label {
  color: var(--muted);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.transition strong { font-size: 11px; font-weight: 650; line-height: 1.45; }
.transition .mechanism strong { color: var(--accent-2); }

.stage-body {
  margin: 0 0 23px;
  color: #b8c4d4;
  font-family: Iowan Old Style, Baskerville, Georgia, "Times New Roman", serif;
  font-size: 15.5px;
  line-height: 1.7;
}

details { border-top: 1px solid var(--line); }

summary {
  position: relative;
  padding: 14px 24px 14px 0;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; position: absolute; right: 2px; color: var(--muted); font-size: 17px; font-weight: 400; }
details[open] summary::after { content: "−"; }

.simplification dl { display: grid; gap: 10px; margin: 0 0 16px; }
.simplification dl div { display: grid; grid-template-columns: 82px 1fr; gap: 8px; }
.simplification dt { color: var(--accent-2); font-size: 9px; }
.simplification dd { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.55; }

.question,
.sources { margin-top: 21px; padding-top: 19px; border-top: 1px solid var(--line); }
.question h2 { margin: 7px 0 12px; font-size: 14px; line-height: 1.4; }
.choices { display: grid; gap: 7px; }

.choice {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(2, 6, 23, 0.6);
  color: #cbd5e1;
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}

.choice:hover { border-color: var(--line-strong); color: var(--text); }
.choice.correct { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.choice.incorrect { border-color: var(--danger); }
.question-feedback { margin: 10px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-heading > span { color: var(--muted); font-size: 8px; }
.sources ul { display: grid; gap: 9px; margin: 12px 0 0; padding: 0; list-style: none; }
.sources a { display: grid; grid-template-columns: auto 1fr; gap: 8px; color: #cbd5e1; font-size: 10px; line-height: 1.4; text-decoration: none; }
.sources a:hover { color: var(--accent); }
.source-kind { align-self: start; padding: 2px 5px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 7px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.method-note { margin-top: 21px; }
.method-note p { margin: 0 0 16px; color: var(--muted); font-size: 10px; line-height: 1.55; }

.stage-rail {
  position: absolute;
  z-index: 4;
  right: 22px;
  bottom: 17px;
  left: 22px;
  overflow-x: auto;
  padding: 3px;
  scrollbar-width: none;
}

.stage-rail::-webkit-scrollbar { display: none; }
.stage-rail ol { display: flex; min-width: max-content; margin: 0; padding: 0; list-style: none; }
.stage-rail li { position: relative; padding-right: 6px; }
.stage-rail li:not(:last-child)::after { content: ""; position: absolute; top: 17px; right: -1px; width: 8px; height: 1px; background: var(--line-strong); }

.stage-button {
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(2, 6, 23, 0.76);
  color: var(--muted);
  font-size: 9px;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

.stage-button span { margin-right: 7px; color: #64748b; font-variant-numeric: tabular-nums; }
.stage-button:hover { color: var(--text); }
.stage-button[aria-current="step"] { border-color: color-mix(in srgb, var(--accent) 55%, transparent); background: color-mix(in srgb, var(--accent) 11%, rgba(2, 6, 23, 0.9)); color: var(--accent); }
.stage-button[aria-current="step"] span { color: var(--accent); }
.stage-button.seen:not([aria-current="step"]) { color: #cbd5e1; }

.controls {
  position: fixed;
  z-index: 20;
  inset: auto 0 0;
  height: 82px;
  display: grid;
  grid-template-columns: auto minmax(220px, 360px) 1fr;
  align-items: center;
  gap: 25px;
  padding: 0 26px;
  border-top: 1px solid var(--line);
  background: rgba(2, 6, 23, 0.94);
  backdrop-filter: blur(18px);
}

.transport { display: flex; align-items: center; gap: 8px; }
.transport button { width: 37px; height: 37px; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.transport button:hover { border-color: var(--line-strong); color: var(--text); }
.transport .play { width: 47px; height: 47px; border-color: color-mix(in srgb, var(--accent) 50%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); color: var(--accent); font-weight: 800; }

.speed-control {
  display: grid;
  grid-template-columns: auto 1fr 34px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.speed-control input { width: 100%; accent-color: var(--accent); }
.speed-control output { color: var(--text); font-variant-numeric: tabular-nums; text-align: right; }
.shortcut-hint { justify-self: end; margin: 0; color: var(--muted); font-size: 9px; }
kbd { display: inline-block; min-width: 22px; margin: 0 3px 0 7px; padding: 3px 5px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--panel-solid); color: #cbd5e1; font: 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@media (max-width: 1050px) {
  .scene { right: 390px; }
  .guide { width: 390px; }
  .guide-scroll { padding: 26px 25px 48px; }
  .shortcut-hint { display: none; }
  .controls { grid-template-columns: auto minmax(180px, 320px); }
}

@media (max-width: 760px) {
  .topbar { height: 64px; padding: 0 14px; }
  .brand-mark { width: 36px; height: 36px; font-size: 9px; }
  .brand strong { max-width: 190px; font-size: 12px; }
  .brand small { display: none; }
  .top-progress { width: 62px; }

  .experience {
    inset: 64px 0 74px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .scene {
    position: relative;
    inset: auto;
    width: 100%;
    height: 43vh;
    min-height: 310px;
  }

  .scene::after { box-shadow: inset 0 -35px 55px rgba(2, 6, 23, 0.75); }
  .scene-caption { top: 12px; left: 12px; max-width: calc(100% - 130px); padding: 7px 9px; font-size: 9px; }
  .scene-actions { top: 12px; right: 12px; }
  .scene-actions button { min-height: 30px; padding: 0 9px; font-size: 8px; }
  .scene-actions .view-button { display: none; }
  .particle-legend { display: none; }
  .stage-rail { right: 9px; bottom: 9px; left: 9px; }
  .stage-button { min-height: 32px; padding: 0 9px; font-size: 8px; }

  .guide {
    position: relative;
    inset: auto;
    width: 100%;
    min-height: 600px;
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.26);
  }

  .guide-scroll { height: auto; padding: 25px 20px 56px; overflow: visible; }
  .guide h1 { font-size: 35px; }
  .stage-short { font-size: 14px; }
  .transition > div { grid-template-columns: 78px 1fr; }

  .controls {
    height: 74px;
    grid-template-columns: auto 1fr;
    gap: 15px;
    padding: 0 14px;
  }

  .transport button { width: 34px; height: 34px; }
  .transport .play { width: 42px; height: 42px; }
  .speed-control { grid-template-columns: 1fr 28px; gap: 6px; }
  .speed-control span { display: none; }
}

@media (max-width: 390px) {
  .brand strong { max-width: 155px; }
  .top-status { gap: 7px; }
  .top-progress { width: 45px; }
  .scene { min-height: 285px; }
  .stage-button { padding: 0 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
