:root {
  --bg: #0b0e13; --card: #141922; --line: #232a35; --line2: #2e3746;
  --text: #e6eaf0; --muted: #9aa4b2; --accent: #4c8dff; --on-accent: #0b0e13;
  --ok-bg: #0f2a1d; --ok: #4ade95; --warn-bg: #2e1712; --warn: #ff8a6b;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa; --card: #ffffff; --line: #dde2ea; --line2: #c9d1dc;
    --text: #141922; --muted: #556070; --accent: #1f5fd1; --on-accent: #ffffff;
    --ok-bg: #e2f6ec; --ok: #136c43; --warn-bg: #fbe9e3; --warn: #a13a1c;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
}
.wrap {
  max-width: 640px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 14px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 4px; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 0.9em; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.brand { text-align: center; padding: 40px 0 8px; display: flex; flex-direction: column; gap: 6px; }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.stack, .field { display: flex; flex-direction: column; gap: 8px; }
.stack { gap: 14px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
label { font-size: 14px; font-weight: 600; }
input {
  min-height: 48px; width: 100%; border-radius: 12px; border: 1px solid var(--line2);
  background: var(--bg); color: var(--text); font: 16px var(--mono); padding: 0 12px;
}
input:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:disabled { opacity: 0.6; }
input.code { letter-spacing: 0.25em; text-align: center; font-size: 20px; }
button {
  min-height: 48px; border-radius: 12px; border: 1px solid var(--line2); padding: 0 16px;
  background: var(--card); color: var(--text); font: 600 15px Inter, system-ui, sans-serif; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
button.ghost { min-height: 44px; }
button:disabled { opacity: 0.6; cursor: progress; }
.tag { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; padding: 3px 7px; border-radius: 6px; text-transform: uppercase; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.miss { background: var(--warn-bg); color: var(--warn); }
.alert { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; }
.notice { background: var(--ok-bg); color: var(--ok); border-radius: 10px; padding: 10px 12px; }
summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.todo { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.kv { display: grid; grid-template-columns: minmax(0, 9rem) minmax(0, 1fr); gap: 8px 12px; margin: 10px 0 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) { .kv { grid-template-columns: minmax(0, 1fr); } .kv dd { margin-bottom: 6px; } }

/* ---- Phase 3: app shell ------------------------------------------------------- */
:root { --pos: #4c8dff; --neg: #db7530; --kill: #c2381f; --amber: #f5c451; --amber-bg: #2a2310; }
@media (prefers-color-scheme: light) {
  :root { --pos: #1f5fd1; --neg: #a8521c; --kill: #b0301a; --amber: #7a5a00; --amber-bg: #fbf1d3; }
}
a { color: var(--accent); }
.center { text-align: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.app { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--line);
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 8px; max-width: 640px; margin: 0 auto;
}
.brandlink { color: var(--text); text-decoration: none; font-size: 18px; min-height: 44px; display: flex; align-items: center; }
.controls { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.controls form { display: contents; }
.controls button { width: 100%; min-height: 48px; padding: 0 8px; }
button.kill {
  position: relative; overflow: hidden; background: var(--kill); color: #fff; border-color: var(--kill);
  font-weight: 800; letter-spacing: 0.06em; touch-action: none; user-select: none; -webkit-user-select: none;
}
button.kill .fill { position: absolute; inset: 0; width: 0; background: rgba(255,255,255,0.35); }
button.kill.holding .fill { width: 100%; transition: width 2s linear; }
button.kill .lbl { position: relative; }
.stale { background: var(--amber-bg); color: var(--amber); border-radius: 10px; padding: 8px 12px; font-weight: 600; }
body.is-stale #live { opacity: 0.55; }
.wrapgap { flex-wrap: wrap; justify-content: flex-start; }
.tag.mode-testnet, .tag.mode-dry { background: var(--amber-bg); color: var(--amber); }
.tag.mode-mainnet { background: var(--warn-bg); color: var(--warn); }
.tag.state-running { background: var(--ok-bg); color: var(--ok); }
.tag.state-paused, .tag.state-close_only { background: var(--amber-bg); color: var(--amber); }
.tag.state-killed { background: var(--kill); color: #fff; }
.tag { background: var(--line); color: var(--text); }
.big { font-size: 22px; font-weight: 700; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
article.pos, article.trade { color: var(--text); }
.card .pos, .card .neg { font-weight: 600; }
article.pos + article.pos { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.reasons, .att, .plain { margin: 8px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.att { list-style: none; padding: 0; }
.att .tag { margin-right: 4px; }
.sev-critical .tag { background: var(--warn-bg); color: var(--warn); }
meter { width: 6rem; vertical-align: middle; }
a.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line2); background: var(--card); color: var(--text);
  font-weight: 600; text-decoration: none;
}
a.button.ghost { border-color: transparent; }
select {
  min-height: 48px; border-radius: 12px; border: 1px solid var(--line2); background: var(--bg);
  color: var(--text); font: 16px Inter, system-ui, sans-serif; padding: 0 10px; width: 100%;
}
.filters { display: grid; grid-template-columns: auto 1fr; gap: 8px 10px; align-items: center; }
.filters button { grid-column: 1 / -1; }
form.inline { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }
.events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ev code { font-size: 12px; color: var(--muted); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.tabs a {
  min-height: 56px; display: flex; align-items: center; justify-content: center; text-align: center;
  color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600;
}
.tabs a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
.subnav { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.subnav a {
  flex: 0 0 auto; min-height: 44px; display: flex; align-items: center; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 14px;
}
.subnav a[aria-current="page"] { border-color: var(--accent); color: var(--accent); }
@media (min-width: 900px) {
  .top, .app > .wrap { max-width: 820px; }
}

/* ---- charts ------------------------------------------------------------------------ */
.chartfilters { display: flex; flex-direction: column; gap: 8px; }
.seg { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.seg button { min-height: 44px; padding: 0; font-size: 13px; }
.seg button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.chartcard { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.headline { font-weight: 600; }
svg.chart { width: 100%; height: auto; display: block; }
svg.chart .tx { fill: var(--muted); }
svg.chart .grid { stroke: var(--line); }
svg.chart .zero { stroke: var(--muted); }
svg.chart .s1, svg.chart .gain { stroke: var(--pos); }
svg.chart .gain { fill: var(--pos); stroke: none; }
svg.chart .loss { fill: var(--neg); stroke: none; }
svg.chart .a1 { fill: var(--neg); }
svg.chart .hit { cursor: pointer; }
.tablewrap { overflow-x: auto; max-height: 360px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: right; padding: 4px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
