:root {
  color-scheme: dark;
  --bg: #121212;
  --surface: #1e1c1b;
  --surface-2: #282522;
  --line: #3b3631;
  --text: #f4eee6;
  --muted: #b8aea3;
  --teal: #48d1c8;
  --amber: #ffbd54;
  --red: #ff5d61;
  --green: #81df82;
  --violet: #bca7ff;
  --shadow: 0 24px 80px rgb(0 0 0 / 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.035), transparent 260px),
    radial-gradient(circle at 10% 0%, rgb(72 209 200 / 0.12), transparent 320px),
    radial-gradient(circle at 85% 8%, rgb(255 189 84 / 0.08), transparent 260px),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  height: 100vh;
  overflow: hidden;
  padding: 10px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 12px;
  align-items: end;
  max-width: 1800px;
  width: 100%;
  margin: 0 auto;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 980px;
  margin-bottom: 0;
  font-size: clamp(1.18rem, 1.55vw, 1.9rem);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 12px;
  font-size: 0.92rem;
  letter-spacing: 0;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(96px, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.status-strip div {
  padding: 9px 10px;
  background: rgb(30 28 27 / 0.9);
}

.status-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

.status-strip strong {
  font-size: 1rem;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(480px, 1fr) 340px;
  gap: 10px;
  max-width: 1800px;
  width: 100%;
  min-height: 0;
  margin: 0 auto;
}

.panel,
.simulation-stage {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(30 28 27 / 0.82);
  box-shadow: var(--shadow);
}

.panel {
  min-height: 0;
  height: 100%;
  overflow: hidden;
  padding: 10px;
}

.preset-row,
.tabs {
  display: grid;
  gap: 1px;
  overflow: hidden;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.preset-row {
  grid-template-columns: repeat(3, 1fr);
}

.tabs {
  grid-template-columns: repeat(5, 1fr);
}

.preset,
.tab {
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
}

.preset:hover,
.tab:hover {
  background: #332f2b;
  color: var(--text);
}

.preset.is-active,
.tab.is-active {
  background: var(--teal);
  color: #101010;
  font-weight: 800;
}

.control-group {
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.control-group:first-of-type {
  border-top: 0;
  padding-top: 0;
}

label {
  display: block;
  margin: 0 0 8px;
}

label span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

output {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.zoom-row {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 8px;
  margin-bottom: 8px;
}

.zoom-row button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.zoom-row button:hover {
  border-color: var(--teal);
}

.scale-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.simulation-stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  background:
    linear-gradient(180deg, rgb(129 223 130 / 0.04), transparent 26%),
    linear-gradient(0deg, rgb(72 209 200 / 0.05), transparent 28%),
    #171615;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.legend {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: 8px;
  background: rgb(20 19 19 / 0.72);
  color: var(--muted);
  backdrop-filter: blur(8px);
  font-size: 0.78rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.simulation-stage.show-legend .legend {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 999px;
}

.electron { background: var(--teal); box-shadow: 0 0 12px var(--teal); }
.proton { background: var(--amber); box-shadow: 0 0 12px var(--amber); }
.leak { background: var(--violet); box-shadow: 0 0 12px var(--violet); }
.ros { background: var(--red); box-shadow: 0 0 12px var(--red); }
.atp { background: var(--green); box-shadow: 0 0 12px var(--green); }

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}

.metrics-grid div,
.equation-card,
.claim-boundary,
.audit-trail p,
.method-list p,
.parameter-card,
.structure-card,
.narration-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgb(40 37 34 / 0.72);
}

.metrics-grid div {
  padding: 8px;
}

dt {
  color: var(--muted);
  font-size: 0.72rem;
}

dd {
  margin: 4px 0 0;
  font-size: 1.04rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.equation-card,
.claim-boundary {
  padding: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.claim-boundary {
  margin-bottom: 12px;
  border-color: rgb(255 189 84 / 0.45);
}

.formula {
  margin-bottom: 6px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.method-list,
.audit-trail,
.parameter-cards,
.structure-cards {
  display: grid;
  gap: 7px;
  margin: 10px 0;
}

.method-list p,
.audit-trail p,
.parameter-card,
.structure-card,
.narration-card {
  margin: 0;
  padding: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.audit-trail strong,
.parameter-card strong,
.structure-card strong,
.narration-card strong {
  color: var(--text);
}

.parameter-card small,
.structure-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.structure-card a {
  color: var(--teal);
  text-decoration: none;
}

.structure-card a:hover {
  text-decoration: underline;
}

.source-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  margin: 0 6px 8px 0;
  padding: 0 12px;
  border: 1px solid var(--teal);
  border-radius: 8px;
  color: var(--teal);
  text-decoration: none;
}

.source-link:hover {
  background: rgb(72 209 200 / 0.12);
}

.narration-card {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  max-height: calc(100vh - 150px);
  overflow: hidden;
}

.readout-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.tab-panel.is-active {
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.tab-panel.is-active#guidePanel {
  overflow: hidden;
}

.narration-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.narration-status strong {
  color: var(--amber);
  font-variant-numeric: tabular-nums;
}

.narration-card p {
  margin: 0;
  max-height: 14vh;
  overflow: auto;
  color: var(--muted);
  line-height: 1.45;
}

.narration-focus {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.narration-focus div {
  display: grid;
  gap: 3px;
  padding: 7px;
  border: 1px solid rgb(255 255 255 / 0.08);
  border-radius: 8px;
  background: rgb(18 18 18 / 0.42);
}

.narration-focus span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.narration-focus strong {
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.25;
}

.narration-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  order: -1;
}

.narration-controls button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.narration-controls button:hover {
  border-color: var(--teal);
  color: var(--teal);
}

@media (max-width: 1180px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .panel,
  .simulation-stage {
    min-height: auto;
    overflow: hidden;
  }

  .simulation-stage {
    order: 1;
    height: min(48vh, 430px);
  }

  .readout-panel {
    order: 2;
    max-height: 48vh;
  }

  .controls-panel {
    order: 3;
    max-height: 52vh;
    overflow: auto;
  }

  canvas {
    height: 100%;
  }

  .controls-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .preset-row {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    gap: 8px;
    padding: 8px;
  }

  .topbar {
    gap: 8px;
  }

  .eyebrow {
    margin-bottom: 4px;
    font-size: 0.66rem;
  }

  h1 {
    font-size: 1.02rem;
    line-height: 1.08;
  }

  .status-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .status-strip div {
    padding: 7px;
  }

  .status-label {
    font-size: 0.6rem;
  }

  .status-strip strong {
    font-size: 0.78rem;
    white-space: normal;
  }

  .controls-panel {
    grid-template-columns: 1fr;
  }

  .workspace {
    gap: 10px;
  }

  .simulation-stage {
    height: 42vh;
    min-height: 300px;
  }

  canvas {
    height: 100%;
    min-height: 0;
  }

  .legend {
    position: static;
    margin: 10px;
  }

  .tabs,
  .narration-controls {
    grid-template-columns: 1fr 1fr;
  }
}
