:root {
  --bg: #0a0a0c;
  --bg-1: #0f1014;
  --bg-2: #14161c;
  --grid: #1c1f29;
  --grid-2: #262a36;
  --ink: #e8e6df;
  --ink-dim: #8d8a82;
  --ink-faint: #56544e;
  --amber: #ffb800;
  --amber-soft: #5b4500;
  --mint: #00ff9d;
  --mint-soft: #003a26;
  --red: #ff3b3b;
  --red-soft: #3d0d0d;
  --violet: #b18cff;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
  --display: 'Fraunces', Georgia, serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 400;
  letter-spacing: 0.01em;
  overflow: hidden;
}

body {
  background-image:
    radial-gradient(1200px 600px at 80% -10%, rgba(255, 184, 0, 0.04), transparent 50%),
    radial-gradient(900px 500px at -10% 110%, rgba(0, 255, 157, 0.03), transparent 50%);
}

/* ===== TOPBAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--grid);
  background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent);
  height: 60px;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-mark {
  font-size: 22px;
  color: var(--amber);
  text-shadow: 0 0 12px rgba(255,184,0,.6);
}
.brand-name {
  font-family: var(--display);
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.03em;
  font-variation-settings: "opsz" 14;
}
.brand-sub {
  font-size: 10.5px;
  color: var(--ink-faint);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.topbar-meta { display: flex; align-items: center; gap: 22px; }
.kv { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.kv .k { font-size: 9.5px; color: var(--ink-faint); letter-spacing: 0.2em; text-transform: uppercase; }
.kv .v { font-size: 13px; font-weight: 500; margin-top: 3px; }

.mode-paper { color: var(--violet); }
.mode-live  { color: var(--red); }

#conn.dot-bad::before, #conn.dot-ok::before {
  content: "●"; margin-right: 6px;
}
.dot-bad { color: var(--red); }
.dot-ok  { color: var(--mint); }

#pnl.up   { color: var(--mint); }
#pnl.down { color: var(--red); }

.ctl {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.18em;
  padding: 9px 16px;
  background: transparent;
  border: 1px solid var(--grid-2);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.12s ease;
}
.ctl:hover { border-color: var(--ink); }
.ctl-halt   { color: var(--red);  border-color: var(--red-soft); }
.ctl-halt:hover   { background: var(--red);  color: #000; border-color: var(--red); }
.ctl-resume { color: var(--mint); border-color: var(--mint-soft); }
.ctl-resume:hover { background: var(--mint); color: #000; border-color: var(--mint); }
.ctl-mini   { padding: 4px 8px; font-size: 13px; line-height: 1; margin-left: 4px; }

/* MODE + BANKROLL buttons — look like values until you hover */
#mode-toggle, #bankroll {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  letter-spacing: inherit;
  background: transparent;
  border: 1px dashed transparent;
  color: inherit;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 2px;
}
#mode-toggle:hover, #bankroll:hover { border-color: var(--ink-faint); }
#mode-toggle.mode-live { color: var(--red); animation: pulse-live 1.6s ease-in-out infinite; }
@keyframes pulse-live {
  0%,100% { box-shadow: 0 0 0 0 var(--red-soft); }
  50%     { box-shadow: 0 0 0 3px transparent; }
}

/* ===== GRID ===== */
.grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 1px;
  background: var(--grid);
  height: calc(100vh - 60px);
}
.panel {
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel-games  { grid-row: 1 / span 2; }
.panel-log    { grid-column: 1 / -1; grid-row: auto; }
.panel-signals, .panel-orders { grid-column: auto; }

/* layout: games | (signals / orders) | (log + clv tucked below)
   The bottom row spans signals+orders for log, with CLV in a slim strip
   alongside on wide screens; on narrow screens CLV stacks under log. */
.grid {
  grid-template-columns: 1.1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr auto;
  grid-template-areas:
    "games signals orders"
    "games log     log"
    "games clv     clv";
}
.panel-games   { grid-area: games; }
.panel-signals { grid-area: signals; }
.panel-orders  { grid-area: orders; }
.panel-log     { grid-area: log; }
.panel-clv     { grid-area: clv; max-height: 180px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 1px solid var(--grid);
  background: var(--bg-2);
}
.panel-head h2 {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.28em;
  color: var(--amber);
  text-transform: uppercase;
}
.panel-head .count {
  font-size: 10px;
  color: var(--ink-faint);
  border: 1px solid var(--grid-2);
  padding: 2px 7px;
  letter-spacing: 0.1em;
}
.panel-head .hint {
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
}

/* ===== GAMES ===== */
.games-list { overflow-y: auto; }
.game {
  border-bottom: 1px solid var(--grid);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  transition: background 0.15s;
}
.game:hover { background: var(--bg-2); }
.game-teams {
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.01em;
}
.game-teams .at { color: var(--ink-faint); margin: 0 8px; font-style: italic; }
.game-score {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 18px;
  color: var(--amber);
  text-align: right;
}
.game-meta {
  font-size: 11px;
  color: var(--ink-dim);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  grid-column: 1 / -1;
}
.game-meta .tag {
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 9.5px;
  margin-right: 4px;
}
.bases {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.base {
  width: 8px; height: 8px;
  background: transparent;
  border: 1px solid var(--ink-faint);
  transform: rotate(45deg);
}
.base.on { background: var(--amber); border-color: var(--amber); }
.fair-bar {
  grid-column: 1 / -1;
  height: 4px;
  background: var(--bg-2);
  position: relative;
  overflow: hidden;
  margin-top: 4px;
}
.fair-bar > span {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: linear-gradient(90deg, var(--mint), var(--amber));
  transition: width 0.3s ease;
}

/* prediction block */
.pred {
  grid-column: 1 / -1;
  margin-top: 10px;
  padding: 8px 10px;
  background: linear-gradient(180deg, rgba(177,140,255,0.05), transparent);
  border-left: 2px solid var(--violet);
  font-size: 10.5px;
}
.pred-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 2px 0;
}
.pred-label {
  font-size: 9px;
  letter-spacing: 0.22em;
  color: var(--ink-faint);
  text-transform: uppercase;
  width: 38px;
}
.pred-dir {
  font-weight: 700;
  letter-spacing: 0.12em;
  font-size: 10.5px;
}
.pred-dir.buy  { color: var(--mint); }
.pred-dir.sell { color: var(--red); }
.pred-dir.hold { color: var(--ink-faint); }
.pred-delta {
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.pred-event {
  color: var(--ink);
  font-weight: 500;
}
.pred-evp {
  color: var(--ink-faint);
  font-weight: 400;
}
.pred-conf {
  margin-left: auto;
  color: var(--violet);
  letter-spacing: 0.1em;
  font-size: 10px;
}

/* ===== ROWS (signals + orders) ===== */
.rows { overflow-y: auto; flex: 1; font-size: 12px; }
.row {
  padding: 9px 16px;
  border-bottom: 1px solid var(--grid);
  display: grid;
  gap: 4px 10px;
  animation: flash 0.5s ease-out;
}
.row .top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.row .ticker { color: var(--amber); font-weight: 500; }
.row .dir { font-weight: 700; letter-spacing: 0.12em; font-size: 10.5px; }
.row .dir.buy  { color: var(--mint); }
.row .dir.sell { color: var(--red); }
.row .meta {
  color: var(--ink-dim);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}
.row .meta b { color: var(--ink); font-weight: 500; }
.row .ts {
  color: var(--ink-faint);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

@keyframes flash {
  0% { background: rgba(255, 184, 0, 0.10); }
  100% { background: transparent; }
}

/* ===== TAPE ===== */
.tape {
  flex: 1;
  overflow-y: auto;
  padding: 6px 14px;
  font-size: 11.5px;
  line-height: 1.7;
}
.tape .line {
  display: grid;
  grid-template-columns: 90px 110px 1fr;
  gap: 14px;
  white-space: nowrap;
  overflow: hidden;
}
.tape .line .t  { color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.tape .line .topic {
  color: var(--violet);
  letter-spacing: 0.08em;
  font-size: 10.5px;
  text-transform: uppercase;
}
.tape .line .msg {
  color: var(--ink-dim);
  text-overflow: ellipsis;
  overflow: hidden;
}
.tape .line.signal .topic    { color: var(--amber); }
.tape .line.fill .topic      { color: var(--mint); }
.tape .line.breach .topic    { color: var(--red); }
.tape .line.intent .topic    { color: var(--mint); }

/* ===== MODAL ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(10, 10, 12, 0.92);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-1);
  border: 1px solid var(--grid-2);
  padding: 32px 36px;
  width: min(420px, 92vw);
  position: relative;
}
.modal-card::before {
  content: "";
  position: absolute; inset: -1px;
  border-top: 2px solid var(--amber);
  pointer-events: none;
}
.modal-card h3 {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.modal-card p { color: var(--ink-dim); margin-bottom: 18px; font-size: 11.5px; }
.modal-card code {
  background: var(--bg-2);
  padding: 1px 6px;
  color: var(--amber);
  font-size: 11px;
}
.modal-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--grid-2);
  color: var(--ink);
  padding: 11px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  margin-bottom: 14px;
  outline: none;
}
.modal-card input:focus { border-color: var(--amber); }
.modal-card button {
  width: 100%;
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.2em;
  font-size: 11.5px;
  padding: 12px;
  background: var(--amber);
  color: #000;
  border: none;
  cursor: pointer;
}
.modal-card button:hover { background: var(--mint); }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--grid-2); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

@media (max-width: 1100px) {
  .grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "games"
      "signals"
      "orders"
      "log";
    grid-template-rows: repeat(4, minmax(220px, 1fr));
    height: auto;
    overflow-y: auto;
  }
  body { overflow: auto; }
}
