:root {
  --paper: #f3efe2;
  --paper-2: #efe8d6;
  --ink: #211d16;
  --ink-soft: #5a5346;
  --ink-faint: #9a917e;
  --grid: rgba(46, 64, 92, .07);
  --grid-major: rgba(46, 64, 92, .12);
  --red: #9c2b25;
  --red-wash: rgba(156, 43, 37, .10);
  --sel: rgba(33, 29, 22, .10);
  --hair: rgba(33, 29, 22, .22);
  --mono: "SFMono-Regular", ui-monospace, "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0c101d;
    --paper-2: #101727;
    --ink: #eee8df;
    --ink-soft: #b5ab9d;
    --ink-faint: #736b60;
    --grid: rgba(209, 191, 163, .08);
    --grid-major: rgba(209, 191, 163, .14);
    --red: #e39a92;
    --red-wash: rgba(227, 154, 146, .14);
    --sel: rgba(238, 232, 223, .12);
    --hair: rgba(238, 232, 223, .24);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
}

button, input { font: inherit; }
.app { display: flex; flex-direction: column; width: 100vw; height: 100vh; }
.deck {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: 7px;
  padding: 9px 14px 8px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}
.deck::after { content: ""; position: absolute; right: 0; bottom: -3px; left: 0; height: 1px; background: var(--hair); }
.deck-top { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.eyebrow { font-size: 10px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; white-space: nowrap; }
.eyebrow .mk { color: var(--red); }
.problem {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  padding-left: 12px;
  border-left: 1px solid var(--hair);
  color: var(--ink-soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.problem b { color: var(--ink); }
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grp { display: flex; align-items: center; gap: 2px; border: 1px solid var(--ink); background: var(--paper-2); }
.tk {
  min-width: 30px;
  padding: 5px 9px;
  border: 0;
  border-right: 1px solid var(--hair);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}
.tk:last-child { border-right: 0; }
.tk:hover { background: var(--sel); }
.tk:active { background: var(--ink); color: var(--paper); }
.tk.play { min-width: 38px; font-weight: 600; }
.scrub { display: flex; flex: 1 1 260px; min-width: 200px; align-items: center; gap: 9px; }
input[type="range"] { width: 100%; height: 18px; cursor: pointer; background: transparent; appearance: none; }
input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  width: 11px;
  height: 11px;
  margin-top: -5px;
  border: 1.5px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  appearance: none;
}
.readout { color: var(--ink-soft); font-size: 11px; font-variant-numeric: tabular-nums; letter-spacing: .04em; white-space: nowrap; }
.readout b { color: var(--ink); }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); cursor: pointer; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; user-select: none; white-space: nowrap; }
.toggle .box { display: inline-flex; width: 14px; height: 14px; align-items: center; justify-content: center; border: 1px solid var(--ink); background: var(--paper-2); color: var(--red); line-height: 1; }
.toggle.on .box::after { content: "✓"; }

.stage { position: relative; display: flex; flex: 1 1 auto; min-height: 0; }
.panel { position: relative; display: flex; min-width: 0; min-height: 0; flex-direction: column; }
.panel-hd { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; padding: 5px 12px; border-bottom: 1px solid var(--hair); background: var(--paper); color: var(--ink-faint); font-size: 10px; letter-spacing: .2em; text-transform: uppercase; }
.panel-hd .hint { letter-spacing: .02em; text-transform: none; }
#left { flex: 1 1 56%; border-right: 1px solid var(--ink); }
#right { flex: 1 1 44%; }
.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(var(--grid-major) 1px, transparent 1px) 0 0 / 110px 110px,
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px) 0 0 / 110px 110px,
    var(--paper-2);
}
.canvas-wrap.panning { cursor: grabbing; }
svg#tree { display: block; width: 100%; height: 100%; }
.edge { stroke: var(--ink-soft); stroke-width: 1.1; }
.edge.pv { stroke: var(--red); stroke-width: 2.3; }
.node { cursor: pointer; }
.node .disc { fill: var(--paper); stroke: var(--ink); stroke-width: 1.5; }
.node .disc.inner { fill: none; }
.node.rejected .disc { stroke: var(--ink-soft); stroke-dasharray: 3 2.5; }
.node.pv .disc, .node.verified .disc { stroke: var(--red); }
.node.sel .disc { fill: var(--sel); stroke-width: 2.4; }
.node .glyph, .node .cap-id, .node .cap-st { font-family: var(--mono); text-anchor: middle; pointer-events: none; }
.node .glyph { font-weight: 600; dominant-baseline: central; }
.node .glyph.tick { fill: var(--red); }
.node .glyph.cross { fill: var(--ink-soft); }
.node .cap-id { fill: var(--ink); font-size: 11px; font-weight: 600; }
.node .cap-st { fill: var(--ink-faint); font-size: 9.5px; font-variant-numeric: tabular-nums; }
.node.sel .cap-id { fill: var(--red); }
.node.born { animation: pop .32s ease-out; }
@keyframes pop { from { opacity: 0; } to { opacity: 1; } }
.titleblock { position: absolute; right: 10px; bottom: 10px; display: grid; grid-template-columns: auto auto; border: 1px solid var(--ink); background: var(--paper); color: var(--ink-soft); font-size: 9px; letter-spacing: .06em; pointer-events: none; }
.titleblock div { padding: 3px 7px; border-right: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.titleblock div:nth-child(2n) { border-right: 0; }
.titleblock div:nth-last-child(-n+2) { border-bottom: 0; }
.titleblock .k { color: var(--ink-faint); text-transform: uppercase; }
.titleblock .v { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.outline { flex: 1 1 auto; overflow: auto; padding: 10px 4px 14px 0; background: var(--paper); white-space: nowrap; }
.row { display: flex; align-items: baseline; padding-left: 12px; cursor: pointer; font-size: 13px; line-height: 1.7; }
.row:hover { background: var(--sel); }
.row.sel { background: var(--red-wash); box-shadow: inset 2px 0 0 var(--red); }
.row .pre { flex: 0 0 auto; color: var(--ink-faint); white-space: pre; }
.row.pv .pre, .row.pv .id { color: var(--red); }
.tog { flex: 0 0 auto; color: var(--ink); white-space: pre; }
.tog.empty { color: var(--ink-faint); }
.row .id { flex: 0 0 auto; padding: 0 7px 0 4px; color: var(--ink); font-weight: 600; }
.row .txt { flex: 0 0 auto; color: var(--ink-soft); }
.row.verified .txt { color: var(--ink); }
.row .st { flex: 0 0 auto; padding-left: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.row .mk { flex: 0 0 auto; padding-left: 7px; }
.row .mk.tick { color: var(--red); }
.row .mk.cross { color: var(--ink-faint); }
.inspector { position: relative; display: flex; flex: 0 0 auto; flex-direction: column; gap: 3px; padding: 7px 14px; border-top: 1px solid var(--ink); background: var(--paper); color: var(--ink-soft); font-size: 11px; }
.inspector::before { content: ""; position: absolute; top: -3px; right: 0; left: 0; height: 1px; background: var(--hair); }
.insp-line { display: flex; flex-wrap: wrap; align-items: baseline; }
.field { font-variant-numeric: tabular-nums; white-space: nowrap; }
.field + .field::before { content: "·"; padding: 0 9px; color: var(--hair); }
.field .k { color: var(--ink-faint); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.field .v { padding-left: 6px; color: var(--ink); font-weight: 600; }
.field .v.red { color: var(--red); }
.insp-text { color: var(--ink); font-size: 12px; white-space: normal; }
.insp-text .lead { color: var(--ink-faint); }
.loading { display: grid; height: 100%; place-items: center; color: var(--ink-soft); letter-spacing: .08em; text-transform: uppercase; }

@media (max-width: 860px) {
  .stage { flex-direction: column; }
  #left { flex: 0 0 52%; border-right: 0; border-bottom: 1px solid var(--ink); }
  #right { flex: 1 1 auto; }
  .problem { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .node.born { animation: none; }
}
