/* ===========================================================================
   LAMBDA TERMINAL — design system
   Dark-only trading desk. One accent (amber). Green/red are semantic P&L only.
   Mono numerals, 1px data separators, cockpit density. Radii locked:
   panels 10px, controls 7px, pills full.
   =========================================================================== */

:root {
  --bg0: #06090f;
  --bg1: #0a0e16;
  --bg2: #0e141f;
  --bg3: #141c2a;
  --bg4: #1c2638;
  --line: rgba(255, 255, 255, 0.06);
  --line2: rgba(255, 255, 255, 0.10);

  --txt1: #eaf0f8;
  --txt2: #8698b0;
  --txt3: #54647a;
  --txt4: #384456;

  --amber: #ffb000;
  --amber-dim: rgba(255, 176, 0, 0.10);
  --up: #26d07c;
  --down: #ff4d4d;
  --up-dim: rgba(38, 208, 124, 0.08);
  --down-dim: rgba(255, 77, 77, 0.08);
  --blue: #36b6ff;
  --violet: #9d7bff;

  --r-panel: 12px;
  --r-ctrl: 8px;

  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --ui: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;

  --topbar-h: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; }

html, body { height: 100%; }

body {
  font-family: var(--ui);
  background: var(--bg0);
  color: var(--txt1);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
}

.mono { font-family: var(--mono); }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--txt2); }
.dim { color: var(--txt3); }

button { font-family: var(--ui); cursor: pointer; color: inherit; }
input, textarea, select { font-family: var(--mono); }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #2a3343; }

/* subtle page vignette so the desk feels lit, not flat */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(120% 90% at 50% -10%, rgba(255, 176, 0, 0.04), transparent 55%);
}

/* ============================ SETUP SCREEN ============================== */
#screen-setup {
  position: relative;
  z-index: 2;
  display: none;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg0);
}
#screen-setup.show { display: block; }
#screen-setup.show ~ #sidebar { display: none; }
.setup-bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(255, 176, 0, 0.06), transparent),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(54, 182, 255, 0.04), transparent),
    radial-gradient(ellipse 50% 40% at 20% 70%, rgba(157, 123, 255, 0.03), transparent);
  pointer-events: none;
}

.setup-inner {
  position: relative;
  z-index: 1;
  max-width: 820px;
  margin: 0 auto;
  padding: clamp(2.5rem, 6vh, 5rem) 1.5rem 5rem;
}

/* ── Hero ── */
.su-hero { margin-bottom: 2.8rem; }
.su-lambda {
  display: inline-block;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 2.8rem;
  color: var(--amber);
  line-height: 1;
  margin-bottom: 0.2rem;
}
.su-title {
  font-family: var(--ui);
  font-weight: 700;
  font-size: clamp(1.6rem, 3.5vw, 2.2rem);
  letter-spacing: -0.03em;
  color: var(--txt1);
  margin: 0.2rem 0 0.5rem;
}
.su-sub {
  font-size: 0.92rem;
  color: var(--txt2);
  line-height: 1.5;
  max-width: 44ch;
}
.su-glow {
  color: var(--txt1);
  font-weight: 500;
}

/* ── Section label ── */
.su-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--txt3);
  margin-bottom: 0.9rem;
}

/* ── Challenge grid ── */
.su-challenges { margin-bottom: 2rem; }

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.65rem;
}
.scn-card {
  position: relative;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 1rem 1rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  overflow: hidden;
}
.scn-card::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  opacity: 0;
  background: radial-gradient(ellipse at 0% 0%, rgba(255, 176, 0, 0.04), transparent 70%);
  transition: opacity 0.3s;
  pointer-events: none;
}
.scn-card:hover::before { opacity: 1; }
.scn-card:hover { border-color: var(--line2); background: var(--bg2); transform: translateY(-1px); }
.scn-card.sel {
  border-color: var(--amber);
  background: linear-gradient(135deg, rgba(255, 176, 0, 0.08), rgba(255, 176, 0, 0.02));
}
.scn-card.sel::before { opacity: 1; }
.scn-card.sel::after {
  content: "";
  position: absolute; top: 0; left: 0; width: 3px; height: 100%;
  background: var(--amber);
  border-radius: 0 2px 2px 0;
}

.scn-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem; }
.scn-name { font-weight: 600; font-size: 0.95rem; }
.scn-tag {
  font-family: var(--mono);
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: var(--bg3);
  color: var(--txt2);
  white-space: nowrap;
}
.scn-card.sel .scn-tag { background: rgba(255, 176, 0, 0.15); color: var(--amber); }
.scn-desc { color: var(--txt2); font-size: 0.8rem; line-height: 1.5; min-height: 3.2em; }
.scn-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.6rem;
  padding-top: 0.55rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.66rem;
  color: var(--txt3);
}
.diff-dots { display: inline-flex; gap: 3px; }
.diff-dot { width: 5px; height: 5px; border-radius: 999px; background: var(--bg4); }
.diff-dot.on { background: var(--amber); }
.scn-stars { color: var(--amber); letter-spacing: 1px; font-size: 0.72rem; }

/* ── Configuration card ── */
.su-config {
  margin-bottom: 2rem;
}
.su-config-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 1.2rem;
}
.su-cfg-label {
  display: block;
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--txt3);
  margin-bottom: 0.6rem;
}
.cap-row, .seed-row { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.chip-btn {
  flex: 1;
  min-width: 48px;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--r-ctrl);
  background: var(--bg2);
  color: var(--txt2);
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  transition: 0.15s;
}
.chip-btn:hover { border-color: var(--line2); color: var(--txt1); }
.chip-btn.sel {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(255, 176, 0, 0.08);
  box-shadow: 0 0 0 1px rgba(255, 176, 0, 0.15);
}
.su-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctrl);
  color: var(--txt1);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.5rem 0.65rem;
  outline: none;
  transition: border-color 0.15s;
}
.su-input::placeholder { color: var(--txt4); }
.su-input:focus { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(255, 176, 0, 0.06); }

/* ── Actions ── */
.su-actions { display: flex; gap: 0.7rem; align-items: center; }
.su-btn-primary {
  position: relative;
  background: var(--amber);
  color: #1a1300;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.8rem 2rem;
  letter-spacing: 0.01em;
  transition: 0.2s;
  overflow: hidden;
}
.su-btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.su-btn-primary:active { transform: translateY(0); }
.su-btn-glow {
  position: absolute; top: -50%; left: -50%; width: 200%; height: 200%;
  background: radial-gradient(ellipse at 50% 30%, rgba(255, 255, 255, 0.2), transparent 60%);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
.su-btn-primary:hover .su-btn-glow { opacity: 1; }
.su-btn-text { position: relative; z-index: 1; }

.su-btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: transparent;
  border: 1px solid var(--line2);
  border-radius: 999px;
  color: var(--txt2);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.78rem 1.2rem;
  transition: 0.15s;
  cursor: pointer;
}
.su-btn-secondary:hover { color: var(--txt1); border-color: var(--txt3); }
.su-btn-secondary svg { opacity: 0.6; }

/* ============================ SIDEBAR =================================== */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: 190px;
  background: var(--bg1);
  border-right: 1px solid var(--line);
  z-index: 30;
  padding: 0.8rem 0.5rem;
}
.sb-brand {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--amber);
  text-align: center;
  padding: 0.4rem 0 1rem;
  letter-spacing: -0.02em;
}
.sb-links {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.sb-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  background: transparent;
  border: none;
  border-radius: var(--r-ctrl);
  color: var(--txt3);
  font-family: var(--ui);
  font-size: 0.82rem;
  font-weight: 500;
  transition: 0.15s;
  text-align: left;
}
.sb-btn:hover {
  color: var(--txt1);
  background: var(--bg2);
}
.sb-btn.sel {
  color: var(--amber);
  background: var(--amber-dim);
  font-weight: 600;
}
.sb-ic {
  font-size: 1rem;
  width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}
.sb-lbl { white-space: nowrap; }
.sb-spacer { flex: 1; }
#sb-back { margin-top: 0.5rem; border-top: 1px solid var(--line); padding-top: 0.7rem; }
#sb-back:hover { color: var(--down); }

/* ── Main content area ── */
#main-content {
  margin-left: 190px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
/* ── Page sections ── */
.page {
  display: none;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: auto;
}
.page.show { display: flex; }

/* ============================ TERMINAL ================================== */
/* Terminal pages are now handled by .page sections */

/* ── Top bar ── */
#top-bar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0 0.85rem;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
}
.tb-menu {
  display: none;
  background: none;
  border: none;
  color: var(--txt2);
  font-size: 1.15rem;
  padding: 0.2rem;
  -webkit-tap-highlight-color: transparent;
}
.tb-logo { font-family: var(--mono); font-weight: 700; font-size: 1.05rem; color: var(--amber); }
.tb-sep { width: 1px; height: 22px; background: var(--line2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.6rem;
  border-radius: var(--r-ctrl);
  background: var(--bg2);
  border: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: nowrap;
}
.chip .lbl { color: var(--txt3); font-size: 0.62rem; letter-spacing: 0.08em; }
.regime-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--txt3); }
.regime-bull .regime-dot, .regime-bull { color: var(--up); }
.regime-bull .regime-dot { background: var(--up); }
.regime-bear .regime-dot, .regime-bear { color: var(--down); }
.regime-bear .regime-dot { background: var(--down); }
.regime-range { color: var(--blue); }
.regime-range .regime-dot { background: var(--blue); }
.regime-volatile, .regime-crash { color: var(--amber); }
.regime-volatile .regime-dot, .regime-crash .regime-dot { background: var(--amber); }

.tb-spacer { flex: 1; }
.tb-objective { color: var(--txt2); font-size: 0.78rem; }
.tb-objective b { color: var(--txt1); }

/* portfolio group: invested / value / equity */
.pf-group {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  font-family: var(--mono);
  flex-shrink: 0;
}
.pf-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  line-height: 1.2;
}
.pf-lbl {
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  color: var(--txt3);
}
.pf-val {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--txt1);
  transition: color 0.2s;
}
.pf-pnl {
  font-size: 0.78rem;
  font-weight: 600;
  min-width: 3em;
  text-align: right;
  line-height: 1.2;
}
#pf-invested .pf-lbl,
#pf-value .pf-lbl {
  font-size: 0.48rem;
}
#pf-invested .pf-val { color: var(--txt2); }
#pf-value .pf-val { color: var(--txt2); }
.pf-sep {
  width: 1px;
  height: 24px;
  background: var(--line);
  flex-shrink: 0;
}

.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--r-ctrl);
  background: var(--bg2); color: var(--txt2); font-size: 0.95rem; transition: 0.15s;
}
.icon-btn:hover { color: var(--txt1); border-color: var(--line2); }
.icon-btn.live { color: var(--amber); border-color: var(--amber); }

.speed-group { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-ctrl); overflow: hidden; }
.speed-group button {
  background: var(--bg2); border: none; color: var(--txt3);
  font-family: var(--mono); font-size: 0.68rem; padding: 0.35rem 0.5rem;
  border-right: 1px solid var(--line);
}
.speed-group button:last-child { border-right: none; }
.speed-group button.sel { background: var(--amber-dim); color: var(--amber); }

/* ── Main grid ── */
#desk {
  flex: 1;
  display: grid;
  grid-template-columns: 222px 1fr 312px;
  gap: 1px;
  background: var(--line);
  min-height: 0;
}
.col { background: var(--bg0); display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.panel { background: var(--bg1); display: flex; flex-direction: column; min-height: 0; }
.panel + .panel { margin-top: 1px; }
.panel-head {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.7rem;
  font-family: var(--mono); font-size: 0.64rem; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--txt3);
  border-bottom: 1px solid var(--line);
}
.panel-body { overflow-y: auto; min-height: 0; }

/* ── Watchlist ── */
#watchlist { flex: 1; }
.wl-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.3rem;
  align-items: center;
  padding: 0.42rem 0.7rem;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s;
}
.wl-row:hover { background: var(--bg2); }
.wl-row.sel { background: var(--amber-dim); box-shadow: inset 2px 0 0 var(--amber); }
.wl-sym { font-family: var(--mono); font-weight: 600; font-size: 0.82rem; }
.wl-name { font-size: 0.62rem; color: var(--txt3); }
.wl-right { text-align: right; font-family: var(--mono); }
.wl-price { font-size: 0.8rem; }
.wl-chg { font-size: 0.66rem; }
.flash-up { animation: flashUp 0.6s ease-out; }
.flash-down { animation: flashDown 0.6s ease-out; }
@keyframes flashUp { 0% { background: var(--up-dim); } 100% { background: transparent; } }
@keyframes flashDown { 0% { background: var(--down-dim); } 100% { background: transparent; } }

/* market stats mini panel */
#market-stats { flex-shrink: 0; }
.stat-row { display: flex; justify-content: space-between; padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--line); font-size: 0.75rem; }
.stat-row .k { color: var(--txt3); }
.stat-row .v { font-family: var(--mono); }

/* ── Center column ── */
.chart-head {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: var(--bg1);
  flex-wrap: wrap;
}
.ch-sym { font-family: var(--mono); font-weight: 700; font-size: 1.1rem; }
.ch-name { color: var(--txt3); font-size: 0.72rem; }
.ch-price { font-family: var(--mono); font-size: 1.5rem; font-weight: 600; }
.ch-chg { font-family: var(--mono); font-size: 0.85rem; }
.ch-ohlc { display: flex; gap: 0.9rem; font-family: var(--mono); font-size: 0.68rem; color: var(--txt3); margin-left: auto; }
.ch-ohlc b { color: var(--txt2); font-weight: 500; }
.ema-legend { display: flex; gap: 0.7rem; font-family: var(--mono); font-size: 0.62rem; }
.ema-legend span::before { content: "■ "; }

#chart-wrap { flex: 1; min-height: 200px; background: var(--bg1); position: relative; }

/* ── Bottom dock with tabs ── */
#dock { flex-shrink: 0; height: 248px; display: flex; flex-direction: column; background: var(--bg1); border-top: 1px solid var(--line); }
.dock-tabs { display: flex; flex-shrink: 0; border-bottom: 1px solid var(--line); }
.dock-tab {
  background: transparent; border: none; color: var(--txt3);
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 0.6rem 0.95rem; border-bottom: 2px solid transparent;
}
.dock-tab:hover { color: var(--txt1); }
.dock-tab.sel { color: var(--amber); border-bottom-color: var(--amber); }
.dock-panel { flex: 1; overflow: auto; display: none; }
.dock-panel.show { display: block; }

/* tables */
.data-table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 0.75rem; }
.data-table th {
  position: sticky; top: 0;
  text-align: right; color: var(--txt3); font-weight: 500; font-size: 0.62rem;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 0.45rem 0.7rem; background: var(--bg1); border-bottom: 1px solid var(--line);
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table td { text-align: right; padding: 0.42rem 0.7rem; border-bottom: 1px solid var(--line); }
.data-table tr:hover td { background: var(--bg2); }
.side-long { color: var(--up); }
.side-short { color: var(--down); }
.mini-btn {
  background: var(--bg3); border: 1px solid var(--line2); border-radius: 5px;
  color: var(--txt2); font-family: var(--mono); font-size: 0.66rem; padding: 0.2rem 0.5rem;
}
.mini-btn:hover { color: var(--down); border-color: var(--down); }
.empty-state { padding: 2rem; text-align: center; color: var(--txt3); font-size: 0.82rem; }

/* ── Right column: order ticket ── */
#ticket { flex-shrink: 0; }

#positions-panel { flex-shrink: 0; max-height: 180px; display: none; }
#positions-panel.has-pos { display: flex; flex-direction: column; }
#positions-panel .panel-body { overflow-y: auto; }
.pos-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.3rem;
  align-items: center;
  padding: 0.35rem 0.7rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
}
.pos-row:hover { background: var(--bg2); }
.pos-sym { font-weight: 600; }
.pos-side { font-size: 0.58rem; }
.pos-side.LONG { color: var(--up); }
.pos-side.SHORT { color: var(--down); }
.pos-pnl { text-align: right; font-weight: 600; }
.pos-close {
  background: transparent;
  border: 1px solid var(--line2);
  border-radius: 4px;
  color: var(--txt3);
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  cursor: pointer;
  transition: 0.12s;
}
.pos-close:hover { border-color: var(--down); color: var(--down); background: var(--down-dim); }
.ticket-body { padding: 0.8rem; }
.ticket-asset { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.7rem; }
.ticket-asset .sym { font-family: var(--mono); font-weight: 700; font-size: 1rem; }
.ticket-asset .px { font-family: var(--mono); margin-left: auto; color: var(--txt2); }
.amt-wrap { position: relative; margin-bottom: 0.5rem; }
.amt-wrap .cur { position: absolute; left: 0.65rem; top: 50%; transform: translateY(-50%); color: var(--txt3); font-family: var(--mono); }
.amt-input {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r-ctrl);
  color: var(--txt1); font-size: 1.05rem; padding: 0.6rem 0.6rem 0.6rem 1.5rem; outline: none;
}
.amt-input:focus { border-color: var(--amber); }
.amt-presets { display: flex; gap: 0.35rem; margin-bottom: 0.7rem; }
.amt-presets button {
  flex: 1; background: var(--bg2); border: 1px solid var(--line); border-radius: 5px;
  color: var(--txt2); font-family: var(--mono); font-size: 0.68rem; padding: 0.3rem 0;
}
.amt-presets button:hover { border-color: var(--line2); color: var(--txt1); }
.trade-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.btn-buy, .btn-short {
  border: none; border-radius: var(--r-ctrl); font-weight: 700; font-size: 0.86rem;
  padding: 0.7rem 0; letter-spacing: 0.03em; transition: 0.12s;
}
.btn-buy { background: var(--up); color: #042a17; }
.btn-short { background: var(--down); color: #2e0606; }
.btn-buy:hover, .btn-short:hover { filter: brightness(1.1); }
.btn-buy:active, .btn-short:active { transform: translateY(1px); }
.close-row { margin-top: 0.45rem; }
.btn-close {
  width: 100%;
  background: transparent;
  border: 1px solid var(--line2);
  border-radius: var(--r-ctrl);
  color: var(--txt3);
  font-family: var(--ui);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.5rem 0;
  transition: 0.15s;
}
.btn-close:hover { border-color: var(--down); color: var(--down); background: var(--down-dim); }
.ticket-est { margin-top: 0.6rem; font-family: var(--mono); font-size: 0.68rem; color: var(--txt3); display: flex; justify-content: space-between; }
.ticket-msg { margin-top: 0.5rem; font-size: 0.72rem; min-height: 1em; }
.ticket-msg.err { color: var(--down); }
.ticket-msg.ok { color: var(--up); }

/* ── News feed ── */
#news-feed { flex: 1; }
.news-item {
  padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--line); border-left: 2px solid var(--txt4);
  animation: newsIn 0.35s ease-out;
}
@keyframes newsIn { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }
.news-item.pos { border-left-color: var(--up); }
.news-item.neg { border-left-color: var(--down); }
.news-meta { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.25rem; }
.news-cat { font-family: var(--mono); font-size: 0.56rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--txt3); }
.news-mag { font-family: var(--mono); font-size: 0.54rem; padding: 0.05rem 0.3rem; border-radius: 999px; background: var(--bg3); color: var(--txt2); margin-left: auto; }
.news-mag.CRITICAL { background: var(--down-dim); color: var(--down); }
.news-mag.MAJOR { background: var(--amber-dim); color: var(--amber); }
.news-head { font-size: 0.8rem; line-height: 1.4; }
.news-affected { font-family: var(--mono); font-size: 0.6rem; color: var(--txt3); margin-top: 0.2rem; }

/* ── Quant Lab ── */
.ql-wrap { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1px; height: 100%; background: var(--line); }
.ql-left, .ql-right { background: var(--bg1); display: flex; flex-direction: column; min-height: 0; }
.ql-toolbar { display: flex; gap: 0.5rem; align-items: center; padding: 0.5rem 0.7rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ql-select, .ql-num {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 5px; color: var(--txt1);
  font-family: var(--mono); font-size: 0.72rem; padding: 0.3rem 0.4rem;
}
.ql-num { width: 64px; }
.ql-code {
  flex: 1; width: 100%; background: #0a0e14; border: none; resize: none; outline: none;
  color: #cfe3f5; font-family: var(--mono); font-size: 0.74rem; line-height: 1.55; padding: 0.7rem;
  tab-size: 2;
}
.ql-blurb { padding: 0.5rem 0.7rem; font-size: 0.72rem; color: var(--txt2); border-bottom: 1px solid var(--line); min-height: 2.5em; }
.ql-results { padding: 0.7rem; overflow: auto; }
.ql-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-ctrl); overflow: hidden; }
.ql-metric { background: var(--bg2); padding: 0.55rem 0.6rem; }
.ql-metric .k { font-family: var(--mono); font-size: 0.58rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--txt3); }
.ql-metric .v { font-family: var(--mono); font-size: 1.05rem; font-weight: 600; margin-top: 0.15rem; }
.ql-actions { display: flex; gap: 0.5rem; padding: 0.5rem 0.7rem; border-top: 1px solid var(--line); }
.btn-amber { background: var(--amber); color: #1a1300; border: none; border-radius: var(--r-ctrl); font-weight: 700; font-size: 0.74rem; padding: 0.45rem 0.9rem; }
.btn-amber:hover { filter: brightness(1.08); }
.btn-danger { background: var(--down); color: #2e0606; border: none; border-radius: var(--r-ctrl); font-weight: 700; font-size: 0.74rem; padding: 0.45rem 0.9rem; }
.btn-danger:hover { filter: brightness(1.08); }
.ql-err { color: var(--down); font-family: var(--mono); font-size: 0.72rem; padding: 0.6rem 0.7rem; white-space: pre-wrap; }
.spark { width: 100%; height: 56px; margin-top: 0.7rem; display: block; }

/* ============================ MODALS / TOASTS =========================== */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 1.5rem;
  background: rgba(3, 5, 9, 0.72); backdrop-filter: blur(6px);
}
.overlay.show { display: flex; }
.modal {
  background: var(--bg1); border: 1px solid var(--line2); border-radius: 14px;
  width: min(460px, 96vw); padding: 1.6rem; box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6);
}
.modal h2 { font-size: 1.4rem; margin-bottom: 0.3rem; }
.modal .sub { color: var(--txt2); font-size: 0.85rem; margin-bottom: 1.2rem; }
.result-stars { font-size: 2rem; color: var(--amber); letter-spacing: 4px; margin: 0.5rem 0 1rem; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-ctrl); overflow: hidden; margin-bottom: 1.3rem; }
.result-cell { background: var(--bg2); padding: 0.7rem 0.8rem; }
.result-cell .k { font-family: var(--mono); font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--txt3); }
.result-cell .v { font-family: var(--mono); font-size: 1.2rem; font-weight: 600; margin-top: 0.2rem; }
.modal-actions { display: flex; gap: 0.7rem; }
.modal-actions button { flex: 1; }

#toast-wrap { position: fixed; top: calc(var(--topbar-h) + 12px); right: 14px; z-index: 120; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; }
.toast {
  background: var(--bg2); border: 1px solid var(--line2); border-left-width: 3px; border-radius: var(--r-ctrl);
  padding: 0.6rem 0.85rem; max-width: 320px; font-size: 0.8rem;
  animation: toastIn 0.3s ease-out; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}
.toast.ok { border-left-color: var(--up); }
.toast.err { border-left-color: var(--down); }
.toast.info { border-left-color: var(--amber); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ============================ TUTORIAL ================================= */
.tut-overlay { position: fixed; inset: 0; z-index: 200; display: none; }
.tut-overlay.show { display: block; }
.tut-overlay::before { content: ""; position: absolute; inset: 0; background: rgba(3, 5, 9, 0.62); }
.tut-spot {
  position: absolute; border-radius: 8px; transition: all 0.25s ease;
  box-shadow: 0 0 0 9999px rgba(3, 5, 9, 0.62), 0 0 0 2px var(--amber);
}
.tut-card {
  position: absolute; width: 320px; background: var(--bg2); border: 1px solid var(--amber);
  border-radius: 12px; padding: 1.1rem; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  transition: all 0.25s ease;
}
.tut-step { font-family: var(--mono); font-size: 0.66rem; color: var(--amber); margin-bottom: 0.4rem; }
.tut-title { font-size: 1.05rem; margin-bottom: 0.4rem; }
.tut-body { color: var(--txt2); font-size: 0.82rem; line-height: 1.55; margin-bottom: 1rem; }
.tut-actions { display: flex; justify-content: space-between; align-items: center; }
.tut-skip { background: none; border: none; color: var(--txt3); font-size: 0.78rem; }
.tut-skip:hover { color: var(--txt1); }
.tut-next { background: var(--amber); color: #1a1300; border: none; border-radius: 6px; font-weight: 700; font-size: 0.8rem; padding: 0.45rem 1rem; }

/* ============================ QUANT PAGE =============================== */
.qp-header {
  flex-shrink: 0;
  padding: 1rem 1.2rem 0.8rem;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
}
.qp-title {
  font-family: var(--ui);
  font-weight: 700;
  font-size: 1.2rem;
  margin-bottom: 0.2rem;
}
.qp-sub {
  color: var(--txt2);
  font-size: 0.78rem;
  margin-bottom: 0.8rem;
}
.qp-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.qp-preset {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  transition: 0.15s;
  white-space: nowrap;
}
.qp-preset:hover {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-dim);
}

.qp-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1px;
  background: var(--line);
  min-height: 0;
}
.qp-left, .qp-right {
  background: var(--bg1);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.qp-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.qp-spacer { flex: 1; }
.qp-hint {
  color: var(--txt3);
  font-size: 0.68rem;
  font-style: italic;
}

/* ── Portfolio Page ── */
.pfp-header {
  flex-shrink: 0;
  padding: 1rem 1.2rem 0.8rem;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
}
.pfp-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  min-height: 0;
  overflow: hidden;
}
.pfp-card {
  background: var(--bg1);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.pfp-card-head {
  flex-shrink: 0;
  padding: 0.6rem 0.9rem;
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--txt3);
  border-bottom: 1px solid var(--line);
}
.pfp-card-body {
  flex: 1;
  overflow: auto;
  padding: 0;
}
.pfp-card:first-child {
  grid-row: 1 / 3;
}
.pfp-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
}
.pfp-stat {
  background: var(--bg2);
  padding: 0.7rem 0.8rem;
}
.pfp-stat-k {
  display: block;
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--txt3);
  margin-bottom: 0.2rem;
}
.pfp-stat-v {
  display: block;
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 600;
}
.pfp-close {
  background: transparent;
  border: 1px solid var(--line2);
  border-radius: 5px;
  color: var(--txt3);
  font-size: 0.75rem;
  padding: 0.15rem 0.4rem;
  cursor: pointer;
  transition: 0.12s;
}
.pfp-close:hover { border-color: var(--down); color: var(--down); background: var(--down-dim); }

/* ── Explore Page ── */
.exp-header {
  flex-shrink: 0;
  padding: 1rem 1.2rem 0.8rem;
  background: var(--bg1);
  border-bottom: 1px solid var(--line);
}
.exp-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.5rem;
  padding: 0.7rem;
  overflow: auto;
  align-content: start;
}
.exp-card {
  background: var(--bg1);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 0.8rem 0.9rem;
  cursor: pointer;
  transition: 0.15s;
}
.exp-card:hover {
  border-color: var(--line2);
  background: var(--bg2);
  transform: translateY(-1px);
}
.exp-sym {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.95rem;
}
.exp-name {
  font-size: 0.72rem;
  color: var(--txt3);
  margin-bottom: 0.4rem;
}
.exp-info {
  display: flex;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}
.exp-tag {
  font-family: var(--mono);
  font-size: 0.54rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  background: var(--bg3);
  color: var(--txt2);
}
.exp-price {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.exp-detail {
  display: flex;
  gap: 0.6rem;
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--txt3);
}

/* ============================ MOBILE NAV =============================== */
#mobile-nav { display: none; }

/* ============================ RESPONSIVE =============================== */
@media (max-width: 1100px) {
  #desk { grid-template-columns: 190px 1fr 270px; }
}

#dock-trade-tabs { display: none; }

/* ── Mobile layout: < 900px ── */
@media (max-width: 900px) {
  #main-content { margin-left: 0; }

  /* ── Sidebar becomes an overlay ── */
  #sidebar {
    z-index: 70;
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.5);
    padding: 0.6rem 0.5rem;
  }
  body.sb-open #sidebar {
    transform: translateX(0);
  }
  body.sb-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 65;
    background: rgba(3, 5, 9, 0.55);
    backdrop-filter: blur(3px);
    animation: fadeIn 0.2s ease-out;
  }
  @keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .sb-brand { font-size: 1.2rem; padding: 0.3rem 0 0.8rem; }
  .sb-btn { padding: 0.5rem 0.7rem; font-size: 0.85rem; }
  #sb-back { margin-top: auto; }

  /* ── Top bar ── */
  #top-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 0.3rem;
    padding: 0 0.4rem;
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  #top-bar::-webkit-scrollbar { display: none; }
  .tb-objective { display: none; }
  #speed-group { display: flex; flex-shrink: 0; }
  .speed-group button { padding: 0.3rem 0.4rem; font-size: 0.6rem; }
  .tb-sep { display: none; }
  #regime-chip .lbl,
  #tick-chip .lbl,
  #clock-chip .lbl { display: none; }
  .pf-group { gap: 0.4rem; }
  .pf-lbl { display: none; }
  .pf-val { font-size: 0.72rem; }
  .pf-pnl { font-size: 0.65rem; }
  #pf-value { display: none; }
  #pf-invested .pf-val { font-size: 0.65rem; }
  #pf-equity .pf-val { font-size: 0.8rem; }
  .icon-btn { width: 28px; height: 28px; font-size: 0.8rem; flex-shrink: 0; }
  .chip { font-size: 0.6rem; padding: 0.15rem 0.35rem; flex-shrink: 0; }
  .tb-menu { display: flex !important; }
  #clock-chip { display: none; }

  /* ── Trade desk: single column with tab switching ── */
  #desk {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    gap: 0;
    background: var(--bg0);
  }
  .col { display: none; }
  .col.m-active { display: flex; }

  /* col-left and col-right become full-view panels controlled by the dock tabs */
  #dock-trade-tabs {
    display: flex;
    flex-shrink: 0;
    border-bottom: 1px solid var(--line);
    background: var(--bg1);
    overflow-x: auto;
    scrollbar-width: none;
  }
  #dock-trade-tabs::-webkit-scrollbar { display: none; }
  .dock-trade-tab {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    color: var(--txt3);
    font-family: var(--mono);
    font-size: 0.58rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.55rem 0.4rem;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
  }
  .dock-trade-tab:hover { color: var(--txt1); }
  .dock-trade-tab.sel {
    color: var(--amber);
    border-bottom-color: var(--amber);
  }

  /* ── Chart on mobile ── */
  .chart-head { padding: 0.4rem 0.5rem; gap: 0.35rem; flex-wrap: nowrap; }
  .ch-sym { font-size: 0.85rem; }
  .ch-price { font-size: 1rem; }
  .ch-chg { font-size: 0.7rem; }
  .ch-ohlc { display: none; }
  .ema-legend { display: none; }
  #chart-wrap { min-height: 200px; }
  .ch-name { display: none; }

  /* ── Watchlist panel ── */
  #col-left .panel { flex: 1; }
  .wl-row { padding: 0.35rem 0.55rem; }
  .wl-sym { font-size: 0.75rem; }
  .wl-price { font-size: 0.72rem; }

  /* ── Order ticket ── */
  #col-right .panel { flex: none; }
  #news-feed { flex: 1; min-height: 80px; }
  #positions-panel { max-height: 140px; }
  .ticket-body { padding: 0.5rem; }
  .amt-input { font-size: 0.9rem; padding: 0.45rem 0.5rem 0.45rem 1.3rem; }
  .btn-buy, .btn-short { font-size: 0.75rem; padding: 0.55rem 0; }
  .ticket-asset .sym { font-size: 0.85rem; }

  /* ── Quant page mobile ── */
  .qp-header { padding: 0.7rem 0.8rem; }
  .qp-title { font-size: 1rem; }
  .qp-sub { font-size: 0.72rem; }
  .qp-quick { gap: 0.3rem; }
  .qp-preset { font-size: 0.65rem; padding: 0.3rem 0.6rem; }
  .qp-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow: auto;
  }
  .qp-left { min-height: 180px; }
  .qp-right { min-height: 200px; }
  .ql-code { font-size: 0.65rem; min-height: 100px; }
  .ql-toolbar { font-size: 0.6rem; padding: 0.35rem 0.5rem; }
  .ql-select, .ql-num { font-size: 0.65rem; padding: 0.25rem 0.3rem; }
  .ql-metrics { grid-template-columns: 1fr 1fr; }
  .ql-metric { padding: 0.4rem 0.45rem; }
  .ql-metric .v { font-size: 0.85rem; }
  .ql-blurb { font-size: 0.65rem; padding: 0.4rem 0.5rem; }
  .ql-results { padding: 0.5rem; }
  .qp-actions { padding: 0.4rem 0.5rem; flex-wrap: wrap; }

  /* ── Portfolio page mobile ── */
  .pfp-header { padding: 0.7rem 0.8rem; }
  .pfp-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    overflow: auto;
  }
  .pfp-card:first-child { grid-row: auto; }
  .pfp-card-head { padding: 0.45rem 0.65rem; font-size: 0.58rem; }
  .pfp-stat { padding: 0.5rem 0.6rem; }
  .pfp-stat-k { font-size: 0.52rem; }
  .pfp-stat-v { font-size: 0.85rem; }

  /* ── Explore page mobile ── */
  .exp-header { padding: 0.7rem 0.8rem; }
  .exp-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.4rem;
    padding: 0.5rem;
  }
  .exp-card { padding: 0.6rem; }
  .exp-sym { font-size: 0.85rem; }
  .exp-price { font-size: 0.85rem; }

  /* ── Tables ── */
  .data-table { font-size: 0.6rem; }
  .data-table th,
  .data-table td { padding: 0.25rem 0.35rem; }

  /* ── Mobile nav ── */
  #mobile-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 60;
    background: var(--bg1); border-top: 1px solid var(--line2);
    height: 52px;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  #mobile-nav button {
    background: none; border: none; color: var(--txt3);
    font-family: var(--mono); font-size: 0.45rem; letter-spacing: 0.02em;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    padding: 2px 0;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
  }
  #mobile-nav button .ic {
    font-size: 1.1rem;
    line-height: 1;
  }
  #mobile-nav button.sel { color: var(--amber); }
  #mobile-nav button:active { opacity: 0.6; }

  /* ── Terminal container respects mobile nav ── */
  .page { padding-bottom: calc(52px + env(safe-area-inset-bottom, 0)); }

  /* ── Setup screen ── */
  .setup-inner { padding: 1.2rem 0.8rem 6rem; }
  .scenario-grid { grid-template-columns: 1fr; gap: 0.5rem; }
  .su-config-body { grid-template-columns: 1fr; padding: 0.8rem; }
  .su-lambda { font-size: 1.8rem; }
  .su-title { font-size: 1.3rem; }
  .su-sub { font-size: 0.78rem; }
  .su-hero { margin-bottom: 1.5rem; }
  .su-btn-primary { width: 100%; justify-content: center; display: flex; }
  .chip-btn { font-size: 0.68rem; padding: 0.35rem 0.4rem; min-width: 36px; }
  .scn-card { padding: 0.8rem 0.8rem 0.65rem; }

  /* ── Modal ── */
  .modal { width: 90vw; padding: 1rem; }
  .result-stars { font-size: 1.3rem; }
  .result-grid { grid-template-columns: 1fr 1fr; }
  .result-cell { padding: 0.45rem; }
  .result-cell .v { font-size: 0.9rem; }

  /* ── Toast ── */
  #toast-wrap { top: calc(var(--topbar-h) + 4px); right: 6px; }
  .toast { max-width: 220px; font-size: 0.68rem; padding: 0.4rem 0.55rem; }
}

/* ── Small phones ── */
@media (max-width: 420px) {
  #top-bar { min-height: 40px; padding: 0 0.25rem; gap: 0.2rem; }
  .chip { font-size: 0.5rem; padding: 0.1rem 0.2rem; }
  .pf-val { font-size: 0.62rem; }
  .pf-pnl { font-size: 0.55rem; }
  .pf-group { gap: 0.3rem; }
  #pf-invested .pf-val { font-size: 0.55rem; }
  #pf-equity .pf-val { font-size: 0.7rem; }
  #mobile-nav { height: 44px; }
  #mobile-nav button { font-size: 0.38rem; }
  #mobile-nav button .ic { font-size: 0.9rem; }
  .page { padding-bottom: calc(44px + env(safe-area-inset-bottom, 0)); }
  .ch-price { font-size: 0.85rem; }
  .ch-sym { font-size: 0.75rem; }
  .chart-head { padding: 0.3rem 0.4rem; }
  #chart-wrap { min-height: 150px; }
  .speed-group button { font-size: 0.5rem; padding: 0.2rem 0.3rem; }
  .chip-btn { font-size: 0.6rem; padding: 0.25rem 0.3rem; min-width: 30px; }
  .su-lambda { font-size: 1.5rem; }
  .su-title { font-size: 1.1rem; }
  .exp-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}


