/* Dark by default, light from prefers-color-scheme or the header toggle (data-theme, the
   pages' head script). play.js, handles.js and steps.js draw their canvases in these tokens,
   read again on "themechange"; every token here is #RRGGBB (the canvases add alpha to it). */
:root {
  --bg: #08090B; --bg-raised: #0D0F13; --bg-card: #111318; --bg-sunken: #040507;
  --line-1: #121419; --line-2: #1D2026; --line-3: #272B31; --line-4: #33373E;
  --text: #ECEFF4; --text-2: #C3C8D1; --text-3: #A8AEB9; --muted: #666C78;
  --reality: #4DA6FF; --intent: #A78BFA; --hi: #FF5CB3; --bad: #FF4D5E;
  --plot-v: #5BD48A; --plot-a: #F2A94A; --plot-j: #C9A2FF;   /* the handles page's strips */
  --r: 2px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme=dark]) {
    color-scheme: light;
    --bg: #F3F2EE; --bg-raised: #EBEAE5; --bg-card: #E3E2DC; --bg-sunken: #FFFFFF;
    --line-1: #E0DFD9; --line-2: #D4D3CC; --line-3: #BDBCB5; --line-4: #A9A8A1;
    --text: #0B0B0C; --text-2: #2C2C31; --text-3: #45454B; --muted: #5E5E64;
    --reality: #1764B8; --intent: #6A3FC8; --hi: #C0177A; --bad: #B8182A;
    --plot-v: #1B7F45; --plot-a: #A15C00; --plot-j: #8650D6;
  }
}
:root[data-theme=light] {
  color-scheme: light;
  --bg: #F3F2EE; --bg-raised: #EBEAE5; --bg-card: #E3E2DC; --bg-sunken: #FFFFFF;
  --line-1: #E0DFD9; --line-2: #D4D3CC; --line-3: #BDBCB5; --line-4: #A9A8A1;
  --text: #0B0B0C; --text-2: #2C2C31; --text-3: #45454B; --muted: #5E5E64;
  --reality: #1764B8; --intent: #6A3FC8; --hi: #C0177A; --bad: #B8182A;
  --plot-v: #1B7F45; --plot-a: #A15C00; --plot-j: #8650D6;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }
body { margin: 0 auto; padding: 0 16px; max-width: 1400px; background: var(--bg); color: var(--text-2); font: 14px/1.45 var(--sans); overflow-x: hidden; }
a { color: var(--reality); }
h1 { font-size: 20px; color: var(--text); margin: 16px 0 2px; font-weight: 600; }
h2 { font-size: 13px; color: var(--text); margin: 0 0 8px; font-weight: 600; }
h3 { font-size: 12px; color: var(--text-3); margin: 10px 0 4px; font-weight: 600; }
p { margin: 0; }
.meta { color: var(--muted); margin-top: 2px; font-size: 13px; overflow-wrap: anywhere; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.top { padding-bottom: 12px; border-bottom: 1px solid var(--line-2); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; padding-top: 12px; }
.stage, .side { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }

.bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.btn, .seg button {
  background: var(--bg-card); color: var(--text-2); border: 1px solid var(--line-3); border-radius: var(--r);
  font: 13px var(--sans); padding: 5px 10px; cursor: pointer; width: auto;
}
.btn:hover, .seg button:hover { border-color: var(--line-4); color: var(--text); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { border-color: var(--reality); color: var(--text); min-width: 64px; }
.seg { display: inline-flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.seg button:last-child { border-radius: 0 var(--r) var(--r) 0; }
.seg button[aria-pressed="true"] { background: var(--line-3); color: var(--text); border-color: var(--line-4); position: relative; }
.inline { display: inline-flex; gap: 6px; align-items: center; color: var(--text-3); font-size: 13px; }
.inline output { min-width: 52px; color: var(--text-2); }
.presets .btn { color: var(--intent); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 1px solid var(--reality); outline-offset: 1px; }

.plotwrap { display: flex; gap: 8px; min-width: 0; }
.plot { position: relative; flex: 1; min-width: 0; height: clamp(440px, 64vh, 640px); }
.plot canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#overlay { touch-action: none; cursor: crosshair; }
#rail { width: 56px; flex: none; height: clamp(440px, 64vh, 640px); }
@media (max-width: 600px) { .plot, #rail { height: 480px; } #rail { width: 40px; } }
.readout { color: var(--text-3); font-size: 12px; min-height: 18px; white-space: pre-wrap; }

.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-3); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { flex: none; }

.card { background: var(--bg-raised); border: 1px solid var(--line-2); border-radius: var(--r); padding: 12px; min-width: 0; }
.tablewrap { overflow-x: auto; max-height: 280px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line-3); padding: 3px 8px 3px 0; position: sticky; top: 0; background: var(--bg-raised); }
td { border-bottom: 1px solid var(--line-1); padding: 3px 8px 3px 0; vertical-align: top; }
td.mono { white-space: nowrap; color: var(--text-3); }
td.k { color: var(--hi); white-space: nowrap; }

.row { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: center; margin: 4px 0; font-size: 13px; color: var(--text-3); }
.opt { margin: 8px 0; }
.opt .head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--text-3); gap: 8px; }
.opt .ctl { display: grid; grid-template-columns: minmax(0, 1fr) 76px; gap: 8px; align-items: center; }
input[type="number"], select {
  background: var(--bg-sunken); color: var(--text); border: 1px solid var(--line-3); border-radius: var(--r);
  font: 13px var(--mono); padding: 3px 6px; width: 100%; min-width: 0;
}
select { font-family: var(--sans); }
input[type="range"] { width: 100%; min-width: 0; accent-color: var(--reality); margin: 0; }
.inline input[type="range"] { width: 120px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 10px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text-2); }
.kv dd.bad { color: var(--hi); }

.keys { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 12px; padding: 14px 0 6px; margin-top: 14px; border-top: 1px solid var(--line-2); }
kbd { font: 11px var(--mono); color: var(--text-3); border: 1px solid var(--line-3); border-radius: var(--r); padding: 0 4px; background: var(--bg-card); }
.status { color: var(--hi); font-size: 13px; min-height: 20px; padding-bottom: 16px; }

/* planner steps (steps.js) */
.steps { display: flex; flex-direction: column; gap: 10px; }
.steps:focus { outline: none; }
.sthead h2 { margin-bottom: 6px; }
.sthead .bar input[type="range"] { flex: 1 1 140px; width: auto; min-width: 100px; }
.sthead output { min-width: 72px; color: var(--text-3); font-size: 12px; }
.sthead select { width: auto; }
.sttitle { margin-top: 8px; color: var(--text); font: 600 14px var(--sans); min-height: 20px; }
.stgrid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 8px; }
.stpanel { position: relative; background: var(--bg-sunken); border: 1px solid var(--line-2); border-radius: var(--r); min-width: 0; height: 300px; }
.stscope, .stlog { height: 236px; }
.stpanel canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stlog { overflow: hidden; }
.stlog .ptitle { font-size: 10px; color: var(--muted); padding: 8px 10px 2px; }
.stlog ol { list-style: none; margin: 0; padding: 2px 10px 8px; font-size: 12px; line-height: 1.6; }
.stlog li { white-space: pre; overflow: hidden; text-overflow: ellipsis; color: var(--text-3); }
.stlog li.head { color: var(--text-2); }
.stlog li.now { color: var(--text); }
.stlog li.ok { color: var(--reality); }
.stlog li.bad { color: var(--bad); }
.stlog li.muted { color: var(--muted); }
.stlist { position: relative; height: 216px; overflow-y: auto; background: var(--bg-sunken); border: 1px solid var(--line-2); border-radius: var(--r); }
.stlist > div { position: relative; }
.strow { position: absolute; left: 0; right: 0; height: 24px; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: none; border: 0; border-left: 2px solid transparent;
  color: var(--text-3); font: 12px var(--sans); text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strow.d1 { padding-left: 30px; color: var(--muted); }
.strow:hover { color: var(--text); background: var(--bg-card); }
.strow.cur { color: var(--text); background: var(--line-2); border-left-color: var(--reality); }
.strow .n { color: var(--muted); min-width: 34px; font-size: 11px; }
.strow .mark { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.strow .mark.ok { background: var(--reality); }
.strow .mark.bad { background: var(--bad); }
#steps-toggle[aria-pressed="true"] { border-color: var(--reality); color: var(--text); background: var(--line-3); }
@media (max-width: 700px) { .stgrid { grid-template-columns: minmax(0, 1fr); } .stpanel { height: 260px; } .stscope, .stlog { height: 236px; } }
