:root {
  --bg: #0c1114;
  --stage: #0e1418;
  --panel: #141b20;
  --line: #2a3841;
  --ink: #e7efeb;
  --muted: #8ea399;
  --faint: #617068;
  --teal: #3ddec0;
  --amber: #ffb03a;
  --blue: #9eb6ff;
  --rose: #ff5c78;
  --lilac: #d4c4ff;
  --hot: #ff4462;
  --good: #7dcea0;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Public Sans", "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0.01em;
}

button, input { font: inherit; color: inherit; }

button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

button:hover:not(:disabled) { border-color: #6d8280; }

button:disabled { opacity: 0.38; cursor: default; }

button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.mark {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-weight: 560;
  font-size: 28px;
  letter-spacing: -0.03em;
  line-height: 1;
}

.thesis {
  margin: 6px 0 0;
  max-width: 46rem;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.chapter {
  margin: 0;
  color: var(--teal);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  background:
    radial-gradient(1200px 700px at 50% 45%, #182228 0%, var(--stage) 70%);
}

.stage canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.stage::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 90px rgba(0, 0, 0, 0.25);
}

.legend {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.legend span { display: flex; align-items: center; gap: 7px; }

.swatch {
  width: 18px;
  height: 3px;
  border-radius: 99px;
  display: inline-block;
}

.swatch.truth { background: var(--teal); }
.swatch.odom { background: var(--amber); }
.swatch.est { background: var(--blue); }
.swatch.hot { background: linear-gradient(90deg, #8fb3a8, var(--hot)); height: 4px; }
.swatch.loop { background: var(--rose); height: 4px; }
.swatch.sight { background: var(--lilac); height: 2px; }

.route {
  position: absolute;
  left: 16px;
  right: 16px;
  top: 34px;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 99px;
  overflow: hidden;
}

.route span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--teal);
}

.drive-hint {
  position: absolute;
  right: 16px;
  bottom: 12px;
  margin: 0;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.toast {
  position: absolute;
  top: 46px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 48px));
  padding: 10px 14px;
  background: rgba(16, 22, 26, 0.92);
  border: 1px solid rgba(61, 222, 192, 0.35);
  border-radius: 12px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.toast.on { opacity: 1; }

.tooltip {
  position: absolute;
  z-index: 2;
  max-width: 230px;
  padding: 8px 10px;
  background: rgba(10, 14, 16, 0.94);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  color: var(--ink);
}

.tooltip b { font-weight: 600; }
.tooltip .dim { color: var(--muted); }

aside {
  width: 400px;
  flex: none;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 16px 28px;
}

.lesson h2 {
  margin: 4px 0 8px;
  font-family: Fraunces, Georgia, serif;
  font-weight: 560;
  font-size: 24px;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.kicker {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.body p {
  margin: 0 0 8px;
  color: #d5e0db;
  font-size: 14px;
  line-height: 1.45;
}

.body p:last-child { margin-bottom: 0; }

.term { color: var(--teal); font-weight: 600; }

.watch {
  margin: 10px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--amber);
  font-size: 13px;
  line-height: 1.4;
}

.fig { margin: 8px 0; }
.fig svg { width: 100%; height: auto; display: block; }
.fig .formula {
  margin: 0;
  padding: 8px 10px;
  background: #10171b;
  border-radius: 8px;
  font-family: Fraunces, Georgia, serif;
  font-size: 16px;
  line-height: 1.45;
}
.fig .formula.dim {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.nav button { padding: 6px 10px; font-size: 13px; }

.dots { display: flex; gap: 6px; flex: 1; justify-content: center; }

.dots button {
  width: 8px;
  height: 8px;
  padding: 0;
  border-radius: 99px;
  border-color: #3d4f4c;
  background: #3d4f4c;
}

.dots button.on {
  background: var(--teal);
  border-color: var(--teal);
  width: 18px;
}

.callout, .banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.4;
  font-size: 13.5px;
}

.callout {
  background: rgba(255, 92, 120, 0.08);
  border: 1px solid rgba(255, 92, 120, 0.45);
}

.callout strong { display: block; margin-bottom: 2px; }

.banner {
  background: rgba(255, 68, 98, 0.12);
  border: 1px solid var(--hot);
  white-space: pre-wrap;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
}

.controls { display: flex; flex-direction: column; gap: 8px; }

.row { display: flex; gap: 8px; align-items: center; }

.row button { flex: 1; }

button.primary {
  background: var(--ink);
  color: #12181c;
  border-color: var(--ink);
  font-weight: 600;
}

button.optimize {
  background: #143f38;
  border-color: #1f6d60;
  color: var(--teal);
  font-weight: 600;
}

button.loop {
  border-color: rgba(255, 92, 120, 0.7);
  color: #ffd0d8;
}

button.texty {
  border: none;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 4px;
  border-radius: 6px;
}

.seed {
  color: var(--faint);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

button.suggest:not(:disabled) {
  animation: pulse 1.6s ease-in-out infinite;
}

#btn-loop.suggest:not(:disabled) { animation-name: pulse-rose; }
#lab-land.suggest, #btn-false.suggest:not(:disabled) {
  animation: pulse-rose 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% { box-shadow: 0 0 0 4px rgba(61, 222, 192, 0.22); }
}

@keyframes pulse-rose {
  50% { box-shadow: 0 0 0 4px rgba(255, 92, 120, 0.22); }
}

.toggles {
  margin: 14px 0 0;
  padding: 8px 0 0;
  border: none;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.toggles legend {
  padding: 0;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.check {
  display: flex;
  gap: 7px;
  align-items: center;
  font-size: 13px;
  color: #d5e0db;
}

#lab-land { grid-column: 1 / -1; }

.metrics {
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 16px;
}

.metrics div { min-width: 0; }
.metrics .wide { grid-column: 1 / -1; }

.metrics dt {
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.metrics dd {
  margin: 1px 0 0;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.metrics dd.good { color: var(--teal); }
.metrics dd.bad { color: var(--amber); }
.metrics dd.over { color: var(--teal); }
.metrics dd.exact { color: var(--amber); }
.metrics dd.under { color: var(--rose); }

.footnote {
  margin: 8px 0 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.4;
}

#chart {
  width: 100%;
  height: 84px;
  margin-top: 12px;
  display: block;
  background: #10171b;
  border-radius: 8px;
}

.chart-cap {
  margin: 4px 0 0;
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.04em;
}

details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 8px; }

summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  margin-top: 10px;
  font-size: 13px;
  color: #d5e0db;
}

.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--teal); }
.slider output { color: var(--muted); font-variant-numeric: tabular-nums; }

#experiments .row { margin-top: 10px; }
#experiments .texty { margin-top: 8px; }

#test-out {
  margin: 8px 0 0;
  padding: 8px;
  background: #10171b;
  border-radius: 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.keys {
  margin: 16px 0 0;
  color: var(--faint);
  font-size: 12px;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-family: inherit;
}

@media (max-width: 980px) {
  .workspace { flex-direction: column; }
  .stage { min-height: 68vh; flex: none; }
  aside { width: auto; border-left: none; border-top: 1px solid var(--line); }
  .top { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  button.suggest:not(:disabled),
  #lab-land.suggest,
  #btn-false.suggest:not(:disabled) { animation: none; outline: 1px solid var(--teal); }
  .toast { transition: none; }
}
