/* FLYBRAIN floor - DESIGN.md is binding: tokens §4, type §5, layout §2, components §6.
   Spacing uses only 4 8 12 16 24 32 48 64. Dark only (color-scheme: dark), no external fonts.
   No inline styles in the HTML (CSP style-src 'self'); the script sets only sizes/colours of
   data marks through the CSSOM. */

:root {
  color-scheme: dark;
  --ground: #06070a;
  --plate: #0b0d12;
  --plate-2: #10141b;
  --line: #1b212b;
  --line-2: #2a3340;
  --ink: #e2eaf1;
  --ink-dim: #a3b0bc;
  --ink-faint: #8793a0;
  --accent: #7deaff;
  --up: #6fdca6;
  --down: #ff8a8a;
  --amber: #f0bc5f;
  --s-trader: #22a3c4;
  --s-blind: #c7cdd4;
  --s-random: #d55181;
  --s-hold: #6a62e0;
  --zero: #2a3340;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --gutter: 16px;
  --gap: 16px;
  --pad: 16px;
  --radius: 6px;
  --desk-h: 360px;
}
@media (min-width: 768px) { :root { --gutter: 24px; } }
@media (min-width: 1050px) { :root { --desk-h: 440px; } }
@media (min-width: 1280px) { :root { --gutter: 32px; --gap: 24px; --pad: 24px; } }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink-dim);
  font: 15px/1.6 var(--sans);
  overflow-x: hidden;
}
p, h1, h2, h3, h4, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
b, strong { color: var(--ink); font-weight: 600; }
em { font-style: italic; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 16px; top: -64px; z-index: 10; padding: 8px 12px; background: var(--plate-2); color: var(--ink); border: 1px solid var(--accent); border-radius: 4px; }
.skip:focus { top: 16px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 var(--gutter); }

/* ------------------------------------------------------------------ type */
.label, .panel-title, .panel-status, th, .chip, dt, .lg-name, .seg button, .keyrow, .caption {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.label {
  font-size: 11px; line-height: 1.4; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint);
}
.val {
  font: 20px/1.3 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub {
  font: 12px/1.4 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.caption {
  font-size: 11px; line-height: 1.6; letter-spacing: .04em; color: var(--ink-faint); max-width: 72ch;
}
.up { color: var(--up); }
.down { color: var(--down); }
.amber { color: var(--amber); }
.dim { color: var(--ink-faint); }

/* ------------------------------------------------------------------ masthead */
.mast { border-bottom: 1px solid var(--line); }
.mast-in {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 16px; padding-top: 24px; padding-bottom: 24px;
}
.brand { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.wordmark {
  font: 400 28px/1.2 var(--serif); color: var(--ink); letter-spacing: .08em;
}
@media (min-width: 1050px) { .wordmark { font-size: 36px; } }
.tagline { color: var(--ink-dim); max-width: 72ch; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 22px; padding: 0 8px;
  border: 1px solid var(--line-2); border-radius: 4px;
  font-size: 11px; line-height: 1; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim);
  white-space: nowrap;
}
.chip-paper { color: var(--ink); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); flex: none; }
.chip-live[data-state="live"] .dot { background: var(--accent); }
.chip-live[data-state="live"] { color: var(--ink); }
.chip-live[data-state="stalled"] .dot,
.chip-live[data-state="connecting"] .dot,
.chip-live[data-state="reconnecting"] .dot { background: var(--amber); }
.chip-live[data-state="offline"] .dot { background: var(--down); }

/* ------------------------------------------------------------------ banner (explicit offline / stalled) */
.banner {
  margin-top: 16px; padding: 12px 16px; border: 1px solid var(--line-2); border-left: 4px solid var(--amber);
  border-radius: var(--radius); background: var(--plate);
}
.banner[data-kind="offline"] { border-left-color: var(--down); }
.banner-title { color: var(--ink); font-weight: 600; }
.banner-text { font-size: 13px; }

/* ------------------------------------------------------------------ grid */
.floor {
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap);
  padding-top: var(--gap); padding-bottom: 48px;
}
.floor > * { grid-column: 1 / -1; min-width: 0; }
@media (min-width: 1050px) {
  .floor > .span-8 { grid-column: span 8; }
  .floor > .span-4 { grid-column: span 4; }
  .floor > .span-6 { grid-column: span 6; }
}

/* ------------------------------------------------------------------ panel */
.panel {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--plate); border: 1px solid var(--line); border-radius: var(--radius);
}
.panel-h {
  flex: none; height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 var(--pad); background: var(--plate-2); border-bottom: 1px solid var(--line);
  border-radius: 5px 5px 0 0; min-width: 0;
}
.panel-title {
  font-size: 11px; line-height: 1.4; letter-spacing: .12em; text-transform: uppercase; font-weight: 600;
  color: var(--ink-faint); white-space: nowrap;
}
.panel-status {
  font-size: 11px; line-height: 1.4; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; text-align: right;
}
.panel-b { flex: 1 1 auto; display: flex; flex-direction: column; gap: 16px; padding: var(--pad); min-width: 0; min-height: 0; }

.stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

/* canvases: radius 0, never capture wheel, never trap focus */
.canvas-wrap { position: relative; width: 100%; background: var(--ground); }
.canvas-wrap canvas, .fill canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; }
.overlay {
  position: absolute; left: 12px; right: 12px; top: 12px; padding: 8px 12px; margin: 0;
  background: rgba(6, 7, 10, .9); border: 1px solid var(--line-2); border-radius: 4px;
  font: 12px/1.4 var(--mono); color: var(--ink);
}

/* ------------------------------------------------------------------ A. room */
/* The aspect is the room's (JS sets it from /state frame, and --room-ar to match). On a short
   screen the screen is capped so the whole room fits under the header; it then sits centred. */
.room-wrap {
  aspect-ratio: 948 / 922; margin: 0 auto;
  max-width: max(320px, calc((100vh - 200px) * var(--room-ar, 1.0282)));
}
.readouts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
@media (min-width: 768px) { .readouts { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.smellbar {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px;
  padding-top: 12px; border-top: 1px solid var(--line);
}
@media (min-width: 768px) { .smellbar { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.dbar { position: relative; height: 8px; background: var(--plate-2); border: 1px solid var(--line); }
.dbar-mid { position: absolute; left: 50%; top: -4px; bottom: -4px; width: 1px; background: var(--line-2); }
.dbar-fill { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; background: var(--zero); }
.keyrow { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 11px; letter-spacing: .04em; color: var(--ink-faint); }
.keyrow li { display: inline-flex; align-items: center; gap: 8px; }
.key { display: inline-block; flex: none; }
.key-look { width: 6px; height: 6px; border-radius: 50%; background: var(--s-trader); }
.key-eye { width: 16px; height: 12px; border: 1px solid var(--accent); }
.key-stop { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--amber); }
.key-commit { width: 8px; height: 8px; transform: rotate(45deg); background: var(--ink); border: 2px solid var(--amber); }

/* scoreboard: the trader screen drives the row; the stats share its height evenly */
.score-b { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 16px; }
.score-b > .stat { padding-top: 12px; border-top: 1px solid var(--line); justify-content: center; }
.score-b > .book-stat { grid-column: span 6; }
.score-b > .more-stat { grid-column: span 12; }
@media (min-width: 768px) {
  .score-b > .book-stat { grid-column: span 3; }
  .score-b > .more-stat { grid-column: span 4; }
}
@media (min-width: 1050px) {
  .score-b { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(7, minmax(0, 1fr)); gap: 0; }
  .score-b > .book-stat, .score-b > .more-stat { grid-column: 1; }
  .score-b > .stat { padding: 12px 0; }
  .score-b > .stat:first-child { border-top: 0; }
}
.sw { display: inline-block; width: 16px; height: 0; margin-right: 8px; vertical-align: middle; border-top: 2px solid; }
.sw-trader { border-top-color: var(--s-trader); }
.sw-blind { border-top: 2px dashed var(--s-blind); }
.sw-random { border-top-color: var(--s-random); }
.sw-hold { border-top-color: var(--s-hold); }

/* ------------------------------------------------------------------ B. scouts (3-up only if each cell >= 300px) */
.row-b { container-type: inline-size; display: flex; flex-direction: column; gap: 12px; }
.scouts { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
@container (min-width: 932px) {
  .scouts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.row-caption { max-width: none; }
.scout-map { aspect-ratio: 2 / 1; }
.duo { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.channels { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.ch { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ch .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar { position: relative; height: 8px; background: var(--plate-2); border: 1px solid var(--line); }
.hbar span { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--amber); }
.chv { font: 15px/1.3 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.ops { display: flex; flex-direction: column; gap: 4px; }
.ops-bars {
  position: relative; display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; height: 48px;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.ops-bars::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line-2); }
.ops-col { position: relative; }
.ops-col span { position: absolute; left: 16%; right: 16%; height: 0; top: 50%; background: var(--zero); }
.ops-col.cur { background: var(--plate-2); }
.ops-labels { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; height: 32px; }
.ops-labels span {
  display: flex; justify-content: center; width: 100%;
  font: 11px/16px var(--mono); color: var(--ink-faint); white-space: nowrap;
}
.ops-labels span:nth-child(even) { align-self: end; }
.ops-labels span.cur { color: var(--ink); }
.feed-wrap { display: flex; flex-direction: column; gap: 4px; }
.feed { display: flex; flex-direction: column; height: 120px; overflow: hidden; border-top: 1px solid var(--line); }
.feed li {
  display: grid; grid-template-columns: auto auto minmax(0, 1fr) auto; gap: 8px; align-items: baseline;
  height: 24px; line-height: 24px; border-bottom: 1px solid var(--line);
  font: 12px/24px var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-dim);
}
.feed li.empty { display: block; color: var(--ink-faint); }
.feed .t { color: var(--ink-faint); }
.feed .s { color: var(--ink); }
.feed .x { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ C. chart */
.legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
@media (min-width: 768px) { .legend { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.legend li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.lg-name { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }
.lg-val { font: 13px/1.4 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: auto; }
.ln { display: inline-block; width: 24px; height: 0; flex: none; border-top: 2px solid; }
.ln-trader { border-top: 2px solid var(--s-trader); }
.ln-blind { border-top: 2px dashed var(--s-blind); }
.ln-random { border-top: 2px solid var(--s-random); }
.ln-hold { border-top: 2px solid var(--s-hold); }
.chart-wrap { position: relative; height: 240px; background: var(--plate); }
@media (min-width: 768px) { .chart-wrap { height: 320px; } }
.chart-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; }
.tip {
  position: absolute; top: 8px; z-index: 2; min-width: 160px; padding: 8px 12px; pointer-events: none;
  background: rgba(6, 7, 10, .94); border: 1px solid var(--line-2); border-radius: 4px;
  font: 12px/1.6 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink);
}
.tip .tt { color: var(--ink-faint); }
.tip .tr { display: flex; justify-content: space-between; gap: 16px; }
.runnote { font-size: 13px; max-width: 72ch; }

/* ------------------------------------------------------------------ tables */
.tbl { width: 100%; border-collapse: collapse; font: 12px/1.4 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-dim); }
.tbl th {
  position: sticky; top: 0; z-index: 1; height: 32px; padding: 0 8px; text-align: left; white-space: nowrap;
  background: var(--plate-2); color: var(--ink-faint);
  font-size: 11px; font-weight: 400; letter-spacing: .12em; text-transform: uppercase;
  border-bottom: 1px solid var(--line);
}
.tbl td { height: 32px; padding: 0 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl tbody tr:hover { background: var(--plate-2); }
.tbl .num { text-align: right; }
.tbl .sym { color: var(--ink); }
.tbl tr.empty td { color: var(--ink-faint); white-space: normal; }
.tbl tr.empty:hover { background: transparent; }
/* a reason is never hidden behind an ellipsis: it wraps inside its row (DESIGN.md §6 tape row) */
.tbl .why { width: 38%; min-width: 120px; white-space: normal; line-height: 1.35; padding-top: 4px; padding-bottom: 4px; overflow-wrap: anywhere; }
.tape-tbl th, .tape-tbl td { padding: 0 6px; }
.tape-tbl th:first-child, .tape-tbl td:first-child { padding-left: 8px; }
.tape-tbl .why { padding: 4px 8px 4px 6px; }
.tbl .act-pass, .tbl .why-risk { color: var(--amber); }
.tbl .act-buy, .tbl .act-sell { color: var(--ink); }
.fly { display: inline-flex; align-items: center; gap: 8px; }
.fly i { display: inline-block; width: 12px; height: 0; border-top: 2px solid var(--line-2); }
.fly.trader i { border-top-color: var(--s-trader); }
.fly.blind i { border-top: 2px dashed var(--s-blind); }
.fly.random i { border-top-color: var(--s-random); }
.fly.hold i { border-top-color: var(--s-hold); }

/* ------------------------------------------------------------------ D. desk: equal height, internal scroll */
.desk-b { height: var(--desk-h); flex: none; }
.quad { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; flex: none; }
@media (min-width: 768px) { .quad { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tbl-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; border: 1px solid var(--line); overscroll-behavior: contain; }
.tbl-x { overflow-x: auto; }

/* ------------------------------------------------------------------ E. research matrix */
/* two equal columns from 1050 px; below that a column would be ~340 px and the brain map would be
   stretched to the height of the prose beside it, so the columns stack in order. */
.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
@media (min-width: 1050px) { .split { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.heat td.op { text-align: right; color: var(--ink); }
.heat td.op.dark { color: var(--ground); }
.heat td.op.scouting { text-decoration: underline; text-underline-offset: 4px; }
.heat tr.cur td { box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.heat tr.cur td:first-child { box-shadow: inset 1px 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.heat tr.cur td:last-child { box-shadow: inset -1px 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.heat .nm { color: var(--ink-faint); margin-left: 8px; }
.scale { display: flex; align-items: center; gap: 8px; font: 11px/1.4 var(--mono); color: var(--ink-faint); }
.scale-bar { flex: 1; height: 8px; background: linear-gradient(90deg, var(--down), var(--zero) 50%, var(--up)); }
.mb-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; flex: none; }
.lessons-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; }
.seg button {
  height: 24px; padding: 0 8px; border: 0; border-left: 1px solid var(--line-2); background: transparent; cursor: pointer;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint);
}
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--plate-2); color: var(--ink); }
.fill { position: relative; flex: 1 1 auto; min-height: 240px; }
.fill > .scroller { position: absolute; inset: 0; overflow: auto; border: 1px solid var(--line); overscroll-behavior: contain; }
.kind-sugar { color: var(--up); }
.kind-shock { color: var(--down); }

/* ------------------------------------------------------------------ F. connectome */
.split-2 { margin-top: 16px; padding-top: var(--pad); border-top: 1px solid var(--line); }
.prose h3, .live-map h3 { font: 400 20px/1.3 var(--serif); color: var(--ink); }
.prose h4, .live-map h4 { font: 400 11px/1.4 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--ink-faint); }
.prose p, .live-map p:not(.caption):not(.overlay) { max-width: 72ch; }
.plain { display: flex; flex-direction: column; gap: 12px; max-width: 72ch; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr); border-top: 1px solid var(--line); }
.kv > div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 4px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.kv dt { font-size: 12px; color: var(--ink-faint); min-width: 0; }
.kv dd { font: 13px/1.6 var(--mono); font-variant-numeric: tabular-nums; color: var(--ink); text-align: right; min-width: 0; }
.kv dd[data-fmt="str"] { font-size: 12px; overflow-wrap: anywhere; }
@media (min-width: 1050px) { .kv-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 16px; } }
.map-fill { min-height: 320px; background: var(--ground); }
.live-map .tbl-x { flex: none; }
.cx-mismatch { color: var(--amber); }

/* ------------------------------------------------------------------ footer */
.foot { border-top: 1px solid var(--line); }
.foot-in { display: flex; flex-direction: column; gap: 8px; padding-top: 24px; padding-bottom: 48px; font-size: 13px; }
.foot-in p { max-width: 72ch; }
.build { font: 11px/1.4 var(--mono); color: var(--ink-faint); letter-spacing: .04em; }
