:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --border: #e2e1dc;
  --grid: #ecebe7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --accent: #2a78d6;
  --rise: #c4352f;
  --drop: #1f7a3d;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --neutral-line: #8a8984;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --border: #2e2e2c;
    --grid: #262624;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e88;
    --accent: #3987e5;
    --rise: #ef7a74;
    --drop: #5cc581;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --neutral-line: #8f8e88;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #111110;
  --surface-1: #1a1a19;
  --border: #2e2e2c;
  --grid: #262624;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e88;
  --accent: #3987e5;
  --rise: #ef7a74;
  --drop: #5cc581;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --neutral-line: #8f8e88;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
}

.muted { color: var(--text-muted); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 12px max(16px, calc((100vw - 1200px) / 2));
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand strong { font-size: 16px; }
.brand .home { color: inherit; text-decoration: none; }

nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
}
nav a:hover { background: var(--surface-0); }
nav a.active { background: var(--accent); color: #fff; }

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

main > section, .grid > * { min-width: 0; }

footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 32px;
  font-size: 12px;
}

h2 { margin: 0 0 4px; font-size: 18px; }
h3 { margin: 0 0 8px; font-size: 14px; color: var(--text-secondary); font-weight: 600; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
}

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
.grid.multiples { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 12px; }

.tile .label { color: var(--text-secondary); font-size: 12px; }
.tile .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--text-muted); }

.multiple { cursor: pointer; padding: 12px; }
.multiple:hover { border-color: var(--accent); }
.multiple .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.multiple .name { font-weight: 600; }
.multiple .stats { font-size: 12px; font-variant-numeric: tabular-nums; }

.up { color: var(--rise); }
.down { color: var(--drop); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font: inherit;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
input[type="search"], select {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  min-width: 0;
}
input[type="search"] { flex: 1 1 240px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; }
td.wrap { white-space: normal; min-width: 220px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-0); }

.chart { width: 100%; min-width: 0; overflow: hidden; }
.uplot { font-family: inherit; }
.u-legend { font-size: 12px; color: var(--text-secondary); text-align: left; }
.u-legend .u-marker { border-radius: 2px; }
.u-legend th { font-weight: 500; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: baseline; }
