:root {
  --bg: #0b0e13;
  --panel: #131820;
  --panel-2: #182029;
  --line: #232c38;
  --text: #e6ecf5;
  --muted: #8595aa;
  --accent: #4ea3ff;
  --good: #45d483;
  --warn: #ffb347;
  --bad: #ff6b6b;
  --radius: 10px;
}

* { box-sizing: border-box; }

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

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 17px; }
h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
h3 { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

.fatal {
  padding: 10px 18px; font-size: 13px;
  background: #3a1512; border-bottom: 1px solid var(--bad); color: #ffc9c0;
}

/* ── top bar ───────────────────────────────────────────────────────────── */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #141b24, #0e131a);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  font-size: 24px; line-height: 1;
  width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--accent);
}
.brand .sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.pill {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
  white-space: nowrap;
}
.pill.live { color: var(--good); border-color: #23543c; background: #12251c; }
.pill.paused { color: var(--warn); border-color: #5a4520; background: #241c10; }
.pill.error { color: var(--bad); border-color: #5c2626; background: #241313; }

/* ── buttons ───────────────────────────────────────────────────────────── */

.btn {
  font: inherit; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 7px 12px; transition: background .12s, border-color .12s;
}
.btn:hover { background: #202b37; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06121f; font-weight: 600; }
.btn.primary:hover { background: #6ab3ff; }
.btn.warn { background: #2a1f12; border-color: #5a4520; color: var(--warn); }
.btn.warn:hover { background: #3a2a17; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn.full { width: 100%; margin-top: 8px; }

kbd {
  font: 11px ui-monospace, Consolas, monospace;
  background: #0d1218; border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; color: var(--muted);
}

/* ── layout ────────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(520px, 1.5fr) 340px 300px;
  gap: 14px; padding: 14px; align-items: start;
}
@media (max-width: 1400px) { .layout { grid-template-columns: 1fr 340px; } .settings { grid-column: 1 / -1; } }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } .settings { grid-column: auto; } }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 10px; flex-wrap: wrap;
}
.panel-head.tight { margin-top: 14px; }
.head-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }

/* ── capture sources ───────────────────────────────────────────────────── */

.sources { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 1200px) { .sources { grid-template-columns: 1fr; } }

.source {
  border: 1px solid var(--line); border-radius: 10px; padding: 8px;
  background: #10161d;
}
.source.primary { border-color: #2c4a68; background: #101922; }
.source-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
}
.source-head h3 { margin: 0 0 2px; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }
.source-sub { margin: 0; font-size: 11px; color: var(--muted); }
.source-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  padding: 1px 6px; border-radius: 999px; vertical-align: middle;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.badge.live-badge { color: var(--accent); border-color: #2c4a68; background: #0f1c28; }

/* ── learning: what it has been taught ─────────────────────────────────── */

.taught-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 8px;
}
.chips { display: flex; gap: 3px; flex-wrap: wrap; }
.chip {
  font: 11px ui-monospace, Consolas, monospace;
  padding: 1px 5px; border-radius: 4px;
  background: #0d1218; border: 1px solid var(--line); color: #55627a;
}
.chip.has { color: var(--good); border-color: #23543c; background: #12251c; }

/* ── capture stage ─────────────────────────────────────────────────────── */

.stage { position: relative; border-radius: 10px; overflow: hidden; background: #05070a; }
.stage canvas { display: block; width: 100%; height: auto; cursor: crosshair; }
.stage-hint {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 24px; color: var(--muted); font-size: 13px; pointer-events: none;
}
.stage-hint b { color: var(--text); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.debug-wrap {
  display: flex; gap: 12px; margin-top: 12px; padding: 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
}
.debug-wrap canvas { width: 320px; height: auto; background: #000; border-radius: 6px; flex: none; }
.debug-meta { display: flex; flex-direction: column; gap: 3px; font-size: 12px; min-width: 0; }
.debug-meta > div { display: flex; gap: 8px; }
.debug-meta .k { color: var(--muted); min-width: 78px; }
.debug-meta p { margin: 6px 0 0; }
.debug-meta .warnval { color: var(--bad); font-weight: 600; }
.debug-meta button { align-self: flex-start; margin-top: 6px; }

/* ── learning strip ────────────────────────────────────────────────────── */

.hint.tight { margin-bottom: 8px; }
.hint em { color: var(--text); font-style: normal; }

.strip-nav {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px;
}
.strip-nav .btn { padding: 2px 8px; line-height: 1.4; }
.strip-nav .btn:disabled { opacity: .35; cursor: default; }
.strip-nav #pageLabel { min-width: 120px; }
.strip-nav .nav-note { margin-left: auto; }

/* No scrolling: a page holds one hand, so the tiles wrap and the strip grows to
   fit them. Nothing gets hidden below a fold you have to go looking for. */
.strip {
  display: flex; gap: 8px; flex-wrap: wrap; min-height: 64px;
  align-content: flex-start;
  padding: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
}
.strip .empty { margin: 0; max-width: 640px; }

.tile {
  display: flex; flex-direction: column; gap: 4px; width: 122px;
  padding: 6px; background: #10161d; border: 1px solid var(--line); border-radius: 8px;
}
.tile.pending { border-color: #5a4520; background: #1c1710; }
.tile.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

.tile-imgs { position: relative; cursor: pointer; border-radius: 5px; overflow: hidden; }
.tile-photo {
  display: block; width: 100%; height: auto; border-radius: 5px; background: #05070a;
}
.tile-photo.none {
  height: 74px; display: grid; place-items: center;
  color: #55627a; font-size: 11px; border: 1px dashed var(--line);
}
.tile-glyph {
  position: absolute; right: 3px; bottom: 3px;
  border-radius: 3px; image-rendering: pixelated;
  border: 1px solid rgba(255, 255, 255, .18); opacity: .9;
}

.tile-verdict {
  font: 600 11px ui-monospace, Consolas, monospace;
  text-align: center; padding: 2px 0; border-radius: 4px;
  background: #0d1218; color: var(--muted);
}
.tile-verdict.read { color: var(--good); }
.tile-verdict.unsure { color: var(--warn); }
.tile-verdict.fixed { color: var(--accent); }
.tile-verdict.typed { color: var(--muted); }

.tile > select {
  width: 100%; font: 12px inherit; padding: 2px 3px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 5px;
}
.tile.pending > select { border-color: #6b5224; color: var(--warn); }

.tile-row { display: flex; gap: 2px; align-items: center; justify-content: space-between; }
.verdict-btn {
  flex: 1; cursor: pointer; border: 1px solid var(--line); border-radius: 5px;
  background: var(--panel-2); color: var(--muted);
  font-size: 12px; line-height: 1.4; padding: 2px 0;
}
.verdict-btn.tick:hover { color: var(--good); border-color: #23543c; background: #12251c; }
.verdict-btn.x:hover { color: var(--warn); border-color: #5a4520; background: #241c10; }
.verdict-btn.err:hover { color: var(--bad); border-color: #5c2626; background: #241313; }
.tile-tag { font: 600 11px ui-monospace, Consolas, monospace; }
.tile-tag.pos { color: var(--good); }
.tile-tag.neg { color: var(--bad); }
.tile-tag.zero { color: var(--muted); }
.tile-tag { min-width: 18px; text-align: center; }

/* ── count readout ─────────────────────────────────────────────────────── */

.count { display: flex; flex-direction: column; gap: 14px; }
.readout { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px;
}
.stat .label { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat .value { font: 600 22px/1.2 ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.stat.big .value { font-size: 34px; }
.stat.accent .value { color: var(--accent); }
.stat .value.pos { color: var(--good); }
.stat .value.neg { color: var(--bad); }

.pen-bar {
  position: relative; height: 9px; background: #0c1117;
  border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.pen-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--warn)); transition: width .25s; }
.pen-fill.past-cut { background: linear-gradient(90deg, var(--warn), var(--bad)); }
.pen-cut { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--bad); left: 50%; }
.pen-row { display: flex; justify-content: space-between; margin-top: 4px; gap: 8px; }
.pen-row b { color: var(--text); font-variant-numeric: tabular-nums; }

.banner {
  padding: 8px 10px; border-radius: 8px; font-size: 12px;
  background: #2a1512; border: 1px solid #6b2f26; color: #ffb0a3;
  animation: pulse 1.4s ease-in-out infinite;
}
.banner b { color: #fff; }
@keyframes pulse { 50% { border-color: var(--bad); } }

.group { border-top: 1px solid var(--line); padding-top: 12px; }
.group.grow { display: flex; flex-direction: column; min-height: 0; }
.field-row { display: flex; gap: 8px; margin-bottom: 8px; }
.field-row label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input[type="number"], select {
  font: inherit; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; width: 100%;
}
input[type="number"]:focus, select:focus { outline: none; border-color: var(--accent); }

.rankpad { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.rankpad button {
  font: 600 13px/1 ui-monospace, Consolas, monospace;
  padding: 9px 0; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
.rankpad button:hover { background: #202b37; }
.rankpad button[data-tag="1"] { border-bottom: 2px solid var(--good); }
.rankpad button[data-tag="-1"] { border-bottom: 2px solid var(--bad); }
.rankpad button[data-tag="0"] { border-bottom: 2px solid var(--muted); }

/* ── log ───────────────────────────────────────────────────────────────── */

.log { overflow-y: auto; max-height: 320px; display: flex; flex-direction: column-reverse; gap: 3px; }
.log-row {
  display: grid; grid-template-columns: 46px 1fr 34px 46px 20px;
  align-items: center; gap: 6px; padding: 3px 5px; border-radius: 6px;
  background: var(--panel-2); font-size: 12px;
}
.log-row .t { color: var(--muted); font: 11px ui-monospace, Consolas, monospace; }
.log-row select { padding: 2px 4px; font-size: 12px; }
.log-row .tag { text-align: center; font: 600 12px ui-monospace, Consolas, monospace; }
.log-row .tag.pos { color: var(--good); }
.log-row .tag.neg { color: var(--bad); }
.log-row .tag.zero { color: var(--muted); }
.log-row .rc { text-align: right; font: 12px ui-monospace, Consolas, monospace; color: var(--muted); }
.log-row .x { cursor: pointer; border: none; background: none; color: var(--muted); padding: 0; }
.log-row .x:hover { color: var(--bad); }
.log-row.cv { border-left: 2px solid var(--accent); }
.log-row.manual { border-left: 2px solid var(--muted); }
.log-row.taught { border-left: 2px solid var(--good); }
.log-row.corrected { border-left: 2px solid var(--warn); }
.log-row.disputed { border-left: 2px solid var(--bad); }

/* ── settings ──────────────────────────────────────────────────────────── */

.tune-grid { display: flex; flex-direction: column; gap: 12px; }
.tune { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.tune > span { display: flex; justify-content: space-between; color: var(--muted); }
.tune > span b { color: var(--text); font: 600 12px ui-monospace, Consolas, monospace; }
.tune small { color: #6c7c92; font-size: 11px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.check small { flex-basis: 100%; color: #6c7c92; font-size: 11px; }
.check input { accent-color: var(--accent); }

.note {
  margin-top: 14px; padding: 10px; border-radius: 8px; font-size: 12px; line-height: 1.6;
  background: #101720; border: 1px solid var(--line); color: var(--muted);
}
.note b { color: var(--text); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #26313e; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

.debug-meta .dbg-head {
  margin: 8px 0 2px; font-size: 11px; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
}

.suppress-log {
  max-height: 132px; overflow-y: auto; font-size: 11px;
  background: #0d1218; border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 6px; min-width: 260px;
}
.suppress-log.muted { color: var(--muted); }
.sup-row { display: flex; gap: 7px; align-items: baseline; padding: 1px 0; }
.sup-row .t { color: var(--muted); font: 10px ui-monospace, Consolas, monospace; min-width: 32px; }
.sup-row .kind { min-width: 78px; }
.sup-row .rank { font: 600 11px ui-monospace, Consolas, monospace; min-width: 20px; color: var(--text); }
.sup-row .detail { color: #6c7c92; }
.sup-row.moved .kind { color: var(--accent); }
.sup-row.overlapping .kind { color: var(--warn); }

.strip-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab {
  font: inherit; font-size: 12px; cursor: pointer;
  padding: 5px 12px; border-radius: 8px 8px 0 0;
  border: 1px solid var(--line); border-bottom: none;
  background: transparent; color: var(--muted);
}
.tab:hover { background: var(--panel-2); }
.tab.active { background: var(--panel-2); color: var(--text); border-color: var(--accent); }
.tab-badge {
  display: inline-block; min-width: 18px; text-align: center;
  margin-left: 4px; padding: 0 5px; border-radius: 999px;
  font: 600 11px ui-monospace, Consolas, monospace;
  background: #0d1218; border: 1px solid var(--line); color: var(--muted);
}
.tab.has-work .tab-badge { color: var(--warn); border-color: #5a4520; background: #241c10; }

/* Confidence in a counted read. Low ones want your eye. */
.tile-verdict.read-fair { color: var(--warn); }
.tile-verdict.read-weak { color: var(--bad); }
.tile.low-conf { border-color: #5a4520; }

.roi-info {
  margin: 6px 0 0; font: 11px ui-monospace, Consolas, monospace;
}

.tile-reason {
  font-size: 10px; line-height: 1.2; text-align: center;
  color: var(--warn); opacity: .85;
}
