/* horizon — quiet, editorial UI: white paper, ink type, hairline rules. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface-1: #ffffff;
  --surface-2: #f6f6f4;
  --border: #ebebea;
  --border-strong: #d6d6d3;
  --text-primary: #222222;
  --text-secondary: #6e6e6b;
  --text-muted: #a5a5a1;
  --grid: #f0f0ee;
  --series-1: #2a78d6;      /* model */
  --series-2: #eb6834;      /* baseline */
  --actual: #222222;        /* observed data */
  --train-fill: rgba(42, 120, 214, 0.05);
  --hold-fill: rgba(34, 34, 34, 0.03);
  --king: #c48a00;
  --good: #1f7a45;
  --bad: #c43d3d;
  --ink: #222222;
  --font: 'Inter Tight', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --mono: 'Inter Tight', 'Helvetica Neue', Arial, sans-serif;
  --gutter: 48px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141414; --surface-1: #141414; --surface-2: #1c1c1c;
    --border: #262626; --border-strong: #363636;
    --text-primary: #ececea; --text-secondary: #a3a3a0; --text-muted: #6f6f6c;
    --grid: #1f1f1f; --series-1: #3987e5; --series-2: #d95926; --actual: #e6e6e3;
    --train-fill: rgba(57, 135, 229, 0.06); --hold-fill: rgba(255,255,255,0.03);
    --king: #e2ad3b; --good: #4cbb7a; --bad: #e66767; --ink: #ececea;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141414; --surface-1: #141414; --surface-2: #1c1c1c;
  --border: #262626; --border-strong: #363636;
  --text-primary: #ececea; --text-secondary: #a3a3a0; --text-muted: #6f6f6c;
  --grid: #1f1f1f; --series-1: #3987e5; --series-2: #d95926; --actual: #e6e6e3;
  --train-fill: rgba(57, 135, 229, 0.06); --hold-fill: rgba(255,255,255,0.03);
  --king: #e2ad3b; --good: #4cbb7a; --bad: #e66767; --ink: #ececea;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text-primary); font: 400 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; font-feature-settings: 'ss01', 'cv11'; }
.mono, .num { font-family: var(--font); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h1, h2, h3 { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
h1 { font-size: 26px; letter-spacing: -0.02em; line-height: 1.15; }
h2 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.06em; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-primary); }
.sub, .hint { color: var(--text-secondary); font-size: 12.5px; margin: 0; }
.hint { line-height: 1.55; }
.blurb, .model-blurb { font-family: var(--serif); font-size: 16px; line-height: 1.4; color: var(--text-primary); margin: 0 0 12px; letter-spacing: -0.005em; }
.model-blurb { font-size: 15px; color: var(--text-secondary); }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; }

/* ---------- buttons & inputs ---------- */
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; text-transform: uppercase; letter-spacing: 0.06em; font-size: 11px; font-weight: 500; color: var(--text-primary); transition: color .12s, opacity .12s; }
button:hover { color: var(--text-secondary); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 1px solid var(--ink); outline-offset: 3px; }
button.ghost { background: none; }
button.small { font-size: 10.5px; }
button.icon { font-size: 14px; letter-spacing: 0; text-transform: none; }
button.primary { background: var(--ink); color: var(--bg); padding: 12px 22px; font-size: 11.5px; letter-spacing: 0.08em; }
button.primary:hover { opacity: .82; color: var(--bg); }
button:disabled { opacity: .35; cursor: not-allowed; }
.btn-row { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; }
.btn-row button { color: var(--text-secondary); }
.btn-row button:hover { color: var(--text-primary); }

select, input[type=text], input:not([type]) {
  background: transparent; border: 0; border-bottom: 1px solid var(--border-strong); border-radius: 0; padding: 5px 0; outline: none;
}
select { appearance: none; -webkit-appearance: none; padding-right: 18px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 7px) 55%, calc(100% - 3px) 55%; background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }
select:hover, input:hover { border-bottom-color: var(--text-secondary); }
select:focus, input:focus { border-bottom-color: var(--ink); outline: none; }

/* range: hairline track, small ink thumb */
input[type=range] { -webkit-appearance: none; appearance: none; background: transparent; height: 16px; margin: 0; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: var(--border-strong); }
input[type=range]::-moz-range-track { height: 1px; background: var(--border-strong); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 11px; height: 11px; border-radius: 50%; background: var(--ink); margin-top: -5px; border: 0; transition: transform .1s; }
input[type=range]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 50%; background: var(--ink); border: 0; }
input[type=range]:hover::-webkit-slider-thumb { transform: scale(1.2); }
input[type=checkbox] { accent-color: var(--ink); margin: 0; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 28px; padding: 22px var(--gutter); background: var(--bg); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; border-bottom: 1px solid transparent; }
.brand { display: flex; align-items: center; gap: 9px; color: inherit; text-decoration: none; font-weight: 500; font-size: 16px; letter-spacing: -0.02em; }
.brand svg { width: 18px; height: 18px; }
.brand:hover span { color: var(--text-secondary); }
.challenge-bar { display: flex; align-items: center; gap: 18px; flex: 1; min-width: 0; }
.challenge-bar select { max-width: 280px; min-width: 0; font-size: 13px; }
.chip { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
#challengeIdChip { text-transform: none; letter-spacing: 0.02em; }
.player { display: flex; align-items: center; gap: 12px; }
.player label { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; }
.player input { width: 130px; font-size: 13px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr) 280px; gap: 48px; padding: 8px var(--gutter) 80px; max-width: 1760px; margin: 0 auto; align-items: start; }
.controls, .board { display: flex; flex-direction: column; gap: 0; }
.controls { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow-y: auto; padding-right: 10px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.workspace { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.card, .panel { background: none; border: 0; border-top: 1px solid var(--border); border-radius: 0; box-shadow: none; }
.panel { padding: 16px 0 24px; }
.card { padding: 18px 0 24px; }
.panel-h { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.panel-h h2 { flex: 1; }
.step { font: 400 11px var(--font); color: var(--text-muted); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; flex: none; }
.step::before { content: 'N° '; }
.step.big { font-size: 11px; padding-top: 2px; }

details summary { cursor: pointer; user-select: none; }
.group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); margin: 18px 0 4px; font-weight: 500; }

/* slider rows */
.ctl { display: grid; grid-template-columns: 1fr 58px; align-items: center; gap: 0 14px; padding: 5px 0; }
.ctl label { font-size: 12.5px; color: var(--text-secondary); grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 6px; }
.ctl label .why { color: var(--text-muted); cursor: help; font-size: 11px; }
.ctl input[type=range] { width: 100%; }
.ctl input[type=number] { width: 58px; padding: 2px 0; font: 400 12.5px var(--font); font-variant-numeric: tabular-nums; text-align: right; background: transparent; border: 0; border-bottom: 1px solid transparent; color: var(--text-primary); -moz-appearance: textfield; }
.ctl input[type=number]::-webkit-inner-spin-button, .ctl input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.ctl input[type=number]:hover, .ctl input[type=number]:focus { border-bottom-color: var(--border-strong); outline: none; }
.ctl.disabled { opacity: .3; }
.ctl select { grid-column: 1 / -1; font-size: 13px; }
.ctl.check { grid-template-columns: auto 1fr; gap: 10px; }
.ctl.check label { grid-column: 2; }

/* text tabs with an underline, like a filter row */
.seg { display: flex; gap: 2px 18px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.seg button { padding: 6px 0 8px; margin-bottom: -1px; border-bottom: 1px solid transparent; font-size: 13px; text-transform: none; letter-spacing: -0.005em; font-weight: 400; color: var(--text-muted); white-space: nowrap; }
.seg button:hover { color: var(--text-primary); }
.seg button[aria-selected=true] { color: var(--text-primary); border-bottom-color: var(--ink); }

/* ---------- charts ---------- */
.chart-card { border-top: 0; padding-top: 0; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.chart-head .sub { margin-top: 6px; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 4px 18px; flex-wrap: wrap; }
.legend button { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text-secondary); }
.legend button:hover { color: var(--text-primary); }
.legend button[aria-pressed=false] { opacity: .4; }
.legend button[aria-pressed=false] .sw { filter: grayscale(1); }
.sw { width: 14px; height: 0; border-top: 1.5px solid; display: inline-block; }
.sw.dash { border-top-style: dashed; }
.sw.band { height: 9px; border: 0; }
.chart-wrap { position: relative; height: 420px; touch-action: none; }
.chart-wrap.small { height: 170px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
#mainChart { cursor: crosshair; }
.tooltip { position: absolute; pointer-events: none; background: var(--bg); border: 1px solid var(--border-strong); padding: 9px 12px; font-size: 12px; min-width: 160px; z-index: 2; box-shadow: 0 6px 24px rgba(0,0,0,.06); }
.tooltip .t-h { color: var(--text-muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 5px; }
.tooltip .t-r { display: flex; align-items: center; gap: 10px; justify-content: space-between; line-height: 1.7; }
.tooltip .t-r span:first-child { display: flex; align-items: center; gap: 7px; color: var(--text-secondary); }
.tooltip .t-r b { font-weight: 500; font-variant-numeric: tabular-nums; }
.mini-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.mini-head .sub { font-size: 12px; color: var(--text-muted); }
.diag { display: grid; grid-template-columns: 1fr 1fr; gap: 0 40px; }

/* ---------- metric row ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 40px; border-top: 1px solid var(--border); padding: 18px 0 24px; }
.tile { padding: 0; }
.tile .k { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.tile .v { font: 300 34px/1.15 var(--font); letter-spacing: -0.03em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .d { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.tile .d.good { color: var(--good); } .tile .d.bad { color: var(--bad); }

/* ---------- apply ---------- */
.apply-card { display: flex; align-items: center; justify-content: space-between; gap: 24px; flex-wrap: wrap; padding: 24px 0; }
.apply-text { display: flex; gap: 14px; align-items: baseline; flex: 1; min-width: 260px; }
.apply-text h2 { font-size: 11.5px; }
.apply-text .hint { margin-top: 6px; max-width: 560px; font-family: var(--serif); font-size: 15px; color: var(--text-secondary); line-height: 1.45; }
.result { padding: 22px 0 26px; }
.result.crowned { border-top: 1.5px solid var(--ink); }
.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 40px; margin-top: 16px; }
.result-grid .k { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.result-grid .v { font: 300 30px/1.2 var(--font); letter-spacing: -0.03em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.result .headline { font-family: var(--serif); font-size: 22px; font-weight: 400; letter-spacing: -0.01em; display: flex; align-items: center; gap: 8px; }
.result .hint { margin-top: 12px !important; }

/* ---------- board ---------- */
.board .card:first-child { border-top: 0; padding-top: 0; }
.king { text-align: left; padding-bottom: 28px; }
.king .crown { font-size: 18px; line-height: 1; color: var(--king); }
.king .kname { font-family: var(--serif); font-size: 34px; font-weight: 400; line-height: 1.1; margin-top: 10px; letter-spacing: -0.015em; word-break: break-word; }
.king .kscore { font-size: 12.5px; color: var(--text-secondary); margin-top: 8px; font-variant-numeric: tabular-nums; }
.king .ksince { font-size: 10.5px; color: var(--text-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.king.empty .kname { font-size: 24px; color: var(--text-primary); }
.ranks, .reigns, .hills { list-style: none; margin: 0; padding: 0; }
.ranks li { display: grid; grid-template-columns: 22px 1fr auto; gap: 2px 12px; align-items: baseline; padding: 11px 0; border-top: 1px solid var(--border); font-size: 13.5px; }
.ranks li:first-child { border-top: 0; }
.ranks li.empty-note, .reigns li.empty-note { display: block; border: 0; }
.ranks li.me .nm { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.ranks .pos { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.ranks li:first-child .pos { color: var(--text-primary); }
.ranks .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranks .sc { font-variant-numeric: tabular-nums; }
.ranks .meta { grid-column: 2 / -1; font-size: 11.5px; color: var(--text-muted); }
.ranks .meta button { font-size: 10px; margin-left: 8px; color: var(--text-secondary); text-decoration: underline; text-underline-offset: 2px; }
.reigns li { font-size: 12.5px; padding: 8px 0; border-top: 1px solid var(--border); color: var(--text-secondary); }
.reigns li:first-child { border-top: 0; }
.reigns b { color: var(--text-primary); font-weight: 500; }
.hills li { padding: 9px 0; border-top: 1px solid var(--border); font-size: 13px; display: flex; justify-content: space-between; gap: 10px; }
.hills li:first-child { border-top: 0; }
.hills a { color: var(--text-primary); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hills a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.hills .muted { color: var(--text-muted); white-space: nowrap; font-size: 12px; }
.empty-note { color: var(--text-muted); font-size: 12.5px; padding: 4px 0; }
#spoilerNote { margin-top: 10px; }

.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 11px 18px; font-size: 12.5px; z-index: 50; max-width: calc(100vw - 32px); }

/* ---------- series customisation ---------- */
.btn-row.tight { margin: 0 0 16px; }
.custom-name { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.custom-name label { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.custom-name input { width: 100%; font-size: 14px; }
.components { margin: 0 0 10px; }
.components .mini-head { margin-bottom: 4px; }
#compChart { width: 100%; height: 108px; display: block; }
.gen-group { border-top: 1px solid var(--border); }
.gen-group summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 11px 0; font-size: 13px; color: var(--text-primary); }
.gen-group summary::-webkit-details-marker { display: none; }
.gen-group summary::before { content: '+'; color: var(--text-muted); width: 10px; font-size: 13px; }
.gen-group[open] summary::before { content: '−'; }
.gen-group summary .on { margin-left: auto; font-size: 10.5px; color: var(--series-1); text-transform: uppercase; letter-spacing: 0.05em; }
.gen-group[open] { padding-bottom: 8px; }
.ctl.changed label span:first-child::after { content: ' •'; color: var(--series-1); }
#seriesMode.custom { color: var(--series-1); }

/* ---------- fold-up series panel ---------- */
.fold-btn { margin-left: 6px; color: var(--text-secondary); }
.fold-summary { display: block; width: 100%; text-align: left; text-transform: none; letter-spacing: 0; font: 400 13px/1.5 var(--font); color: var(--text-secondary); padding: 0; }
.fold-summary b { font-family: var(--serif); font-size: 17px; font-weight: 400; color: var(--text-primary); display: block; margin-bottom: 2px; }
.fold-summary:hover b { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
#genPanel.folded { padding-bottom: 20px; }

/* ---------- model tabs ---------- */
.ctl-note { grid-column: 1 / -1; margin: 2px 0 6px; font-size: 12px; color: var(--text-secondary); }

/* ---------- GBM insight ---------- */
.importance { display: flex; flex-direction: column; gap: 7px; max-height: 210px; overflow-y: auto; }
.imp-row { display: grid; grid-template-columns: 96px 1fr 36px; align-items: center; gap: 12px; font-size: 12.5px; }
.imp-name { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.imp-bar { height: 6px; background: var(--surface-2); overflow: hidden; }
.imp-bar i { display: block; height: 100%; background: var(--series-1); }
.imp-val { font-variant-numeric: tabular-nums; text-align: right; }
.legend-inline { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-secondary); }
.legend-inline .sw { margin-left: 10px; }

/* ---------- auto parameter discovery ---------- */
.auto-btn { width: 100%; margin: 18px 0 0; padding: 12px; border: 1px solid var(--ink); color: var(--text-primary); font-size: 11px; letter-spacing: 0.08em; }
.auto-btn:hover { background: var(--ink); color: var(--bg); }
.auto-dlg { position: fixed; right: var(--gutter); bottom: 28px; width: 380px; max-width: calc(100vw - 32px); max-height: calc(100vh - 110px); overflow-y: auto; z-index: 40;
  background: var(--bg); border: 1px solid var(--border-strong); padding: 20px 22px 22px; box-shadow: 0 24px 60px rgba(0,0,0,.10); }
.auto-dlg[hidden] { display: none; }
.auto-dlg .v-setup, .auto-dlg .v-running, .auto-dlg .v-done { display: none; }
.auto-dlg[data-view="setup"] .v-setup, .auto-dlg[data-view="running"] .v-running, .auto-dlg[data-view="done"] .v-done { display: block; }
.auto-dlg[data-view="setup"] button.v-setup, .auto-dlg[data-view="done"] button.v-done { display: inline-block; }
.auto-dlg[data-view="running"] .auto-actions.v-running, .auto-dlg[data-view="done"] .v-done .auto-actions { display: flex; }
.auto-dlg[data-view="running"] .auto-legend .v-running { display: inline; }
.auto-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.auto-dlg .hint { margin: 0 0 14px; }
.auto-opt { display: grid; grid-template-columns: 56px 1fr; align-items: end; gap: 10px; margin-bottom: 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.auto-opt .seg { margin: 0; }
button.wide { width: 100%; margin-top: 4px; }
.auto-model { display: flex; justify-content: space-between; gap: 8px; font-family: var(--serif); font-size: 17px; margin-bottom: 10px; }
.auto-model .num { font: 400 12px var(--font); color: var(--text-muted); font-variant-numeric: tabular-nums; align-self: center; }
.auto-progress { height: 1px; background: var(--border-strong); margin-bottom: 16px; }
.auto-progress i { display: block; height: 100%; width: 0; background: var(--ink); transition: width .15s linear; }
.auto-stats { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.auto-stats .k { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.auto-stats .v { font: 300 34px/1.15 var(--font); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.auto-gain { font-size: 12px; color: var(--good); text-align: right; max-width: 55%; }
.auto-chart-wrap { height: 120px; }
#autoChart { width: 100%; height: 100%; display: block; }
.auto-legend { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; font-size: 11.5px; color: var(--text-secondary); margin: 6px 0 12px; }
.auto-legend span { display: inline-flex; align-items: center; gap: 6px; }
.auto-legend .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); display: inline-block; }
#autoPhase { margin-left: auto; color: var(--text-muted); }
.auto-results { list-style: none; margin: 0 0 10px; padding: 0; }
.auto-results li { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13px; color: var(--text-secondary); border-top: 1px solid var(--border); }
.auto-results li:first-child { border-top: 0; }
.auto-results li.cur { color: var(--text-primary); }
.auto-results li.win { color: var(--text-primary); }
.auto-results li.win { font-weight: 500; }
.auto-results .num { font-variant-numeric: tabular-nums; color: var(--text-primary); }
.auto-actions { display: flex; gap: 20px; justify-content: flex-end; align-items: center; margin-top: 8px; }
.auto-actions .primary { padding: 10px 16px; }
body.auto-running .controls, body.auto-running #mainChart, body.auto-running .legend { pointer-events: none; }
body.auto-running #modelControls input[type=range]::-webkit-slider-thumb { background: var(--king); }
body.auto-running #modelControls input[type=range]::-moz-range-thumb { background: var(--king); }
.tag-auto { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--series-1); margin-left: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 1320px) {
  :root { --gutter: 32px; }
  .layout { grid-template-columns: 290px minmax(0, 1fr); gap: 40px; }
}
@media (max-width: 860px) {
  :root { --gutter: 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding-bottom: 48px; }
  .controls { position: static; max-height: none; overflow: visible; order: 1; padding-right: 0; }
  .workspace { order: 0; }
  .tiles, .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 24px; }
  .diag { grid-template-columns: minmax(0, 1fr); }
  .chart-wrap { height: 300px; }
  .topbar { padding: 16px var(--gutter); gap: 14px 20px; }
  .challenge-bar { order: 3; flex-basis: 100%; }
  h1 { font-size: 22px; }
  .auto-dlg { left: 16px; right: 16px; bottom: 12px; width: auto; }
}

/* ---------- clearer separation in the left column ----------
   Main sections get a full-ink rule, more air and a larger header;
   sub-groups inside keep the light hairlines, so the hierarchy reads at a glance. */
.controls { gap: 36px; }
.controls .panel { border-top: 1.5px solid var(--ink); padding: 14px 0 4px; }
.controls .panel:first-child { padding-top: 14px; }
.controls .panel-h { margin-bottom: 16px; }
.controls .panel-h h2 { font-size: 13px; font-weight: 600; letter-spacing: 0.07em; }
.controls .panel-h .step { font-size: 12px; color: var(--text-secondary); }
.controls .group-label { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 16px; color: var(--text-secondary); }
.controls .seg + .model-blurb, .controls #modelControls > .group-label:first-child { margin-top: 4px; }
#genPanel.folded { padding-bottom: 4px; }

/* ---------- left column: keep the scrollbar off the content ---------- */
.controls { padding-right: 22px; margin-right: -6px; scrollbar-gutter: stable; }

/* ---------- series from file ---------- */
.file-info { margin: 4px 0 8px; }
.file-meta { font-size: 13px; color: var(--text-secondary); margin-bottom: 10px; }
.file-meta b { display: block; font-family: var(--serif); font-size: 17px; font-weight: 400; color: var(--text-primary); margin-bottom: 2px; word-break: break-all; }
.file-col { margin-bottom: 8px; }
.file-info .hint { margin-top: 4px; }
.drop-overlay { position: fixed; inset: 0; z-index: 60; display: none; place-items: center; background: color-mix(in srgb, var(--bg) 88%, transparent); border: 1.5px dashed var(--ink); margin: 14px; pointer-events: none; }
.drop-overlay div { text-align: center; }
.drop-overlay b { display: block; font-family: var(--serif); font-size: 28px; font-weight: 400; margin-bottom: 6px; }
.drop-overlay span { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.06em; }
body.dropping .drop-overlay { display: grid; }

/* best-score card (replaces the old 'king' presentation) */
.king .klabel { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.king .kscore-big { font: 300 44px/1.05 var(--font); letter-spacing: -0.03em; margin-top: 8px; font-variant-numeric: tabular-nums; }
.king .kscore { font-size: 13px; color: var(--text-primary); margin-top: 8px; }
.king.empty .kname { font-family: var(--serif); font-size: 22px; margin-top: 8px; }

/* ---------- 3D parameter search space ---------- */
.space-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 22px; margin-bottom: 6px; }
.space-controls label { display: inline-flex; align-items: baseline; gap: 8px; font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.space-controls select { font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--text-primary); max-width: 190px; }
.space-controls .spin { margin-left: auto; align-items: center; }
.space-wrap { position: relative; height: 440px; touch-action: none; }
#spaceChart { width: 100%; height: 100%; display: block; cursor: grab; }
#spaceChart:active { cursor: grabbing; }
.space-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px 24px; flex-wrap: wrap; margin: 4px 0 10px; font-size: 12px; color: var(--text-secondary); }
.space-legend { display: inline-flex; align-items: center; gap: 8px; }
.space-legend span:first-child { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-right: 4px; }
.space-legend i { display: inline-block; width: 120px; height: 8px; }
.space-key { display: inline-flex; gap: 16px; flex-wrap: wrap; }
.space-key span { display: inline-flex; align-items: center; gap: 6px; }
.space-key .ring { width: 10px; height: 10px; border: 1.5px solid var(--text-primary); border-radius: 50%; display: inline-block; }
.space-key .hollow { width: 6px; height: 6px; border: 1px solid var(--text-muted); border-radius: 50%; display: inline-block; }
@media (max-width: 860px) { .space-wrap { height: 340px; } .space-controls .spin { margin-left: 0; } }

/* ---------- balance the left column: right inset (where its scrollbar lives)
   matches the page's left gutter; column widened so content keeps its width ---------- */
.layout { grid-template-columns: 340px minmax(0, 1fr); column-gap: 36px; }
.controls { padding-right: 46px; margin-right: 0; scrollbar-gutter: auto; }
@media (max-width: 1320px) {
  .layout { grid-template-columns: 322px minmax(0, 1fr); column-gap: 30px; }
  .controls { padding-right: 34px; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .controls { padding-right: 0; }
}

/* ---------- search landscape ---------- */
.space-foot { justify-content: flex-start; gap: 10px 28px; }
.space-legend i { width: 90px; }
.space-key .floor { width: 3px; height: 3px; background: var(--text-muted); display: inline-block; }
#surfNote { margin-bottom: 4px; }
#surfNote b { font-weight: 500; color: var(--text-primary); }
.strips-head { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--border); }
.strips-head .sub { max-width: 640px; }
.strips { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 24px; }
.strip-h { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.strip-h span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip-h b { font-weight: 500; color: var(--text-primary); white-space: nowrap; }
.strip canvas { width: 100%; height: 64px; display: block; }
.strip-ax { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.strip.inactive { opacity: .4; }

/* ---------- leaderboard: secondary, in a drawer opened from the top bar ---------- */
.board-btn { margin-left: auto; display: inline-flex; align-items: baseline; gap: 10px; font-size: 12.5px; color: var(--text-secondary); padding: 6px 0; border-bottom: 1px solid var(--border); }
.board-btn:hover, .board-btn[aria-expanded="true"] { color: var(--text-primary); border-bottom-color: var(--text-primary); }
.board-btn-meta { font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.board-btn + .player { margin-left: 0; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(400px, 100vw); background: var(--bg); border-left: 1px solid var(--border); z-index: 40; overflow-y: auto; padding: 22px 32px 48px; transform: translateX(100%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; scrollbar-width: thin; }
.drawer.open { transform: none; visibility: visible; transition: transform .22s ease; box-shadow: -24px 0 48px rgba(0,0,0,.08); }
.drawer-h { display: flex; align-items: center; justify-content: space-between; padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1.5px solid var(--text-primary); }
.drawer-h h2 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 24px; letter-spacing: -0.01em; }
.drawer .drawer-h + .card { border-top: 0; padding-top: 0; }
.drawer-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.18); z-index: 35; }
@media (prefers-reduced-motion: reduce) { .drawer, .drawer.open { transition: none; } }
@media (max-width: 860px) { .drawer { padding: 16px 16px 40px; } .board-btn { margin-left: 0; } }
.ghost.link { color: var(--text-primary); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; padding: 0; margin-left: 6px; font-size: inherit; }

/* ---------- auto discovery: a bar floating along the bottom; the chart keeps its full size ---------- */
.auto-dlg { top: auto; bottom: 16px; left: var(--auto-left, var(--gutter)); right: var(--gutter); width: auto; max-width: none; max-height: 46vh; padding: 14px 22px 16px; }
.auto-dlg .auto-h { margin-bottom: 10px; }
.auto-dlg .auto-h h2 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--font); font-weight: 500; }
.auto-dlg[data-view="running"] .auto-row.v-running, .auto-dlg[data-view="done"] .auto-row.v-done { display: grid; }
.auto-dlg[data-view="setup"] .auto-row.v-setup { display: grid; }
.auto-row { grid-template-columns: minmax(200px, 1.1fr) minmax(220px, 1.6fr) minmax(170px, 1fr) minmax(200px, 1fr); gap: 0 32px; align-items: start; }
.auto-setup { grid-template-columns: minmax(240px, 1.6fr) auto auto auto; align-items: center; gap: 0 36px; }
.auto-setup .auto-opt { grid-template-columns: auto auto; align-items: center; margin: 0; }
.auto-setup .hint { margin: 0 !important; }
.auto-setup .wide { width: auto; margin: 0; padding: 10px 22px; }
.auto-dlg .auto-chart-wrap { height: 92px; }
.auto-dlg .auto-legend { margin: 4px 0 0; }
.auto-dlg .auto-stats .v { font-size: 28px; }
.auto-dlg .auto-results { margin: 0; max-height: 132px; overflow-y: auto; }
.auto-dlg .auto-results li { padding: 4px 0; font-size: 12.5px; }
.auto-side .auto-actions { justify-content: flex-end; flex-wrap: wrap; gap: 12px 18px; margin-top: 0; }
.auto-side .hint { margin: 0 0 10px !important; font-size: 12px; }
.auto-dlg[data-view="done"] .auto-side .v-done { display: block; }
.auto-dlg[data-view="running"] .auto-side .auto-actions.v-running { display: flex; }
body.auto-open { padding-bottom: 46vh; }
@media (max-width: 1100px) {
  .auto-row, .auto-setup { grid-template-columns: 1fr 1fr; gap: 12px 24px; }
}
@media (max-width: 860px) {
  .auto-dlg { left: 8px; right: 8px; bottom: 8px; }
  .auto-row, .auto-setup { grid-template-columns: 1fr; }
  .auto-dlg .auto-results { display: none; }
}

/* auto discovery: model picker */
.auto-models { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; }
.model-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { font-size: 12.5px; padding: 5px 10px; border: 1px solid var(--border-strong); color: var(--text-muted); text-transform: none; letter-spacing: 0; display: inline-flex; align-items: center; gap: 5px; }
.pick:hover { color: var(--text-primary); border-color: var(--text-primary); }
.pick[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.pick-cur { font-size: 10px; opacity: .7; }
.auto-quick { display: flex; gap: 12px; }
.auto-quick button { font-size: 11px; color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; text-transform: none; letter-spacing: 0; }
.auto-quick button:hover { color: var(--text-primary); }
#autoStart:disabled { opacity: .4; cursor: not-allowed; }
.auto-setup { grid-template-columns: minmax(220px, 1fr) minmax(0, 2.2fr) auto auto; }
.auto-dlg[data-view="done"] .auto-actions.v-running { display: none !important; }
