:root {
  --bg: #070b12;
  --bg-elev: #0d1420;
  --panel: #0b111c;
  --card: #111a29;
  --border: #1e2c42;
  --border-hi: #2d4466;
  --text: #dce6f4;
  --muted: #8295b0;
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.16);
  --ok: #22c55e;
  --warn: #f59e0b;
  --crit: #ef4444;
  --esc: #a855f7;
  --earth: #3b82f6;
  --moon: #cbd5e1;
  --bh: #ff7b29;
  --roche: #f43f5e;
  --mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.brand .sub {
  font-size: 12px;
  color: var(--muted);
}

.hud-strip {
  display: flex;
  align-items: stretch;
  gap: 6px;
  flex-wrap: wrap;
}

.hud-cell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4px 8px;
  min-width: 86px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.hud-cell.audio-cell {
  min-width: 132px;
}

.hud-cell .k {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.hud-cell .v {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

.hud-cell.status {
  min-width: 112px;
  align-items: center;
  background: transparent;
  border-color: transparent;
  padding: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 4px 10px;
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  border: 1px solid currentColor;
}

.badge.ok {
  color: var(--ok);
  background: rgba(34, 197, 94, 0.12);
}

.badge.warn {
  color: var(--warn);
  background: rgba(245, 158, 11, 0.14);
}

.badge.crit {
  color: var(--crit);
  background: rgba(239, 68, 68, 0.18);
}

.badge.esc {
  color: var(--esc);
  background: rgba(168, 85, 247, 0.16);
}

.workspace {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

.panel {
  width: 312px;
  flex: 0 0 312px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px 11px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.group h2 {
  margin: 0 0 1px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--text);
}

.field span {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
}

.field strong {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 600;
}

select {
  width: 100%;
  padding: 5px 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 12px;
  outline: none;
}

select:focus {
  border-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  margin: 1px 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  padding-top: 2px;
}

.check input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.note {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.42;
  color: var(--muted);
}

.note.micro {
  font-size: 10.5px;
  line-height: 1.35;
  color: #6f84a3;
}

.note.mono-note {
  font-family: var(--mono);
  font-size: 10.5px;
  color: #93c5fd;
  line-height: 1.38;
}

.btn-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 5px;
}

.btn-row.view-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.btn-row.view-grid button {
  padding: 5px 2px;
  font-size: 10.5px;
}

button {
  padding: 6px 8px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover {
  border-color: var(--accent);
  background: #132033;
}

button.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: #bae6fd;
}

button.primary:hover {
  background: rgba(56, 189, 248, 0.28);
}

button.active {
  border-color: var(--ok);
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.14);
}

.legend ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--muted);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 9px;
}

.dot.earth {
  background: var(--earth);
  box-shadow: 0 0 6px var(--earth);
}

.dot.moon {
  background: var(--moon);
}

.dot.bh {
  background: #050507;
  border: 2px solid var(--bh);
  box-shadow: 0 0 6px var(--bh);
}

.dot.roche {
  background: transparent;
  border: 1.5px dashed var(--roche);
}

.stage {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 45%, #0c1424 0%, #05080f 75%);
}

.canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}

.plot-wrap {
  flex: 0 0 172px;
  height: 172px;
  position: relative;
  border-top: 1px solid var(--border);
  background: #080d16;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

@media (max-width: 900px) {
  html,
  body {
    overflow: auto;
  }

  .workspace {
    flex-direction: column;
  }

  .panel {
    width: 100%;
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
  }

  .canvas-wrap {
    height: 460px;
    flex: 0 0 460px;
  }
}
