/*
 * Page layout and widget styling for the Primordial Solar System simulator.
 *
 * The colour tokens all come from src/ui/views.css (the --ssv-* custom properties), which is also
 * what the canvas components mirror into their own THEME object. Redefining a token there
 * restyles the page and the canvases together; nothing in this file invents a colour that the
 * views do not know about.
 *
 * No fonts, images or scripts are loaded from the network.
 */

:root {
  --gap: 8px;
  --bar-h: 62px;
  --file-h: 34px;
  --radius: 5px;
  --left-w: 320px;
  --right-w: 420px;
  --ok: #4fbf8b;
  --warn: #f5b942;
  --bad: #e2725b;
  --ink-dim: var(--ssv-dim);
}

* { box-sizing: border-box; }

/* The `hidden` attribute is only `display: none` in the UA stylesheet, so any author rule that
   sets `display` silently beats it — `.view-stack { display: grid }` was keeping the 2-D views on
   screen underneath the 3-D theatre. Make `hidden` mean hidden. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: #070a0f;
  color: var(--ssv-fg);
  font: var(--ssv-font);
  overflow: hidden;
}

button, select, input {
  font: var(--ssv-font-small);
  color: var(--ssv-fg);
  background: var(--ssv-panel);
  border: 1px solid var(--ssv-grid-strong);
  border-radius: 3px;
  padding: 3px 6px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--ssv-accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: #1b3550; border-color: #33608c; color: #dbeaff; }
button.primary:hover { border-color: var(--ssv-accent); }
button.danger { background: #3a1b1b; border-color: #7a3a3a; color: #ffc9c0; }
button.toggle.on, button.max-toggle.on { background: #1b3550; border-color: var(--ssv-accent); color: #dbeaff; }
input[type=checkbox] { accent-color: var(--ssv-accent); vertical-align: middle; }
input.num { width: 76px; text-align: right; font-variant-numeric: tabular-nums; }
input.num.tiny { width: 52px; }
input[type=range] { accent-color: var(--ssv-accent); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #27303f; border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------------------------------------------------------- *
 * Page grid
 * ---------------------------------------------------------------- */

#app {
  display: grid;
  height: 100vh;
  grid-template-columns: var(--left-w) minmax(380px, 1fr) minmax(360px, var(--right-w));
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top    top    top"
    "left   centre right";
  gap: var(--gap);
  padding: var(--gap);
}

#topbar { grid-area: top; }
#controls { grid-area: left; }
#centre { grid-area: centre; min-width: 0; }
#right { grid-area: right; min-width: 0; }

.panel {
  border: 1px solid var(--ssv-grid-strong);
  border-radius: var(--radius);
  background: var(--ssv-bg);
  min-height: 0;
  min-width: 0;
  position: relative;
}

/* ---------------------------------------------------------------- *
 * Top bar: transport strip + details drawer
 * ---------------------------------------------------------------- */

.topbar {
  border: 1px solid var(--ssv-grid-strong);
  border-radius: var(--radius);
  background: var(--ssv-panel);
}

.tb-strip {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 10px;
  min-height: 52px;
}

/* Number boxes that sit beside a slider or a segmented control get no spinner: the native
   arrows are a few pixels tall, unhittable, and they steal the width the number needs. */
input.num,
.step-custom,
.sm-editor {
  appearance: textfield;
  -moz-appearance: textfield;
}
input.num::-webkit-outer-spin-button,
input.num::-webkit-inner-spin-button {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
}

/* The clock block is FIXED width. Its three lines are rewritten many times a second, and any
   change in their length used to resize the block and shove every control to its right sideways
   — the play button visibly jittering while the run was going. Fixed width + tabular numerals +
   clipped overflow means the strip geometry never depends on the values in it. */
.tb-clocks {
  flex: 0 0 auto;
  width: 30ch;
  min-width: 30ch;
  max-width: 30ch;
  overflow: hidden;
}
.tb-clocks > div {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.clock-main { font: var(--ssv-font-bold); font-size: 18px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.clock-bp { color: var(--ink-dim); font-size: 11px; }
.clock-fine { color: var(--ssv-accent); font: var(--ssv-font-small); font-variant-numeric: tabular-nums; }

.tb-transport { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.tb-transport button { height: 30px; font-size: 14px; }
.tb-transport .play { min-width: 40px; }
.tb-transport .step-one { min-width: 34px; }
.tb-transport .step-n { font-size: 11px; min-width: 74px; }
.tb-transport .play.running { background: #1b3550; border-color: var(--ssv-accent); }

.tb-stepsize { flex: 0 0 auto; display: flex; flex-direction: column; gap: 2px; }
.segmented { display: flex; align-items: stretch; }
.segmented .seg {
  border-radius: 0;
  border-right-width: 0;
  min-width: 30px;
  padding: 3px 5px;
  font-variant-numeric: tabular-nums;
}
.segmented .seg:first-child { border-radius: 3px 0 0 3px; }
.segmented .seg.on { background: #1b3550; border-color: var(--ssv-accent); color: #dbeaff; }
.step-custom {
  width: 72px;                 /* seven digits at 11px tabular */
  border-radius: 0 3px 3px 0;
  text-align: right;
}
.step-note { color: var(--ssv-faint); font: var(--ssv-font-small); font-variant-numeric: tabular-nums; }

.tb-speed { flex: 1 1 320px; min-width: 240px; }
.tb-right { display: flex; align-items: center; gap: 6px; margin-left: auto; flex: 0 0 auto; }
/* Everything else in the strip that carries a changing value is given a fixed footprint too. */
.total-count {
  color: var(--ssv-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  width: 11ch;
  text-align: right;
}
/* With a sea running the count carries a suffix and needs a wider slot. The width changes only
   when a sea appears or goes — never while the numbers tick — so the strip still never jitters. */
.total-count.has-sea { width: 25ch; }
.badge { width: 16ch; text-align: center; box-sizing: border-box; overflow: hidden; }
.tb-transport .step-n { width: 84px; }
.step-note { width: 22ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font: var(--ssv-font-small);
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
  white-space: nowrap;
  cursor: help;
}
.badge.green { background: rgba(79, 191, 139, 0.15); border-color: var(--ok); color: #93e3c0; }
.badge.amber { background: rgba(245, 185, 66, 0.15); border-color: var(--warn); color: #ffd98a; }
.badge.red { background: rgba(226, 114, 91, 0.18); border-color: var(--bad); color: #ffb3a4; }

.drawer-toggle { min-width: 28px; height: 26px; font-size: 13px; line-height: 1; }

/* ---- speed meter ---- */

.speed-meter { display: flex; flex-direction: column; gap: 1px; }
.sm-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  height: 19px;                /* fixed: the readout and the CPU note change length constantly */
  overflow: hidden;
  white-space: nowrap;
}
.sm-readout { flex: 0 0 auto; }
.sm-exact { flex: 0 0 auto; width: 11ch; }
.sm-limit { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.sm-readout {
  border: none;
  background: none;
  padding: 0;
  color: var(--ssv-fg);
  font: var(--ssv-font-bold);
  font-size: 15px;
  white-space: nowrap;
  cursor: text;
  border-bottom: 1px dotted transparent;
}
.sm-readout:hover { border-bottom-color: var(--ssv-grid-strong); }
.sm-readout.limited { color: #ffd98a; }
.sm-readout.bad { color: var(--bad); }
.sm-editor { width: 130px; font-size: 13px; }
.sm-exact { color: var(--ssv-faint); font: var(--ssv-font-small); font-variant-numeric: tabular-nums; }
.sm-limit { color: var(--warn); font: var(--ssv-font-small); white-space: nowrap; }
.sm-limit[hidden] { display: none; }

.sm-row { display: flex; align-items: center; gap: 6px; }
.sm-track {
  position: relative;
  flex: 1;
  height: 12px;
  border: 1px solid var(--ssv-grid-strong);
  border-radius: 6px;
  background: #0d1119;
  cursor: pointer;
  overflow: hidden;
}
.sm-track:focus-visible { outline: 1px solid var(--ssv-accent); outline-offset: 1px; }
.sm-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, #1d4a6e, #4aa3e0);
  pointer-events: none;
}
.sm-hatch {
  position: absolute;
  top: 0; bottom: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    45deg, rgba(226, 114, 91, 0.30) 0 3px, rgba(226, 114, 91, 0.06) 3px 7px);
}
.sm-hatch[hidden] { display: none; }
.sm-hatch-label {
  position: absolute;
  left: 3px; top: -1px;
  font-size: 8px;
  color: #ffb3a4;
  white-space: nowrap;
  line-height: 13px;
}
.sm-ticks { position: absolute; inset: 0; pointer-events: none; }
.sm-tick {
  position: absolute;
  top: 2px; bottom: 2px;
  width: 1px;
  background: var(--ssv-faint);
  opacity: 0.55;
}
.sm-tick.major { top: 0; bottom: 0; opacity: 0.9; background: var(--ssv-dim); }
.sm-handle {
  position: absolute;
  top: -2px;
  width: 9px;
  height: 16px;
  margin-left: -4.5px;
  border-radius: 3px;
  background: var(--ssv-fg);
  border: 1px solid #0d1119;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}
.sm-handle.at-max { background: var(--ssv-accent); }
.sm-max { min-width: 38px; padding: 2px 6px; font-size: 10px; }
.sm-max.on { background: #1b3550; border-color: var(--ssv-accent); color: #dbeaff; }

.sm-labels { position: relative; height: 13px; }
.sm-label {
  position: absolute;
  transform: translateX(-50%);
  border: none;
  background: none;
  padding: 0 2px;
  color: var(--ssv-faint);
  font-size: 9px;
  line-height: 12px;
  white-space: nowrap;
  cursor: pointer;
}
.sm-label.major { color: var(--ssv-dim); }
.sm-label:hover { color: var(--ssv-accent); }
.sm-label.on { color: var(--ssv-fg); font-weight: 600; }
.sm-label[hidden] { display: none; }

/* ---- drawer ---- */

.tb-drawer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 26px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--ssv-grid);
  font: var(--ssv-font-small);
}
.tb-drawer[hidden] { display: none; }
.dw-group { min-width: 150px; }
.dw-group h4 { margin: 0 0 3px; font-size: 10px; color: var(--ssv-accent); letter-spacing: 0.04em; }
.dw-facts { display: grid; grid-template-columns: auto auto; gap: 0 10px; margin: 0; }
.dw-facts dt { color: var(--ssv-faint); }
.dw-facts dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.dw-facts dd.bad { color: var(--bad); font-weight: 600; }
.dw-line { color: var(--ssv-dim); margin-bottom: 4px; }
.dw-buttons { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.bg-indicator { color: var(--ssv-accent); margin-top: 4px; }
.bg-indicator.active { color: var(--ssv-accent); }

/* The file controls live in the drawer's button row. It must stay a wrapping flex row: the
   status line and the headless-runner note are full-width items that each take their own row. */
#file-bar { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.file-label {
  display: inline-block;
  padding: 3px 6px;
  border: 1px solid var(--ssv-grid-strong);
  border-radius: 3px;
  background: var(--ssv-panel);
  cursor: pointer;
}
.file-label:hover { border-color: var(--ssv-accent); }
.file-label input { display: none; }
.file-status { color: var(--ssv-faint); width: 100%; flex: 0 0 100%; }
.headless-note {
  width: 100%;
  flex: 0 0 100%;
  color: var(--ssv-faint);
  font-style: italic;
  cursor: help;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: 1px solid var(--ssv-grid);
  border-radius: 10px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- *
 * Controls (left)
 * ---------------------------------------------------------------- */

.controls {
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  font-size: 11px;
}
.controls-head { position: sticky; top: 0; z-index: 4; background: #070a0f; padding-bottom: 6px; }
.notice {
  margin: 0 0 6px;
  padding: 5px 7px;
  border-left: 2px solid var(--ssv-accent);
  background: rgba(124, 197, 255, 0.07);
  color: var(--ink-dim);
  line-height: 1.45;
}
.apply-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.apply-bar .pending-count { color: var(--ssv-faint); }
.controls.dirty .apply-bar .pending-count { color: var(--warn); }
button.has-pending { background: #4a3a10; border-color: var(--warn); color: #ffe2a6; }

.group {
  border: 1px solid var(--ssv-grid);
  border-radius: var(--radius);
  margin-bottom: 6px;
  background: rgba(18, 23, 34, 0.6);
}
.group > summary {
  cursor: pointer;
  padding: 5px 8px;
  color: var(--ssv-accent);
  font-size: 11px;
  letter-spacing: 0.02em;
  user-select: none;
}
.group[open] > summary { border-bottom: 1px solid var(--ssv-grid); }
.group-body { padding: 6px 8px 8px; display: flex; flex-direction: column; gap: 7px; }

.row { display: grid; grid-template-columns: 1fr auto; gap: 3px 6px; align-items: center; }
.row-label { grid-column: 1; color: var(--ssv-dim); line-height: 1.3; cursor: help; }
.row .tag { grid-column: 2; grid-row: 1; justify-self: end; }
.row .num-wrap { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; }
.row .num-wrap input[type=range] { flex: 1; min-width: 60px; }
.row > select, .row > input[type=checkbox] { grid-column: 1 / -1; justify-self: start; }
.row > select { width: 100%; }
.row-note, .row-warn { grid-column: 1 / -1; margin: 0; color: var(--ssv-faint); line-height: 1.4; }
.row.changed { background: rgba(245, 185, 66, 0.1); outline: 1px solid rgba(245, 185, 66, 0.35); border-radius: 3px; padding: 2px 3px; }

/* Shortcut buttons that set several parameters at once, and the advice line under disk.rIn. */
.shortcut-row { border-top: 1px solid var(--ssv-grid); padding-top: 7px; margin-top: 2px; }
.shortcut-bar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.shortcut-what { grid-column: 1 / -1; margin: 0; color: var(--ssv-faint); line-height: 1.4; }
.advice-row { grid-template-columns: 1fr auto; align-items: baseline; gap: 4px 6px; }
.advice-text { grid-column: 1; margin: 0; color: var(--ssv-faint); line-height: 1.35; }
.advice-row.warn .advice-text { color: var(--warn); font-weight: 600; }
.advice-row > button { grid-column: 2; justify-self: end; white-space: nowrap; }
.row.unphysical { background: rgba(226, 114, 91, 0.08); outline: 1px solid rgba(226, 114, 91, 0.3); border-radius: 3px; padding: 3px 4px; }
.row.unphysical .row-label { color: #ffb3a4; }
.row-warn { color: var(--bad); font-weight: 600; }
.row-caution {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--warn);
  font-weight: 600;
  line-height: 1.35;
}
.auto-null { display: inline-flex; gap: 3px; align-items: center; color: var(--ssv-faint); white-space: nowrap; }

.tag {
  font-size: 8.5px;
  letter-spacing: 0.06em;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid;
  cursor: help;
}
.tag.live { color: #93e3c0; border-color: rgba(79, 191, 139, 0.5); background: rgba(79, 191, 139, 0.1); }
.tag.restart { color: #ffd98a; border-color: rgba(245, 185, 66, 0.45); background: rgba(245, 185, 66, 0.08); }

.preset-info { grid-column: 1 / -1; }
.preset-desc { margin: 2px 0; color: var(--ink-dim); line-height: 1.45; }
.preset-ref { margin: 2px 0 0; color: var(--ssv-faint); font-style: italic; line-height: 1.4; }

.ic-summary {
  border: 1px solid var(--ssv-grid-strong);
  border-left: 2px solid var(--ssv-accent);
  border-radius: var(--radius);
  padding: 6px 8px;
  margin-bottom: 6px;
  background: rgba(18, 23, 34, 0.9);
}
.ic-head { display: flex; justify-content: space-between; align-items: center; }
.icon-btn { border: none; background: none; color: var(--ssv-dim); padding: 0 4px; font-size: 13px; }
.ic-facts, .insp-facts, .det-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1px 8px;
  margin: 4px 0 0;
}
.ic-facts dt, .insp-facts dt, .det-facts dt { color: var(--ssv-faint); }
.ic-facts dd, .insp-facts dd, .det-facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.ic-notes { margin: 6px 0 0; padding-left: 16px; color: var(--ssv-faint); line-height: 1.45; }
.ic-notes li { margin-bottom: 3px; }
/* A note the core marked as a warning must not read like the book-keeping beside it. */
.ic-notes li.warn { color: var(--warn); font-weight: 600; }
.controls-foot { padding: 4px 0 20px; }

/* ---------------------------------------------------------------- *
 * Centre column
 * ---------------------------------------------------------------- */

.centre {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gap);
  min-height: 0;
}
.view-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 8px;
  border: 1px solid var(--ssv-grid-strong);
  border-radius: var(--radius);
  background: var(--ssv-panel);
  font: var(--ssv-font-small);
}
.tb-field { display: inline-flex; align-items: center; gap: 4px; color: var(--ssv-faint); }
.tb-check { display: inline-flex; align-items: center; color: var(--ssv-dim); white-space: nowrap; }
.view-toolbar .spacer { flex: 1; }

.view-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(120px, 30%);
  gap: var(--gap);
  min-height: 0;
}
.orbit-panel, .edge-panel, .theatre-panel { overflow: hidden; }
/* The theatre builds its own root inside this panel and sizes its canvas from the container, so
   the panel must be a plain positioned box: a flex container with `align-items: center` collapses
   .thv-root (which has no intrinsic height) to nothing and the scene renders blank. */
.theatre-panel { min-height: 0; }
.theatre-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  padding: 20px;
  color: var(--warn);
  text-align: center;
  line-height: 1.5;
}

.interp-note {
  position: absolute;
  top: 6px;
  right: 8px;
  z-index: 3;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(12, 16, 24, 0.85);
  border: 1px solid var(--ssv-accent);
  color: var(--ssv-accent);
  font: var(--ssv-font-small);
  pointer-events: none;
}

/* ---------------------------------------------------------------- *
 * Right column: tabs
 * ---------------------------------------------------------------- */

#right {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--gap);
  min-height: 0;
}
#tab-bar {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--ssv-grid-strong);
  padding-bottom: 3px;
}
.tab {
  border: 1px solid transparent;
  background: none;
  color: var(--ssv-dim);
  padding: 4px 6px;
  font-size: 10.5px;
  white-space: nowrap;
}
.tab.active { background: var(--ssv-panel); border-color: var(--ssv-grid-strong); color: var(--ssv-fg); }
#tab-panels { position: relative; min-height: 0; }
.tab-panel { position: absolute; inset: 0; overflow: auto; }
.tab-panel[hidden] { display: none; }

.plots-grid {
  display: grid;
  grid-template-rows: auto repeat(4, minmax(120px, 1fr));
  gap: var(--gap);
  overflow: hidden;
}
.plot-bar { display: flex; gap: 6px; align-items: center; font: var(--ssv-font-small); color: var(--ssv-dim); }
.plot-box { min-height: 130px; }

/* Every id in the UI is a handle on that body. */
.body-chip {
  border: 1px solid var(--ssv-grid-strong);
  background: rgba(124, 197, 255, 0.08);
  color: var(--ssv-accent);
  border-radius: 3px;
  padding: 0 4px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  line-height: 1.3;
}
.body-chip:hover { border-color: var(--ssv-accent); background: rgba(124, 197, 255, 0.18); }
.tab-pin {
  border: 1px solid transparent;
  background: none;
  padding: 2px 4px;
  font-size: 10px;
  opacity: 0.45;
  margin-left: auto;
}
.tab-pin.on { opacity: 1; background: var(--ssv-panel); border-color: var(--ssv-accent); }
.tab.pinned { border-bottom: 2px solid var(--ssv-accent); }

/* ---- event director ---- */

.toast-host {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 5px;
  pointer-events: none;
  max-width: 340px;
}
.toast-stack { display: contents; }
.toast {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  padding: 5px 7px;
  border: 1px solid var(--ssv-grid-strong);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: rgba(12, 16, 24, 0.93);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.55);
  font: var(--ssv-font-small);
}
.toast-collision { border-left-color: #f5d547; }
.toast-nearMiss { border-left-color: #7fd8b8; }
.toast-capture { border-left-color: #b39ddb; }
.toast-ejection { border-left-color: #b39ddb; }
.toast-star { border-left-color: var(--ssv-sun); }
.toast-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.toast-body { flex: 1; min-width: 0; }
.toast-text { color: var(--ssv-fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-time { color: var(--ssv-faint); }
.toast-watch { padding: 1px 6px; font-size: 9px; background: #1b3550; border-color: var(--ssv-accent); color: #dbeaff; }
.toast-close { border: none; background: none; color: var(--ssv-faint); padding: 0 3px; font-size: 13px; }

.encounter-banner {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border: 1px solid var(--warn);
  border-radius: 12px;
  background: rgba(12, 16, 24, 0.92);
  color: #ffd98a;
  font: var(--ssv-font-small);
  white-space: nowrap;
}
.encounter-banner[hidden] { display: none; }

.dw-director { min-width: 260px; }
.dir-modes { display: flex; margin-bottom: 4px; }
.dir-modes .seg { border-radius: 0; border-right-width: 0; padding: 2px 6px; font-size: 9.5px; }
.dir-modes .seg:first-child { border-radius: 3px 0 0 3px; }
.dir-modes .seg:last-child { border-radius: 0 3px 3px 0; border-right-width: 1px; }
.dir-modes .seg.on { background: #1b3550; border-color: var(--ssv-accent); color: #dbeaff; }
.dir-note { margin: 0 0 5px; color: var(--ssv-faint); line-height: 1.35; max-width: 42ch; }
.dir-note.degraded { color: var(--warn); }
.dir-class { display: flex; align-items: center; gap: 3px; margin-bottom: 2px; flex-wrap: wrap; }
.dir-class .chip { flex: 0 0 auto; min-width: 118px; }
.dir-unit { color: var(--ssv-faint); }
.dir-class .num.tiny { width: 46px; }

.warn-chip {
  display: block;
  margin-top: 5px;
  padding: 3px 7px;
  border: 1px solid var(--warn);
  border-radius: 10px;
  background: rgba(245, 185, 66, 0.12);
  color: #ffd98a;
  font: var(--ssv-font-small);
  text-align: left;
  line-height: 1.35;
  max-width: 38ch;
}
.warn-chip[hidden] { display: none; }

.empty { color: var(--ssv-faint); padding: 14px; line-height: 1.5; }

/* ---------------------------------------------------------------- *
 * Event log
 * ---------------------------------------------------------------- */

.eventlog { display: flex; flex-direction: column; height: 100%; gap: 4px; }
.log-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font: var(--ssv-font-small);
  color: var(--ssv-dim);
}
.log-filters .filter-title { color: var(--ssv-faint); align-self: center; }
.log-filters .swatch { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.log-tools { display: flex; align-items: center; gap: 8px; font: var(--ssv-font-small); color: var(--ssv-faint); }
.log-scroller {
  flex: 1;
  min-height: 90px;
  overflow-y: auto;
  border: 1px solid var(--ssv-grid-strong);
  border-radius: var(--radius);
  background: var(--ssv-bg);
}
.log-spacer { position: relative; }
.log-rows { position: absolute; top: 0; left: 0; right: 0; }
.log-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 8px;
  border-bottom: 1px solid rgba(29, 37, 51, 0.6);
  font: var(--ssv-font-small);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  overflow: hidden;
}
.log-row:hover { background: rgba(124, 197, 255, 0.07); }
.log-row.selected { background: rgba(124, 197, 255, 0.14); outline: 1px solid var(--ssv-accent); outline-offset: -1px; }
.log-row .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.log-row .log-t { color: var(--ssv-dim); min-width: 78px; }
.log-row .log-type { color: var(--ssv-fg); min-width: 96px; overflow: hidden; text-overflow: ellipsis; }
.log-row .log-ids { color: var(--ssv-faint); }
.log-row .log-mass, .log-row .log-v, .log-row .log-angle { color: var(--ssv-dim); }
/* A row with a recorded replay has something worth watching on it, so the button says so
   instead of hiding as another grey chip in a dense list. */
.replay-btn {
  margin-left: auto;
  padding: 1px 7px;
  font-size: 9px;
  background: #1b3550;
  border-color: var(--ssv-accent);
  color: #dbeaff;
  font-weight: 600;
}
.replay-btn:hover { background: #26507a; }
.log-row.has-replay { border-left: 2px solid var(--ssv-accent); }

/* ---- view hint + zoom ------------------------------------------- */

.view-hint {
  padding: 2px 8px;
  color: var(--ssv-faint);
  font: var(--ssv-font-small);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.insp-camera { margin-top: 10px; }
.cam-row { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.cam-row .num { width: 64px; }
.pair-hint {
  margin: 4px 0 0;
  padding: 4px 6px;
  border-left: 2px solid var(--warn);
  background: rgba(245, 185, 66, 0.1);
  color: #ffd98a;
  line-height: 1.4;
}
.pair-hint[hidden] { display: none; }
.log-details {
  max-height: 40%;
  overflow: auto;
  border: 1px solid var(--ssv-grid-strong);
  border-radius: var(--radius);
  padding: 6px 8px;
  background: var(--ssv-panel);
  font: var(--ssv-font-small);
}
.det-head { margin-bottom: 4px; }
.det-time { color: var(--ssv-faint); }

/* ---------------------------------------------------------------- *
 * Inspector
 * ---------------------------------------------------------------- */

.inspector { padding: 6px 8px; font-size: 11px; }
.insp-head { display: flex; align-items: baseline; gap: 8px; }
.insp-head h3 { margin: 4px 0; font-size: 14px; }
.insp-head .gone { color: var(--bad); }
.insp-end { margin: 4px 0 8px; color: var(--ink-dim); line-height: 1.45; }
.cmp-table tr.clickable { cursor: pointer; }
.cmp-table tr.clickable:hover td { background: rgba(124, 197, 255, 0.10); }
.inspector h4 { margin: 10px 0 4px; font-size: 11px; color: var(--ssv-accent); letter-spacing: 0.03em; }
.comp-bar {
  display: flex;
  height: 14px;
  border: 1px solid var(--ssv-grid-strong);
  border-radius: 3px;
  overflow: hidden;
  margin: 3px 0;
}
.comp-seg.core { background: #a03020; }
.comp-seg.mantle { background: #8b8f98; }
.comp-seg.water { background: #3078e8; }
.comp-legend { display: flex; gap: 10px; font: var(--ssv-font-small); }
.comp-legend .k-core { color: #d08a78; }
.comp-legend .k-mantle { color: #b8bcc5; }
.comp-legend .k-water { color: #79b8ff; }

.insp-tree, .insp-edit, .insp-add { margin-top: 10px; }
.insp-tree > summary, .insp-edit > summary, .insp-add > summary {
  cursor: pointer;
  color: var(--ssv-accent);
  padding: 3px 0;
}
.tree-note { color: var(--ssv-faint); margin: 2px 0 6px; line-height: 1.4; }
.tree-node > summary { cursor: pointer; padding: 1px 0; }
.tree-kids { border-left: 1px solid var(--ssv-grid-strong); margin-left: 5px; padding-left: 8px; }
.tree-leaf { color: var(--ssv-dim); padding: 1px 0 1px 14px; }
.tree-leaf.missing { color: var(--bad); }
.tree-meta { color: var(--ssv-faint); }

.add-form, .edit-form { display: flex; flex-direction: column; gap: 4px; padding-top: 4px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 6px; color: var(--ssv-dim); }
.field.check { justify-content: flex-start; gap: 6px; }
.field select { width: 96px; }
.add-status { color: var(--ok); margin: 2px 0; }

/* ---------------------------------------------------------------- *
 * Compare
 * ---------------------------------------------------------------- */

.compare { padding: 6px 8px; font-size: 11px; }
.cmp-bar { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.cmp-status { color: var(--ssv-faint); }
.cmp-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; margin-bottom: 10px; }
.stat {
  border: 1px solid var(--ssv-grid-strong);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 5px 7px;
  background: var(--ssv-panel);
}
.stat.good { border-left-color: var(--ok); }
.stat.ok { border-left-color: var(--warn); }
.stat.poor { border-left-color: var(--bad); }
.stat-label { color: var(--ssv-faint); font-size: 10px; }
.stat-value { font: var(--ssv-font-bold); font-size: 15px; font-variant-numeric: tabular-nums; }
.stat-target { color: var(--ssv-faint); font-size: 10px; }

/* The per-analogue table has twelve columns and the panel is 400 px wide, so it scrolls
   sideways rather than being truncated at the panel edge. */
.cmp-scroll { overflow-x: auto; max-width: 100%; }
.cmp-table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 10px; font-variant-numeric: tabular-nums; }
.cmp-table th, .cmp-table td { border: 1px solid var(--ssv-grid); padding: 2px 4px; text-align: right; }
.cmp-table th { color: var(--ssv-faint); font-weight: normal; text-align: right; }
.cmp-table td.zone, .cmp-table th:first-child { text-align: left; color: var(--ssv-fg); }
.cmp-table td.real { color: var(--ssv-faint); }
.cmp-table td.ratio.good { color: #93e3c0; }
.cmp-table td.ratio.ok { color: #ffd98a; }
.cmp-table td.ratio.poor { color: #ffb3a4; }
.cmp-budget, .cmp-detail { margin-top: 12px; }
.cmp-budget h4, .cmp-detail h4 { margin: 0 0 4px; color: var(--ssv-accent); font-size: 11px; }

/* ---------------------------------------------------------------- *
 * Early stage
 * ---------------------------------------------------------------- */

.early-stage { display: flex; flex-direction: column; gap: 8px; padding: 6px 8px; height: 100%; }
.early-warning {
  border: 1px solid var(--warn);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 7px 9px;
  background: rgba(245, 185, 66, 0.08);
  font-size: 11px;
  line-height: 1.5;
}
.early-warning strong { color: var(--warn); display: block; margin-bottom: 4px; }
.early-warning p { margin: 5px 0 0; color: var(--ink-dim); }
.early-bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font: var(--ssv-font-small); }
.early-bar input[type=range] { flex: 1; min-width: 100px; }
.early-clock { color: var(--ssv-accent); font-variant-numeric: tabular-nums; min-width: 140px; }
.early-status { color: var(--warn); }
.early-gas { display: flex; align-items: center; gap: 7px; font: var(--ssv-font-small); color: var(--ssv-dim); }
.gas-bar { flex: 0 0 120px; height: 8px; border: 1px solid var(--ssv-grid-strong); border-radius: 4px; overflow: hidden; }
.gas-fill { height: 100%; background: linear-gradient(90deg, #2a4b6e, #7cc5ff); width: 100%; }
.early-plots { display: grid; grid-template-rows: 1fr 1fr; gap: var(--gap); flex: 1; min-height: 260px; }
.early-plot { border: 1px solid var(--ssv-grid-strong); border-radius: var(--radius); min-height: 130px; }
.early-caption { color: var(--ink-dim); margin: 0; line-height: 1.5; }

/* ---------------------------------------------------------------- *
 * Limitations
 * ---------------------------------------------------------------- */

.limitations { padding: 8px 12px; font-size: 11px; line-height: 1.55; max-width: 70ch; }
.lim-intro { color: var(--ink-dim); }
.lim-toc { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-bottom: 12px; }
.lim-toc a { color: var(--ssv-accent); text-decoration: none; font-size: 10px; }
.lim-toc a:hover { text-decoration: underline; }
.lim-section { margin-bottom: 16px; }
.lim-section h3 { margin: 0 0 3px; font-size: 12px; color: var(--ssv-fg); }
.lim-summary { margin: 0 0 6px; color: var(--ssv-accent); font-style: italic; }
.lim-points { margin: 0; padding-left: 18px; }
.lim-points li { margin-bottom: 6px; color: var(--ink-dim); }
.lim-detail { color: var(--ssv-faint); margin: 3px 0 0; }
.lim-refs { color: var(--ssv-faint); font-style: italic; margin: 2px 0 0; }
.lim-perf { border-collapse: collapse; margin: 6px 0; font-variant-numeric: tabular-nums; }
.lim-perf th, .lim-perf td { border: 1px solid var(--ssv-grid); padding: 3px 8px; text-align: right; }
.lim-perf th { color: var(--ssv-faint); font-weight: normal; }

/* ---------------------------------------------------------------- *
 * Overlays
 * ---------------------------------------------------------------- */

#resume-prompt {
  position: fixed;
  z-index: 40;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 480px;
  padding: 16px 20px;
  border: 1px solid var(--ssv-accent);
  border-radius: 7px;
  background: #0f1420;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  font-size: 12px;
  line-height: 1.5;
}
#resume-prompt[hidden] { display: none; }
.resume-actions { display: flex; gap: 8px; margin: 10px 0; }

#error-bar {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 50;
  max-height: 24vh;
  overflow: auto;
  padding: 6px 10px;
  border: 1px solid #7a2a2a;
  border-radius: var(--radius);
  background: #2a0f12;
  color: #ffb3b3;
  font: var(--ssv-font-small);
  white-space: pre-wrap;
}
#error-bar[hidden] { display: none; }

#selftest {
  position: fixed;
  inset: 0;
  z-index: 60;
  margin: 0;
  padding: 14px;
  overflow: auto;
  background: #05070b;
  color: #cfe4ff;
  font: 11px ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

/* ---------------------------------------------------------------- *
 * Narrow (down to ~1280 px)
 * ---------------------------------------------------------------- */

@media (max-width: 1500px) {
  :root { --left-w: 280px; --right-w: 380px; }
  .tb-speed { min-width: 210px; }
}

@media (max-width: 1320px) {
  :root { --left-w: 250px; --right-w: 340px; --gap: 6px; }
  .tb-strip { gap: 9px; padding: 5px 8px; }
  .clock-main { font-size: 15px; }
  .tb-clocks { min-width: 150px; }
  .sm-readout { font-size: 13px; }
  .tb-transport .step-n { min-width: 62px; }
  .step-custom { width: 58px; }
  .sm-exact { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
