:root {
  --bg: #edeff2;
  --surface: #ffffff;
  --ink: #1a1e23;
  --ink-2: #4e5764;
  --line: #d3d8df;
  --stage: #2a2f36;
  --stage-ink: #eef1f4;
  --stage-ink-2: #a9b2bd;
  --stage-line: #3d444d;

  --fer: #e8002d;
  --mcl: #ff8000;
  --mer: #00a19c;
  --rbr: #3671c6;

  --flag-good: #1e9e55;
  --flag-warn: #f4c300;
  --flag-bad: #d7263d;
  --flag-info: #c9ced6;

  --focus: #3671c6;
  --radius-stage: 6px;
  --radius-chip: 2px;
  --font: "Titillium Web", "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1e2227;
    --ink: #e7eaee;
    --ink-2: #a3acb8;
    --line: #343a42;
    --stage: #0f1215;
    --stage-line: #2b3138;
    --flag-info: #7d8691;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font);
}
img { max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 700; }
h1 { font-size: 36px; letter-spacing: -0.01em; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
p { margin: 0; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.stage :focus-visible { outline-color: #fff; box-shadow: 0 0 0 5px #0b1a33; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---------------------------------------------------------------- masthead */
.masthead { padding: 32px 0 20px; }
.masthead-inner { display: flex; gap: 24px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; }
.lede { margin-top: 8px; max-width: 64ch; color: var(--ink-2); font-size: 18px; }
.model-meta { color: var(--ink-2); font-size: 14px; max-width: 34ch; text-align: right; }

/* ---------------------------------------------------------------- stage */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  background: var(--stage);
  color: var(--stage-ink);
  border-radius: var(--radius-stage);
  overflow: hidden;
  min-height: 420px;
}
.stage-media-area {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 420px;
}
.stage-media-area.drag { box-shadow: inset 0 0 0 3px var(--rbr); }
.dropzone { text-align: center; max-width: 40ch; display: grid; gap: 10px; justify-items: center; }
.dropzone-title { font-size: 21px; font-weight: 600; }
.dropzone-hint { color: var(--stage-ink-2); font-size: 14px; }

.media { position: relative; margin: 0; display: inline-block; line-height: 0; }
.media img#media-img { display: block; max-height: 68vh; max-width: 100%; width: auto; height: auto; }
.cam-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; mix-blend-mode: normal; opacity: 0.85; }
.box-layer { position: absolute; inset: 0; }

.det-box {
  position: absolute;
  border: 3px solid var(--team, #fff);
  border-radius: 2px;
  transition: box-shadow 120ms ease, opacity 120ms ease;
}
.det-box .det-tag {
  position: absolute;
  left: -3px;
  bottom: 100%;
  background: var(--team);
  color: var(--team-ink, #fff);
  font: 700 13px/1 var(--font);
  padding: 4px 6px 3px;
  white-space: nowrap;
  border-radius: 2px 2px 0 0;
}
.det-box.tag-inside .det-tag { bottom: auto; top: 0; left: 0; border-radius: 0 0 2px 0; }
.det-box.dim { opacity: 0.35; }
.det-box.hl { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--team); }
.gt-box {
  position: absolute;
  border: 2px dashed #fff;
  outline: 1px dashed rgba(0, 0, 0, 0.7);
  pointer-events: none;
}
.gt-box .gt-tag {
  position: absolute;
  right: -2px;
  top: 100%;
  background: #fff;
  color: #111;
  font: 600 12px/1 var(--font);
  padding: 3px 5px;
  white-space: nowrap;
}

.busy {
  position: absolute;
  inset: auto 16px 16px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 14px;
  color: var(--stage-ink);
}
.busy-bar { flex: 0 0 64px; height: 4px; background: linear-gradient(90deg, var(--fer), var(--mcl), var(--mer), var(--rbr)); background-size: 200% 100%; animation: sweep 900ms linear infinite; }
@keyframes sweep { to { background-position: -200% 0; } }

.stage-error { max-width: 44ch; text-align: center; display: grid; gap: 6px; }
.stage-error-title { font-weight: 700; font-size: 18px; }
.stage-error-hint { color: var(--stage-ink-2); font-size: 14px; }

/* ---------------------------------------------------------------- timing tower */
.tower { border-left: 1px solid var(--stage-line); padding: 16px 0; display: flex; flex-direction: column; min-width: 0; }
.tower-empty { color: var(--stage-ink-2); font-size: 14px; padding: 0 16px; }
.tower-head { padding: 0 16px 12px; border-bottom: 1px solid var(--stage-line); }
.tower-headline { font-weight: 600; font-size: 16px; line-height: 1.35; }
.tower-sub { color: var(--stage-ink-2); font-size: 13px; margin-top: 4px; }
.tower-list { list-style: none; margin: 0; padding: 0; }
.tower-row {
  display: grid;
  grid-template-columns: 22px 5px 1fr auto;
  gap: 0 10px;
  align-items: center;
  padding: 9px 16px;
  border-bottom: 1px solid var(--stage-line);
  cursor: pointer;
  animation: row-in 260ms ease both;
}
.tower-row:hover, .tower-row.hl { background: rgba(255, 255, 255, 0.06); }
.tower-row:focus-visible { outline-offset: -3px; }
.tower-pos { color: var(--stage-ink-2); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.tower-stripe { width: 5px; height: 30px; background: var(--team); border-radius: 1px; }
.tower-team { display: flex; flex-direction: column; min-width: 0; }
.tower-code { font-weight: 700; font-size: 18px; letter-spacing: 0.04em; line-height: 1.1; }
.tower-gap { color: var(--stage-ink-2); font-size: 12px; line-height: 1.2; }
.tower-conf { text-align: right; font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; }
.tower-verdict { grid-column: 3 / 5; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--stage-ink-2); margin-top: 2px; }
.tower-cands { padding: 10px 16px 0; color: var(--stage-ink-2); font-size: 13px; }
.tower-timing { margin-top: auto; padding: 12px 16px 0; color: var(--stage-ink-2); font-size: 12px; }
@keyframes row-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- flags & chips */
.flag {
  display: inline-block;
  width: 14px;
  height: 10px;
  border-radius: 1px;
  flex: 0 0 auto;
  background: var(--flag-info);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.flag-good { background: var(--flag-good); }
.flag-warn { background: var(--flag-warn); }
.flag-bad { background: var(--flag-bad); }
.flag-info { background: var(--flag-info); }

/* ---------------------------------------------------------------- controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  padding: 14px 0 6px;
}
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 8px 16px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--ink-2); }
.btn-primary { background: var(--stage-ink); color: var(--stage); border-color: var(--stage-ink); }
.stage .btn-primary:hover { background: #fff; }
.control-conf { display: grid; gap: 2px; font-size: 14px; color: var(--ink-2); min-width: 220px; }
.control-conf output { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.control-conf input { accent-color: var(--ink); }
.control-toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.control-toggle input { accent-color: var(--ink); width: 16px; height: 16px; }
.source-note { font-size: 13px; color: var(--ink-2); padding: 2px 0 0; overflow-wrap: anywhere; }
.source-note a { color: inherit; }

.history { display: flex; gap: 8px; padding: 10px 0 0; overflow-x: auto; }
.history button { border: 2px solid transparent; padding: 0; background: none; cursor: pointer; border-radius: 3px; line-height: 0; flex: 0 0 auto; }
.history button[aria-current="true"] { border-color: var(--ink); }
.history img { width: 72px; height: 48px; object-fit: cover; border-radius: 2px; }

/* ---------------------------------------------------------------- reasoning */
.reasoning { margin-top: 28px; display: grid; gap: 20px; overflow-anchor: none; }
.reason-summary { display: grid; gap: 10px; }
.outcome-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.outcome-badge { font-weight: 700; font-size: 14px; padding: 3px 10px; border-radius: var(--radius-chip); color: #fff; }
.outcome-success { background: #177a42; }
.outcome-label { background: #46505c; }
.outcome-failure { background: var(--flag-bad); }
.outcome-meta { color: var(--ink-2); font-size: 14px; }
.reason-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-width: 80ch; }
.reason-list li { display: grid; grid-template-columns: 14px 1fr; gap: 10px; align-items: baseline; }
.reason-list li .flag { transform: translateY(1px); }
.reason-title { font-weight: 600; }

.det-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.det-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--team);
  border-radius: 4px;
  padding: 16px 18px;
  display: grid;
  gap: 14px;
  align-content: start;
}
.det-card.hl { box-shadow: 0 0 0 2px var(--team); }
.det-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.det-card-head h3 { font-size: 21px; }
.det-card-conf { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.verdict { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }

.scores { display: grid; gap: 5px; }
.score-row { display: grid; grid-template-columns: 38px 1fr 42px; gap: 8px; align-items: center; font-size: 13px; }
.score-code { font-weight: 700; letter-spacing: 0.04em; }
.score-track { height: 8px; background: color-mix(in srgb, var(--line) 60%, transparent); border-radius: 1px; overflow: hidden; }
.score-fill { height: 100%; background: var(--team); }
.score-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.scores-caption { font-size: 12px; color: var(--ink-2); }

.swatches { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.swatch { display: inline-flex; align-items: center; gap: 6px; }
.swatch i { width: 16px; height: 16px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); display: inline-block; }

.empty-result { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 16px 18px; max-width: 80ch; }

/* ---------------------------------------------------------------- blocks */
.block { margin-top: 56px; }
.block-lede { color: var(--ink-2); margin-top: 6px; max-width: 72ch; }

.sample-group { margin-top: 18px; }
.sample-group h3 { font-size: 16px; font-weight: 600; color: var(--ink-2); margin-bottom: 8px; }
.sample-strip, .gallery { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.thumb {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}
.thumb:hover { border-color: var(--ink-2); }
.thumb img { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; display: block; background: var(--stage); }
.thumb-body { padding: 8px 10px 10px; display: grid; gap: 4px; align-content: start; }
.thumb-title { font-weight: 600; font-size: 14px; line-height: 1.3; }
.thumb-text { font-size: 13px; color: var(--ink-2); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.thumb-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; }
.sample-item { display: grid; gap: 4px; align-content: start; }
.sample-item .thumb { height: 100%; }
.thumb-credit { font-size: 12px; line-height: 1.35; color: var(--ink-2); overflow-wrap: anywhere; }
.thumb-credit a, .footer a { color: inherit; }

.tabs { display: flex; gap: 4px; margin: 18px 0 14px; border-bottom: 1px solid var(--line); }
.tab {
  border: none;
  background: none;
  padding: 8px 14px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

/* ---------------------------------------------------------------- performance */
.perf { display: grid; gap: 28px; margin-top: 14px; }
.perf-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 28px; align-items: start; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 15px; background: var(--surface); border: 1px solid var(--line); }
th, td { padding: 8px 12px; text-align: right; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { font-weight: 600; color: var(--ink-2); font-size: 14px; }
caption { text-align: left; font-size: 13px; color: var(--ink-2); caption-side: bottom; padding-top: 8px; white-space: normal; }
.perf-note { font-size: 14px; color: var(--ink-2); max-width: 72ch; }
.err-bars { display: grid; gap: 8px; }
.err-row { display: grid; grid-template-columns: 150px 1fr 40px; gap: 10px; align-items: center; font-size: 14px; }
.err-track { height: 10px; background: color-mix(in srgb, var(--line) 60%, transparent); }
.err-fill { height: 100%; background: var(--ink-2); }
.err-fill.good { background: var(--flag-good); }
.err-fill.bad { background: var(--flag-bad); }
.err-fill.label { background: #8a94a3; }
.err-val { text-align: right; font-variant-numeric: tabular-nums; }
.confusions { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; display: grid; gap: 4px; }
.plots summary { cursor: pointer; font-weight: 600; }
.plots-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 12px; }
.plots-grid img { background: #fff; border: 1px solid var(--line); border-radius: 4px; }

/* ---------------------------------------------------------------- guide & footer */
.guide { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 32px; margin-top: 14px; }
.flag-legend { margin: 0; display: grid; gap: 12px; }
.flag-legend dt { font-weight: 600; display: flex; gap: 10px; align-items: center; }
.flag-legend dd { margin: 2px 0 0 24px; color: var(--ink-2); font-size: 15px; }
.guide-text { display: grid; gap: 12px; max-width: 70ch; }
.footer { margin-top: 64px; padding: 24px 0 40px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 14px; }
.footer p { max-width: 90ch; }
.footer p + p { margin-top: 8px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 880px) {
  .stage { grid-template-columns: 1fr; }
  .tower { border-left: none; border-top: 1px solid var(--stage-line); }
  .perf-grid, .guide { grid-template-columns: 1fr; }
  .model-meta { text-align: left; }
  h1 { font-size: 30px; }
}
@media (max-width: 480px) {
  .stage-media-area { min-height: 300px; padding: 10px; }
  .det-cards { grid-template-columns: 1fr; }
  .err-row { grid-template-columns: 110px 1fr 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
