:root {
  --bg: #07080b;
  --panel: #0e1117;
  --panel-2: #141922;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e6e9ef;
  --muted: #8b93a3;
  --cl: #5ad1ff;
  --cd: #ff8a5c;
  --accent: #ffb547;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 14px; -webkit-font-smoothing: antialiased; }
#app { display: flex; height: 100%; height: 100dvh; }

#stage { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); overflow: hidden; }
#stack { position: relative; flex: none; }
#stack canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#overlay { cursor: crosshair; }

#hud { position: absolute; top: 18px; left: 22px; pointer-events: none; }
#hud h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: 0.01em; }
#hud p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
#hint { position: absolute; top: 18px; right: 22px; white-space: pre-line; color: var(--muted); font-size: 12px; pointer-events: none; text-align: right; max-width: 42%; }

#readouts { position: absolute; left: 22px; bottom: 18px; display: flex; gap: 18px; flex-wrap: wrap; pointer-events: none; }
.ro { display: flex; flex-direction: column; gap: 2px; }
.ro .k { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.ro .v { font-family: var(--mono); font-size: 17px; font-variant-numeric: tabular-nums; }
.ro.dim .v { color: var(--muted); }
#legend { position: absolute; right: 22px; bottom: 18px; color: var(--muted); font-size: 12px; pointer-events: none; text-align: right; max-width: 40%; }

#nogl[hidden] { display: none; }
#nogl { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 24px; background: var(--bg); }
#nogl p { color: var(--muted); max-width: 46ch; }

#panelToggle { display: none; position: absolute; right: 14px; top: 14px; }

#panel { width: 340px; flex: none; overflow-y: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 14px 18px 30px; scrollbar-width: thin; scrollbar-color: #2a3040 transparent; }
#panel section { padding: 14px 0; border-top: 1px solid var(--line); }
#panel section:first-of-type { border-top: 0; }
#panel h2 { margin: 0 0 10px; font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.toolbar { display: flex; gap: 8px; padding-bottom: 10px; }
.toolbar .close { display: none; margin-left: auto; }

button { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 7px 12px; cursor: pointer; transition: background 0.15s, border-color 0.15s; }
button:hover { background: #1b2230; }
button.on { background: #22304a; border-color: #35507a; }
button.primary { background: #23324a; border-color: #35507a; width: 100%; }
button.primary:hover { background: #2b3d5c; }
button.ghost { background: transparent; }

.seg { display: flex; margin: 0 0 10px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; padding: 7px 4px; background: transparent; font-size: 12.5px; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: #22304a; color: #fff; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 0 25%; border-left: 0; border-top: 1px solid var(--line); }
.seg.wrap button:nth-child(-n+4) { border-top: 0; }
.seg.wrap button:not(:nth-child(4n+1)) { border-left: 1px solid var(--line); }
#stl { cursor: grab; }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row .seg { flex: 1; }

label { display: block; margin: 8px 0; font-size: 12.5px; color: #c3c9d4; }
label output { float: right; font-family: var(--mono); font-size: 12px; color: var(--text); }
label.chk { display: flex; align-items: center; gap: 8px; }
label.chk input { accent-color: var(--cl); margin: 0; }
label.sel select { display: block; width: 100%; margin-top: 6px; font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }

input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; margin: 4px 0 0; background: transparent; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: #262d3a; border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%; background: #dfe5f0; border: 2px solid var(--panel); box-shadow: 0 0 0 1px #3b4658; }
input[type=range]::-moz-range-track { height: 3px; background: #262d3a; border-radius: 2px; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #dfe5f0; border: 2px solid var(--panel); }
input[type=range]:disabled { opacity: 0.4; }

.naca { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.naca b { font-family: var(--mono); color: var(--text); font-weight: 500; }
.tip { margin: 6px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.tip a { color: var(--cl); }
.sw { display: inline-block; width: 10px; height: 3px; vertical-align: middle; margin: 0 2px 0 4px; border-radius: 2px; }
.sw.cl { background: var(--cl); } .sw.cd { background: var(--cd); } .sw.th { background: repeating-linear-gradient(90deg, rgba(90,209,255,0.6) 0 3px, transparent 3px 5px); }

.chart { display: block; width: 100%; height: 170px; margin-top: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; }
.chart.small { height: 70px; margin-top: 0; }
.prog { height: 4px; margin-top: 10px; background: #1b2230; border-radius: 2px; overflow: hidden; }
.prog div { height: 100%; width: 0; background: var(--cl); transition: width 0.2s; }

.about p { margin: 8px 0; font-size: 13px; line-height: 1.55; color: #c3c9d4; }
.about b { color: var(--text); font-weight: 600; }

@media (max-width: 860px) {
  #app { flex-direction: column; }
  #panel { position: fixed; inset: auto 0 0 0; height: 72vh; width: auto; border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; transform: translateY(105%); transition: transform 0.25s ease; z-index: 5; box-shadow: 0 -10px 40px rgba(0,0,0,0.5); }
  body.panel-open #panel { transform: none; }
  #panelToggle { display: block; z-index: 4; }
  .toolbar .close { display: block; }
  #hud h1 { font-size: 17px; }
  #hud p, #hint { display: none; }
  #readouts { gap: 12px; left: 14px; bottom: 12px; }
  .ro .v { font-size: 14px; }
  .ro.dim { display: none; }
  #legend { display: none; }
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 10px; font-size: 12.5px; border-radius: 999px; }
#toast { position: absolute; left: 50%; bottom: 64px; transform: translateX(-50%); background: #1b2230; border: 1px solid #35507a; color: var(--text); padding: 9px 14px; border-radius: 8px; font-size: 13px; max-width: 80%; text-align: center; box-shadow: 0 8px 30px rgba(0,0,0,0.5); z-index: 6; }
#toast[hidden] { display: none; }
