:root {
  color-scheme: dark;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  background: #070b10;
  color: #d8e5f1;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(circle at 20% 0, #102336 0, #070b10 46%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: tabular-nums; }
.terminal { max-width: 1180px; margin: 0 auto; padding: 12px 14px 28px; }

/* Topbar */
.topbar {
  display: flex; gap: 8px; align-items: center;
  border-bottom: 1px solid #223647; padding: 8px 0 10px;
  font-size: 13px; flex-wrap: nowrap;
}
.prompt { color: #68b7ff; font-weight: 700; white-space: nowrap; }
.conn-pill { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid #284255; white-space: nowrap; }
.spacer { flex: 1; }
.pause-btn {
  background: #2b1d10; border: 1px solid #c9822b; color: #ffd480;
  border-radius: 4px; padding: 5px 10px; font: inherit; font-size: 12px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
.pause-btn:hover { background: #3d2814; }
.pause-btn.paused {
  background: #4d1419; border-color: #ff4d4f; color: #ffccc7;
  box-shadow: 0 0 10px rgba(255, 77, 79, 0.35);
}
button {
  background: #173b54; border: 1px solid #3e7799; color: #dcefff;
  border-radius: 4px; padding: 7px 12px; font: inherit; cursor: pointer;
}
button:hover { background: #1e506c; }
.ghost { background: transparent; padding: 5px 9px; font-size: 12px; }
.small { padding: 3px 9px; font-size: 11px; }

/* Panels */
.panel {
  background: #0d141d; border: 1px solid #213444; border-radius: 8px;
  padding: 12px 14px; margin: 11px 0; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.label, .section-title { color: #7a98ad; font-size: 11px; letter-spacing: .07em; font-weight: 600; }
.muted { color: #738899; font-size: 12px; margin-top: 6px; }
.muted-tag { color: #7e97aa; font-size: 11px; }
.error { color: #ff8e8e; min-height: 18px; margin-top: 10px; font-size: 12px; }
.line { color: #7ed7a5; margin-bottom: 12px; }
form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
input { background: #080b10; border: 1px solid #355166; color: #fff; border-radius: 4px; padding: 8px; width: min(360px, 70vw); }

/* Top Grid */
.top-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.kv-box { min-width: 0; }
.value { margin-top: 4px; color: #f0f6fc; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.value-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.risk-pill {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: #133126; color: #7ed7a5; border: 1px solid #2a6e51;
}
.risk-pill.warn { background: #332711; color: #ffd479; border-color: #7c5b1f; }
.risk-pill.bad { background: #3b151a; color: #ff8e8e; border-color: #8c2a33; }

/* Full-width BTC/PTB Price Card */
.price-card { border-color: #29465c; }
.oracle-pill {
  font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: #112b22; color: #6ce0a6; border: 1px solid #245f46; white-space: nowrap;
}
.oracle-pill.warn { background: #332610; color: #ffd479; border-color: #7b591d; }
.price-rows { display: flex; flex-direction: column; gap: 6px; padding-bottom: 10px; border-bottom: 1px solid #1c2e3d; }
.price-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.price-lbl { color: #8da6b8; font-size: 12px; white-space: nowrap; }
.price-val { color: #f2f8fd; font-size: 16px; font-weight: 700; white-space: nowrap; }
.metric-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.metric-cell {
  background: #091018; border: 1px solid #1b2c3a; border-radius: 6px; padding: 8px 10px; min-width: 0;
}
.metric-lbl { color: #7b95a8; font-size: 10px; letter-spacing: .03em; margin-bottom: 4px; }
.metric-val { font-size: 14px; font-weight: 700; white-space: nowrap; }

/* Quotes */
.quotes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quote { padding: 10px 12px; border: 1px solid #233a4c; border-radius: 6px; background: #0a1119; }
.quote strong { display: block; margin-top: 4px; font-size: 19px; color: #f4f9fe; }

/* Open Positions Floating Card */
.open-pos-panel { border-color: #d4942a; background: linear-gradient(180deg, #161c24 0, #0d141d 100%); }
.live-dot { font-size: 10px; font-weight: 700; color: #ffd479; padding: 2px 7px; border: 1px solid #8a621c; border-radius: 999px; }
.open-pos-list { display: flex; flex-direction: column; gap: 8px; }
.pos-card { background: #091018; border: 1px solid #2c4356; border-radius: 6px; padding: 10px 12px; }
.pos-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.pos-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; font-size: 12px; }
.pos-kv span { display: block; color: #7a93a6; font-size: 10px; }
.pos-kv strong { font-size: 13px; }

/* Primary Neural Engine Cards (Mobile-friendly dual-line, zero clipping) */
.engine-list { display: flex; flex-direction: column; gap: 10px; }
.engine-card {
  background: #0a1119; border: 1px solid #264156; border-radius: 8px; padding: 11px 12px;
}
.engine-card.v5 { border-left: 3px solid #59c8ff; }
.engine-card.v4 { border-left: 3px solid #7ed7a5; }
.engine-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.engine-title-wrap { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; min-width: 0; }
.engine-name { font-size: 14px; font-weight: 700; color: #f2f8fd; }
.arch-pill {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  background: #122333; color: #84c5f8; border: 1px solid #264866;
}
.mode-badge {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 4px;
  border: 1px solid #355166; background: #10202e; color: #cfe4f5;
}
.mode-badge.live { background: #143624; border-color: #36a36b; color: #7ef0b2; }
.mode-badge.locked { opacity: .82; cursor: default; }
.mode-badge.clickable { cursor: pointer; }
.mode-badge.clickable:hover { background: #1c384f; }
.engine-metrics {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
  padding: 7px 0; border-top: 1px solid #182836; border-bottom: 1px solid #182836;
}
.em-item span { display: block; color: #758fa3; font-size: 10px; }
.em-item strong { font-size: 13px; color: #ecf4fb; }
.engine-brain {
  display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; font-size: 11px; color: #9db6c8;
}
.engine-brain b { color: #e4f0fa; font-weight: 600; }

/* Collapsible Experimental Strategies */
.exp-group { margin-top: 12px; border-top: 1px dashed #23384a; padding-top: 10px; }
.exp-group summary {
  cursor: pointer; color: #8aa5b8; font-size: 12px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; list-style: none;
}
.exp-group summary::-webkit-details-marker { display: none; }
.exp-group summary::before { content: '▸'; color: #68b7ff; }
.exp-group[open] summary::before { content: '▾'; }
.cb-mini-badge {
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px;
  background: #451419; color: #ff6b6b; border: 1px solid #a82b34;
}
.exp-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.exp-card {
  background: #091017; border: 1px solid #1d2f3e; border-radius: 6px; padding: 9px 11px;
}
.exp-card.cb-tripped { border-color: #9e2a33; background: #170c0e; }
.cb-alert {
  margin-top: 6px; color: #ff5c61; font-size: 11px; font-weight: 700;
  word-break: break-word; line-height: 1.4;
}

/* Recent Trades */
.trade-list { display: flex; flex-direction: column; gap: 7px; }
.trade-row {
  background: #0a1119; border: 1px solid #1e3140; border-radius: 6px; padding: 8px 10px;
}
.trade-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.trade-sub { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 5px; font-size: 11px; color: #8ba3b5; }
.side-tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; }
.side-tag.up { background: #123326; color: #7ed7a5; border: 1px solid #286e51; }
.side-tag.down { background: #3b171b; color: #ff9494; border: 1px solid #7d2c35; }
.strat-tag { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: #14283b; color: #7dc7ff; }

/* Colors */
.ok, .positive { color: #7ed7a5 !important; }
.warn { color: #ffd479 !important; }
.bad, .negative { color: #ff7875 !important; }

/* History */
.history-layout { display: grid; grid-template-columns: minmax(260px, 38%) 1fr; gap: 12px; margin-top: 10px; }
.market-list { max-height: 480px; overflow: auto; border: 1px solid #203544; border-radius: 6px; }
.market-row {
  padding: 9px 10px; border-bottom: 1px solid #1a2a36; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.market-row:hover, .market-row.active { background: #142d40; }
.market-row-left { min-width: 0; }
.market-row-left b { display: block; font-size: 13px; color: #e8f2fa; }
.market-row-left small { display: block; color: #748d9f; font-size: 11px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.market-badges { display: flex; gap: 5px; align-items: center; flex-shrink: 0; }
.m-badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
.m-badge.up { background: #123326; color: #7ed7a5; }
.m-badge.down { background: #3b171b; color: #ff9494; }
.m-badge.live { background: #332711; color: #ffd479; }
.m-badge.traded { background: #163047; color: #73c5ff; border: 1px solid #2b608c; }

.history-result { min-width: 0; }
.chart-panel { background: #080b10; border: 1px solid #203544; padding: 10px; border-radius: 6px; }
.chart-title { color: #8da7ba; font-size: 11px; letter-spacing: .08em; margin: 4px 0 6px; }
canvas { display: block; width: 100%; height: 220px; background: #080b10; }
.chart-panel canvas + .chart-title { margin-top: 14px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; color: #95a9b6; font-size: 11px; margin-top: 8px; }
.legend span::before { content: '●'; margin-right: 5px; }
.legend .binance::before { color: #f39b72; }
.legend .chainlink::before { color: #5dd3ae; }
.legend .ptb::before { color: #e9bd63; }
.legend .up::before { color: #7bb9ed; }
.legend .down::before { color: #f08b88; }
.raw-detail { margin-top: 10px; }
.raw-detail summary { cursor: pointer; color: #8da7ba; font-size: 12px; }
.detail {
  margin: 8px 0 0; max-height: 480px; overflow: auto; white-space: pre-wrap;
  word-break: break-word; color: #c1d4e4; background: #080b10; border: 1px solid #203544; padding: 10px; font-size: 11px;
}

@media (max-width: 760px) {
  .terminal { padding: 8px 10px 24px; }
  .top-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-strip { grid-template-columns: 1fr; }
  .engine-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pos-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .history-layout { grid-template-columns: 1fr; }
  .quote strong { font-size: 16px; }
  .price-val { font-size: 15px; }
  canvas { height: 190px; }
}
