:root {
  --bg: #0f1220;
  --panel: #171b2e;
  --line: #2a3050;
  --text: #e6e9f5;
  --muted: #8b93b8;
  --accent: #7c9cff;
  --pos: #4ea8ff;
  --neg: #ff7a59;
  --gold: #ffd166;
  --chg: #ffd640;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, select, input {
  font: inherit;
  color: var(--text);
  background: #232842;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.active, button.primary { background: var(--accent); color: #0b0e1a; border-color: transparent; font-weight: 600; }
input[type="number"] { width: 72px; }
input[type="range"] { padding: 0; width: 110px; vertical-align: middle; accent-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }
code, kbd { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #232842; border-radius: 4px; padding: 1px 5px; }
kbd { border: 1px solid var(--line); }

header.top {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; }
.brand small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.modes { display: flex; flex-wrap: wrap; gap: 6px; }
.modes button { padding: 7px 14px; }
.modes small { opacity: 0.75; font-weight: 400; margin-left: 4px; }

main { max-width: 1500px; margin: 0 auto; padding: 12px 16px 40px; }

.stage { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #5aa2e6; }
#game { display: block; width: 100%; aspect-ratio: 5 / 2; max-height: 50vh; }
.hud {
  position: absolute;
  left: 10px;
  top: 22px;
  right: 10px;
  width: fit-content;
  background: rgba(10, 12, 26, 0.72);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
  pointer-events: none;
}
.hud .lvl { color: var(--gold); margin-right: 6px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px 22px; align-items: center; padding: 10px 0 0; }
.toolbar.settings { padding: 8px 12px; margin-top: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; gap: 8px 18px; }
.toolbar label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.toolbar output { color: var(--text); min-width: 34px; font-variant-numeric: tabular-nums; }
.group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lbl { color: var(--muted); margin-right: 2px; }
.reset-hint { color: var(--gold); font-size: 12.5px; }

.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; margin-top: 12px; }
@media (min-width: 1100px) {
  .panels { grid-template-columns: 1.35fr 1fr; }
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.panel h2 { font-size: 14px; margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.panel h2 select { margin-left: auto; font-size: 12px; padding: 3px 6px; }
.panel h3 { font-size: 12.5px; color: var(--muted); font-weight: 500; margin: 10px 0 4px; }
.sub { color: var(--muted); font-weight: 400; font-size: 12px; }
#net { display: block; width: 100%; height: 340px; }
#heat { display: block; width: 100%; height: 230px; }
#chart { display: block; width: 100%; height: 190px; }
#chart2 { display: block; width: 100%; height: 100px; }
.caption { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
.legend { font-size: 12px; display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.chg { color: var(--chg); }
.up { color: #2ecc71; }
.down { color: var(--neg); }

.explain p, .explain ol { margin: 0 0 8px; }
.explain ol { padding-left: 20px; }
.explain li { margin-bottom: 3px; }
.tip { color: var(--muted); font-size: 12.5px; border-left: 3px solid var(--accent); padding-left: 8px; }
.log { margin: 8px 0 0; padding: 8px 8px 8px 26px; max-height: 190px; overflow: auto; background: #10142a; border-radius: 8px; font-size: 12.5px; }
.log:empty { display: none; }
.log li { margin-bottom: 2px; }

.concepts { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.concepts summary { cursor: pointer; font-weight: 600; }
.concept-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 4px 18px; margin-top: 8px; }
.concept-grid h4 { margin: 10px 0 2px; color: var(--accent); font-size: 13.5px; }
.concept-grid p { margin: 0; color: #c9cfe8; font-size: 13px; }

body:not(.mode-evo) .only-evo,
body:not(.mode-dqn) .only-dqn,
body.mode-play .not-play { display: none !important; }

@media (max-width: 600px) {
  main { padding: 10px 10px 30px; }
  .hud { font-size: 11.5px; top: 18px; }
  #net { height: 300px; }
}
.modes .lang { margin-left: 6px; background: transparent; }

/* ── Step-by-step tour ── */
.panel.wide { grid-column: 1 / -1; }
.tour summary { cursor: pointer; font-weight: 700; font-size: 15px; margin-bottom: 8px; }
.tour-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tour-steps button { font-size: 12.5px; padding: 4px 9px; }
.tour-text p, .tour-text ul, .tour-text ol { margin: 0 0 8px; }
.tour-text ul, .tour-text ol { padding-left: 20px; }
.tour-code { margin-top: 10px; }
.code-title { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.tour-code pre {
  margin: 0; padding: 10px 12px; background: #0b0e1c; border: 1px solid var(--line); border-radius: 8px;
  font: 12px/1.55 ui-monospace, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere;
}
.c-com { color: #7f88aa; }
.c-kw { color: #c792ea; }
.c-num { color: #f78c6c; }
.c-str { color: #c3e88d; }
.c-live { color: var(--gold); font-weight: 700; background: rgba(255, 209, 102, 0.12); border-radius: 3px; padding: 0 2px; }
.tour-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tour-foot button:disabled { opacity: 0.4; cursor: default; }
.tour-paused { color: var(--gold); font-size: 12.5px; margin: 8px 0 0; }

.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0 10px; }
.flow div { background: #232842; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; text-align: center; font-size: 18px; min-width: 88px; }
.flow b { display: block; font-size: 13px; }
.flow small { display: block; color: var(--muted); font-size: 11px; }
.flow span { color: var(--muted); font-size: 18px; }

table.eyes { border-collapse: collapse; margin: 4px 0; font-size: 12px; }
table.eyes th { color: var(--muted); font-weight: 400; padding: 2px 6px; text-align: right; }
table.eyes td { width: 34px; height: 26px; text-align: center; border: 1px solid var(--line); font-family: ui-monospace, monospace; }
table.eyes td.solid { background: rgba(78, 168, 255, 0.35); }
table.eyes td.danger { background: rgba(255, 60, 60, 0.45); }
table.eyes td.ahead { border: 0; color: var(--muted); text-align: left; font-family: inherit; }
.extra { color: var(--muted); font-size: 12.5px; }

table.calc { border-collapse: collapse; font-size: 12.5px; margin: 4px 0 6px; width: 100%; }
table.calc th { color: var(--muted); font-weight: 400; text-align: left; border-bottom: 1px solid var(--line); padding: 3px 6px; }
table.calc td { padding: 3px 6px; border-bottom: 1px solid rgba(42, 48, 80, 0.5); font-variant-numeric: tabular-nums; }
table.calc td.muted, .muted { color: var(--muted); }
.eq { background: #10142a; border-radius: 8px; padding: 6px 10px; font-family: ui-monospace, monospace; font-size: 12.5px; }
.tanh-box { display: flex; align-items: center; gap: 10px; margin: 4px 0 8px; color: var(--muted); }
svg.tanh .ax { stroke: #2a3050; }
svg.tanh .curve { fill: none; stroke: var(--pos); stroke-width: 2; }
svg.tanh .dot { fill: var(--gold); }
svg.tanh text { fill: var(--muted); font-size: 10px; }

.bars { display: grid; gap: 3px; margin: 4px 0 8px; }
.tbar { display: grid; grid-template-columns: 82px 1fr 48px; gap: 8px; align-items: center; font-size: 12px; }
.tbar.on { color: var(--gold); font-weight: 700; }
.tbar .track { position: relative; height: 10px; background: #232842; border-radius: 5px; }
.tbar .track::after { content: ''; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--muted); }
.tbar i { position: absolute; top: 0; bottom: 0; border-radius: 5px; }
.tbar i.p { background: var(--pos); }
.tbar i.n { background: var(--neg); }
.tbar code { background: none; text-align: right; }
.diffs { font-size: 12.5px; }

/* ── 🧪 Neuron lab ── */
.lab { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin: 6px 0 4px; }
.lab-col { min-width: 0; }
.lab-input { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.lab-input button { width: 40px; height: 40px; font: 700 18px ui-monospace, monospace; border-radius: 8px; background: #10142a; border: 2px solid var(--accent); }
.lab-input b { display: block; font-size: 13px; }
.lab-input small { color: var(--muted); font-size: 11.5px; }
.lab-slider { display: grid; grid-template-columns: 70px 1fr 44px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.lab-slider input { width: 100%; }
.lab-slider output { font-family: ui-monospace, monospace; text-align: right; }
.lab-verdict { font-weight: 700; margin: 6px 0; }
.st-on { color: #2ecc71; }
.st-off { color: var(--muted); }
.st-mid { color: var(--gold); }
.lab-table tr.cur td { background: rgba(124, 156, 255, 0.15); }
.lab-h { margin: 12px 0 4px; font-size: 13.5px; }
.lab-challenges { padding-left: 20px; margin: 0 0 8px; }
.lab-challenges li { margin-bottom: 5px; }
.lab-challenges li.done { color: #2ecc71; }
.lab-challenges button { font-size: 11.5px; padding: 1px 7px; margin-left: 4px; }
.lab-challenges .ck { display: inline-block; width: 1.4em; }
.lab-why { background: #10142a; border-left: 3px solid var(--gold); border-radius: 6px; padding: 8px 10px; margin: 6px 0; color: var(--text); }
