:root {
  --bg: #0f1216;
  --panel: #161a20;
  --panel-2: #1d222a;
  --line: #2a313b;
  --text: #e6eaf0;
  --muted: #9aa5b3;
  --accent: #ff9d3c;
  --pch: #ff9d3c;
  --pca: #ffd27a;
  --thr: #5cb8ff;
  --radius: 8px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
a { color: var(--accent); }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.top {
  display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.mark { font-weight: 700; letter-spacing: 0.02em; text-decoration: none; }
.top h1 { font-size: 16px; font-weight: 600; margin: 0; }
.tag { margin: 0; color: var(--muted); flex: 1 1 260px; min-width: 0; }

.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 12px; color: var(--text);
}
.ghost:hover { border-color: var(--muted); }

.layout {
  flex: 1; min-height: 0;
  display: grid; gap: 0;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "stage panel" "timeline panel";
  height: calc(100dvh - 53px);
}
.stage { grid-area: stage; position: relative; min-height: 0; overflow: hidden; background: #12161b; }
#view { display: block; width: 100%; height: 100%; touch-action: none; }
.timeline { grid-area: timeline; border-top: 1px solid var(--line); padding: 8px 16px 10px; min-width: 0; }
.panel {
  grid-area: panel; border-left: 1px solid var(--line); background: var(--panel);
  padding: 12px 16px; overflow-y: auto; min-width: 0;
}

/* overlays on the 3-D view */
.readout {
  position: absolute; left: 12px; top: 10px; pointer-events: none;
  background: rgba(15, 18, 22, 0.72); border-radius: var(--radius); padding: 8px 10px; min-width: 168px;
  font-variant-numeric: tabular-nums;
}
.readout .row { display: flex; gap: 8px; align-items: center; }
.readout .big { font-size: 18px; font-weight: 600; margin: 2px 0 4px; }
.readout dl { display: grid; grid-template-columns: auto auto; gap: 1px 12px; margin: 0; }
.readout dt { color: var(--muted); }
.readout dd { margin: 0; text-align: right; }
.phase { text-transform: uppercase; font-size: 11px; letter-spacing: 0.08em; color: var(--accent); font-weight: 700; }
.phase.burn { color: #ffb36b; }
.kbadge { font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--muted); }

.views { position: absolute; right: 12px; top: 10px; display: flex; gap: 4px; }
.views button, .seg button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px;
  min-height: 32px;
}
.views button:hover, .seg button:hover { border-color: var(--muted); }
.seg button[aria-checked="true"] { background: var(--accent); color: #15181d; border-color: var(--accent); font-weight: 600; }
.seg button:disabled { opacity: 0.4; cursor: not-allowed; }

.legend {
  position: absolute; right: 12px; top: 54px; bottom: 40px; max-height: 300px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px; pointer-events: none;
}
.legend[hidden] { display: none; }
.lg-title { font-size: 12px; color: var(--text); background: rgba(15, 18, 22, 0.72); padding: 1px 6px; border-radius: 4px; }
.lg-body { flex: 1; display: flex; gap: 6px; flex-direction: row-reverse; min-height: 0; }
.lg-bar { width: 12px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, 0.15); }
.lg-labels {
  display: flex; flex-direction: column; justify-content: space-between; text-align: right;
  font-size: 11px; font-variant-numeric: tabular-nums;
}
.lg-labels span { background: rgba(15, 18, 22, 0.72); padding: 0 4px; border-radius: 3px; }

.status {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(15, 18, 22, 0.85); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 12px; font-size: 13px; color: var(--muted); max-width: calc(100% - 32px);
  pointer-events: none; transition: opacity 0.2s;
}
.status.hide { opacity: 0; }
.status.error { color: #ff8a80; border-color: #6b2b27; }

/* timeline */
.transport { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.play {
  width: 40px; height: 36px; border-radius: var(--radius); border: 0;
  background: var(--accent); color: #15181d; font-size: 16px; font-weight: 700;
}
.speed { color: var(--muted); display: flex; align-items: center; gap: 6px; }
select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; min-height: 32px;
}
.rate, .frameno { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.frameno { margin-left: auto; }
.plotwrap { position: relative; height: 120px; }
#plot { display: block; width: 100%; height: 100%; touch-action: none; cursor: pointer; }
.plotkey { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.plotkey span::before { content: ""; display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
.k-pch::before { background: var(--pch); }
.k-pca::before { background: var(--pca); }
.k-thr::before { background: var(--thr); }
.plotkey .k-note::before { display: none; }

/* controls */
fieldset { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
legend { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; padding: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.cutrow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 28px; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.devrange { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); }
.devrange[hidden] { display: none; }

/* about */
.info {
  max-width: min(680px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px 24px; overflow-y: auto;
}
.info::backdrop { background: rgba(0, 0, 0, 0.6); }
.info h2 { margin: 0 0 8px; font-size: 18px; }
.info h3 { margin: 16px 0 4px; font-size: 14px; color: var(--accent); }
.info ul { padding-left: 18px; margin: 4px 0; }
.info li { margin: 4px 0; }
.info .close {
  position: absolute; right: 12px; top: 10px; width: 34px; height: 34px;
  background: transparent; border: 1px solid var(--line); border-radius: 8px; font-size: 18px;
}
.made { color: var(--muted); margin-top: 16px; }
.nojs { padding: 16px; }

/* phone / narrow */
@media (max-width: 860px) {
  .layout {
    display: flex; flex-direction: column; height: auto;
  }
  .stage { height: 58vh; min-height: 300px; max-height: 620px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .tag { display: none; }
  .readout { left: 8px; top: 8px; min-width: 0; padding: 6px 8px; font-size: 12px; }
  .readout .big { font-size: 15px; }
  .views { right: 8px; top: 8px; }
  .views button { padding: 4px 8px; }
  .legend { right: 8px; top: 48px; bottom: 44px; }
  .plotwrap { height: 110px; }
}
