:root {
  --bg: #0c0f0e;
  --panel: #121716;
  --panel-2: #171d1b;
  --line: #222b28;
  --line-strong: #2f3b37;
  --text: #e4e9e6;
  --text-2: #9aa5a0;
  --text-3: #66726d;
  --green: #3fbf7f;
  --green-soft: rgba(63, 191, 127, 0.14);
  --green-dim: #2b7f56;
  --amber: #d9a441;
  --red: #d95c5c;
  --blue: #5aa9e6;
  --violet: #9b8bd9;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--green); text-decoration: none; }
b { font-weight: 600; color: var(--text); }
.num, .quote .px, .sig .v, .tile .v, td, .line .ts, .conf .v, .backlog .p { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.topbar {
  position: relative; z-index: 2;
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 32px; align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--green); }
.mark { width: 32px; height: 32px; }
.word { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; color: var(--text); line-height: 1; text-transform: capitalize; }
.tag { color: var(--text-3); font-size: 12px; margin-top: 3px; }

.quote { display: flex; align-items: baseline; gap: 10px; }
.quote .sym { color: var(--text-2); font-weight: 500; }
.quote .px { font-size: 20px; font-weight: 600; color: var(--text); transition: color .25s; }
.quote .px.flash-up { color: var(--green); }
.quote .px.flash-down { color: var(--red); }
.quote .chg { font-weight: 500; font-size: 12px; }
.chg.up { color: var(--green); } .chg.down { color: var(--red); }

.pipeline { display: flex; gap: 4px; list-style: none; margin: 0; padding: 3px; justify-content: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; width: max-content; justify-self: center; }
.pipeline li {
  padding: 5px 12px; border-radius: 999px; color: var(--text-3);
  font-size: 11px; font-weight: 500; letter-spacing: .02em; text-transform: capitalize;
  transition: all .2s;
}
.pipeline li.done { color: var(--text-2); }
.pipeline li.on { color: var(--bg); background: var(--green); font-weight: 600; }

.status { text-align: right; font-size: 12px; color: var(--text-2); }
.led-row { display: flex; align-items: center; justify-content: flex-end; gap: 8px; font-weight: 500; color: var(--text); text-transform: capitalize; }
.led { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.led.on { background: var(--green); }
.led.off { background: var(--red); }
.meta { margin-top: 3px; color: var(--text-3); }
.meta b { color: var(--text-2); font-weight: 500; }
.sep { margin: 0 6px; color: var(--line-strong); }

/* ---------- grid ---------- */
.grid {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) minmax(360px, 1fr);
  grid-template-areas:
    "chart mind"
    "treasury decision"
    "ledger build";
  gap: 16px;
  padding: 20px 28px 12px;
}
.chart-panel { grid-area: chart; }
.mind { grid-area: mind; }
.decision { grid-area: decision; }
.treasury { grid-area: treasury; }
.ledger { grid-area: ledger; }
.build { grid-area: build; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  position: relative;
  display: flex; flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: baseline; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.ph-title { color: var(--text); font-weight: 600; text-transform: capitalize; }
.ph-sub { color: var(--text-3); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ph-right { margin-left: auto; color: var(--text-3); font-size: 11px; }
.legend i { display: inline-block; width: 12px; height: 2px; vertical-align: middle; margin: 0 5px 0 10px; border-radius: 1px; }
.l-ema9 { background: var(--green); }
.l-ema21 { background: var(--green-dim); }
.l-buy { background: var(--blue); height: 8px !important; width: 8px !important; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.l-burn { background: var(--amber); height: 8px !important; width: 8px !important; border-radius: 2px; }
.l-deep { background: var(--violet); height: 8px !important; width: 8px !important; border-radius: 50%; }
.chk { cursor: pointer; user-select: none; }
.chk input { accent-color: var(--green); vertical-align: middle; }

/* ---------- chart ---------- */
.chart-wrap { position: relative; flex: 1; min-height: 380px; }
#chart { width: 100%; height: 100%; display: block; }
.hud {
  position: absolute; top: 10px; left: 14px; pointer-events: none;
  font-family: var(--mono); font-size: 11px; color: var(--text-3); white-space: pre; line-height: 1.5;
}
.hud b { color: var(--text-2); font-weight: 500; }
.phase-detail {
  position: absolute; right: 14px; bottom: 12px; pointer-events: none;
  font-size: 11px; color: var(--text-2);
  padding: 4px 10px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel-2);
}
.phase-detail::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--green); margin-right: 7px; vertical-align: 1px; }
.signals {
  display: grid; grid-template-columns: repeat(8, 1fr);
  border-top: 1px solid var(--line);
}
.sig { padding: 10px 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.sig:last-child { border-right: 0; }
.sig .k { font-size: 11px; color: var(--text-3); }
.sig .v { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; }
.sig .v.good { color: var(--green); } .sig .v.bad { color: var(--red); } .sig .v.warn { color: var(--amber); }
.bar { display: block; height: 3px; background: var(--line); position: relative; overflow: hidden; border-radius: 2px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--green); transition: width .5s; }

/* ---------- mind ---------- */
.mind { min-height: 420px; }
.stream {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  font-family: var(--mono); font-size: 12px; line-height: 1.65;
  scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
  max-height: 560px;
}
.line { display: grid; grid-template-columns: 58px 34px 1fr; gap: 10px; align-items: baseline; padding: 1px 0; animation: fadein .2s; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.line .ts { color: var(--text-3); font-size: 11px; }
.line .src { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.line .txt { white-space: pre-wrap; word-break: break-word; color: var(--text-2); }
.line.system .src { color: var(--text-3); }
.line.reflex .src { color: var(--green); }
.line.cortex .src { color: var(--blue); }
.line.cortex .txt { color: var(--text); }
.line.cortex.thinking .txt { color: var(--text-3); font-style: italic; }
.line.build .src { color: var(--violet); }
.line.log .src { color: var(--amber); }
.line.log.error .txt { color: var(--red); }
.line.action .src { color: var(--amber); }
.line.action .txt { color: var(--text); font-weight: 500; }
.line.decision .src { color: var(--text-2); }
.line.decision .txt { color: var(--text); font-weight: 500; }
.line.shipped .txt { color: var(--violet); }
.cursor { display: inline-block; width: 6px; height: 12px; background: var(--text-2); vertical-align: -2px; margin-left: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
body.hide-thinking .line.thinking { display: none; }

/* ---------- decision ---------- */
.dec-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.dec-action { font-size: 22px; font-weight: 600; text-transform: capitalize; color: var(--green); line-height: 1.2; }
.dec-action.refused { color: var(--red); }
.dec-action.hold { color: var(--text-2); }
.dec-action small { font-size: 11px; font-weight: 500; color: var(--text-3); margin-left: 10px; vertical-align: middle; text-transform: none; }
.dec-size { color: var(--text); font-weight: 500; min-height: 1.2em; font-family: var(--mono); font-size: 12px; }
.conf { display: grid; grid-template-columns: 76px 1fr 44px; gap: 10px; align-items: center; }
.conf .k { font-size: 11px; color: var(--text-3); }
.conf .v { text-align: right; font-weight: 500; font-size: 12px; }
.dec-reason { color: var(--text); border-left: 2px solid var(--green); padding-left: 10px; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 11px; }
.checks li { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.checks li::before { content: "✓ "; color: var(--green); }
.checks li.fail { color: var(--red); }
.checks li.fail::before { content: "✕ "; color: var(--red); }

/* ---------- treasury ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); }
.tile { padding: 14px 16px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.tile:nth-child(3n) { border-right: 0; }
.tile .k { font-size: 11px; color: var(--text-3); }
.tile .v { font-size: 20px; font-weight: 500; color: var(--text); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .u { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.tile.hot .v { color: var(--amber); }
.counts { padding: 10px 16px; color: var(--text-3); font-size: 11px; }

/* ---------- ledger ---------- */
.table-wrap { overflow: auto; max-height: 260px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; font-size: 11px; color: var(--text-3); padding: 9px 14px; border-bottom: 1px solid var(--line); font-weight: 500; position: sticky; top: 0; background: var(--panel); }
td { padding: 8px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; color: var(--text-2); }
tr.empty td { color: var(--text-3); text-align: center; padding: 24px; font-family: var(--sans); }
td.kind { font-weight: 600; text-transform: capitalize; font-family: var(--sans); }
td.kind.buyback { color: var(--blue); } td.kind.burn { color: var(--amber); } td.kind.deepen { color: var(--violet); }
td .st { padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 500; text-transform: capitalize; font-family: var(--sans); background: var(--panel-2); border: 1px solid var(--line-strong); }
td .st.filled { color: var(--green); border-color: transparent; background: var(--green-soft); }
td .st.submitted { color: var(--amber); }
td .st.failed { color: var(--red); }
td.ref { color: var(--text-3); }
tr.new td { animation: rowflash 1.2s ease-out; }
@keyframes rowflash { from { background: var(--green-soft); } to { background: transparent; } }

/* ---------- backlog ---------- */
.backlog { list-style: none; margin: 0; padding: 6px 0; }
.backlog li { padding: 10px 16px; display: grid; grid-template-columns: 72px 1fr 40px; gap: 12px; align-items: center; border-bottom: 1px solid var(--line); }
.backlog li:last-child { border-bottom: 0; }
.backlog .st { font-size: 10px; font-weight: 500; padding: 2px 8px; border-radius: 999px; text-align: center; color: var(--text-2); background: var(--panel-2); border: 1px solid var(--line-strong); text-transform: capitalize; }
.backlog .st.building { color: var(--green); background: var(--green-soft); border-color: transparent; }
.backlog .st.shipped { color: var(--violet); }
.backlog .t { font-weight: 500; color: var(--text); }
.backlog .w { color: var(--text-3); font-size: 11px; }
.backlog .bar { margin-top: 6px; }
.backlog .p { text-align: right; color: var(--text-3); font-size: 11px; }

/* ---------- footer ---------- */
.foot { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 20px; padding: 10px 28px 20px; color: var(--text-3); font-size: 11px; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .pipeline { grid-column: 1 / -1; justify-self: start; }
  .grid { grid-template-columns: 1fr; grid-template-areas: "chart" "mind" "decision" "treasury" "ledger" "build"; }
  .signals { grid-template-columns: repeat(4, 1fr); }
  .sig:nth-child(4) { border-right: 0; }
  .sig:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; gap: 14px; }
  .grid { padding: 14px 16px; }
  .chart-wrap { min-height: 280px; }
  .signals { grid-template-columns: repeat(2, 1fr); }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile:nth-child(3n) { border-right: 1px solid var(--line); }
  .tile:nth-child(2n) { border-right: 0; }
  .status { display: none; }
  .checks { grid-template-columns: 1fr; }
  .legend, .hud { display: none; }
  .pipeline li { padding: 4px 9px; }
  .quote .px { font-size: 17px; }
  .sig .v { font-size: 13px; }
  .tile .v { font-size: 17px; }
}
