/* Dark by design: the network view relies on glow against black. */
:root {
  color-scheme: dark;
  --bg: #0d0b0f;
  --panel: #151218;
  --ink: #f2ede8;
  --ink-2: #c4bcb6;
  --ink-3: #8c847f;
  --rule: #2c262d;
  --accent: #f2553a;
  --gold: #ffc37a;
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pixel: "Press Start 2P", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hero {
  max-width: 1180px;
  margin: 0 auto;
  padding: 56px 16px 24px;
}
.eyebrow {
  margin: 0 0 12px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.hero h1 {
  margin: 0 0 12px;
  font: 400 clamp(1.4rem, 4vw, 2.2rem)/1.3 var(--pixel);
  color: #fff;
  text-shadow: 0 0 18px rgba(242, 85, 58, 0.55);
}
.lede { margin: 0; max-width: 680px; color: var(--ink-2); font-size: 1.1rem; }

main { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* ---------- stage ---------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  gap: 20px;
  align-items: stretch;
}
@media (max-width: 900px) { .stage { grid-template-columns: 1fr; } }

.game-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.screen {
  position: relative;
  border: 4px solid #1f1d26;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #3a3340, 0 12px 40px rgba(0, 0, 0, 0.5);
  background: #000;
  line-height: 0;
}
#game {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 2px;
}

.verdict {
  position: absolute;
  top: 10px; right: 10px;
  padding: 6px 10px;
  font: 10px/1.4 var(--pixel);
  color: #1f1d26;
  background: #fbf7ef;
  border: 2px solid #1f1d26;
  opacity: 0;
  pointer-events: none;
}
.verdict.show { animation: pop 1.1s ease-out forwards; }
.verdict.hit { background: #ffd9cf; }
.verdict.miss { background: #d9e6f7; }
@keyframes pop {
  0% { opacity: 0; transform: translateY(4px); }
  12% { opacity: 1; transform: none; }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

.under { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.compass {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  grid-template-rows: auto repeat(3, 34px);
  gap: 4px;
  font-size: 0.8rem;
}
.compass-title {
  grid-column: 1 / -1;
  font: 9px var(--pixel);
  color: var(--ink-3);
  margin-bottom: 4px;
}
#p-0 { grid-column: 2; grid-row: 2; }
#p-3 { grid-column: 1; grid-row: 3; }
#p-1 { grid-column: 3; grid-row: 3; }
#p-2 { grid-column: 2; grid-row: 4; }
.cell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.cell .bar {
  position: absolute; inset: 0 auto 0 0;
  width: calc(var(--v, 0) * 100%);
  background: rgba(242, 85, 58, 0.22);
  transition: width 0.25s;
}
.cell .arrow, .cell .num { position: relative; }
.cell .num { margin-left: auto; color: var(--ink-2); }
.cell.best { border-color: var(--accent); box-shadow: 0 0 12px rgba(242, 85, 58, 0.45); }
.cell.best .num { color: #fff; }
.cell.blocked { opacity: 0.35; }

.dpad {
  display: none;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
  touch-action: none;
}
.dpad button {
  font-size: 1.1rem;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  user-select: none;
  -webkit-user-select: none;
}
.dpad button:active { background: #2a2026; border-color: var(--accent); }
.dpad [data-dir="0"] { grid-column: 2; grid-row: 1; }
.dpad [data-dir="3"] { grid-column: 1; grid-row: 2; }
.dpad [data-dir="1"] { grid-column: 3; grid-row: 2; }
.dpad [data-dir="2"] { grid-column: 2; grid-row: 3; }
@media (pointer: coarse) { .dpad { display: grid; } .hint { display: none; } }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.controls button {
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 12px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  cursor: pointer;
}
.controls button:hover { border-color: var(--accent); }
#autopilot.on { border-color: var(--accent); background: #2a1612; }
.toggle { display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); font-size: 0.9rem; cursor: pointer; }
.toggle input { accent-color: var(--accent); }

.hint { margin: 0; color: var(--ink-3); font-size: 0.85rem; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  margin-right: 2px;
  padding: 0 4px;
  font: 0.75rem/1.5 var(--font);
  text-align: center;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink-2);
}

.net-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.net {
  position: relative;
  flex: 1;
  min-height: 420px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  cursor: grab;
}
.net:active { cursor: grabbing; }
.net canvas { display: block; }
.net-labels { position: absolute; inset: 0; }
.net-label {
  font: 11px/1 var(--font);
  color: rgba(255, 214, 204, 0.62);
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 0 4px #000;
}
.net-arrow { font-size: 15px; color: rgba(255, 230, 220, 0.85); }
.net-head { font: 9px var(--pixel); color: rgba(255, 214, 204, 0.5); }

.key { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 0; list-style: none; font-size: 0.82rem; color: var(--ink-2); }
.key li { display: inline-flex; align-items: center; gap: 6px; }
.key i { width: 18px; height: 3px; border-radius: 2px; }
.k-pos { background: #c3271a; box-shadow: 0 0 6px #ff3b1f; }
.k-neg { background: #2c4bb8; }
.k-flow { background: #ff6a3d; height: 6px !important; width: 6px !important; border-radius: 50% !important; box-shadow: 0 0 8px #ff3b1f; }
.k-learn { background: var(--gold); box-shadow: 0 0 8px var(--gold); }

/* ---------- scores ---------- */
.scores {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-top: 28px;
}
@media (max-width: 760px) { .scores { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.stat-label { font-size: 0.8rem; color: var(--ink-3); }
.stat-num { font: 400 1.3rem/1.3 var(--pixel); color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-num.small { font-size: 1rem; }
.stat-num.model { text-shadow: 0 0 12px rgba(242, 85, 58, 0.6); }

.chart-wrap {
  grid-column: 1 / -1;
  margin: 0;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.chart-wrap figcaption { font-size: 0.8rem; color: var(--ink-3); margin-bottom: 6px; }
.chart-box { position: relative; }
#chart { display: block; width: 100%; height: 170px; touch-action: pan-y; }
.chart-tip {
  position: absolute;
  top: 6px;
  padding: 6px 9px;
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--ink);
  background: #1f1a21;
  border: 1px solid var(--rule);
  border-radius: 6px;
  pointer-events: none;
  white-space: nowrap;
}
.chart-tip i, .legend i {
  display: inline-block;
  width: 10px; height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 2px;
  background: var(--c);
}
.legend { display: flex; gap: 16px; margin: 6px 0 0; padding: 0; list-style: none; font-size: 0.8rem; color: var(--ink-2); }

/* ---------- notes ---------- */
.notes { max-width: 680px; margin: 64px auto 0; }
.notes h2 {
  margin: 0 0 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.notes h3 { margin: 36px 0 8px; font-size: 1.15rem; }
.notes p, .notes li { color: var(--ink-2); }
.notes b { color: var(--ink); font-weight: 600; }
.notes em { color: var(--ink); }
.notes ul { padding-left: 20px; }

.foot { max-width: 680px; margin: 0 auto; padding: 48px 16px; font-size: 0.85rem; color: var(--ink-3); }

/* ---------- RL controls ---------- */
.seg { display: inline-flex; align-items: center; gap: 0; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.seg-label { padding: 0 10px; font-size: 0.85rem; color: var(--ink-3); }
.controls .seg button { border: 0; border-left: 1px solid var(--rule); border-radius: 0; }
.seg button[aria-pressed="true"] { background: #2a1612; color: #fff; box-shadow: inset 0 -2px 0 var(--accent); }
.slider { display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--ink-2); }
.slider input { accent-color: var(--accent); width: 120px; }
.slider span { min-width: 1.5em; font-variant-numeric: tabular-nums; color: var(--ink); }
.badge {
  margin-left: 6px; padding: 2px 6px; font: 8px var(--pixel); color: #1f1d26;
  background: var(--gold); border-radius: 3px; vertical-align: 1px;
}
.net-col .under { align-items: flex-start; }
.net-col .net { flex: none; height: 360px; min-height: 0; }
.net-col .key { flex-direction: column; flex-wrap: nowrap; }
.compass { grid-template-columns: repeat(3, 82px); }
.eq {
  padding: 10px 14px; font: 0.9rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ink) !important; background: var(--panel); border: 1px solid var(--rule); border-radius: 8px;
  overflow-x: auto;
}
