: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; background: var(--bg); overflow: hidden; }
.view { position: absolute; inset: 0; }
.view[hidden] { display: none; }
#plot { position: absolute; background: #0b0e14; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#gl { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#overlay, #labels3d { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#gl3d { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#gl3d:active { cursor: grabbing; }
#tip { position: absolute; pointer-events: none; background: rgba(14, 17, 23, 0.94); border: 1px solid #2a3040; border-radius: 7px; padding: 7px 9px; font-family: var(--mono); font-size: 11.5px; line-height: 1.45; white-space: pre; z-index: 4; box-shadow: 0 8px 30px rgba(0,0,0,0.5); }
#tip[hidden] { display: none; }

#hud { position: absolute; top: 18px; left: 22px; pointer-events: none; z-index: 2; }
#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; }
#viewSeg { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); width: 240px; z-index: 3; margin: 0; background: rgba(14, 17, 23, 0.9); }
#hint { position: absolute; top: 42px; right: 22px; color: var(--muted); font-size: 12px; pointer-events: none; text-align: right; max-width: 42%; z-index: 2; }

#readouts { position: absolute; left: 22px; bottom: 18px; display: flex; gap: 18px; flex-wrap: wrap; pointer-events: none; z-index: 2; }
.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; top: 60px; color: var(--muted); font-size: 12px; pointer-events: none; text-align: right; max-width: 42%; z-index: 2; }

#scrub { position: absolute; left: 22px; right: 22px; bottom: 72px; display: flex; gap: 10px; align-items: center; z-index: 3; }
#scrub input[type=range] { flex: 1; margin: 0; }
#scrub output { font-family: var(--mono); font-size: 12px; min-width: 15ch; }
#scrub select { font: inherit; font-size: 12px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 5px 6px; }

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

#panelToggle { display: none; position: absolute; right: 14px; top: 14px; z-index: 4; }

#panel { width: 360px; 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; }
#panel h3 { margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: #c3c9d4; }
.toolbar { display: flex; gap: 8px; padding-bottom: 10px; flex-wrap: wrap; }
.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:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--cl); outline-offset: 1px; }
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; }
button.small { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
button:disabled { opacity: 0.5; cursor: default; }

.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; }
.row { display: flex; gap: 8px; align-items: flex-start; }
.row .seg { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

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, label.in input, label.in select { display: block; width: 100%; margin-top: 5px; font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
label.in input { font-family: var(--mono); font-size: 12.5px; }
input[type=date] { color-scheme: dark; }
input[type=number] { font-family: var(--mono); }

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; }

.tip { margin: 6px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }
.tip a { color: var(--cl); }
.tip b { color: var(--text); font-weight: 500; }
.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.ac { background: var(--accent); } .sw.nb { background: #b48cff; }

.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: 110px; }
.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.15s; }
.prog[hidden] { display: none; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.tbl th { text-align: left; font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 500; padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); }
.tbl td { padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; color: #c3c9d4; }
.tbl td.n { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; color: var(--text); }
.tbl td.head { color: var(--muted); font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; padding-top: 8px; }
.tbl tr.strong td { color: var(--text); font-weight: 500; }
.tbl tr.total td { color: var(--accent); font-weight: 600; border-bottom: 0; }
.tbl td small { display: block; color: var(--muted); font-size: 11px; }
.tbl td.bad { color: var(--cd); }
.tbl input { width: 100%; font: inherit; font-family: var(--mono); font-size: 12px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 3px 5px; }
.tablewrap { overflow-x: auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 5px 10px; font-size: 12.5px; border-radius: 999px; }
#seqChips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
#seqChips .chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel-2); font-size: 12.5px; }
#seqChips .chip .dot { width: 8px; height: 8px; border-radius: 50%; }
#seqChips .chip button { padding: 0 6px; border: 0; background: transparent; color: var(--muted); font-size: 13px; line-height: 1; }
#seqChips .chip button:hover { color: var(--text); }
#seqChips .arrow { color: var(--muted); font-size: 12px; }
.addrow { display: flex; gap: 8px; align-items: center; }
.addrow select { flex: 1; font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }

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

@media (max-width: 860px) {
  #app { flex-direction: column; }
  #panel { position: fixed; inset: auto 0 0 0; height: 74vh; 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; }
  .toolbar .close { display: block; }
  #hud { top: 12px; left: 14px; }
  #hud h1 { font-size: 16px; }
  #hud p, #hint { display: none; }
  #viewSeg { top: 48px; left: 14px; transform: none; width: 200px; }
  #readouts { gap: 10px 14px; left: 14px; right: 14px; bottom: 12px; }
  .ro .v { font-size: 13.5px; }
  .ro.dim { display: none; }
  #legend { display: none; }
  #scrub { left: 14px; right: 14px; bottom: 58px; gap: 6px; }
  #scrub output { min-width: 0; font-size: 11px; }
}
