:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #14171c;
  --text-2: #4a5160;
  --muted: #7a8291;
  --accent: #116dff;
  --accent-soft: #e6efff;
  --up: #0a8a5a;
  --down: #d1333d;
  --up-soft: rgba(10, 138, 90, .12);
  --down-soft: rgba(209, 51, 61, .12);
  --warn: #b26b00;
  --row-hover: #f5f8ff;
  --row-sel: #eaf1ff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1015; --surface: #151a21; --surface-2: #1c222b; --border: #262d38;
    --text: #e8ebf0; --text-2: #b4bccb; --muted: #7d8696;
    --accent: #4d8dff; --accent-soft: #1a2a47;
    --up: #2fbf86; --down: #f0606a; --up-soft: rgba(47, 191, 134, .14); --down-soft: rgba(240, 96, 106, .14);
    --warn: #e0a040; --row-hover: #1a212b; --row-sel: #1b2840;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1015; --surface: #151a21; --surface-2: #1c222b; --border: #262d38;
  --text: #e8ebf0; --text-2: #b4bccb; --muted: #7d8696;
  --accent: #4d8dff; --accent-soft: #1a2a47;
  --up: #2fbf86; --down: #f0606a; --up-soft: rgba(47, 191, 134, .14); --down-soft: rgba(240, 96, 106, .14);
  --warn: #e0a040; --row-hover: #1a212b; --row-sel: #1b2840;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding: 0 20px 20px; max-width: 1680px; margin: 0 auto;
}
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --- header */
.top { display: flex; align-items: center; gap: 24px; padding: 16px 0; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 34px; height: 34px; flex: none; }
.brand svg rect { fill: var(--accent); stroke: none; }
.brand svg path { stroke: #fff; stroke-width: 3; }
.brand p { margin: 0; font-size: 12.5px; }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 12px; min-width: 92px; }
.stat b { display: block; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }
.top-actions { display: flex; gap: 6px; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-2); }
.icon-btn:hover { color: var(--text); border-color: var(--muted); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spin svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- filters */
.filters { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px; display: grid; gap: 12px; margin-bottom: 14px; }
.flag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface-2); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; color: var(--text-2); }
.chip:hover { border-color: var(--muted); color: var(--text); }
.chip .n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 11.5px; }
.chip .w { font-size: 10.5px; font-weight: 600; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 4px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] .n, .chip[aria-pressed="true"] .w { color: var(--accent); border-color: currentColor; }
.chip.zero { opacity: .5; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.search { display: flex; align-items: center; gap: 6px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; height: 34px; }
.search:focus-within { border-color: var(--accent); }
.search svg { width: 15px; height: 15px; color: var(--muted); }
.search input { border: 0; background: none; outline: none; color: var(--text); font: inherit; width: 140px; text-transform: uppercase; }
.search input::placeholder { text-transform: none; color: var(--muted); }
.ctl { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.ctl input[type=range] { accent-color: var(--accent); width: 120px; }
.ctl output { font-weight: 600; color: var(--text); min-width: 16px; font-variant-numeric: tabular-nums; }
select { font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; height: 34px; padding: 0 8px; }
.toggle { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { width: 34px; height: 20px; border-radius: 99px; background: var(--border); position: relative; transition: background .15s; }
.toggle span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(14px); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.link-btn { background: none; border: 0; color: var(--accent); padding: 0; font-size: 13px; }
.btn { margin-left: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  height: 34px; padding: 0 12px; font-size: 13px; font-weight: 500; }
.btn:hover { border-color: var(--muted); }

/* --- layout */
.layout { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); gap: 8px; }
.pill { font-size: 12px; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; padding: 0 8px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* --- table */
.table-wrap { overflow: auto; max-height: calc(100vh - 250px); min-height: 300px; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: right; font-weight: 500;
  font-size: 11.5px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap; cursor: pointer; user-select: none; }
th:hover { color: var(--text); }
th.l, td.l { text-align: left; }
th[aria-sort] { color: var(--text); }
th[aria-sort="ascending"]::after { content: " ↑"; }
th[aria-sort="descending"]::after { content: " ↓"; }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--row-hover); }
tbody tr.sel td { background: var(--row-sel); }
tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
td.sym { font-weight: 600; }
td.sym small { font-weight: 500; font-size: 10px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 0 3px; margin-left: 6px; vertical-align: 1px; }
.scorecell { display: inline-flex; align-items: center; gap: 6px; }
.scorebar { width: 38px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.scorebar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.up { color: var(--up); }
.down { color: var(--down); }
.hot { color: var(--text); font-weight: 600; }
.dim { color: var(--muted); }
.mini-flags { display: flex; gap: 4px; }
.mf { font-size: 10.5px; font-weight: 600; padding: 1px 5px; border-radius: 4px; background: var(--surface-2);
  color: var(--text-2); border: 1px solid var(--border); }
.oiv { font-size: 11.5px; padding: 1px 6px; border-radius: 4px; }
.oiv.bull { background: var(--up-soft); color: var(--up); }
.oiv.bear { background: var(--down-soft); color: var(--down); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; color: var(--text); }

/* --- detail */
.detail { position: sticky; top: 14px; padding: 14px; }
.detail-empty { padding: 60px 0; text-align: center; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-head h2 { font-size: 22px; }
.detail-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
#dClose { font-size: 15px; font-weight: 500; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); color: var(--text-2); }
.score-badge { text-align: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); padding: 6px 12px; }
.score-badge b { display: block; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-badge span { font-size: 10.5px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.flag-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; }
.flag-list .chip { cursor: default; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 1px; margin: 0 0 12px;
  background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.metrics div { background: var(--surface); padding: 7px 10px; }
.metrics dt { font-size: 11px; color: var(--muted); }
.metrics dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; min-height: 28px; }
.readout { font-size: 11.5px; color: var(--text-2); display: flex; flex-wrap: wrap; gap: 2px 10px; }
.readout b { color: var(--muted); font-weight: 400; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; flex: none; }
.seg button { border: 0; background: none; padding: 3px 10px; border-radius: 6px; font-size: 12px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.chart { width: 100%; height: 470px; }
.pane-labels { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; }
.pane-labels span::before { content: ""; display: inline-block; width: 10px; height: 2px; vertical-align: middle;
  margin-right: 5px; background: var(--c); }
.links { display: flex; gap: 14px; margin-top: 10px; }
.links a { color: var(--accent); text-decoration: none; }
.links a:hover { text-decoration: underline; }

footer { margin-top: 18px; text-align: center; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .detail { position: static; }
  .table-wrap { max-height: 60vh; }
}
@media (max-width: 640px) {
  body { padding: 0 16px 16px; }
  .stats { margin-left: 0; width: 100%; }
  .stat { flex: 1; min-width: 0; }
  .btn { margin-left: 0; }
  .chart { height: 400px; }
  .search input { width: 110px; }
}
