:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;
  --edge: #b9b8b0;
  --mid: #f0efec;
  /* sequential blue, near-zero first */
  --seq: #cde2fb,#9ec5f4,#6da7ec,#3987e5,#256abf,#184f95,#0d366b;
  /* diverging: blue arm, gray mid, red arm */
  --div-lo: #256abf; --div-lo2: #86b6ef; --div-hi2: #f0a3a2; --div-hi: #c23b3a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --edge: #4a4a46; --mid: #383835;
    --good-text: #0ca30c;
    --seq: #1c3a5e,#184f95,#1c5cab,#2a78d6,#5598e7,#86b6ef,#cde2fb;
    --div-lo: #5598e7; --div-lo2: #2a4f7e; --div-hi2: #7a3030; --div-hi: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --edge: #4a4a46; --mid: #383835;
  --good-text: #0ca30c;
  --seq: #1c3a5e,#184f95,#1c5cab,#2a78d6,#5598e7,#86b6ef,#cde2fb;
  --div-lo: #5598e7; --div-lo2: #2a4f7e; --div-hi2: #7a3030; --div-hi: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page); color: var(--ink);
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1 { font-size: 16px; margin: 0; }
h2 { font-size: 14px; margin: 0; }
h3 { font-size: 12px; margin: 0 0 6px; color: var(--ink-2); font-weight: 600; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
input[type=number] { width: 72px; }
input, select, button { font: inherit; color: inherit; }
input[type=number], select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 3px 6px;
}

.btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.file input { display: none; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; min-width: 0; }
.top-actions { display: flex; gap: 6px; }

.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
}
.controls label { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 4px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.adv { position: relative; }
.adv summary { cursor: pointer; color: var(--ink-2); }
.adv[open] > label { display: flex; margin-top: 6px; }
.adv[open] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
}

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 0;
  height: calc(100vh - 100px); min-height: 460px;
}
.panes { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); min-width: 0; }
.panes .empty { padding: 40px; }
.pane { display: flex; flex-direction: column; min-width: 0; border-right: 1px solid var(--border); background: var(--surface); }
.pane-head { display: flex; align-items: baseline; gap: 10px; padding: 8px 12px 4px; flex-wrap: wrap; }
.pane-head .stats { color: var(--ink-2); }
.pane-tools { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 4px 12px 6px; color: var(--ink-2); }
.pane-tools label { display: inline-flex; align-items: center; gap: 5px; }
.pane-tools .vals { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.pane-tools .vals label { gap: 2px; }
.sep { flex: 1; }
.game-summary { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend b { font-weight: 700; }
.pane-tools input[type=range] { width: 160px; }
.policy { padding: 0 12px 6px; display: grid; grid-template-columns: minmax(0, 1fr) 90px 90px; grid-auto-rows: 16px; line-height: 16px; gap: 1px 8px; font-size: 11px; max-height: 120px; overflow: auto; }
.policy .hdr { color: var(--muted); }
.bar { position: relative; height: 10px; background: var(--surface-2); border-radius: 0 3px 3px 0; align-self: center; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 0 3px 3px 0; }
.bar.prior > i { background: var(--muted); }
.bar > b { position: absolute; right: 2px; top: -3px; font-weight: 400; font-size: 10px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canvas { flex: 1; position: relative; min-height: 200px; overflow: hidden; border-top: 1px solid var(--border); }
.canvas svg { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
.canvas svg.drag { cursor: grabbing; }
.canvas svg:focus { outline: none; }
.canvas svg:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.legend { display: flex; align-items: center; gap: 12px; padding: 4px 12px; font-size: 11px; color: var(--ink-2); flex-wrap: wrap; border-top: 1px solid var(--border); }
.ramp { width: 120px; height: 8px; border-radius: 2px; }
.legend .sw { display: inline-flex; align-items: center; gap: 4px; }
.stale { background: var(--surface-2); color: var(--ink-2); padding: 2px 8px; border-radius: 4px; }

.edge { fill: none; stroke: var(--edge); }
.edge.diverged { stroke: var(--serious); stroke-dasharray: 4 3; }
.edge.below { stroke-dasharray: 1 3; opacity: .55; }
.node.below { opacity: .55; }
.mk { font-size: 11px; font-weight: 700; pointer-events: none; }
.mk-none { fill: var(--critical); color: var(--critical); }
.mk-approx { fill: var(--ink-2); color: var(--ink-2); }
.nvals { font-size: 9px; fill: var(--muted); pointer-events: none; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.nlabel.best { font-weight: 700; fill: var(--ink); }
.playbtn { cursor: pointer; }
.playbtn rect { fill: var(--surface); stroke: var(--accent); stroke-width: 1.2; }
.playbtn path { fill: var(--accent); }
.playbtn.best rect { fill: var(--accent); }
.playbtn.best path { fill: var(--accent-ink); }
.playbtn:hover rect { fill: var(--accent); }
.playbtn:hover path { fill: var(--accent-ink); }
.edge.on-path { stroke: var(--ink); }
.edge.replay { stroke: var(--accent); }
.node { stroke: var(--surface); stroke-width: 1.5; cursor: pointer; }
.node.nodata { fill: var(--surface) !important; stroke: var(--muted); }
.node.sel { stroke: var(--ink); stroke-width: 3; }
.node.twin { stroke: var(--accent); stroke-width: 3; }
.nlabel { font-size: 10px; fill: var(--ink-2); pointer-events: none; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.badge { font-size: 9px; fill: var(--muted); pointer-events: none; }

.inspector { overflow: auto; padding: 10px 14px 40px; background: var(--surface); border-left: 1px solid var(--border); }
.inspector h2 { margin-bottom: 4px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px 4px; margin: 4px 0 10px; font-size: 11px; }
.crumbs a { color: var(--accent); cursor: pointer; text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.kpi { background: var(--surface-2); border-radius: 6px; padding: 5px 8px; }
.kpi .k { color: var(--muted); font-size: 10px; }
.kpi .v { font-size: 13px; font-variant-numeric: tabular-nums; }
.sec { margin: 12px 0; }
table { border-collapse: collapse; width: 100%; font-size: 11px; }
th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--grid); padding: 2px 4px; }
td { padding: 2px 4px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
td.num, th.num { text-align: right; }
tr.hl td { background: color-mix(in srgb, var(--serious) 18%, transparent); }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--surface-2); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.two ul { margin: 0; padding-left: 16px; font-size: 11px; }
.flag { font-size: 10px; padding: 0 5px; border-radius: 3px; border: 1px solid var(--border); white-space: nowrap; }
.flag.bad { color: var(--critical); border-color: currentColor; }
.flag.ok { color: var(--good-text); border-color: currentColor; }
.heat { display: grid; gap: 1px; font-size: 9px; }
.heat div { text-align: center; padding: 1px 0; font-variant-numeric: tabular-nums; border-radius: 2px; }
.heats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

.history { margin: 0; padding-left: 20px; font-size: 11px; }

.tip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 300px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 11px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
}
.tip b { font-weight: 600; }
.tip .row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tip .row span:first-child { color: var(--muted); }
.err { color: var(--critical); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panes { grid-auto-flow: row; }
  .pane { height: 70vh; }
  .inspector { border-left: 0; border-top: 1px solid var(--border); }
}

/* ------------------------------------------------------------ model picker */
.picker {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px;
  background: rgba(0, 0, 0, 0.45);
}
.picker[hidden] { display: none; }
.picker-card {
  width: min(760px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
}
.picker.required .picker-close { display: none; }
.picker-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
#picker-body { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.picker-top { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.picker-tabs small { color: var(--muted); margin-left: 2px; }
.picker-tabs button.on small { color: inherit; opacity: 0.8; }
.picker-search {
  flex: 1; min-width: 160px; padding: 4px 8px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px;
}
.picker-list { display: flex; flex-direction: column; gap: 2px; overflow: auto; min-height: 120px; max-height: 52vh; }
.picker-run {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline; text-align: left;
  padding: 5px 8px; background: transparent; border: 1px solid transparent; border-radius: 6px; cursor: pointer;
}
.picker-run:hover { background: var(--surface-2); }
.picker-run.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.picker-run.current .picker-run-name::after { content: " ●"; color: var(--good-text); }
.picker-run-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-run-meta { color: var(--muted); font-size: 11px; white-space: nowrap; }
.picker-foot { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; }
.picker-foot label { display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); }
.picker-foot .muted { flex: 1; min-width: 120px; }
.picker-err { flex-basis: 100%; }
.picker-err:empty { display: none; }
.picker-env { display: inline-block; margin-right: 6px; padding: 0 5px; font-size: 10px; border: 1px solid var(--border); border-radius: 3px; color: var(--muted); vertical-align: 1px; }

/* ------------------------------------------------------------ growth + autoplay */
.node.fresh { animation: nodeIn 0.35s cubic-bezier(0.2, 1.5, 0.4, 1) both; transform-box: fill-box; transform-origin: center; }
@keyframes nodeIn { from { transform: scale(0); opacity: 0; } }
.pane.growing .canvas::after {
  content: "growing · click or space to skip"; position: absolute; right: 10px; bottom: 8px;
  font-size: 11px; color: var(--muted); pointer-events: none;
}
.btn.autoplay.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
@media (prefers-reduced-motion: reduce) { .node.fresh { animation: none; } }

/* ------------------------------------------------------------ settings popover + help */
.adv { position: relative; }
.adv[open] { background: none !important; border: 0 !important; box-shadow: none !important; padding: 0 !important; }
.adv-panel {
  position: absolute; z-index: 25; top: calc(100% + 6px); left: 0; width: 260px;
  display: grid; gap: 6px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.adv-panel label { display: flex !important; justify-content: space-between; margin: 0 !important; }
.help-card { width: min(640px, 100%); }
.help-body { overflow: auto; line-height: 1.5; font-size: 14px; }
.help-body ul { padding-left: 18px; display: grid; gap: 6px; }
.help-body kbd { padding: 0 4px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 3px; font-size: 11px; }

.pane-tools .adv-panel .vals { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.pane-tools .adv-panel .btn { justify-self: start; }

.compare-note { margin: 12px 0 4px; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--surface-2); font-size: 12px; color: var(--ink-2); }

/* new parts of a growing tree: edges draw in, labels fade in (all themes) */
.edge.fresh-edge { stroke-dasharray: 1; stroke-dashoffset: 1; animation: drawIn 0.45s ease-out forwards; }
@keyframes drawIn { to { stroke-dashoffset: 0; } }
.label-in { animation: labelIn 0.5s ease 0.2s both; }
@keyframes labelIn { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .edge.fresh-edge, .label-in { animation: none; stroke-dasharray: none; } }

/* ------------------------------------------------------------ guided tour */
.tour { position: fixed; inset: 0; z-index: 40; }
.tour[hidden] { display: none; }
.tour-spot {
  position: fixed; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55), 0 0 0 2px var(--accent), 0 0 24px 4px var(--accent);
  transition: left 0.35s ease, top 0.35s ease, width 0.35s ease, height 0.35s ease;
}
.tour-bubble {
  position: fixed; width: min(420px, calc(100vw - 24px)); padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  transition: left 0.35s ease, top 0.35s ease;
}
.tour-count { font-size: 11px; color: var(--muted); }
.tour-title { margin: 2px 0 6px; font-size: 16px; color: var(--ink); }
.tour-text { margin: 0 0 10px; line-height: 1.5; font-size: 14px; }
.tour-nav { display: flex; gap: 6px; align-items: center; }
@media (prefers-reduced-motion: reduce) { .tour-spot, .tour-bubble { transition: none; } }

/* the hidden attribute wins over display rules (static hosting hides the live-search controls) */
[hidden] { display: none !important; }

/* live search (live.js) */
.live-card { max-width: 640px; margin: 48px auto; padding: 24px 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--ink); }
.live-card h2 { margin: 0 0 10px; }
.live-card ul { padding-left: 1.2em; line-height: 1.55; }
.live-card li { margin-bottom: 6px; }
.live-actions { margin: 18px 0 8px; }
.lv-est { font-size: 12px; color: var(--muted); }
.lv-est.warn { color: var(--serious); font-weight: 600; }
.lv-est.bad { color: var(--critical); font-weight: 700; }
.lv-game { margin-left: auto; font-size: 12px; color: var(--ink-2); }
