/* Roles, not raw hex: light and dark values swap here. Status colours are fixed in both modes;
   the categorical slots are the validated default palette's first three hues. */
:root {
  color-scheme: light;
  --plane: #f9f9f7; --surface: #fcfcfb; --surface-2: #f1f0ec; --ink: #0b0b0b; --ink-2: #52514e;
  --muted: #898781; --grid: #e1e0d9; --axis: #c3c2b7; --line: rgba(11, 11, 11, .12);
  --accent: #2a78d6; --accent-wash: #e8f1fc; --header: #17303a;
  --good: #0ca30c; --critical: #d03b3b; --good-text: #006300; --critical-text: #a12a2a;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #ffffff; --ink-2: #c3c2b7;
    --muted: #898781; --grid: #2c2c2a; --axis: #383835; --line: rgba(255, 255, 255, .12);
    --accent: #3987e5; --accent-wash: #1d2a3b; --header: #10191d;
    --good-text: #0ca30c; --critical-text: #e66767;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #ffffff; --ink-2: #c3c2b7;
  --muted: #898781; --grid: #2c2c2a; --axis: #383835; --line: rgba(255, 255, 255, .12);
  --accent: #3987e5; --accent-wash: #1d2a3b; --header: #10191d;
  --good-text: #0ca30c; --critical-text: #e66767;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--plane); }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.site-header { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 20px; background: var(--header); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .06em; }
.brand-mark { background: #fff; color: #17303a; border-radius: 6px; padding: 2px 7px; font-family: var(--mono); }
.brand-sub { display: block; font-weight: 400; letter-spacing: 0; opacity: .8; font-size: 12px; }
.site-header nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.site-header a, .site-header .text-button { color: #fff; }
.view-tabs { display: flex; gap: 4px; }
.view-tab { border: 1px solid rgba(255, 255, 255, .35); background: transparent; color: #fff; border-radius: 6px; padding: 3px 12px; }
.view-tab.active { background: #fff; color: #17303a; border-color: #fff; font-weight: 600; }
.help { background: var(--surface-2); border-bottom: 1px solid var(--line); padding: 10px 20px; }
.help p { margin: 6px 0; max-width: 1100px; }

.workspace { display: grid; grid-template-columns: 320px minmax(0, 1fr); min-height: calc(100vh - 52px); }
.sidebar { border-right: 1px solid var(--line); background: var(--surface); padding: 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.split-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 5px 4px; font-size: 13px; }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
#search { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.filters label { font-size: 12px; color: var(--ink-2); display: flex; flex-direction: column; gap: 2px; }
.filters label.wide { grid-column: 1 / -1; }
.filters select { padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; }
.hint { color: var(--ink-2); font-size: 12px; }
.mono { font-family: var(--mono); }
.problem-list { list-style: none; margin: 0; padding: 0; }
.problem-item { width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; margin-bottom: 6px; }
.problem-item:hover { border-color: var(--accent); }
.problem-item.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); background: var(--accent-wash); }
.problem-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.problem-id { font-weight: 600; font-family: var(--mono); font-size: 12.5px; }
.problem-preview { margin: 3px 0 4px; color: var(--ink-2); font-size: 12px; max-height: 3.1em; overflow: hidden; }
.problem-stats { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--ink-2); font-family: var(--mono); }
.spark { display: inline-flex; gap: 2px; }
.spark i { display: inline-block; width: 7px; height: 11px; border-radius: 2px; }
.spark i.ok { background: var(--good); }
.spark i.bad { background: var(--critical); }
.more { width: 100%; margin-top: 4px; }

.detail { padding: 18px 24px 80px; min-width: 0; }
.empty-state { color: var(--ink-2); padding: 40px; text-align: center; }
.kicker { margin: 0; color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.tree-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.tree-head h2 { margin: 0; font-family: var(--mono); font-size: 20px; }
.nav-buttons { display: flex; gap: 6px; flex: none; }
.button { border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 6px; padding: 3px 10px; }
.button.secondary { background: var(--surface); color: var(--accent); }
.text-button { border: 0; background: none; color: var(--accent); padding: 0 4px; text-decoration: underline; }
.text-button.tiny { font-size: 11px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 16px; margin: 12px 0; }
.panel > h3 { margin: 0 0 6px; font-size: 15px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.panel-head h3 { margin: 0 0 6px; font-size: 15px; }
.tree-table td.letter { width: auto; white-space: nowrap; }
.text-block.reasoning pre.plain { max-height: 70vh; overflow-y: auto; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 8px 0 0; font-size: 13px; }
.facts div { display: flex; gap: 6px; align-items: baseline; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 600; }
.gold-line { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-top: 6px; }
.gold-line .label { color: var(--ink-2); font-size: 13px; }
.answer-math { font-size: 15px; overflow-x: auto; max-width: 100%; }
details > summary { cursor: pointer; font-weight: 600; }

/* The tree. */
.tree-scroll { overflow-x: auto; padding-bottom: 4px; }
.tree-svg { display: block; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.tree-svg text { fill: var(--ink); }
.tree-svg .col-label { font-size: 12px; font-weight: 600; fill: var(--ink-2); }
.tree-svg .point-label { font-size: 11px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.tree-svg .spine-band { fill: var(--surface-2); }
.tree-svg .final-tag { font-size: 10.5px; fill: var(--ink-2); }
.edge { fill: none; stroke-width: 2; }
.edge.spine-edge { stroke-width: 3.5; }
.edge-recheck { stroke: var(--series-1); }
.edge-revise { stroke: var(--series-2); stroke-dasharray: 6 3; }
.edge-regenerate { stroke: var(--series-3); stroke-dasharray: 1.5 3.5; stroke-linecap: round; stroke-width: 2.5; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 12; pointer-events: stroke; cursor: pointer; }
.tnode { cursor: pointer; }
.tnode rect.body { stroke: var(--surface); stroke-width: 2; }
.tnode.ok rect.body { fill: var(--good); }
.tnode.bad rect.body { fill: var(--critical); }
.tnode.unknown rect.body { fill: var(--axis); }
.tnode text { font-size: 12.5px; font-weight: 600; pointer-events: none; }
/* Fixed status fills take fixed ink: dark on green (6.4:1), white on red (4.8:1). */
.tree-svg .tnode.ok text { fill: #0b0b0b; }
.tree-svg .tnode.bad text { fill: #ffffff; }
.tnode .ring { fill: none; stroke: transparent; stroke-width: 2.5; }
.tnode:hover .ring, .tnode:focus-visible .ring { stroke: var(--ink-2); }
.tnode.selected .ring { stroke: var(--ink); stroke-width: 3; }
.tnode:focus { outline: none; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 12px; color: var(--ink-2); margin: 6px 0 2px; align-items: center; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-node { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 18px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.legend-node.ok { background: var(--good); color: #0b0b0b; }
.legend-node.bad { background: var(--critical); color: #fff; }
.legend-edge { width: 30px; height: 10px; }
.legend-edge line { stroke-width: 2; }

.answers { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.answers th { text-align: left; color: var(--ink-2); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--grid); padding: 3px 8px 3px 0; }
.answers td { border-bottom: 1px solid var(--grid); padding: 4px 8px 4px 0; vertical-align: top; }
.answers td.num { font-variant-numeric: tabular-nums; text-align: right; width: 64px; }
.answers td.letter { font-family: var(--mono); font-weight: 700; width: 48px; }
.answers tr.chosen td { background: var(--accent-wash); }
.answers button.text-button { font-family: var(--mono); font-weight: 700; text-decoration: none; }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 9px; font-size: 12px; background: var(--surface-2); color: var(--ink); white-space: nowrap; border: 1px solid var(--line); }
.badge.ok { color: var(--good-text); border-color: var(--good); }
.badge.bad { color: var(--critical-text); border-color: var(--critical); }
.badge.mode-recheck { border-color: var(--series-1); }
.badge.mode-revise { border-color: var(--series-2); }
.badge.mode-regenerate { border-color: var(--series-3); }
.badge .swatch { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

.node-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.node-head h3 { margin: 0; font-size: 16px; font-family: var(--mono); }
.node-section { margin-top: 12px; }
.node-section > h4 { margin: 0 0 4px; font-size: 13px; color: var(--ink-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.critique { border-left: 3px solid var(--axis); padding: 2px 0 2px 12px; }
.children { display: flex; flex-wrap: wrap; gap: 6px; }
.child-button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 3px 8px; font-size: 12.5px; display: inline-flex; gap: 6px; align-items: center; }
.child-button:hover { border-color: var(--accent); }
.subtle { color: var(--ink-2); font-weight: 400; }

.text-block { border: 1px solid var(--line); border-radius: 6px; padding: 4px 12px 8px; background: var(--surface); }
.text-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px solid var(--grid); padding-bottom: 3px; margin-bottom: 4px; }
.prose { overflow-wrap: anywhere; }
.prose p { margin: 6px 0; }
.prose pre, pre.plain { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 8px; border-radius: 6px; margin: 6px 0; }
.prose code { font-family: var(--mono); font-size: 12.5px; background: var(--surface-2); padding: 0 3px; border-radius: 3px; }
.prose table { border-collapse: collapse; margin: 6px 0; }
.prose th, .prose td { border: 1px solid var(--grid); padding: 2px 6px; }
.table-scroll { overflow-x: auto; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.lazy-block { margin-top: 8px; }
.lazy-block > summary { color: var(--accent); font-weight: 500; }
.error { color: var(--critical-text); }
.marker { font-family: var(--mono); font-size: 12px; background: var(--accent-wash); border-radius: 4px; padding: 0 4px; }
.prompt-message { margin: 6px 0; }
.prompt-role { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); text-transform: uppercase; }
.prompt-text { white-space: pre-wrap; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12px; background: var(--surface-2); border-radius: 6px; padding: 6px 8px; margin: 2px 0 0; }

.tooltip { position: fixed; z-index: 20; max-width: 360px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 18px rgba(0, 0, 0, .18); padding: 8px 10px; font-size: 12.5px; pointer-events: none; }
.tooltip .tt-title { font-weight: 700; font-family: var(--mono); }
.tooltip .tt-row { display: flex; gap: 8px; justify-content: space-between; }
.tooltip .tt-row span:first-child { color: var(--ink-2); }
.tooltip .tt-text { color: var(--ink-2); margin-top: 4px; overflow-wrap: anywhere; }

/* Overview. */
.overview { padding: 18px 24px 80px; max-width: 1180px; }
.overview h2 { margin: 0 0 4px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 14px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.tile .value { font-size: 26px; font-weight: 700; line-height: 1.2; }
.tile .label { color: var(--ink-2); font-size: 12.5px; }
table.stats { border-collapse: collapse; font-size: 13px; margin-top: 4px; }
table.stats th { text-align: right; color: var(--ink-2); font-weight: 500; font-size: 12px; border-bottom: 1px solid var(--axis); padding: 4px 10px; white-space: nowrap; }
table.stats th:first-child, table.stats td:first-child { text-align: left; padding-left: 0; }
table.stats td { text-align: right; border-bottom: 1px solid var(--grid); padding: 4px 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.stats td .sub { color: var(--ink-2); font-size: 11.5px; }
.panel .note { color: var(--ink-2); font-size: 12.5px; margin: 6px 0 0; max-width: 900px; }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; max-height: 50vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .detail, .overview { padding: 14px; }
}
@media (forced-colors: active) {
  .tnode rect.body { stroke: CanvasText; }
  .edge { stroke: CanvasText; }
}
