:root {
  --bg: #05070d;
  --bg2: #080b14;
  --panel: #0b101d;
  --panel2: #0f1526;
  --line: #1a2238;
  --line2: #263152;
  --text: #dbe3f6;
  --muted: #7d89a8;
  --dim: #4b5675;
  --accent: #5ee6ff;
  --accent-ink: #022a33;
  --violet: #b48cff;
  --amber: #ffb547;
  --neg: #ff8a3d;
  --good: #7cf0a8;
  --radius: 10px;
  --mono: "JetBrains Mono", "Cascadia Code", "SF Mono", ui-monospace, Consolas, monospace;
  --sans: "Inter", "Segoe UI", system-ui, -apple-system, Ubuntu, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #0c1630 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--sans);
  display: flex; flex-direction: column;
  overflow: hidden;
  user-select: none;
}
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
a { color: var(--accent); }

/* ------------------------------------------------------------ top bar */
.topbar {
  height: 52px; flex: none;
  display: flex; align-items: center; gap: 24px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 7, 13, 0.7);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); min-width: 190px; }
.mark { width: 28px; height: 28px; }
.mark.big { width: 56px; height: 56px; color: var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b { color: var(--text); letter-spacing: 0.28em; font-size: 12px; }
.brand-text span { color: var(--accent); letter-spacing: 0.52em; font-size: 10px; font-weight: 600; }
.tabs { display: flex; gap: 4px; background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 16px; border-radius: 999px; font: 500 13px var(--sans); cursor: pointer;
  display: flex; align-items: center; gap: 8px;
}
.tab .k { font: 10px var(--mono); color: var(--dim); border: 1px solid var(--line2); border-radius: 4px; padding: 0 4px; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--panel2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
.tab.active .k { color: var(--accent); border-color: rgba(94, 230, 255, 0.4); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.status { color: var(--muted); }

/* ------------------------------------------------------------ layout */
main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: flex; }
.side {
  width: 292px; flex: none; overflow-y: auto;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11, 16, 29, 0.85), rgba(8, 11, 20, 0.85));
  padding: 6px 0 24px;
}
.side::-webkit-scrollbar, .regions::-webkit-scrollbar { width: 8px; }
.side::-webkit-scrollbar-thumb, .regions::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 4px; }
.group { padding: 12px 16px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0; font: 600 10px var(--sans); letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }
.hint { margin: 0; color: var(--muted); font-size: 12px; }
.hint.strong { color: var(--text); font-weight: 600; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stage { flex: 1; min-width: 0; padding: 12px; gap: 12px; display: grid; }

/* ------------------------------------------------------------ controls */
button {
  font: 500 12px var(--sans); color: var(--text);
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 7px;
  padding: 6px 11px; cursor: pointer;
}
button:hover { border-color: #3a4870; background: #131b30; }
button:active { transform: translateY(1px); }
button.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.accent:hover { background: #8aefff; }
button.ghost { background: transparent; }
button.small { padding: 3px 8px; font-size: 11px; }
button.icon { width: 30px; height: 26px; padding: 0; display: grid; place-items: center; font-size: 12px; }
button.icon.on { color: var(--accent); border-color: rgba(94, 230, 255, 0.5); }
button:disabled { opacity: 0.4; cursor: default; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { color: var(--muted); font-size: 11px; }
select {
  font: 12px var(--sans); color: var(--text); background: var(--panel2);
  border: 1px solid var(--line2); border-radius: 7px; padding: 6px 8px; width: 100%;
}
.slider { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
.slider label { color: var(--muted); font-size: 11px; }
.slider output { font: 11px var(--mono); color: var(--text); }
.slider input { grid-column: 1 / -1; width: 100%; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 18px; background: transparent; margin: 0; }
input[type=range]::-webkit-slider-runnable-track { height: 3px; background: linear-gradient(90deg, var(--accent) var(--p, 0%), var(--line2) var(--p, 0%)); border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%; margin-top: -5px; background: var(--text); border: 2px solid var(--accent); }
.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); font-size: 12px; }
.toggle.inline { display: inline-flex; }
.toggle input { -webkit-appearance: none; appearance: none; width: 28px; height: 16px; border-radius: 999px; background: var(--line2); position: relative; cursor: pointer; margin: 0; flex: none; transition: background 0.15s; }
.toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); transition: transform 0.15s, background 0.15s; }
.toggle input:checked { background: rgba(94, 230, 255, 0.35); }
.toggle input:checked::after { transform: translateX(12px); background: var(--accent); }

/* ------------------------------------------------------------ cards */
.card {
  background: linear-gradient(180deg, rgba(15, 21, 38, 0.9), rgba(11, 16, 29, 0.9));
  border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden;
}
.card > header {
  height: 38px; flex: none; display: flex; align-items: center; gap: 10px;
  padding: 0 10px 0 14px; border-bottom: 1px solid var(--line);
  font-weight: 600; font-size: 12px;
}
.card > header .muted { font-weight: 400; font-size: 11px; }
.canvas-wrap { position: relative; flex: 1; min-height: 0; }
.canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.canvas-wrap.square { flex: none; aspect-ratio: 1 / 1; }
.canvas-wrap.short { flex: 1; min-height: 90px; }

.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.tiles.compact { grid-template-columns: repeat(3, 1fr); gap: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; display: flex; flex-direction: column; gap: 2px;
}
.tiles.compact .tile { border: 0; border-radius: 0; background: transparent; padding: 8px 12px; }
.tiles.compact .tile + .tile { border-left: 1px solid var(--line); }
.tile span { color: var(--muted); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; }
.tile b { font: 600 18px var(--mono); color: var(--text); white-space: nowrap; }
.tiles.compact .tile b { font-size: 15px; }

/* ------------------------------------------------------------ lab */
.lab-grid {
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1.25fr) minmax(0, 0.8fr) minmax(0, 0.8fr) auto;
  grid-template-areas: "graph raster" "graph rate" "graph trace" "stats stats";
}
.lab-graph { grid-area: graph; }
.lab-raster { grid-area: raster; }
.lab-rate { grid-area: rate; }
.lab-trace { grid-area: trace; }
.lab-stats { grid-area: stats; }
#lab-graph.edit { cursor: crosshair; }

/* ------------------------------------------------------------ deep */
.deep-grid { grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); }
.deep-out .canvas-wrap.square { margin: 0; }
.epoch { color: var(--accent); }
.datasets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.dataset { padding: 0; border-radius: 8px; overflow: hidden; aspect-ratio: 1; position: relative; border: 1px solid var(--line2); background: var(--bg2); }
.dataset canvas { width: 100%; height: 100%; display: block; }
.dataset span { position: absolute; left: 0; right: 0; bottom: 0; font-size: 9px; letter-spacing: 0.06em; background: rgba(5, 7, 13, 0.75); color: var(--muted); padding: 1px 0; text-align: center; }
.dataset.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dataset.active span { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 999px; padding: 4px 10px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.chip.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.layers { display: flex; flex-direction: column; gap: 6px; }
.layer-row { display: flex; align-items: center; gap: 8px; }
.layer-row .name { color: var(--muted); font-size: 11px; width: 54px; }
.layer-row .count { font: 600 13px var(--mono); width: 26px; text-align: center; }
.layer-row .dots { flex: 1; display: flex; gap: 3px; flex-wrap: wrap; }
.layer-row .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0.7; }

/* ------------------------------------------------------------ connectome */
.conn-grid { grid-template-rows: minmax(0, 1fr) 190px; }
.three-wrap { background: #05070d; }
.label-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.label-layer div {
  position: absolute; transform: translate(-50%, -50%);
  font: 600 10px var(--sans); letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap;
  padding: 2px 6px; border-radius: 4px; background: rgba(5, 7, 13, 0.55); border: 1px solid rgba(255, 255, 255, 0.06);
}
.sel-panel {
  position: absolute; top: 12px; right: 12px; width: 250px;
  background: rgba(8, 11, 20, 0.92); border: 1px solid var(--line2); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; font-size: 12px;
}
.sel-panel h4 { margin: 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.sel-panel .kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.sel-panel .kv span:nth-child(odd) { color: var(--muted); }
.sel-panel .kv span:nth-child(even) { font-family: var(--mono); text-align: right; }
.sel-panel .partners { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.sel-panel .partners div { display: flex; gap: 8px; align-items: center; }
.sel-panel .partners b { font: 11px var(--mono); margin-left: auto; color: var(--muted); }
.swatch { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.hidden { display: none !important; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 7, 13, 0.6); color: var(--accent); font: 600 12px var(--mono); letter-spacing: 0.2em; }
.stim-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stim-grid button { text-align: left; display: flex; align-items: center; gap: 7px; white-space: nowrap; overflow: hidden; font-size: 11.5px; padding: 6px 8px; }
.regions { display: flex; flex-direction: column; gap: 2px; max-height: 360px; overflow-y: auto; }
.region-row { display: grid; grid-template-columns: auto auto 1fr 54px; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.region-row:hover { background: var(--panel2); }
.region-row input { margin: 0; accent-color: var(--accent); }
.region-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.region-row .bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.region-row .bar i { display: block; height: 100%; width: 0; border-radius: 2px; }
.report { font: 11px/1.5 var(--mono); color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.report:empty { display: none; }

/* ------------------------------------------------------------ brain console */
.field input:not([type=range]):not([type=checkbox]), .field textarea {
  width: 100%; min-width: 0; font: 12px var(--sans); color: var(--text);
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 7px; padding: 7px 8px;
  user-select: text;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus-visible, .field textarea:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.import-options { display: flex; flex-direction: column; font-size: 12px; }
.import-options > summary { color: var(--accent); cursor: pointer; }
.import-options > .field, .import-options > .hint { margin-top: 9px; }
.import-options #conn-edge-options > .field, .import-options #conn-matrix-options > .field { margin-top: 9px; }
.brain-grid {
  grid-template-columns: minmax(340px, 1fr) minmax(320px, 1fr);
  grid-template-rows: minmax(280px, .9fr) minmax(310px, 1fr);
  grid-template-areas: "recording measurements" "conversation results";
  overflow: auto;
}
.brain-recording { grid-area: recording; }
.brain-measurements { grid-area: measurements; }
.brain-conversation { grid-area: conversation; }
.brain-results { grid-area: results; }
.brain-transcript { flex: 1; min-height: 100px; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; user-select: text; }
.brain-message { max-width: 94%; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; align-self: flex-start; background: var(--bg2); }
.brain-message.user { align-self: flex-end; background: #101e2c; border-color: #24465a; }
.brain-message.error { border-color: #733448; }
.brain-message-label { display: block; margin-bottom: 5px; color: var(--muted); font: 600 10px var(--sans); letter-spacing: .1em; text-transform: uppercase; }
.brain-message-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.65; }
.brain-examples { border-top: 1px solid var(--line); padding: 10px 12px 0; display: flex; gap: 5px; flex-wrap: wrap; }
.brain-compose { padding: 10px 12px 12px; display: flex; gap: 8px; align-items: flex-end; }
.brain-compose > .field { flex: 1; min-width: 0; }
.brain-compose > button { min-height: 32px; }
.brain-tiles .tile b { font-size: 14px; }
.brain-table-wrap { flex: 1; min-height: 0; overflow: auto; user-select: text; }
.brain-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.brain-table th { background: var(--panel); position: sticky; top: 0; color: var(--muted); font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.brain-table th, .brain-table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: right; }
.brain-table th:first-child, .brain-table td:first-child { text-align: left; }
.brain-table td:not(:first-child) { font-family: var(--mono); font-size: 11px; }
.brain-readout-note { padding: 12px; border-top: 1px solid var(--line); }
.brain-number-fields { align-items: flex-start; flex-wrap: nowrap; }
.brain-number-fields > .field { flex: 1; min-width: 0; }
.brain-phase-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.brain-phase-fields .field > span { font-size: 10px; white-space: nowrap; }
.brain-details > summary { cursor: pointer; color: var(--accent); font-size: 12px; }
.brain-details > :not(summary) { margin-top: 10px; }
.brain-details > button { width: 100%; }
.brain-details .toggle { flex-wrap: wrap; }
#brain-progress { height: 5px; width: 100%; border: 0; border-radius: 4px; accent-color: var(--accent); }
#brain-progress::-webkit-progress-bar { background: var(--line); border-radius: 4px; }
#brain-progress::-webkit-progress-value { background: var(--accent); border-radius: 4px; }
#brain-progress-label { font-size: 11px; }
.brain-plot-heading { display: flex; flex: none; justify-content: space-between; gap: 10px; padding: 9px 12px 0; color: var(--muted); font-size: 10px; }
.brain-plot-heading > :last-child { text-align: right; font-family: var(--mono); }
.brain-rate-plot { min-height: 95px; }
.brain-raster-plot { min-height: 95px; border-top: 1px solid var(--line); }
.brain-result-note { padding: 12px; font-size: 11px; }
.brain-result-footnote { padding: 10px 12px; font-size: 10px; border-top: 1px solid var(--line); }
.brain-aggregate-wrap { flex: 1; min-height: 90px; }
.brain-trials { flex: none; border-top: 1px solid var(--line); }
.brain-trials > summary { padding: 8px 12px; cursor: pointer; color: var(--accent); font-size: 11px; }
.brain-trials > .brain-table-wrap { max-height: 170px; }
.brain-trials .brain-table th, .brain-trials .brain-table td { padding: 7px 8px; }
.remote-config { display: flex; flex-direction: column; gap: 9px; }
#brain-model-limitations { color: var(--amber); font-size: 11px; }
@media (max-width: 1180px) {
  .topbar { gap: 10px; }
  .brand { min-width: 150px; }
  .tab { padding: 6px 10px; gap: 5px; }
  .topbar-right { gap: 5px; }
  .topbar-right .status { display: none; }
  .brain-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: 310px 290px 350px 340px; grid-template-areas: "recording" "results" "conversation" "measurements"; }
}
@media (max-width: 740px) {
  #view-brain.active { flex-direction: column; overflow-y: auto; }
  #view-brain .side { width: 100%; flex: none; max-height: 330px; border-right: 0; border-bottom: 1px solid var(--line); }
  #view-brain .brain-grid { flex: none; overflow: visible; }
}

/* ------------------------------------------------------------ misc */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line2); border-radius: 14px; padding: 0; width: 420px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(3px); }
.about { padding: 28px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; }
.about h2 { margin: 6px 0 0; letter-spacing: 0.04em; }
.about p { margin: 4px 0; }
.about form { margin-top: 12px; }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--panel2); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 14px;
  transition: opacity 0.2s, transform 0.2s; pointer-events: none; z-index: 10; max-width: 70vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: #ff4d6d; color: #ffc2cc; }

/* ------------------------------------------------------------ editions */
.edition {
  font: 600 10px var(--mono); letter-spacing: 0.16em; text-transform: uppercase;
  padding: 5px 10px; border-radius: 999px; background: transparent; color: var(--muted); border-color: var(--line2);
}
.edition[data-tier="pro"] { color: var(--accent); border-color: rgba(94, 230, 255, 0.5); }
.edition[data-tier="premium"] { color: var(--violet); border-color: rgba(180, 140, 255, 0.55); }
.lock {
  font: 600 8.5px var(--mono); letter-spacing: 0.12em; color: var(--accent-ink); background: var(--accent);
  border-radius: 4px; padding: 1px 4px; margin-left: 6px; vertical-align: middle;
}
.locked .lock { display: inline-block; }
.locked { opacity: 0.85; }
.license { padding: 24px 26px; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.license h2 { margin: 0; font-size: 17px; }
.license p { margin: 0; }
.license textarea {
  font: 12px var(--mono); color: var(--text); background: var(--bg2); border: 1px solid var(--line2);
  border-radius: 8px; padding: 8px; width: 100%; resize: vertical; user-select: text;
}
.license .updates { border-top: 1px solid var(--line); padding-top: 10px; }
.license .end { justify-content: flex-end; }
#license-dialog, #upgrade-dialog { width: 480px; }
