/* Density is the product (brief §4). Everything is sized to fit one 1440p
   screen with no scrolling anywhere except the tape. Small type, tight rows,
   no decorative whitespace — a tidy sparse screen is a failed v1. */

:root {
  --bg: #07090c;
  --panel: #0d1117;
  --panel2: #11161f;
  --line: #1e2733;
  --txt: #c9d4e0;
  --dim: #5d6b7c;
  --dimmer: #3a4653;
  --up: #17c964;
  --down: #f31260;
  --warn: #f5a524;
  --accent: #4aa8ff;
  --be: #d6b74a;
  --stop: #f31260;
  --trail: #b565f5;
  --mono: 'SF Mono', 'Menlo', 'DejaVu Sans Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--mono);
  font-size: 12px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* The armed frame. Step 2 of the click path: "it is impossible not to notice." */
#arm-frame {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  border: 3px solid transparent;
  transition: none; /* a transition here would be a lie about latency */
}
body.armed #arm-frame {
  border-color: var(--up);
  box-shadow: inset 0 0 22px rgba(23, 201, 100, 0.45), inset 0 0 90px rgba(23, 201, 100, 0.12);
}
body.lockedout #arm-frame {
  border-color: #4a4a4a;
  box-shadow: inset 0 0 22px rgba(120, 120, 120, 0.35);
}

#cockpit {
  display: grid;
  height: 100vh;
  grid-template-columns: 1fr 268px;
  grid-template-rows: 26px 1fr 168px 74px;
  grid-template-areas:
    'hdr hdr'
    'chart rail'
    'tape rail'
    'foot rail';
  gap: 1px;
  background: var(--line);
}

/* ── header ─────────────────────────────────────────────────────────────── */
#hdr {
  grid-area: hdr;
  display: flex;
  align-items: stretch;
  background: var(--panel);
  font-size: 11px;
}
.hcell {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
.hcell.grow { flex: 1; border-right: none; }
.hcell .lbl { color: var(--dim); font-size: 9px; letter-spacing: 0.08em; }
.hcell .val { font-variant-numeric: tabular-nums; }
.hcell.big .val { font-size: 15px; font-weight: 600; }
.hcell.sym { font-weight: 700; color: #fff; letter-spacing: 0.04em; }
.hcell.sym .sub { color: var(--dim); font-weight: 400; font-size: 9px; }
.hcell.prefix {
  color: var(--warn);
  font-size: 15px;
  font-weight: 700;
  min-width: 34px;
  justify-content: center;
}
.hcell.armstate {
  background: #1a1d22;
  color: var(--dim);
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 0 14px;
}
body.armed .hcell.armstate { background: var(--up); color: #04120a; }
body.lockedout .hcell.armstate { background: #5a1f2b; color: #ffb3c1; }

.up { color: var(--up); }
.warn { color: var(--warn); }
.down { color: var(--down); }
.flat { color: var(--dim); }

/* ── chart ──────────────────────────────────────────────────────────────── */
#chartwrap { grid-area: chart; position: relative; background: var(--panel); overflow: hidden; }
#chart { position: absolute; inset: 0; }
#overlay { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#chart-legend {
  position: absolute; top: 5px; left: 8px; z-index: 6;
  display: flex; gap: 10px; font-size: 9px; letter-spacing: 0.05em; pointer-events: none;
}
.lg::before { content: '▬ '; }
.lg-entry { color: var(--accent); }
.lg-be { color: var(--be); }
.lg-stop { color: var(--stop); }
.lg-trail { color: var(--trail); }
.lg-r { color: #6d7f92; }
.lg-pred { color: #ff7ac6; }
#zone-label {
  position: absolute; top: 5px; right: 12px; z-index: 6;
  font-size: 10px; letter-spacing: 0.1em; font-weight: 700; pointer-events: none;
}

/* ── right rail ─────────────────────────────────────────────────────────── */
#rail {
  grid-area: rail;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.panel { background: var(--panel); padding: 5px 8px 7px; }
.ptitle {
  color: var(--dim);
  font-size: 9px;
  letter-spacing: 0.13em;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 2px;
}
.ptitle.sub2 { margin-top: 7px; }
.ptitle.row { display: flex; justify-content: space-between; }
.grid2 {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 8px;
  font-size: 11px;
}
.grid2 .k { color: var(--dim); }
.grid2 .v { text-align: right; font-variant-numeric: tabular-nums; }
.grid2 .v.big { font-size: 14px; font-weight: 600; }

#pos-side.buy { color: var(--up); font-weight: 700; }
#pos-side.sell { color: var(--down); font-weight: 700; }

.meter {
  position: relative;
  height: 16px;
  background: var(--panel2);
  border: 1px solid var(--line);
  overflow: hidden;
  margin-bottom: 4px;
}
.meter .fill {
  position: absolute; inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, #7a4a12, var(--warn));
}
.meter.loss .fill { background: linear-gradient(90deg, #5a1220, var(--down)); }
.meter-txt {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px #000;
}

.book { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.bookside { flex: 1; display: flex; align-items: baseline; gap: 5px; }
.bookside.bid { color: var(--up); }
.bookside.ask { color: var(--down); justify-content: flex-end; }
.bookside .bp { font-size: 14px; font-weight: 600; }
.bookside .bl { font-size: 9px; color: var(--dim); }
.bookmid { color: var(--dim); font-size: 10px; }
.booknote { font-size: 9px; color: var(--warn); margin-top: 3px; min-height: 11px; }

.panel.reserved { flex: 1; display: flex; flex-direction: column; }
.reserved-note {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--dimmer);
  font-size: 10px; text-align: center; line-height: 1.6;
  border: 1px dashed var(--line);
}
.reserved-note .dim { color: #2c3742; }
code { font-family: var(--mono); }

/* ── tape ───────────────────────────────────────────────────────────────── */
#tapewrap { grid-area: tape; background: var(--panel); padding: 4px 8px; display: flex; flex-direction: column; overflow: hidden; }
#tape { flex: 1; overflow-y: auto; font-size: 11px; line-height: 1.42; }
#tape::-webkit-scrollbar { width: 6px; }
#tape::-webkit-scrollbar-thumb { background: var(--line); }
.trow {
  display: grid;
  grid-template-columns: 54px 42px 30px 78px 66px 78px 74px 1fr;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid #0f141b;
  padding: 1px 0;
  white-space: nowrap;
}
.trow .t-time { color: var(--dim); }
.trow .t-kind { letter-spacing: 0.05em; }
.trow.entry .t-kind { color: var(--accent); }
.trow.exit .t-kind { color: var(--be); }
.trow.stop_move .t-kind, .trow.undo .t-kind { color: var(--dim); }
.trow.rejected { color: #6b3a45; }
.trow.rejected .t-kind { color: var(--down); }
.trow.undone { opacity: 0.42; text-decoration: line-through; }
.trow .t-key {
  background: #1b2531; color: #d7e3f0; border-radius: 2px;
  padding: 0 4px; text-align: center; font-weight: 700;
}
.trow.pending { opacity: 0.55; }
.trow.empty { display: block; border-bottom: 0; padding-top: 4px; }
.t-buy { color: var(--up); }
.t-sell { color: var(--down); }

/* ── footer ─────────────────────────────────────────────────────────────── */
#foot { grid-area: foot; display: grid; grid-template-columns: 300px 1fr; gap: 1px; background: var(--line); }
.panel.lat { background: var(--panel); }
.latgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px 10px; font-size: 11px; }
.latgrid > div { display: flex; justify-content: space-between; }
.latgrid .k { color: var(--dim); }
.latgrid .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.panel.keys { background: var(--panel); display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px 12px; font-size: 10px; }
.kchip { display: flex; gap: 4px; align-items: baseline; }
.kchip b { background: #1b2531; padding: 0 4px; border-radius: 2px; color: #dbe6f2; }
.kchip span { color: var(--dim); }

/* ── overlays ───────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(3, 5, 8, 0.86);
  display: flex; align-items: center; justify-content: center;
  padding: 30px;
}
.overlay.hidden { display: none; }
.ovbox {
  background: var(--panel);
  border: 1px solid var(--line);
  max-width: 1100px; width: 100%; max-height: 100%;
  display: flex; flex-direction: column;
}
.ovhead {
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  letter-spacing: 0.12em; font-size: 11px; color: #fff;
}
.ovhead .dim { color: var(--dim); letter-spacing: 0; }
#admin-body, #help-body { overflow-y: auto; padding: 10px 12px; font-size: 11px; }

.fx { border-bottom: 1px solid var(--line); padding: 7px 0; }
.fx-head { display: flex; justify-content: space-between; gap: 12px; }
.fx-key { color: #fff; font-weight: 700; }
.fx-val { color: var(--warn); font-variant-numeric: tabular-nums; }
.fx-formula { color: var(--accent); margin: 3px 0; white-space: pre-wrap; }
.fx-note { color: var(--dim); font-style: italic; }
.fx-inputs { margin-top: 3px; }
.fx-in { display: grid; grid-template-columns: 190px 120px 1fr; gap: 8px; color: var(--dim); }
.fx-in .n { color: #93a4b6; }
.fx-in .v { color: var(--txt); font-variant-numeric: tabular-nums; text-align: right; }
.fx-in .s { color: var(--dimmer); }
.fx-in .s.stub { color: var(--warn); }
.hgroup { color: var(--dim); letter-spacing: 0.12em; margin: 9px 0 3px; font-size: 9px; }
.hrow { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 1px 0; }
.hrow b { background: #1b2531; padding: 0 5px; border-radius: 2px; justify-self: start; }
