/*
 * LIVECORE TERMINAL — a live trading workspace.
 *
 * This is not the old dashboard restyled. The old screen was a grid of
 * equal-weight rectangles containing tables; everything on it competed
 * for attention, so nothing had any. The composition here is ranked:
 *
 *   MONEY  -> the widest, largest, highest-contrast thing on screen
 *   FLOW   -> the second, because watching the engine trade is the point
 *   MARKET -> context around the flow
 *   REST   -> deliberately quiet
 *
 * MOTION RULES. Every animation is driven by a real engine event. There
 * is no idle motion, no decorative particles and no looping shimmer:
 * if something moves on this screen, something happened in the market or
 * in the execution engine. Motion is also cheap — transform and opacity
 * only, never layout — because this runs beside a live socket.
 */

:root {
  /* --- surfaces, darkest to lightest --- */
  --void: #05070b;
  --bg: #080b11;
  --surface: #0d1219;
  --surface-2: #121924;
  --surface-3: #1a2331;
  --line: #1c2534;
  --line-soft: #151d29;

  /* --- ink --- */
  --ink: #e8eef7;
  --ink-2: #9fb0c6;
  --ink-3: #64748b;
  --ink-faint: #3f4c5f;

  /* --- meaning --- */
  --long: #22c55e;
  --long-dim: rgba(34, 197, 94, .14);
  --long-glow: rgba(34, 197, 94, .45);
  --short: #f43f5e;
  --short-dim: rgba(244, 63, 94, .14);
  --short-glow: rgba(244, 63, 94, .45);
  --warn: #f59e0b;
  --info: #38bdf8;
  --accent: #22d3ee;
  --accent-dim: rgba(34, 211, 238, .12);

  --radius: 10px;
  --radius-sm: 6px;
  --mono: "JetBrains Mono", "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Fluid money type: the equity figure is the anchor of the whole UI. */
  --money-xl: clamp(26px, 3.1vw, 46px);
  --money-lg: clamp(20px, 2.1vw, 30px);

  --nav-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { overflow: hidden; }

/* Numbers never reflow as they tick. */
.n, .money, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

button { font-family: inherit; color: inherit; cursor: pointer; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #26344a; }

.up { color: var(--long); }
.down { color: var(--short); }
.flat { color: var(--ink-2); }
.dim { color: var(--ink-3); }
.faint { color: var(--ink-faint); }

/* ======================================================================
   SHELL
   ====================================================================== */

#app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}

/* ======================================================================
   MONEY BAR — the loudest thing on the screen, on every breakpoint.
   ====================================================================== */

#money {
  display: grid;
  grid-template-columns: minmax(230px, auto) 1fr auto;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #0b1017 0%, var(--void) 100%);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

#money::after {
  /* A hairline that carries the engine's state colour across the top. */
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: var(--state-colour, var(--line));
  opacity: .8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #0e7490, #22d3ee);
  color: #04141a;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -.5px;
  flex: none;
}

.brand-text { min-width: 0; }
.brand-name {
  font-size: 12px; font-weight: 700; letter-spacing: .14em;
  text-transform: uppercase; color: var(--ink);
}
.brand-sub {
  font-size: 10px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* --- the money cluster --- */

.money-cluster {
  display: flex;
  align-items: flex-end;
  gap: clamp(14px, 2.4vw, 40px);
  min-width: 0;
}

.money-block { min-width: 0; }

.money-label {
  font-size: 9px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 1px;
  white-space: nowrap;
}

.money-value {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--money-xl);
  font-weight: 650;
  line-height: 1.02;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.money-value.secondary { font-size: var(--money-lg); }

.money-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  white-space: nowrap;
}

/* A change flashes its direction, then decays. Real event, brief signal. */
@keyframes flash-up {
  0% { background: var(--long-dim); box-shadow: inset 0 0 0 1px var(--long-glow); }
  100% { background: transparent; box-shadow: inset 0 0 0 1px transparent; }
}
@keyframes flash-down {
  0% { background: var(--short-dim); box-shadow: inset 0 0 0 1px var(--short-glow); }
  100% { background: transparent; box-shadow: inset 0 0 0 1px transparent; }
}
.flash-up { animation: flash-up .85s ease-out; border-radius: var(--radius-sm); }
.flash-down { animation: flash-down .85s ease-out; border-radius: var(--radius-sm); }

/* --- micro stats --- */

.micro-row { display: flex; gap: 14px; flex-wrap: wrap; }
.micro { min-width: 52px; }
.micro-label {
  font-size: 8.5px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--ink-faint); white-space: nowrap;
}
.micro-value {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 12px; color: var(--ink-2); white-space: nowrap;
}

/* --- status pills --- */

.status-stack { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.pill-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--ink-2);
}

.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-faint); flex: none; }

.pill.state-RUNNING { color: var(--long); border-color: rgba(34,197,94,.35); background: var(--long-dim); }
.pill.state-RUNNING .dot { background: var(--long); box-shadow: 0 0 8px var(--long-glow); animation: pulse 2s ease-in-out infinite; }
.pill.state-CONNECTING { color: var(--info); border-color: rgba(56,189,248,.35); }
.pill.state-CONNECTING .dot { background: var(--info); animation: pulse 1s ease-in-out infinite; }
.pill.state-DEGRADED, .pill.state-STALE { color: var(--warn); border-color: rgba(245,158,11,.35); background: rgba(245,158,11,.1); }
.pill.state-DEGRADED .dot, .pill.state-STALE .dot { background: var(--warn); }
.pill.state-BLOCKED { color: var(--warn); border-color: rgba(245,158,11,.4); }
.pill.state-BLOCKED .dot { background: var(--warn); }
.pill.state-OFFLINE, .pill.state-STOPPED, .pill.state-NOT_STARTED { color: var(--ink-3); }
.pill.state-ERROR, .pill.state-CRASHED { color: var(--short); border-color: rgba(244,63,94,.4); background: var(--short-dim); }
.pill.state-ERROR .dot, .pill.state-CRASHED .dot { background: var(--short); }
.pill.state-INACTIVE { color: var(--ink-faint); }
.pill.state-INACTIVE .dot { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-faint); }
.pill.state-HEALTHY, .pill.state-ONLINE { color: var(--long); }
.pill.state-HEALTHY .dot, .pill.state-ONLINE .dot { background: var(--long); }

.pill.lock {
  color: var(--warn);
  border-color: rgba(245,158,11,.4);
  background: rgba(245,158,11,.08);
}
.pill.lock .dot { background: var(--warn); }

.pill.kill-on {
  color: var(--short); border-color: var(--short);
  background: var(--short-dim);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.btn {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-3); color: var(--ink); border-color: #2a3548; }
.btn.primary {
  background: linear-gradient(180deg, #0e7490, #0b5c73);
  border-color: #13809c; color: #e6fbff;
}
.btn.primary:hover { background: linear-gradient(180deg, #13859f, #0e6a84); }
.btn.danger { color: #ffd9df; background: #3d0f1c; border-color: #6b1a2c; }
.btn.danger:hover { background: #551425; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ======================================================================
   THE FLOOR — desktop workspace
   ====================================================================== */

#floor {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 330px;
  gap: 1px;
  background: var(--line-soft);
  min-height: 0;
  overflow: hidden;
}

.rail {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

#stage {
  background: var(--bg);
  display: grid;
  grid-template-rows: minmax(0, 1.55fr) auto minmax(0, .95fr);
  gap: 1px;
  min-height: 0;
  min-width: 0;
}

/* --- section chrome --- */

.sec {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}

.sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 11px;
  flex: none;
  min-height: 30px;
}

.sec-title {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .17em;
  text-transform: uppercase;
  color: var(--ink-3);
  white-space: nowrap;
}

.sec-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sec-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 9px 9px; }
.sec-body.flush { padding: 0; }

/* --- empty states: the screen is finished even when nothing runs --- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 22px 16px;
  text-align: center;
  color: var(--ink-faint);
  min-height: 90px;
}
.empty-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 14px;
}
.empty-text { font-size: 11px; max-width: 250px; line-height: 1.5; color: var(--ink-3); }
.empty-hint { font-size: 10px; color: var(--ink-faint); }

/* ======================================================================
   MARKET CARDS — pressure, not a table
   ====================================================================== */

.mkt {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line-soft);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 9px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s;
}
.mkt:hover { background: var(--surface-2); border-color: var(--line); }
.mkt.sel {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-dim), var(--surface-2));
}
.mkt.has-pos { box-shadow: inset 2px 0 0 var(--accent); }

.mkt-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.mkt-sym { font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.mkt-price { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.mkt-mid { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin: 5px 0 4px; }
.mkt-chip {
  font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-3); padding: 1px 5px; border-radius: 3px; background: var(--surface-3);
  white-space: nowrap;
}
.mkt-chip.long { color: var(--long); background: var(--long-dim); }
.mkt-chip.short { color: var(--short); background: var(--short-dim); }
.mkt-spread { font-family: var(--mono); font-size: 9.5px; color: var(--ink-faint); }

/* The dual pressure bar: one glance tells you which way the book leans. */
.pressure {
  position: relative;
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  display: flex;
}
.pressure-short, .pressure-long { height: 100%; transition: width .45s cubic-bezier(.22,.61,.36,1); }
.pressure-short { background: linear-gradient(90deg, var(--short), rgba(244,63,94,.35)); margin-right: auto; }
.pressure-long { background: linear-gradient(90deg, rgba(34,197,94,.35), var(--long)); margin-left: auto; }
.pressure-mid {
  position: absolute; left: 50%; top: -1px; bottom: -1px;
  width: 1px; background: var(--bg); opacity: .9;
}

.mkt-scores {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 9.5px; margin-top: 3px;
}

/* ======================================================================
   CHART
   ====================================================================== */

#chart-sec { position: relative; }
#chart-wrap { position: relative; flex: 1; min-height: 0; }
#chart, #m-chart { display: block; width: 100%; height: 100%; }

.chart-legend {
  position: absolute;
  top: 8px; left: 10px;
  display: flex; gap: 10px; align-items: center;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  background: rgba(8, 11, 17, .72);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  flex-wrap: wrap;
  max-width: calc(100% - 20px);
}
.legend-key { display: inline-flex; align-items: center; gap: 4px; }
.legend-swatch { width: 8px; height: 2px; border-radius: 1px; }

.chart-tools { display: flex; gap: 4px; align-items: center; }
.tool {
  padding: 2px 7px; border-radius: 4px; font-size: 10px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-3);
}
.tool.on { color: var(--accent); border-color: rgba(34,211,238,.4); background: var(--accent-dim); }

/* ======================================================================
   FLOW RAIL — the signature element. Real orders move along it.
   ====================================================================== */

#flow-sec { flex: none; }

.rail-track {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  padding: 4px 9px 9px;
  min-height: 118px;
}

.stage {
  position: relative;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--line);
  background: linear-gradient(180deg, rgba(18,25,36,.5), rgba(13,18,25,.2));
  padding: 20px 5px 5px;
  min-width: 0;
  transition: border-color .3s, background .3s;
}
.stage.hot {
  border-style: solid;
  border-color: rgba(34,211,238,.4);
  background: linear-gradient(180deg, rgba(34,211,238,.08), rgba(13,18,25,.3));
}

.stage-name {
  position: absolute;
  top: 5px; left: 7px; right: 5px;
  font-size: 8px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stage.hot .stage-name { color: var(--accent); }

.stage-count {
  position: absolute; top: 4px; right: 6px;
  font-family: var(--mono); font-size: 9px; color: var(--ink-3);
}

/* the connecting arrows between stages */
.rail-track .stage + .stage::before {
  content: "";
  position: absolute;
  left: -6px; top: 50%;
  width: 6px; height: 1px;
  background: var(--line);
}

/* a runner: one real order/position moving through the pipeline */
.runner {
  border-radius: 5px;
  padding: 4px 6px;
  margin-bottom: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left-width: 2px;
  font-size: 10px;
  animation: runner-in .35s cubic-bezier(.22,.61,.36,1);
  overflow: hidden;
}
@keyframes runner-in {
  from { opacity: 0; transform: translateX(-10px) scale(.96); }
  to { opacity: 1; transform: none; }
}
.runner.long { border-left-color: var(--long); }
.runner.short { border-left-color: var(--short); }
.runner.done-win { border-left-color: var(--long); background: var(--long-dim); }
.runner.done-loss { border-left-color: var(--short); background: var(--short-dim); }
.runner.rejected { border-left-color: var(--warn); background: rgba(245,158,11,.1); }

.runner-sym { font-weight: 700; font-size: 10px; letter-spacing: .01em; }
.runner-line {
  font-family: var(--mono); font-size: 9px; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.runner-amt { font-family: var(--mono); font-size: 11px; font-weight: 600; }

.fillbar {
  height: 3px; border-radius: 2px; background: var(--surface-3);
  margin-top: 3px; overflow: hidden;
}
.fillbar > i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), #7dd3fc);
  transition: width .4s cubic-bezier(.22,.61,.36,1);
}

/* ======================================================================
   BRAIN
   ====================================================================== */

#brain-sec .sec-body { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.brain-gauge { display: flex; flex-direction: column; gap: 8px; }

.gauge-row { display: flex; align-items: center; gap: 8px; }
.gauge-tag {
  width: 42px; flex: none;
  font-size: 9px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700;
}
.gauge-track {
  flex: 1; height: 16px; border-radius: 4px;
  background: var(--surface-2); overflow: hidden; position: relative;
  border: 1px solid var(--line-soft);
}
.gauge-fill {
  height: 100%;
  transition: width .5s cubic-bezier(.22,.61,.36,1);
  position: relative;
}
.gauge-fill.long { background: linear-gradient(90deg, rgba(34,197,94,.45), var(--long)); }
.gauge-fill.short { background: linear-gradient(90deg, rgba(244,63,94,.45), var(--short)); }
.gauge-num {
  width: 38px; flex: none; text-align: right;
  font-family: var(--mono); font-size: 13px; font-weight: 650;
}

/* the entry threshold marker, so a score has a meaning not just a size */
.gauge-mark {
  position: absolute; top: -2px; bottom: -2px; width: 1px;
  background: var(--ink-faint);
}

.brain-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.fact {
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 5px 7px; min-width: 0;
}
.fact-label {
  font-size: 8px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); white-space: nowrap;
}
.fact-value {
  font-size: 11px; font-weight: 600; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.ev-list { display: flex; flex-direction: column; gap: 3px; }
.ev {
  display: grid;
  grid-template-columns: 1fr 58px;
  align-items: center;
  gap: 6px;
  font-size: 10px;
}
.ev-name { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-bar { height: 4px; border-radius: 2px; background: var(--surface-3); overflow: hidden; }
.ev-bar > i { display: block; height: 100%; transition: width .4s; }
.ev-bar > i.long { background: var(--long); }
.ev-bar > i.short { background: var(--short); }

.ev-head {
  font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-faint); margin: 6px 0 3px;
}

/* ======================================================================
   ORDER BOOK — a depth ladder, not a table
   ====================================================================== */

.book { display: flex; flex-direction: column; font-family: var(--mono); font-size: 10.5px; }

.book-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 52px;
  gap: 4px;
  padding: 1.5px 8px;
  align-items: center;
}
.book-depth {
  position: absolute; top: 0; bottom: 0; right: 0;
  opacity: .16;
  transition: width .35s ease-out;
  pointer-events: none;
}
.book-row.ask .book-depth { background: var(--short); }
.book-row.bid .book-depth { background: var(--long); }
.book-row.ask .book-px { color: var(--short); }
.book-row.bid .book-px { color: var(--long); }
.book-px, .book-sz, .book-cum { position: relative; z-index: 1; }
.book-sz { color: var(--ink-2); text-align: right; }
.book-cum { color: var(--ink-faint); text-align: right; font-size: 9.5px; }

.book-row.best { background: rgba(255,255,255,.035); }
.book-row.best .book-px { font-weight: 700; }

.book-spread {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 8px; margin: 3px 0;
  background: var(--surface-2);
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  font-size: 10px;
}
.book-mid { font-family: var(--mono); font-size: 13px; font-weight: 650; }

.imbalance {
  display: flex; height: 4px; border-radius: 2px; overflow: hidden;
  background: var(--surface-3); margin: 6px 8px 2px;
}
.imbalance > i { transition: width .45s cubic-bezier(.22,.61,.36,1); }
.imbalance > i.bid { background: var(--long); }
.imbalance > i.ask { background: var(--short); }

/* ======================================================================
   TAPE
   ====================================================================== */

.tape { font-family: var(--mono); font-size: 10px; }
.tape-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 6px;
  padding: 2px 8px;
  border-left: 2px solid transparent;
}
.tape-row.buy { border-left-color: var(--long); }
.tape-row.sell { border-left-color: var(--short); }
.tape-row.buy .tape-px { color: var(--long); }
.tape-row.sell .tape-px { color: var(--short); }
.tape-t { color: var(--ink-faint); }
.tape-sz { color: var(--ink-2); text-align: right; }
.tape-row.fresh { animation: tape-in .5s ease-out; }
@keyframes tape-in {
  from { opacity: 0; transform: translateY(-6px); background: rgba(255,255,255,.06); }
  to { opacity: 1; transform: none; background: transparent; }
}

/* ======================================================================
   ORDERS / POSITIONS / OUTCOMES — live objects, not rows
   ====================================================================== */

.card {
  border: 1px solid var(--line-soft);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 7px 9px;
  margin-bottom: 6px;
  border-left-width: 2px;
}
.card.long { border-left-color: var(--long); }
.card.short { border-left-color: var(--short); }
.card.win { border-left-color: var(--long); }
.card.loss { border-left-color: var(--short); }
.card.neutral { border-left-color: var(--ink-faint); }

.card-top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px; margin-bottom: 3px;
}
.card-sym { font-size: 11.5px; font-weight: 700; }
.card-val { font-family: var(--mono); font-size: 12.5px; font-weight: 650; }
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 3px 8px; margin-top: 4px;
}
.card-cell { min-width: 0; }
.card-k { font-size: 8px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.card-v {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.tag {
  display: inline-block;
  font-size: 8.5px; letter-spacing: .08em; text-transform: uppercase;
  padding: 1px 5px; border-radius: 3px;
  background: var(--surface-3); color: var(--ink-3);
  white-space: nowrap;
}
.tag.buy { background: var(--long-dim); color: var(--long); }
.tag.sell { background: var(--short-dim); color: var(--short); }
.tag.state { background: var(--accent-dim); color: var(--accent); }
.tag.warn { background: rgba(245,158,11,.14); color: var(--warn); }

/* the order state track — a visible lifecycle, not a word */
.track { display: flex; gap: 2px; margin-top: 5px; }
.track-step {
  flex: 1; height: 3px; border-radius: 2px;
  background: var(--surface-3);
  transition: background .3s;
}
.track-step.done { background: var(--accent); }
.track-step.now { background: var(--accent); box-shadow: 0 0 6px rgba(34,211,238,.6); }
.track-step.bad { background: var(--short); }

/* ======================================================================
   BOTTOM STRIP
   ====================================================================== */

#strip {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 1px;
  background: var(--line-soft);
  height: 148px;
  flex: none;
}
#strip > .sec { background: var(--bg); border-bottom: none; }

#equity-chart, #m-equity-chart { display: block; width: 100%; height: 100%; }
#equity-wrap { flex: 1; min-height: 0; position: relative; padding: 0 4px 4px; }

.meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 4px 10px; }
.meter { min-width: 0; }
.meter-k {
  font-size: 8px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-faint); white-space: nowrap;
}
.meter-v { font-family: var(--mono); font-size: 12px; color: var(--ink); }

/* ======================================================================
   MOBILE SHELL
   ====================================================================== */

#mobile { display: none; }

.m-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px calc(var(--nav-h) + var(--safe-b) + 14px);
  min-height: 0;
}

.m-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: rgba(8, 11, 17, .97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  z-index: 40;
}

.m-tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  border: none; background: none;
  color: var(--ink-faint);
  font-size: 9px; letter-spacing: .09em; text-transform: uppercase; font-weight: 600;
  /* a comfortable target regardless of the label size */
  min-height: 44px;
  transition: color .15s;
}
.m-tab .ic { font-size: 15px; line-height: 1; }
.m-tab.on { color: var(--accent); }
.m-tab.on .ic { filter: drop-shadow(0 0 6px rgba(34,211,238,.5)); }

/* mobile vertical trade flow */
.vflow { position: relative; padding-left: 20px; }
.vflow::before {
  content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px;
  width: 1px; background: var(--line);
}
.vstep { position: relative; padding: 0 0 10px 0; }
.vstep::before {
  content: ""; position: absolute; left: -17px; top: 5px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--surface-3); border: 1px solid var(--line);
}
.vstep.on::before { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 8px rgba(34,211,238,.6); }
.vstep.win::before { background: var(--long); border-color: var(--long); }
.vstep.loss::before { background: var(--short); border-color: var(--short); }
.vstep-k {
  font-size: 8.5px; letter-spacing: .13em; text-transform: uppercase; color: var(--ink-faint);
}
.vstep-v { font-size: 11.5px; color: var(--ink-2); font-family: var(--mono); }

/* mobile sticky money header is the #money bar itself, recomposed */

/* ======================================================================
   BREAKPOINTS
   ====================================================================== */

/* --- tablet landscape: drop the right rail into the stage --- */
@media (max-width: 1400px) {
  #floor { grid-template-columns: 236px minmax(0, 1fr) 296px; }
}

@media (max-width: 1180px) {
  #floor { grid-template-columns: 210px minmax(0, 1fr); }
  #rail-right {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 300px;
    z-index: 25;
    border-left: 1px solid var(--line);
    background: var(--bg);
    transform: translateX(100%);
    transition: transform .25s cubic-bezier(.22,.61,.36,1);
    box-shadow: -18px 0 40px rgba(0,0,0,.5);
  }
  #floor.show-right #rail-right { transform: none; }
  #drawer-toggle { display: inline-flex; }
  #strip { grid-template-columns: 1fr 1fr; height: 132px; }
  #strip > .sec:nth-child(3) { display: none; }
}

/* --- tablet portrait --- */
@media (max-width: 1024px) and (orientation: portrait) {
  #floor { grid-template-columns: 200px minmax(0, 1fr); }
  #stage { grid-template-rows: minmax(0, 1.3fr) auto minmax(0, 1fr); }
  .rail-track { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .rail-track .stage:nth-child(n+5) { display: none; }
}

/* --- MOBILE: a different product, not a squeezed one --- */
@media (max-width: 860px) {
  body { font-size: 13px; }

  #floor, #strip { display: none !important; }

  #mobile {
    display: grid;
    grid-template-rows: minmax(0, 1fr);
    min-height: 0;
  }

  #app { grid-template-rows: auto minmax(0, 1fr); }

  #money {
    position: sticky;
    top: 0;
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand pills" "money money";
    gap: 6px 10px;
    padding: 8px 12px 10px;
  }
  .brand { grid-area: brand; }
  .status-stack { grid-area: pills; }
  .money-cluster {
    grid-area: money;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 14px;
    align-items: end;
  }
  #money .micro-row { display: none; }
  #money .money-value { font-size: clamp(24px, 8vw, 34px); }
  #money .money-value.secondary { font-size: clamp(19px, 6.4vw, 26px); }
  .brand-sub { display: none; }

  /* Engine state, mode and the LIVE lock stay; the ENGINE CONTROLS move
     to the More tab. Three buttons in a phone header is a header that
     has stopped being about status. */
  #m-controls { display: none; }
  .status-stack { align-items: flex-end; }
  #m-pills { flex-wrap: nowrap; gap: 4px; }
  #m-pills .pill { padding: 3px 7px; font-size: 9px; letter-spacing: .04em; }

  .sec { border-bottom: none; }
  .sec-head { padding: 10px 2px 6px; }
  .sec-body { padding: 0; overflow: visible; }

  .m-card {
    background: var(--surface);
    border: 1px solid var(--line-soft);
    border-radius: 12px;
    padding: 10px 11px;
    margin-bottom: 9px;
  }

  /* touch targets */
  .mkt { padding: 11px 11px; margin-bottom: 8px; border-radius: 12px; }
  .mkt-sym { font-size: 13.5px; }
  .mkt-price { font-size: 14px; }
  .btn { padding: 9px 14px; font-size: 12px; }
  .tool { padding: 7px 11px; font-size: 11px; }

  .card { padding: 10px 11px; border-radius: 12px; }
  .card-sym { font-size: 13px; }
  .card-val { font-size: 14px; }

  .book-row { padding: 3px 6px; font-size: 11px; }
  .tape-row { padding: 3.5px 6px; font-size: 11px; }

  #brain-sec .sec-body { grid-template-columns: 1fr; }
  .gauge-track { height: 20px; }
  .gauge-num { font-size: 15px; width: 44px; }
}

@media (pointer: coarse) {
  .btn { padding: 10px 15px; font-size: 12px; min-height: 40px; }
  .tool { padding: 8px 12px; font-size: 11px; min-height: 36px; }
  .mkt { padding: 11px; }
  .m-tab { min-height: 48px; }
  /* Stop is destructive: keep it away from everything else. */
  .btn.danger, #btn-stop { margin-left: 10px; }
}

@media (max-width: 400px) {
  #money { padding: 7px 10px 9px; }
  .money-cluster { gap: 3px 10px; }
  .brand-mark { width: 26px; height: 26px; font-size: 11px; }
  .meters { grid-template-columns: repeat(2, 1fr); }
}

/* --- mobile landscape: keep the chart usable --- */
@media (max-width: 926px) and (orientation: landscape) and (max-height: 500px) {
  #money { padding: 5px 10px; grid-template-areas: "brand money pills"; grid-template-columns: auto 1fr auto; }
  .money-cluster { display: flex; }
  #money .money-value { font-size: 20px; }
  #money .money-value.secondary { font-size: 17px; }
  .m-scroll { padding-bottom: calc(var(--nav-h) + 8px); }
}

/* --- reduced motion: keep every state, drop the movement --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* --- staleness: the one thing a live screen must never hide --- */
body.stale .money-value,
body.stale .mkt-price,
body.stale .book,
body.stale .tape { opacity: .45; }
body.stale #money::after { background: var(--warn); }

.drawer-scrim { display: none; }
@media (max-width: 1180px) {
  #floor.show-right .drawer-scrim {
    display: block;
    position: absolute; inset: 0;
    background: rgba(5,7,11,.5);
    z-index: 24;
  }
  #floor { position: relative; }
}
@media (min-width: 1181px) { #drawer-toggle { display: none; } }
