:root{
  --ink:#05141a;
  --panel:#0d272f;
  --panel-2:#12333d;
  --rule:#1d4552;
  --text:#dfeef0;
  --text-dim:#8bb0b8;
  --text-faint:#5f8a94;
  --signal:#e8a33d;
  --signal-soft:#ffd98a;
  --rail:356px;
}
*{box-sizing:border-box}
html,body{height:100%;margin:0}
@supports (height:100dvh){html,body,.shell{height:100dvh}}
body{
  background:var(--ink);
  color:var(--text);
  font-family:'IBM Plex Sans',system-ui,-apple-system,'Segoe UI',sans-serif;
  font-size:14px;line-height:1.5;overflow:hidden;overscroll-behavior:none;
}
.shell{display:flex;height:100%;width:100%}

/* ---------- stage ---------- */
.stage{position:relative;flex:1;min-width:0;background:var(--ink)}
canvas{display:block;width:100%;height:100%;touch-action:none;cursor:grab}
canvas.grabbing{cursor:grabbing}
.stage-head{
  position:absolute;top:0;left:0;right:0;padding:14px 18px 26px;
  background:linear-gradient(180deg,rgba(5,20,26,.92),rgba(5,20,26,0));
  pointer-events:none;display:flex;align-items:baseline;gap:14px;flex-wrap:wrap;
}
.stage-head h1{margin:0;font-size:17px;font-weight:600;letter-spacing:-.01em}
.stage-head p{margin:0;color:var(--text-faint);font-size:12.5px}

.readout,.legend{
  position:absolute;background:rgba(8,26,32,.86);border:1px solid var(--rule);
  border-radius:10px;backdrop-filter:blur(8px);pointer-events:none;
}
.readout{
  left:18px;bottom:18px;padding:10px 12px;min-width:196px;
  font-family:'IBM Plex Mono',ui-monospace,monospace;font-size:12px;
}
.readout .rk{color:var(--text-faint)}
.readout .rv{float:right;color:var(--text);font-variant-numeric:tabular-nums}
.readout .rl{display:block}
.readout .rhead{
  font-family:'IBM Plex Sans',sans-serif;color:var(--text-dim);
  font-size:11.5px;margin-bottom:6px;
}
.legend{right:18px;bottom:18px;padding:9px 12px 10px}
.legend .bar{height:9px;width:150px;border-radius:2px;margin:5px 0 4px}
.legend .ends{display:flex;justify-content:space-between;gap:14px;
  font-family:'IBM Plex Mono',monospace;font-size:10.5px;color:var(--text-faint)}
.legend .cap{font-size:11.5px;color:var(--text-dim)}

/* ---------- rail ---------- */
.rail{
  width:var(--rail);flex:0 0 var(--rail);height:100%;overflow-y:auto;
  background:var(--panel);border-left:1px solid var(--rule);padding:16px 16px 28px;
}
.rail h2{font-size:12.5px;font-weight:600;color:var(--text-dim);margin:0 0 9px}
.group{padding-bottom:16px;margin-bottom:16px;border-bottom:1px solid var(--rule)}
.group:last-child{border-bottom:0;margin-bottom:0}

.seg{display:flex;border:1px solid var(--rule);border-radius:9px;overflow:hidden}
.seg button{
  flex:1;appearance:none;border:0;background:transparent;color:var(--text-dim);
  font:inherit;font-size:13px;padding:9px 4px;cursor:pointer;
  border-right:1px solid var(--rule);transition:background .12s,color .12s;
}
.seg button:last-child{border-right:0}
.seg button:hover{background:var(--panel-2);color:var(--text)}
.seg button[aria-pressed=true]{background:var(--panel-2);color:var(--signal-soft);box-shadow:inset 0 -2px 0 var(--signal)}
.seg button:focus-visible{outline:2px solid var(--signal);outline-offset:-2px}
#axisseg button{font-family:'IBM Plex Mono',monospace;font-size:12.5px}
.mode-note{margin:9px 0 0;font-size:12.5px;color:var(--text-faint);line-height:1.45}

.row{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:10px 0 2px}
.row label{font-size:13px;color:var(--text-dim)}
.row .val{font-family:'IBM Plex Mono',monospace;font-size:12px;font-variant-numeric:tabular-nums}
input[type=range]{-webkit-appearance:none;appearance:none;width:100%;height:22px;background:transparent;cursor:pointer;margin:0}
input[type=range]::-webkit-slider-runnable-track{height:3px;background:var(--rule);border-radius:2px}
input[type=range]::-moz-range-track{height:3px;background:var(--rule);border-radius:2px}
input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:15px;height:15px;border-radius:50%;background:var(--signal);margin-top:-6px;border:0}
input[type=range]::-moz-range-thumb{width:15px;height:15px;border-radius:50%;background:var(--signal);border:0}
input[type=range]:focus-visible{outline:2px solid var(--signal);outline-offset:3px;border-radius:4px}

.checks{display:flex;flex-direction:column;gap:7px}
.check{display:flex;align-items:center;gap:9px;font-size:13px;color:var(--text-dim);cursor:pointer}
.check input{accent-color:var(--signal);width:15px;height:15px;margin:0}

.chips{display:flex;flex-wrap:wrap;gap:6px}
.chips button{
  appearance:none;border:1px solid var(--rule);background:transparent;color:var(--text-dim);
  font:inherit;font-size:12.5px;padding:6px 11px;border-radius:20px;cursor:pointer;transition:border-color .12s,color .12s;
}
.chips button:hover{border-color:var(--signal);color:var(--signal-soft)}
.chips button:focus-visible{outline:2px solid var(--signal);outline-offset:2px}

.facts{font-family:'IBM Plex Mono',monospace;font-size:12px}
.facts div{display:flex;justify-content:space-between;gap:12px;padding:3px 0}
.facts span:first-child{color:var(--text-faint);font-family:'IBM Plex Sans',sans-serif;font-size:12.5px}
.facts span:last-child{font-variant-numeric:tabular-nums;white-space:nowrap}

.prose{font-size:12.8px;color:var(--text-faint);line-height:1.55}
.prose b{color:var(--text-dim);font-weight:500}
.hint{font-size:12.3px;color:var(--text-faint);line-height:1.5}

.railtoggle{
  display:none;position:absolute;top:12px;right:12px;z-index:5;appearance:none;
  border:1px solid var(--rule);background:rgba(8,26,32,.9);color:var(--text);
  font:inherit;font-size:13px;padding:8px 13px;border-radius:8px;cursor:pointer;
}

@media (max-width:820px){
  :root{--rail:100%}
  .shell{flex-direction:column}
  .stage{flex:1 1 auto;min-height:0}
  .rail{
    position:absolute;inset:auto 0 0 0;height:64%;width:100%;
    border-left:0;border-top:1px solid var(--rule);border-radius:14px 14px 0 0;
    transform:translateY(100%);transition:transform .22s ease;z-index:4;
    padding-bottom:calc(28px + env(safe-area-inset-bottom));
  }
  .rail.open{transform:translateY(0)}
  .railtoggle{display:block}
  /* Leave a lane for the Controls button so the title never runs under it. */
  .stage-head{padding:12px 108px 22px 14px}
  .stage-head h1{font-size:16px}
  /* Readout moves off the wrapping title and shares the bottom edge with the
     legend, which is where both sit on a wide screen anyway. */
  .readout{
    top:auto;bottom:calc(12px + env(safe-area-inset-bottom));
    left:calc(12px + env(safe-area-inset-left));
    min-width:150px;font-size:11px;padding:8px 10px;
  }
  .legend{
    bottom:calc(12px + env(safe-area-inset-bottom));
    right:calc(12px + env(safe-area-inset-right));padding:8px 10px;
  }
  .legend .bar{width:96px}
}
@media (max-width:560px){
  /* Double-click has no touch equivalent; drop it rather than wrap four lines. */
  .hint-more{display:none}
}
@media (orientation:landscape) and (max-height:480px){
  .stage-head{padding-bottom:14px}
  .stage-head p{display:none}
  .readout,.legend{font-size:10.5px}
  .readout{min-width:136px}
  .legend .bar{width:84px}
}
@media (prefers-reduced-motion:reduce){*{transition:none!important;animation:none!important}}
