:root {
  --bg: #0e110f;
  --surface: #151917;
  --surface-2: #1c211e;
  --line: #2a312d;
  --text: #e4e8e1;
  --muted: #8d978f;
  --accent: #c8f26b;
  --accent-ink: #18200a;
  --still: #7cc7ff;
  --osc: #ffb35c;
  --ship: #ff6f91;
  --active: #e4e8e1;
  --danger: #ff7a6b;
  --mono: 'IBM Plex Mono', ui-monospace, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, sans-serif;
  --r: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar { height: 52px; display: flex; align-items: center; gap: 20px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-weight: 600; color: var(--accent); letter-spacing: .02em; }
.readouts { display: flex; gap: 18px; align-items: center; flex: 1; overflow-x: auto; white-space: nowrap; }
.readouts > div { display: flex; gap: 6px; align-items: baseline; }
.lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.chip { font-family: var(--mono); font-size: 12px; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.chip.live { color: var(--accent); border-color: #4b5d26; }
.chip.done { color: var(--still); border-color: #2c4a5e; }

.layout { display: grid; grid-template-columns: 1fr 340px; height: calc(100% - 52px); }
.stage { position: relative; overflow: hidden; }
#board { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#board.pan { cursor: grab; } #board.select { cursor: pointer; }
.hud { position: absolute; font: 12px var(--mono); color: var(--muted); background: rgba(14,17,15,.8); padding: 4px 8px; border-radius: 4px; pointer-events: none; }
.hud-tl { top: 10px; left: 10px; } .hud-br { bottom: 10px; right: 10px; }
#minimap { position: absolute; bottom: 10px; left: 10px; width: 180px; height: 120px; border: 1px solid var(--line); background: rgba(14,17,15,.88); border-radius: 4px; cursor: pointer; }

.focus-card { position: absolute; top: 10px; right: 10px; width: 250px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.fc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.fc-head strong { color: var(--accent); font-family: var(--mono); font-size: 13px; }
.x { background: none; border: 0; font-size: 18px; color: var(--muted); cursor: pointer; }
.focus-card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 0 0 8px; font-size: 12px; }
.focus-card dt { color: var(--muted); } .focus-card dd { margin: 0; font-family: var(--mono); text-align: right; }
.check { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 4px; }

.panel { border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; padding: 4px 0 24px; }
details { border-bottom: 1px solid var(--line); padding: 10px 14px; }
summary { cursor: pointer; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); list-style: none; margin-bottom: 8px; }
summary::-webkit-details-marker { display: none; }
summary::before { content: '▸ '; } details[open] > summary::before { content: '▾ '; }
.row { display: flex; gap: 6px; margin: 6px 0; align-items: center; flex-wrap: wrap; }
.btn { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #46504a; }
.btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.toggle.on { border-color: var(--accent); color: var(--accent); }
.btn.wide { flex: 1; }
.seg { display: flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg button { flex: 1; background: var(--surface-2); border: 0; border-right: 1px solid var(--line); padding: 6px; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
input[type=number], input[type=text], select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r); padding: 6px 8px; min-width: 0; }
#run-n { width: 80px; } #snap-name { flex: 1; } select { flex: 1; }
textarea { width: 100%; font-family: var(--mono); font-size: 12px; resize: vertical; }
.mini { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); } .mini input { width: 76px; }
.slider { display: block; font-size: 12px; color: var(--muted); margin: 8px 0; }
.slider span { color: var(--text); font-family: var(--mono); float: right; }
.slider input { width: 100%; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.snaps { list-style: none; padding: 0; margin: 4px 0 0; font-size: 13px; }
.snaps li { display: flex; justify-content: space-between; gap: 6px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.snaps button { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0 4px; }
.snaps button.load { color: var(--text); text-align: left; flex: 1; }
.tally-sum { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.tally-sum b { color: var(--text); font-weight: 500; }
.table-wrap { max-height: 280px; overflow-y: auto; } .table-wrap.tall { max-height: none; }
table.tally { width: 100%; border-collapse: collapse; font-size: 12px; }
.tally th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.tally td { padding: 4px; border-bottom: 1px solid #202622; font-variant-numeric: tabular-nums; }
.tally tbody tr { cursor: pointer; } .tally tbody tr:hover { background: var(--surface-2); }
.tally .n { text-align: right; font-family: var(--mono); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.t-still { background: var(--still); } .t-osc { background: var(--osc); } .t-ship { background: var(--ship); } .t-active { background: var(--active); }
#spark { width: 100%; height: 70px; }
.keys { padding-left: 16px; margin: 0; font-size: 12px; color: var(--muted); }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; color: var(--text); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 32px 16px; z-index: 10; }
.modal[hidden], .focus-card[hidden], .toast[hidden] { display: none; }
.modal-box { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; width: min(1180px, 100%); padding: 20px 24px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 20px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 16px 0; }
.kpi { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.kpi .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.kpi .v { font-family: var(--mono); font-size: 20px; margin-top: 2px; }
.kpi .s { font-size: 12px; color: var(--muted); }
.rep-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 20px; }
figure { margin: 0; } figcaption { font-size: 12px; color: var(--muted); margin: 8px 0 6px; }
#rep-heat, #rep-pop { width: 100%; height: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; display: block; }
.legend { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 6px; }
.legend i { flex: 1; height: 8px; border-radius: 2px; background: linear-gradient(90deg, #1d2b3a, #2f6f8f, #7fd3a8, #e9f27a, #fff6d8); }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 90px 1fr 70px; gap: 8px; align-items: center; font-size: 12px; }
.bar .track { height: 10px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.bar .fill { height: 100%; }
.bar .n { text-align: right; font-family: var(--mono); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: var(--r); z-index: 20; font-size: 13px; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .rep-grid { grid-template-columns: 1fr; }
  .topbar { gap: 10px; } .brand span { display: none; }
  #minimap { width: 120px; height: 80px; }
  .focus-card { width: 210px; }
}
@media print {
  body { background: #fff; color: #000; }
  .topbar, .layout, .modal-head .row, .toast { display: none !important; }
  .modal { position: static; background: none; padding: 0; }
  .modal-box { border: 0; width: 100%; background: #fff; color: #000; }
  .kpi, .tally th { background: #fff; color: #000; }
  .tally td { border-color: #ccc; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
