:root {
  --bg: #05070a;
  --bg-panel: rgba(8, 12, 18, 0.82);
  --bg-panel-solid: #080c12;
  --line: rgba(120, 180, 210, 0.18);
  --line-strong: rgba(140, 200, 230, 0.32);
  --ink: #cfe3ee;
  --ink-dim: #6f8896;
  --ink-mute: #4a5e6b;
  --cyan: #7cf1ff;
  --cyan-dim: #2a8aa0;
  --amber: #ffb347;
  --amber-dim: #a66a1e;
  --green: #6ee2a0;      /* terrestrial */
  --gold:  #f0c65a;      /* gas giant */
  --ice:   #7cd5ff;      /* ice giant */
  --magenta: #e678d0;    /* dwarf */
  --white-class: #d8e2ea;/* asteroid */
  --comet: #ff7a5a;      /* comet */
  --danger: #ff5a5a;
  --ok: #6ee2a0;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #000; color: var(--ink); font-family: var(--sans); }
body { user-select: none; -webkit-user-select: none; }

#scene { position: fixed; inset: 0; z-index: 0; }
#scene canvas { display: block; }

/* ---------- HUD frame (mission control chrome) ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud .pane { pointer-events: auto; }

/* corner crosshairs */
.crosshair {
  position: fixed;
  width: 22px; height: 22px;
  border: 1px solid var(--line-strong);
  pointer-events: none;
  z-index: 6;
}
.crosshair.tl { top: 8px; left: 8px; border-right: none; border-bottom: none; }
.crosshair.tr { top: 8px; right: 8px; border-left: none; border-bottom: none; }
.crosshair.bl { bottom: 8px; left: 8px; border-right: none; border-top: none; }
.crosshair.br { bottom: 8px; right: 8px; border-left: none; border-top: none; }

/* top band */
#topband {
  position: fixed; top: 0; left: 0; right: 0;
  height: 34px;
  display: flex; align-items: center; gap: 18px;
  padding: 0 48px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(to bottom, rgba(8,12,18,0.82), rgba(8,12,18,0.4) 70%, rgba(8,12,18,0) 100%);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  color: var(--ink-dim); text-transform: uppercase;
  z-index: 5;
  pointer-events: none;
}
#topband .brand { color: var(--cyan); letter-spacing: 0.22em; font-weight: 500; }
#topband .sep { color: var(--ink-mute); }
#topband .utc { color: var(--ink); }
#topband .spacer { flex: 1; }
#topband .warn { color: var(--amber); }

/* Scanlines overlay (very subtle) */
#scanlines {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.012) 0px,
    rgba(255,255,255,0.012) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: screen;
  opacity: 0.7;
}

/* ---------- Panel base ---------- */
.panel {
  position: fixed;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  z-index: 11;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-dim);
  font-weight: 500;
}
.panel-head .dot { width: 6px; height: 6px; background: var(--cyan); display: inline-block; margin-right: 8px; box-shadow: 0 0 6px var(--cyan); }
.panel-head .ctl { display: flex; gap: 4px; }
.panel-head .ctl button {
  background: transparent; border: 1px solid var(--line); color: var(--ink-dim);
  font-family: var(--mono); font-size: 10px; padding: 1px 6px; cursor: pointer; line-height: 1.4;
}
.panel-head .ctl button:hover { color: var(--cyan); border-color: var(--cyan-dim); }
.panel-body { padding: 8px 10px; }

/* Left panel: body selector */
#left-panel {
  top: 46px; left: 12px; width: 244px;
  max-height: calc(100vh - 160px);
  display: flex; flex-direction: column;
}
#left-panel .panel-body { overflow-y: auto; flex: 1; padding: 0; }
#left-panel .group {
  padding: 6px 10px 4px;
  border-bottom: 1px solid var(--line);
}
#left-panel .group-hd {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 9px; letter-spacing: 0.2em; color: var(--ink-mute);
  margin-bottom: 4px; text-transform: uppercase;
}
#left-panel .group-hd .count { color: var(--ink-mute); font-size: 9px; }
#left-panel .row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 4px;
  cursor: pointer;
  border-left: 2px solid transparent;
  margin-left: -2px;
  color: var(--ink);
  font-size: 11px;
}
#left-panel .row:hover { background: rgba(124,241,255,0.05); color: var(--cyan); }
#left-panel .row.active { border-left-color: var(--cyan); background: rgba(124,241,255,0.08); color: var(--cyan); }
#left-panel .row .bullet { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
#left-panel .row .id { flex: 1; font-family: var(--mono); letter-spacing: 0.02em; }
#left-panel .row .tag { font-size: 9px; color: var(--ink-mute); letter-spacing: 0.1em; }

#left-panel .toggles { padding: 8px 10px; border-top: 1px solid var(--line); }
#left-panel .toggle {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 0; cursor: pointer; font-size: 11px;
  color: var(--ink-dim);
}
#left-panel .toggle:hover { color: var(--ink); }
#left-panel .toggle .sw {
  width: 24px; height: 12px; border: 1px solid var(--line-strong); position: relative;
}
#left-panel .toggle .sw::after {
  content: ''; position: absolute; top: 1px; left: 1px;
  width: 8px; height: 8px; background: var(--ink-mute); transition: left 0.15s, background 0.15s;
}
#left-panel .toggle.on .sw::after { left: 13px; background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
#left-panel .toggle.on { color: var(--cyan); }

/* Right panel: telemetry */
#right-panel {
  top: 46px; right: 12px; width: 290px;
  max-height: calc(100vh - 160px);
  display: flex; flex-direction: column;
}
#right-panel .panel-body { padding: 0; overflow-y: auto; }
#right-panel .hero {
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--line);
}
#right-panel .hero .name {
  font-family: var(--mono); font-size: 16px; letter-spacing: 0.1em;
  color: var(--ink); font-weight: 500;
}
#right-panel .hero .designation {
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em;
  color: var(--ink-mute); text-transform: uppercase; margin-top: 2px;
}
#right-panel .hero .class-tag {
  display: inline-block; margin-top: 8px;
  padding: 1px 6px;
  border: 1px solid currentColor;
  font-size: 9px; letter-spacing: 0.2em; text-transform: uppercase;
}

#right-panel .tel {
  display: grid; grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
#right-panel .tel .k {
  font-size: 9px; letter-spacing: 0.15em; text-transform: uppercase;
  color: var(--ink-mute); align-self: center;
}
#right-panel .tel .v {
  font-family: var(--mono); font-size: 11px; color: var(--ink);
  text-align: right; letter-spacing: 0.02em;
}
#right-panel .tel .v.amber { color: var(--amber); }
#right-panel .tel .v.cyan { color: var(--cyan); }

#right-panel .section-hd {
  font-size: 9px; letter-spacing: 0.22em; color: var(--ink-mute);
  text-transform: uppercase; padding: 8px 12px 2px;
  display: flex; justify-content: space-between;
}
#right-panel .bar {
  height: 4px; background: rgba(124,241,255,0.1);
  position: relative; margin: 6px 12px 10px;
}
#right-panel .bar .fill { position: absolute; top: 0; left: 0; bottom: 0; background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
#right-panel .bar .tick { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--amber); }

/* Bottom time bar */
#timebar {
  position: fixed; left: 12px; right: 12px; bottom: 12px;
  height: 64px;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  z-index: 12;
  display: flex; align-items: stretch;
  font-family: var(--mono);
  color: var(--ink);
}
#timebar .tb-block {
  padding: 8px 14px;
  display: flex; flex-direction: column; justify-content: center;
  border-right: 1px solid var(--line);
  min-width: 0;
}
#timebar .tb-block .k { font-size: 9px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-mute); margin-bottom: 3px; }
#timebar .tb-block .v { font-size: 13px; letter-spacing: 0.06em; color: var(--ink); }
#timebar .tb-block .v.cyan { color: var(--cyan); }
#timebar .tb-block .v.amber { color: var(--amber); }

#timebar .tb-scrubber {
  flex: 1; position: relative;
  padding: 0 16px;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
#timebar .tb-scrubber .ticks {
  position: relative; height: 10px;
  border-bottom: 1px solid var(--line);
}
#timebar .tb-scrubber .ticks .t {
  position: absolute; bottom: 0; width: 1px; background: var(--line-strong);
}
#timebar .tb-scrubber .ticks .t.maj { background: var(--ink-dim); height: 6px; }
#timebar .tb-scrubber .ticks .t.min { height: 3px; }
#timebar .tb-scrubber .ticks .tl {
  position: absolute; bottom: 10px; font-size: 9px; color: var(--ink-mute); transform: translateX(-50%); white-space: nowrap;
}
#timebar .tb-scrubber .track {
  height: 18px; position: relative;
  background: rgba(124,241,255,0.05);
  border: 1px solid var(--line);
  cursor: pointer;
}
#timebar .tb-scrubber .track .now {
  position: absolute; top: 0; bottom: 0; width: 1px; background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
}
#timebar .tb-scrubber .track .cur {
  position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}
#timebar .tb-controls {
  display: flex; align-items: center; gap: 2px;
  padding: 0 10px;
  border-left: 1px solid var(--line);
}
#timebar .tb-controls button {
  width: 32px; height: 32px;
  background: transparent; border: 1px solid var(--line);
  color: var(--ink); font-family: var(--mono); font-size: 12px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#timebar .tb-controls button:hover { border-color: var(--cyan-dim); color: var(--cyan); }
#timebar .tb-controls button.play { color: var(--amber); border-color: var(--amber-dim); width: 40px; }
#timebar .tb-controls button.play.playing { color: var(--cyan); border-color: var(--cyan-dim); }
#timebar .tb-controls .speed {
  padding: 0 8px; font-size: 10px; letter-spacing: 0.12em; color: var(--ink-dim);
  min-width: 92px; text-align: center; text-transform: uppercase;
}
#timebar .tb-controls .speed-wrap { display: flex; flex-direction: column; align-items: center; }
#timebar .tb-controls .speed-wrap .lbl { font-size: 8px; letter-spacing: 0.18em; color: var(--ink-mute); }
#timebar .tb-controls .speed-wrap .val { color: var(--cyan); font-size: 11px; letter-spacing: 0.08em; margin-top: 1px; }

/* Camera preset bar (top-right cluster, below right panel header area) */
#cam-presets {
  position: fixed; top: 46px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 0; z-index: 11;
  background: var(--bg-panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
#cam-presets button {
  background: transparent; border: none;
  border-right: 1px solid var(--line);
  color: var(--ink-dim); font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.18em; text-transform: uppercase;
  padding: 6px 12px; cursor: pointer;
}
#cam-presets button:last-child { border-right: none; }
#cam-presets button:hover { color: var(--cyan); }
#cam-presets button.active { color: var(--cyan); background: rgba(124,241,255,0.06); }

/* Labels layer (DOM labels positioned by JS) */
#labels { position: fixed; inset: 0; z-index: 3; pointer-events: none; }
.label {
  position: absolute;
  font-family: var(--mono); font-size: 10px;
  color: var(--ink); letter-spacing: 0.1em;
  white-space: nowrap; transform: translate(6px, -50%);
  text-shadow: 0 0 4px rgba(0,0,0,0.9);
}
.label.planet { color: var(--ink); }
.label .tick {
  display: inline-block;
  width: 5px; height: 5px;
  border: 1px solid currentColor;
  margin-right: 5px;
  vertical-align: middle;
}
.label.selected { color: var(--amber); }
.label.selected .tick { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.label.dim { opacity: 0.45; }

/* Selection marker ring around focused body */
.selector-ring {
  position: absolute;
  border: 1px solid var(--amber);
  pointer-events: none;
}
.selector-ring::before, .selector-ring::after {
  content: '';
  position: absolute;
  width: 6px; height: 6px;
  border: 1px solid var(--amber);
}
.selector-ring::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.selector-ring::after { bottom: -1px; right: -1px; border-left: none; border-top: none; }

/* Tweaks panel */
#tweaks {
  position: fixed; bottom: 88px; right: 12px; width: 260px;
  z-index: 13;
  display: none;
}
#tweaks.on { display: block; }
#tweaks .panel-body { padding: 8px 12px; }
#tweaks .tweak { margin-bottom: 10px; }
#tweaks .tweak .lbl {
  display: flex; justify-content: space-between;
  font-size: 9px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--ink-mute); margin-bottom: 4px;
}
#tweaks .tweak .lbl .val { color: var(--cyan); }
#tweaks input[type=range] {
  width: 100%; -webkit-appearance: none; appearance: none;
  height: 4px; background: rgba(124,241,255,0.15); outline: none;
}
#tweaks input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; background: var(--cyan); cursor: pointer;
  box-shadow: 0 0 6px var(--cyan);
}
#tweaks input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px; background: var(--cyan); cursor: pointer; border: none;
  box-shadow: 0 0 6px var(--cyan);
}
#tweaks .seg { display: flex; gap: 0; }
#tweaks .seg button {
  flex: 1; background: transparent; border: 1px solid var(--line);
  color: var(--ink-dim); font-family: var(--mono); font-size: 10px;
  padding: 3px 6px; cursor: pointer; margin-left: -1px;
}
#tweaks .seg button:first-child { margin-left: 0; }
#tweaks .seg button.on { color: var(--cyan); border-color: var(--cyan-dim); background: rgba(124,241,255,0.06); }

/* Custom body modal */
#custom-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 100; display: none; align-items: center; justify-content: center;
}
#custom-modal.on { display: flex; }
#custom-modal .card {
  width: 460px; max-width: 92vw;
  background: var(--bg-panel-solid); border: 1px solid var(--line-strong);
  color: var(--ink); font-family: var(--mono);
}
#custom-modal .card .hd {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-size: 11px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--cyan);
}
#custom-modal .card .hd button {
  background: transparent; border: 1px solid var(--line); color: var(--ink-dim);
  font-family: var(--mono); font-size: 10px; padding: 2px 8px; cursor: pointer;
}
#custom-modal .bd { padding: 12px 14px; }
#custom-modal .bd .fld { margin-bottom: 8px; }
#custom-modal .bd .fld label {
  display: block; font-size: 9px; letter-spacing: 0.16em; color: var(--ink-mute);
  text-transform: uppercase; margin-bottom: 3px;
}
#custom-modal .bd .fld input, #custom-modal .bd .fld textarea {
  width: 100%; background: #000; border: 1px solid var(--line);
  color: var(--ink); font-family: var(--mono); font-size: 11px;
  padding: 5px 8px;
}
#custom-modal .bd .fld textarea { resize: vertical; min-height: 60px; }
#custom-modal .bd .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#custom-modal .bd .grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
#custom-modal .bd .hint { font-size: 10px; color: var(--ink-mute); margin: 6px 0; line-height: 1.5; }
#custom-modal .ft {
  padding: 10px 14px; border-top: 1px solid var(--line);
  display: flex; justify-content: flex-end; gap: 8px;
}
#custom-modal .ft button {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  font-family: var(--mono); font-size: 11px; padding: 5px 14px; cursor: pointer;
  letter-spacing: 0.12em; text-transform: uppercase;
}
#custom-modal .ft button.primary { color: var(--cyan); border-color: var(--cyan-dim); }

/* Loading overlay */
#loading {
  position: fixed; inset: 0; background: #000;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; flex-direction: column; gap: 16px;
  font-family: var(--mono);
}
#loading .logo { color: var(--cyan); font-size: 14px; letter-spacing: 0.35em; }
#loading .msg { color: var(--ink-dim); font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; }
#loading .bar { width: 240px; height: 2px; background: rgba(124,241,255,0.15); position: relative; overflow: hidden; }
#loading .bar::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 40%;
  background: var(--cyan);
  animation: loadslide 1.2s infinite ease-in-out;
  box-shadow: 0 0 8px var(--cyan);
}
@keyframes loadslide {
  0% { left: -40%; } 100% { left: 100%; }
}
#loading.done { display: none; }

/* FABs (mobile) */
#fabs { position: fixed; bottom: 84px; right: 12px; z-index: 14; display: none; flex-direction: column; gap: 8px; }
#fabs button {
  width: 42px; height: 42px;
  background: var(--bg-panel); border: 1px solid var(--line);
  color: var(--ink); font-family: var(--mono); font-size: 10px;
  cursor: pointer; letter-spacing: 0.1em;
}
#fabs button:hover, #fabs button.on { border-color: var(--cyan-dim); color: var(--cyan); }

/* Mobile layout */
body.mobile #left-panel, body.mobile #right-panel {
  position: fixed; top: 42px; left: 0; right: 0; width: auto;
  max-height: 55vh; border-left: none; border-right: none;
  transform: translateY(-110%);
  transition: transform 0.25s ease;
}
body.mobile #left-panel.open, body.mobile #right-panel.open { transform: translateY(0); }
body.mobile #fabs { display: flex; }
body.mobile #cam-presets { top: 38px; font-size: 9px; }
body.mobile #cam-presets button { padding: 5px 8px; font-size: 9px; }
body.mobile #timebar { height: 72px; }
body.mobile #timebar .tb-controls button { width: 38px; height: 38px; }
body.mobile #topband { padding: 0 36px; font-size: 10px; gap: 10px; }
body.mobile .crosshair { width: 14px; height: 14px; }

/* Utility */
.kbd {
  display: inline-block;
  padding: 0 4px;
  border: 1px solid var(--line);
  font-family: var(--mono); font-size: 9px; color: var(--ink-dim);
  margin: 0 2px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); }

/* Class color helpers */
.c-terr { color: var(--green) !important; }
.c-gas  { color: var(--gold) !important; }
.c-ice  { color: var(--ice) !important; }
.c-dwarf { color: var(--magenta) !important; }
.c-ast  { color: var(--white-class) !important; }
.c-moon { color: #cfe3ee !important; }
.c-sun  { color: var(--amber) !important; }
.c-comet { color: var(--comet) !important; }
.bg-terr { background: var(--green); }
.bg-gas  { background: var(--gold); }
.bg-ice  { background: var(--ice); }
.bg-dwarf { background: var(--magenta); }
.bg-ast  { background: var(--white-class); }
.bg-moon { background: #8fa9b8; }
.bg-sun  { background: var(--amber); }
.bg-comet { background: var(--comet); }
