:root {
  --bg: #0B1016;
  --panel: #121922;
  --panel-2: #1A2330;
  --line: #243040;          /* decorative dividers only */
  --ctl: #66798F;           /* control borders, 3:1 or better on bg and panel */
  --text: #E7EDF3;
  --muted: #A2B2C3;
  --accent: #F3C641;        /* signal yellow: fills and accent text */
  --on-accent: #0B1016;
  --cd: #F3C641;
  --cl: #6BB7FF;
  --wall-a: #2A3542;
  --wall-b: #151C25;
  --wirxl: #F2703C;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--sans);
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
abbr { text-decoration: none; }
sub { font-size: 0.72em; }
[hidden] { display: none !important; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px 12px; border-bottom: 1px solid var(--line);
}
.title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.mark { width: 34px; height: 34px; flex: none; fill: none; stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; }
h1 { margin: 0; font-size: 21px; line-height: 1.1; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.tag { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.wirxl {
  flex: none; color: var(--muted); text-decoration: none; font-size: 13px; letter-spacing: 0.02em;
  padding: 6px 2px;
}
.wirxl span { color: var(--wirxl); font-weight: 700; letter-spacing: 0.12em; }
.wirxl:hover { color: var(--text); }

/* layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto 1fr;
  grid-template-areas: "stage panel" "about panel";
  align-items: start; min-height: calc(100vh - 66px);
}
.stage { grid-area: stage; padding: 18px 20px 10px; min-width: 0; }
.panel {
  grid-area: panel; align-self: stretch;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 16px 18px 20px;
}

/* the tunnels: one, or A above B to compare */
.tunnels { display: grid; gap: 14px; }

/* a tunnel: the floor hatched like a section drawing; the top is open */
.tunnel-frame {
  --ar: 2.6;
  width: min(100%, max(520px, calc((100vh - 330px) * var(--ar))));
  margin: 0 auto;
  padding: 0 0 7px;
  border-top: 1px dashed var(--wall-a);
  background: repeating-linear-gradient(135deg, var(--wall-a) 0 2px, var(--wall-b) 2px 7px) bottom / 100% 7px no-repeat;
}
.tunnel { position: relative; width: 100%; aspect-ratio: var(--ar); background: #070B10; }
.tunnel canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tunnel canvas.gl { touch-action: none; cursor: grab; }
.tunnel-frame.grabbing canvas.gl { cursor: grabbing; }
.tunnel canvas.shape { pointer-events: none; }
.stage.compare .tunnel-frame:not(.active) canvas.gl { cursor: pointer; }
.who {
  position: absolute; left: 10px; bottom: 8px; pointer-events: none;
  font: 12px var(--mono); color: var(--text); background: rgba(7, 11, 16, 0.82); padding: 2px 7px;
}
.who b { color: var(--accent); margin-right: 7px; }
.stage:not(.compare) .who { display: none; }
.stage.compare .tunnel-frame { width: min(100%, max(440px, calc((100vh - 360px) / 2 * var(--ar)))); }
.stage.compare .tunnel-frame.active .tunnel { outline: 2px solid var(--accent); outline-offset: 3px; }
.wind {
  position: absolute; left: 10px; top: 8px; pointer-events: none;
  font: 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
  background: rgba(7, 11, 16, 0.78); padding: 1px 6px;
}
.notice {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  margin: 0; max-width: calc(100% - 24px);
  background: var(--panel-2); border: 1px solid var(--ctl); color: var(--text);
  padding: 7px 12px; font-size: 14px;
}

/* seen from above: no floor, both edges open */
.tunnel-frame.from-above { background: none; padding-bottom: 0; border-bottom: 1px dashed var(--wall-a); }

/* legend */
.legend { width: min(100%, 560px); margin: 10px auto 0; min-height: 44px; }
.legend-text { margin: 0 0 6px; color: var(--muted); font-size: 13px; text-align: center; }
.bar { height: 10px; border: 1px solid var(--ctl); }
.ticks { position: relative; height: 18px; font: 12px var(--mono); color: var(--muted); }
.ticks span { position: absolute; top: 2px; transform: translateX(-50%); white-space: nowrap; }
.ticks span:first-child { transform: none; }
.ticks span:last-child { transform: translateX(-100%); }

/* tools */
.tools { display: flex; flex-wrap: wrap; gap: 14px 28px; margin-top: 14px; justify-content: center; }
.group { min-width: 0; }
.label {
  display: block; margin: 0 0 7px; font: 12px var(--mono); font-weight: 400;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted);
}
.label.row { display: flex; justify-content: space-between; align-items: baseline; }
.label output { font: 13px var(--mono); letter-spacing: 0; text-transform: none; color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.seg { display: inline-flex; gap: 0; }
.seg .chip + .chip { margin-left: -1.5px; }
.seg.wide { display: flex; }
.seg.wide .chip { flex: 1; justify-content: center; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  background: transparent; border: 1.5px solid var(--ctl); border-radius: 3px;
  padding: 6px 11px; min-height: 36px; cursor: pointer;
  font-size: 14px; color: var(--text); white-space: nowrap;
}
.seg .chip { border-radius: 0; }
.seg .chip:first-child { border-radius: 3px 0 0 3px; }
.seg .chip:last-child { border-radius: 0 3px 3px 0; }
.chip:hover { background: var(--panel-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); position: relative; z-index: 1; }
.chip.small { padding: 6px 0; width: 34px; justify-content: center; font-family: var(--mono); }
.chip canvas { width: 40px; height: 20px; display: block; }

/* readouts */
.readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; padding-bottom: 12px; }
.ro { display: flex; flex-direction: column; min-width: 0; }
.ro .k { font: 12px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.ro .v { font: 600 30px/1.15 var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
.ro .v.small { font-size: 20px; line-height: 1.3; }
.ro .pm { font: 12px var(--mono); color: var(--muted); min-height: 18px; }
.readouts.unsettled .v { color: var(--muted); }
.readouts.nocoef .coef { display: none; }
.after { display: grid; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.settle { margin: 0; font-size: 13px; color: var(--muted); min-height: 20px; }
.spark-key { display: flex; gap: 14px; font: 12px var(--mono); color: var(--muted); margin-bottom: 4px; }
.key-cd, .key-cl { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.key-cd::before, .key-cl::before { content: ''; width: 14px; height: 2px; background: var(--cd); }
.key-cl::before { background: var(--cl); height: 0; border-top: 2px dashed var(--cl); }
.spark-note { margin-left: auto; }
#spark { width: 100%; height: 78px; display: block; background: var(--bg); border: 1px solid var(--line); }
.refnote { margin: 0; font-size: 13px; color: var(--muted); }

/* A against B */
.cmp-wrap { overflow-x: auto; }
.cmp { width: 100%; border-collapse: collapse; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.cmp th, .cmp td { padding: 5px 3px; text-align: right; border-bottom: 1px solid var(--line); }
.cmp th[scope="row"] { padding-left: 0; }
.cmp td.diff { padding-right: 0; }
.cmp td.diff, .cmp thead th:last-child { padding-left: 12px; }
.cmp th[scope="row"] { text-align: left; font-weight: 400; color: var(--muted); }
.cmp thead th { color: var(--accent); font-weight: 600; border-bottom: 0; padding-bottom: 0; white-space: nowrap; }
.cmp .names td { font-size: 12px; color: var(--muted); vertical-align: top; padding-top: 2px; }
.cmp td { color: var(--text); }
.cmp td.unsettled { color: var(--muted); }
.cmp td.diff { color: var(--accent); }
.cmp-sum { margin: 8px 0 0; font-size: 14px; color: var(--text); }
.compare-out { padding-bottom: 6px; }

/* saving and sharing */
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.chip:disabled { cursor: not-allowed; border-style: dashed; color: var(--muted); background: transparent; }
.linkbox input { width: 100%; font: 12px var(--mono); color: var(--text); background: var(--bg); border: 1px solid var(--ctl); border-radius: 3px; padding: 7px 8px; }
.saved-head { display: flex; justify-content: space-between; align-items: baseline; }
.saved-head .label { margin: 0; }
.saved-wrap { overflow-x: auto; margin-top: 6px; }
.saved-table { width: 100%; border-collapse: collapse; font: 12px var(--mono); font-variant-numeric: tabular-nums; }
.saved-table th, .saved-table td { padding: 4px 4px; text-align: right; border-bottom: 1px solid var(--line); color: var(--text); }
.saved-table th { color: var(--muted); font-weight: 400; }
.saved-table th:first-child, .saved-table td:first-child { text-align: left; }
.saved-table .from { color: var(--muted); }
.textbtn { background: none; border: 0; padding: 4px 6px; font: 12px var(--mono); color: var(--muted); text-decoration: underline; cursor: pointer; }
.textbtn:hover { color: var(--text); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* controls */
.controls { padding-top: 14px; display: grid; gap: 16px; }
.ctl { min-width: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 2px 0 0; height: 24px; }
.hint { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.turn { width: min(100%, 300px); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 14px; color: var(--text); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.perf { margin: 0; font: 12px var(--mono); color: var(--muted); word-break: break-word; }

/* about */
.about { grid-area: about; margin: 8px 20px 22px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; max-width: 820px; justify-self: center; }
.about p { margin: 0 0 6px; }
.mini { display: none; margin: 8px 0 0; text-align: center; font: 14px var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
kbd { font: 12px var(--mono); border: 1px solid var(--ctl); border-radius: 3px; padding: 0 4px; color: var(--text); }

.fatal { padding: 40px 20px; text-align: center; color: var(--text); }

@media (pointer: coarse) { .keys { display: none; } }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; grid-template-areas: "stage" "panel" "about"; min-height: 0; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .about { margin: 0; padding: 14px 16px 22px; justify-self: stretch; }
  .mini { display: block; }
  .stage { padding: 12px 12px 16px; }
  .tunnel-frame { width: 100%; }
  .top { padding: 10px 14px; }
  .tag { font-size: 13px; }
  .tools { justify-content: flex-start; }
}
@media (max-width: 520px) {
  .wirxl { font-size: 12px; }
  .mark { width: 28px; height: 28px; }
  h1 { font-size: 18px; }
  .ro .v { font-size: 24px; }
  .chip { padding: 6px 9px; }
}
