:root {
  --bg: #0e1116;
  --card: #171b22;
  --card-2: #1e2430;
  --border: #2c3442;
  --text: #e8edf5;
  --muted: #8b95a8;
  --green: #3dd68c;
  --red: #ff6b6b;
  --amber: #f5b942;
  --blue: #8eb4ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
  max-width: 1100px;
  margin: 0 auto;
}
button, input, select { font: inherit; color: inherit; }
h1, h2 { font-weight: 650; letter-spacing: -0.02em; }
h2 { font-size: 0.95rem; margin: 0 0 10px; }
.note, .lede { color: var(--muted); font-size: 0.9rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

.hero, .card, .gate-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.hero { margin-bottom: 12px; }
.hero-top, .meta-row, .pnl-row, .brand {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.hero-top {
  justify-content: space-between;
  flex-wrap: nowrap;
  align-items: flex-start;
}
.hero-top > div:first-child { min-width: 0; flex: 1; }
.breaker small { overflow-wrap: anywhere; }
.brand { font-weight: 650; }
.equity {
  font-size: 2.1rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  margin: 8px 0 4px;
}
.pnl-row { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.pnl-row .pos { color: var(--green); }
.pnl-row .neg { color: var(--red); }
#spark { width: 100%; height: 72px; display: block; margin-top: 8px; }
.meta-row { margin-top: 6px; color: var(--muted); font-size: 0.82rem; }

.pill, .badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--card-2);
  color: var(--muted);
}
.pill.quiet { text-transform: none; letter-spacing: 0; }
.breaker {
  margin-top: 6px;
  font-size: 0.92rem;
}
.breaker.normal { color: var(--green); }
.breaker.halted { color: var(--amber); }
.breaker.shutdown { color: var(--red); }
.breaker small { display: block; color: var(--muted); font-size: 0.78rem; }

.ghost, .text-btn, form button, .tabs button {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card-2);
  min-height: 40px;
  padding: 8px 12px;
}
.ghost, .text-btn { cursor: pointer; }
.text-btn { border: 0; background: transparent; color: var(--blue); min-height: 32px; padding: 0 6px; }
form button[type="submit"] {
  width: 100%;
  background: var(--blue);
  color: #0e1116;
  font-weight: 700;
  border: 0;
  cursor: pointer;
}
.stale, .banner {
  color: #1a1405;
  background: var(--amber);
  border-radius: 8px;
  padding: 6px 8px;
}
.banner { margin-top: 8px; }

.alloc-bar {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--card-2);
  margin-top: 12px;
}
.alloc-bar span { display: block; height: 100%; }
.seg-cash { background: #6ea8fe; }
.seg-pending { background: var(--amber); }
.seg-pos { background: var(--green); }
.legend { display: flex; flex-wrap: wrap; gap: 10px 14px; margin-top: 8px; font-size: 0.8rem; color: var(--muted); }
.legend b { color: var(--text); font-weight: 600; }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background: #12161d;
  border-top: 1px solid var(--border);
  z-index: 5;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  flex: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  min-height: 52px;
  cursor: pointer;
}
.tabs button.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--blue); }

.tab { display: none; }
.tab.active { display: block; }
.card { margin-bottom: 12px; }
.card h2 .count { color: var(--muted); font-weight: 500; }
.split { display: grid; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
}
.row:first-child { border-top: 0; padding-top: 0; }
.row .sub { color: var(--muted); font-size: 0.8rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.empty { color: var(--muted); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
}
.badge.buy { color: var(--green); }
.badge.sell { color: var(--red); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 550; }

.log-tools { display: flex; gap: 8px; margin-bottom: 8px; }
.log-tools select, .log-tools input, .gate-card input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
.log-tools input { flex: 1; }
.log-view {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
  max-height: 70vh;
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.gate-card { width: min(420px, 100%); box-shadow: var(--shadow); }
.gate-card h1 { margin: 0 0 8px; font-size: 1.5rem; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; color: var(--blue); font-size: 0.75rem; margin: 0; }
.gate-card form { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.gate-card label { font-size: 0.85rem; color: var(--muted); }
.form-error { color: var(--red); margin: 8px 0 0; }

@media (min-width: 840px) {
  body { padding: 28px 24px 32px; }
  .tabs {
    position: sticky;
    top: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
  }
  .tabs button { font-size: 0.95rem; }
  .split { grid-template-columns: 1fr 1fr; }
  .equity { font-size: 2.6rem; }
}
