/* ── Array Studio — themes ────────────────────────────────────────── */
/* Default: "Deep Space" dark dashboard. Alternates override the vars. */
:root {
  --bg: #0b0e14;
  --bg2: #11151f;
  --panel: #151a26;
  --panel2: #1a2030;
  --line: #232b3d;
  --text: #dbe2f0;
  --muted: #7c8699;
  --accent: #34d0ff;
  --accent2: #8a7bff;
  --good: #3ddc97;
  --warn: #ffb454;
  --topbar: rgba(17,21,31,.85);
  --accent-soft: rgba(52,208,255,.15);
  --glow: rgba(52,208,255,.5);
  --grad1: rgba(138,123,255,.10);
  --grad2: rgba(52,208,255,.08);
  --modal-dim: rgba(5,8,14,.6);
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

/* "Phosphor Scope" — radar CRT: near-black, phosphor green, amber warns */
body[data-theme="phosphor"] {
  --bg: #040705;
  --bg2: #081009;
  --panel: #0b150d;
  --panel2: #101d12;
  --line: #1b3320;
  --text: #cfe9cf;
  --muted: #6f8f72;
  --accent: #3aff6e;
  --accent2: #27c9a8;
  --good: #3aff6e;
  --warn: #ffd24d;
  --topbar: rgba(8,16,9,.88);
  --accent-soft: rgba(58,255,110,.13);
  --glow: rgba(58,255,110,.45);
  --grad1: rgba(58,255,110,.06);
  --grad2: rgba(39,201,168,.05);
  --modal-dim: rgba(2,6,3,.65);
}

/* "Daylight Lab" — light, print-friendly, blue ink */
body[data-theme="light"] {
  --bg: #f3f5f9;
  --bg2: #e9edf4;
  --panel: #ffffff;
  --panel2: #f0f3f8;
  --line: #d4dae6;
  --text: #1c2433;
  --muted: #5d6779;
  --accent: #0a6cff;
  --accent2: #7a3cff;
  --good: #0e9f6e;
  --warn: #c97a06;
  --topbar: rgba(255,255,255,.88);
  --accent-soft: rgba(10,108,255,.10);
  --glow: rgba(10,108,255,.35);
  --grad1: rgba(122,60,255,.06);
  --grad2: rgba(10,108,255,.05);
  --modal-dim: rgba(30,40,60,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, var(--grad1), transparent 60%),
    radial-gradient(900px 500px at -10% 0%, var(--grad2), transparent 55%),
    var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── top bar ──────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.brand { font-size: 17px; font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand em { font-style: normal; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand .logo { color: var(--accent); font-size: 20px; }
.brand .tag { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; }
.spacer { flex: 1; }
.status { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.status.busy { color: var(--warn); }

/* ── layout ───────────────────────────────────────────────────────── */
.app { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 290px; flex: none; overflow-y: auto;
  padding: 0 12px 40px;
  border-right: 1px solid var(--line);
  background: var(--bg2);
}
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 12px; gap: 10px; position: relative; }

/* ── sidebar mode stepper (pinned while the sidebar scrolls) ──────── */
/* A 1 › 2 › 3 pipeline: Design → Analyze → Radar, so the intended path
   through the app reads at a glance. */
.modes {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 2px;
  align-items: stretch;
  position: sticky; top: 0; z-index: 6;
  background: var(--bg2);
  padding: 12px 0 10px;
  margin-bottom: 2px;
  box-shadow: 0 6px 12px -8px rgba(0,0,0,.5);
}
.modes .mode {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 2px; border-radius: 11px; cursor: pointer;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line);
  transition: border-color .15s, color .15s, background .15s;
}
.modes .marrow { align-self: center; color: var(--muted); opacity: .55; font-size: 15px; }
.mode .mstep {
  font-size: 9px; font-weight: 700; font-family: var(--mono);
  width: 15px; height: 15px; line-height: 13px; text-align: center;
  border: 1px solid var(--line); border-radius: 999px; color: var(--muted);
}
.mode .mname { font-size: 12px; font-weight: 600; color: var(--text); }
.mode .msub { font-size: 9px; font-weight: 500; letter-spacing: .4px; color: var(--muted); }
.modes .mode:hover { border-color: var(--accent); }
.modes .mode.active { background: var(--accent-soft); border-color: var(--accent); }
.modes .mode.active .mname, .modes .mode.active .msub { color: var(--accent); }
.modes .mode.active .mstep { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* mode-dependent visibility (sections, panels, tab buttons, hints) */
.sec.hidden, .panel.hidden, .btn.hidden, .hint.hidden { display: none; }

/* ── sidebar controls ─────────────────────────────────────────────── */
.sec {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); margin-bottom: 10px; overflow: hidden;
  box-shadow: 0 6px 16px -14px rgba(0,0,0,.55);
}
.sec summary {
  cursor: pointer; list-style: none; user-select: none;
  padding: 10px 12px; font-weight: 600; font-size: 13px;
  color: var(--text); letter-spacing: .3px;
  border-bottom: 1px solid transparent;
}
.sec[open] summary { border-bottom-color: var(--line); background: var(--panel2); }
.sec summary::-webkit-details-marker { display: none; }
.sec summary::before { content: "▸ "; color: var(--accent); font-size: 11px; }
.sec[open] summary::before { content: "▾ "; }

.ctl { padding: 8px 12px 2px; }
.ctl:last-child { padding-bottom: 10px; }
.ctl label { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.ctl output { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.ctl.hidden { display: none; }
.ctl.two { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; align-items: center; }
.ctl.two label { grid-column: 1 / -1; margin-bottom: 2px; }
.hint { padding: 4px 12px 10px; font-size: 11px; color: var(--muted); font-style: italic; }

.null-list { padding: 0 12px; display: flex; flex-direction: column; gap: 4px; }
.null-item {
  display: flex; align-items: center; justify-content: space-between;
  font-family: var(--mono); font-size: 11px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 7px;
  padding: 4px 8px;
}
.null-item b { color: #ff5a8a; font-weight: 600; }
.null-item button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 0 2px;
}
.null-item button:hover { color: #ff5a8a; }
.null-item.jam b { color: var(--warn); }
.null-item .depth { font-weight: 600; }
.null-item .depth.deep { color: var(--good); }
.null-item .depth.mid { color: var(--warn); }
.null-item .depth.shallow { color: #ff5a8a; }

/* ── help modal ───────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: var(--modal-dim); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(560px, 92vw);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px 20px;
  box-shadow: 0 18px 60px rgba(0,0,0,.55);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h3 { margin: 0; font-size: 15px; }
.help-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.help-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); color: var(--text); vertical-align: top; }
.help-table td:first-child { white-space: nowrap; color: var(--accent); width: 38%; }
.help-table tr:last-child td { border-bottom: none; }

input[type="number"], select {
  width: 100%; padding: 6px 8px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px;
  font-family: var(--mono); font-size: 12px;
  outline: none;
}
.ctl.two input[type="number"] { width: 72px; }
input[type="number"]:focus, select:focus { border-color: var(--accent); }
select { font-family: Inter, sans-serif; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  outline: none; margin: 8px 0 6px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent);
  cursor: pointer; box-shadow: 0 0 8px var(--glow);
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); cursor: pointer;
}

.chk { display: flex !important; gap: 7px; align-items: center !important; justify-content: flex-start !important; color: var(--text) !important; font-size: 12px; cursor: pointer; }
.chk input { accent-color: var(--accent); }
.chk.small { font-size: 11px; color: var(--muted) !important; }

.btn {
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); font-size: 12px; font-weight: 500;
  transition: border-color .15s, background .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.small { padding: 5px 9px; font-size: 11px; }
.btn.tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ── metrics strip ────────────────────────────────────────────────── */
.metrics { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: flex; flex-direction: column; gap: 1px;
  padding: 6px 14px; border-radius: 11px;
  background: var(--panel); border: 1px solid var(--line);
  min-width: 96px;
}
.chip .k { font-size: 10px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.chip .v { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--accent); }
/* secondary metrics fold behind a dashed toggle chip */
.metrics-more { display: contents; }
.metrics-more.hidden { display: none; }
.chip-toggle {
  justify-content: center; align-items: center; min-width: 64px; cursor: pointer;
  font: inherit; font-size: 11px; color: var(--muted);
  background: transparent; border: 1px dashed var(--line);
  transition: border-color .15s, color .15s;
}
.chip-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ── panel grid ───────────────────────────────────────────────────── */
.grid {
  flex: 1; min-height: 0;
  display: grid; gap: 10px;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.panel {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 10px 28px -20px rgba(0,0,0,.65);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--line); gap: 8px; flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 600; }
.panel-head .sub { font-size: 11px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.tools { display: flex; gap: 6px; align-items: center; }
.tools select { width: auto; padding: 5px 7px; }
.canvas-wrap { flex: 1; min-height: 0; position: relative; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
#three-container canvas { cursor: grab; }
.plot { flex: 1; min-height: 0; }

/* ── radar stats strip (chips grouped: antenna · detect · waveform · search) */
.radar-stats {
  display: flex; flex-wrap: wrap; gap: 5px 8px;
  padding: 7px 12px; border-bottom: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  min-height: 18px;
}
.radar-stats b { color: var(--accent); font-weight: 600; }
.radar-stats .warn b { color: var(--warn); }
.radar-stats .sg {
  display: inline-flex; gap: 10px; align-items: baseline;
  padding: 3px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg);
}
.radar-stats .sg i {
  font-style: normal; font-size: 9px; text-transform: uppercase;
  letter-spacing: .8px; color: var(--muted); opacity: .85;
}

/* ── progress bar ─────────────────────────────────────────────────── */
#progress {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: transparent; z-index: 10; pointer-events: none;
}
#progressBar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  box-shadow: 0 0 10px var(--glow);
  transition: width .15s linear; opacity: 0;
}
#progressBar.on { opacity: 1; }

/* ── responsive ───────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; grid-template-rows: repeat(4, minmax(340px, 1fr)); }
  body { overflow: auto; }
  .app { min-height: 0; }
  .content { overflow: visible; }
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }
