:root {
  --bg: #f2f6f5;
  --surface: rgba(249, 251, 250, .92);
  --surface-2: rgba(236, 244, 242, .75);
  --ink: #173333;
  --muted: #718382;
  --line: #b8cbc7;
  --line-strong: #6e918c;
  --cyan: #258fa3;
  --teal: #2ba99c;
  --blue: #316fc4;
  --violet: #7657cb;
  --pink: #c95e86;
  --amber: #c49342;
  --red: #d05a69;
  --green: #3f9f86;
  --boost: #d7ff38;
  --shadow: rgba(22, 54, 52, .08);
  --surface-solid: #f8fbfa;
  --surface-tint: rgba(255, 255, 255, .5);
  --surface-glass: rgba(248, 251, 250, .87);
  --code-bg: #eaf1ef;
  --code-ink: #24403e;
  --on-ink: #f5faf9;
  --grid-line: rgba(58, 95, 91, .035);
  --scan-color: rgba(20, 70, 65, .025);
  --scan-blend: multiply;
  color-scheme: light;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Dark palette. Declared twice on purpose: once for the explicit toggle, once
   for the OS preference when no choice has been stored. The toggle wins. */
:root[data-theme="dark"] {
  --bg: #0b1211;
  --surface: rgba(17, 26, 25, .92);
  --surface-2: rgba(26, 38, 36, .75);
  --ink: #dfe9e7;
  --muted: #8a9c99;
  --line: #253230;
  --line-strong: #4a6561;
  --cyan: #3fb0c4;
  --teal: #3fc1b2;
  --blue: #6a9be6;
  --violet: #9d84e3;
  --pink: #de84a6;
  --amber: #dcae5c;
  --red: #e37c8b;
  --green: #5cbf9f;
  --shadow: rgba(0, 0, 0, .5);
  --surface-solid: #131c1b;
  --surface-tint: rgba(255, 255, 255, .04);
  --surface-glass: rgba(17, 26, 25, .88);
  --code-bg: #0e1615;
  --code-ink: #b8cbc7;
  --on-ink: #0b1211;
  --grid-line: rgba(140, 180, 175, .055);
  --scan-color: rgba(140, 180, 175, .04);
  --scan-blend: screen;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #0b1211;
  --surface: rgba(17, 26, 25, .92);
  --surface-2: rgba(26, 38, 36, .75);
  --ink: #dfe9e7;
  --muted: #8a9c99;
  --line: #253230;
  --line-strong: #4a6561;
  --cyan: #3fb0c4;
  --teal: #3fc1b2;
  --blue: #6a9be6;
  --violet: #9d84e3;
  --pink: #de84a6;
  --amber: #dcae5c;
  --red: #e37c8b;
  --green: #5cbf9f;
  --shadow: rgba(0, 0, 0, .5);
  --surface-solid: #131c1b;
  --surface-tint: rgba(255, 255, 255, .04);
  --surface-glass: rgba(17, 26, 25, .88);
  --code-bg: #0e1615;
  --code-ink: #b8cbc7;
  --on-ink: #0b1211;
  --grid-line: rgba(140, 180, 175, .055);
  --scan-color: rgba(140, 180, 175, .04);
  --scan-blend: screen;
  color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--bg);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .25;
  background-image: repeating-linear-gradient(0deg, var(--scan-color) 0 1px, transparent 1px 4px);
  mix-blend-mode: var(--scan-blend);
}

.app-shell { width: min(1680px, calc(100% - 24px)); margin: 12px auto 28px; }

.frame-corners { position: relative; }
.frame-corners::before, .frame-corners::after {
  content: ""; position: absolute; width: 14px; height: 14px; pointer-events: none; z-index: 3;
}
.frame-corners::before { left: -1px; top: -1px; border-left: 2px solid var(--line-strong); border-top: 2px solid var(--line-strong); }
.frame-corners::after { right: -1px; bottom: -1px; border-right: 2px solid var(--line-strong); border-bottom: 2px solid var(--line-strong); }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  padding: 16px 18px; border: 1px solid var(--line); background: var(--surface);
}
.brand-row { display: flex; gap: 14px; align-items: center; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line-strong); color: white; background: var(--blue); font-size: 24px; }
.eyebrow { color: var(--muted); font-size: 10px; letter-spacing: .22em; }
h1 { margin: 2px 0 0; font-size: clamp(17px, 2vw, 27px); letter-spacing: .06em; font-weight: 650; }
.session-block { text-align: right; font-size: 10px; line-height: 1.55; }
.clock { font-size: 20px; letter-spacing: .09em; }
.muted { color: var(--muted); }

.ticker {
  display: flex; align-items: center; gap: 26px; overflow: hidden; white-space: nowrap;
  height: 38px; padding: 0 14px; border: 1px solid var(--line); border-top: 0; background: var(--surface-glass);
  color: var(--muted); font-size: 10px; letter-spacing: .05em;
}
.ticker-label { align-self: stretch; display: flex; align-items: center; margin-left: -14px; padding: 0 14px; background: rgba(49,111,196,.08); color: var(--blue); border-right: 1px solid var(--line); }
.ticker b { color: var(--ink); font-weight: 600; }
.ticker i { font-style: normal; }
.up, .positive { color: var(--teal) !important; }
.amber { color: var(--amber) !important; }

.metrics-strip {
  display: grid; grid-template-columns: 1.25fr repeat(4, 1fr); border: 1px solid var(--line); border-top: 0; background: var(--surface);
}
.metric { padding: 15px 18px; min-width: 0; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric .label { display: block; color: var(--muted); font-size: 10px; letter-spacing: .1em; margin-bottom: 5px; }
.metric strong { display: block; font-size: clamp(22px, 2.6vw, 37px); font-weight: 500; letter-spacing: -.04em; white-space: nowrap; }
.metric strong em { color: var(--muted); font-size: .52em; font-style: normal; }
.metric small { color: var(--muted); font-size: 9px; }

.dashboard-grid {
  display: grid; grid-template-columns: 1.05fr .95fr 1.05fr; grid-template-rows: minmax(520px, 1.15fr) 260px; gap: 12px; margin-top: 12px;
}
.panel { border: 1px solid var(--line-strong); background: var(--surface); min-width: 0; overflow: hidden; box-shadow: 0 8px 26px var(--shadow); }
.panel-vortex { grid-column: 1 / 3; }
.panel-market { grid-column: 3; }
.compact { min-height: 240px; }
.panel-head { height: 42px; padding: 0 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 700; letter-spacing: .06em; }
.index { color: var(--blue); font-size: 9px; margin-right: 9px; }
.tag { padding: 4px 7px; border: 1px solid rgba(49,111,196,.22); color: var(--blue); background: rgba(49,111,196,.05); font-size: 8px; font-weight: 500; }
.tag-green { color: var(--teal); border-color: rgba(43,169,156,.26); background: rgba(43,169,156,.05); }
.tag-red { color: var(--red); border-color: rgba(208,90,105,.24); background: rgba(208,90,105,.05); }
.tag-amber { color: var(--amber); border-color: rgba(196,147,66,.28); background: rgba(196,147,66,.06); }

.panel-body { position: relative; }
.vortex-body { height: 365px; }
.vortex-body canvas { width: 100%; height: 100%; display: block; }
.section-note { position: absolute; top: 14px; left: 14px; z-index: 2; color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.callout { position: absolute; z-index: 2; width: 128px; padding: 8px 10px; border: 1px solid var(--line-strong); background: var(--surface-glass); }
.callout span { display: block; color: var(--muted); font-size: 7px; letter-spacing: .08em; }
.callout b { display: block; margin-top: 3px; color: var(--blue); font-size: 13px; font-weight: 500; }
.callout-left { left: 18px; top: 150px; }
.callout-right { right: 18px; top: 205px; }
.axis-label { position: absolute; right: 18px; top: 18px; text-align: right; color: var(--muted); font-size: 8px; line-height: 1.6; }

.graph-strip { position: relative; height: 152px; border-top: 1px solid var(--line); padding: 10px 14px 0; }
.graph-strip svg { width: 100%; height: 112px; display: block; }
.mini-title { color: var(--muted); font-size: 8px; letter-spacing: .1em; }
.graph-stats { position: absolute; right: 16px; top: 42px; display: grid; gap: 5px; color: var(--muted); font-size: 8px; }
.graph-stats b { color: var(--ink); font-size: 14px; font-weight: 500; margin-right: 6px; }

.panel-foot { border-top: 1px solid var(--line); min-height: 38px; display: grid; align-items: center; color: var(--muted); font-size: 8px; }
.panel-foot.quad { grid-template-columns: repeat(4,1fr); }
.panel-foot.quad span { padding: 0 14px; border-right: 1px solid var(--line); }
.panel-foot.quad span:last-child { border-right: 0; }
.panel-foot b { color: var(--teal); font-size: 11px; font-weight: 500; margin-left: 6px; }
.panel-foot.split { grid-template-columns: 1fr 1fr; padding: 0 14px; }
.panel-foot.split span:last-child { text-align: right; }

.market-header { display: flex; justify-content: space-between; padding: 16px 14px 0; }
.price { color: var(--red); font-size: clamp(32px, 3vw, 50px); letter-spacing: -.045em; }
.tiny { font-size: 9px; }
.ohlc { text-align: right; color: var(--muted); font-size: 8px; line-height: 1.7; }
#marketCanvas { width: 100%; height: 390px; display: block; }

.profit-wrap { padding: 14px 14px 8px; }
.profit-number { color: var(--blue); font-size: 24px; }
.profit-number small { color: var(--muted); font-size: 8px; }
#profitChart { width: 100%; height: 170px; margin-top: 5px; }

.trace-wrap { padding: 14px; }
#traceChart { width: 100%; height: 175px; display: block; margin-top: 8px; }
.execution-list { padding: 8px 14px; font-size: 9px; }
.execution-row { display: grid; grid-template-columns: 64px 50px 1fr auto; gap: 7px; padding: 6px 0; border-bottom: 1px solid rgba(110,145,140,.15); }
.execution-row .agent { color: var(--blue); font-weight: 700; }
.execution-row .gain { color: var(--teal); }
.execution-row .loss { color: var(--red); }

.agents-section { margin-top: 12px; }
.section-heading { display: flex; justify-content: space-between; padding: 0 2px 8px; font-size: 10px; font-weight: 700; letter-spacing: .1em; }
.section-heading span { color: var(--muted); font-weight: 400; }
.agent-grid { display: grid; grid-template-columns: repeat(6,1fr); gap: 8px; }
.agent-card { position: relative; overflow: hidden; min-height: 205px; border: 1px solid var(--line); background: var(--surface); padding: 10px 10px 0; }
.agent-card::before { content: ""; position: absolute; left: 0; top: 0; right: 0; height: 2px; background: var(--agent-color); }
.agent-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 8px; }
.agent-orb { width: 58px; height: 58px; margin: 15px auto 8px; border-radius: 50%; display: grid; place-items: center; position: relative; border: 1px solid color-mix(in srgb, var(--agent-color) 50%, var(--line)); background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--agent-color) 48%, transparent), rgba(7,18,18,.96) 45%, #050a0a 68%); box-shadow: inset 0 0 0 6px rgba(255,255,255,.025), 0 0 0 1px rgba(255,255,255,.06); }
.agent-orb::after { content:""; width: 18px; height: 18px; border: 1px dashed color-mix(in srgb, var(--agent-color) 70%, white); border-radius: 50%; }
.agent-name { text-align: center; color: var(--agent-color); font-size: 16px; letter-spacing: .08em; }
.agent-role { min-height: 26px; text-align: center; color: var(--muted); font-size: 8px; text-transform: uppercase; margin-top: 3px; }
.agent-credit { display: flex; justify-content: space-between; margin-top: 10px; color: var(--muted); font-size: 7px; }
.agent-pnl { text-align: center; margin-top: 4px; color: var(--agent-color); font-size: 22px; }
.agent-spark { height: 38px; margin-top: 4px; border-top: 1px solid rgba(110,145,140,.18); }
.agent-spark svg { width: 100%; height: 100%; display: block; }

.system-footer { margin-top: 9px; border: 1px solid var(--line); background: rgba(20,45,44,.84); color: #c8d7d3; min-height: 36px; display: grid; grid-template-columns: 160px 1fr 160px; align-items: center; padding: 0 12px; font-size: 8px; letter-spacing: .07em; }
.system-footer span:nth-child(2) { text-align: center; color: #9fb3ae; }
.system-footer span:last-child { text-align: right; }
.theme-toggle { appearance: none; cursor: pointer; background: transparent; color: var(--muted); border: 1px solid var(--line); font: 9px var(--mono); letter-spacing: .11em; text-transform: uppercase; padding: 7px 9px; }
.theme-toggle:hover, .theme-toggle:focus-visible { color: var(--ink); background: var(--surface-2); outline: none; }

.status-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; background: var(--muted); }
.status-dot.live { background: var(--blue); box-shadow: 0 0 0 3px rgba(49,111,196,.1); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(63,159,134,.16); }

@media (max-width: 1180px) {
  .dashboard-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto; }
  .panel-vortex { grid-column: 1 / -1; }
  .panel-market { grid-column: auto; }
  .agent-grid { grid-template-columns: repeat(3,1fr); }
  .metrics-strip { grid-template-columns: repeat(2, 1fr); }
  .metric { border-bottom: 1px solid var(--line); }
}

@media (max-width: 720px) {
  .app-shell { width: calc(100% - 12px); margin-top: 6px; }
  .topbar { align-items: flex-start; }
  .session-block { display: none; }
  .ticker { gap: 18px; }
  .metrics-strip, .dashboard-grid, .agent-grid { grid-template-columns: 1fr; }
  .panel-vortex, .panel-market { grid-column: auto; }
  .panel-foot.quad { grid-template-columns: repeat(2,1fr); row-gap: 7px; padding: 8px 0; }
  .system-footer { grid-template-columns: 1fr; gap: 4px; padding: 8px 12px; }
  .system-footer span, .system-footer span:nth-child(2), .system-footer span:last-child { text-align: left; }
}
