:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #74736e;
  --grid: #e7e6e1;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --accent: #2a78d6;
  --critical: #d03b3b;
  --unknown: #8a8984;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --grid: #2c2c29;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --accent: #3987e5;
    --critical: #e66767;
    --unknown: #8f8e87;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c; --text: #f0efec;
  --text-2: #c3c2b7; --muted: #9a998f; --grid: #2c2c29; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --accent: #3987e5; --critical: #e66767; --unknown: #8f8e87;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.3rem; margin: 0; }
h2 { font-size: 1rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error { color: var(--critical); min-height: 1.2em; }
button { font: inherit; cursor: pointer; border-radius: 8px; padding: 0.55rem 1rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; width: 100%; }
button.ghost { background: transparent; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select, input[type="search"] { font: inherit; padding: 0.45rem 0.6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; display: grid; gap: 14px; text-align: center; }

/* app layout */
#app { max-width: 1400px; margin: 0 auto; padding: 12px 16px 32px; display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.topbar p { margin: 2px 0 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 0.35rem 0.75rem; border-radius: 999px; font-size: 0.88rem; }
.chip[aria-pressed="false"] { opacity: 0.5; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
#search { flex: 1 1 160px; min-width: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile h3 { margin: 0 0 10px; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; }
.tile .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat .v { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .l { font-size: 0.75rem; color: var(--text-2); }
.bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 12px; gap: 2px; background: var(--surface); }
.bar span { display: block; height: 100%; }
.bar-legend { display: flex; gap: 12px; font-size: 0.75rem; color: var(--text-2); margin-top: 6px; flex-wrap: wrap; }

.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
#map { height: 62vh; min-height: 380px; background: var(--surface-2); }
.legend { position: absolute; left: 10px; bottom: 10px; z-index: 500; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.78rem; display: grid; gap: 4px; color: var(--text-2); }
.legend .row { display: flex; align-items: center; gap: 8px; }
.legend svg { flex: none; }
.detail { position: absolute; top: 10px; right: 10px; bottom: 10px; width: min(360px, calc(100% - 20px)); z-index: 600; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; overflow-y: auto; box-shadow: 0 4px 18px rgb(0 0 0 / 0.15); }
.detail h2 { font-size: 1.1rem; }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 12px 0; font-size: 0.88rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail h3 { font-size: 0.85rem; margin: 14px 0 6px; color: var(--text-2); }
.detail ol { list-style: none; padding: 0; margin: 0; font-size: 0.84rem; display: grid; gap: 6px; }
.detail li { display: grid; grid-template-columns: 88px 1fr; gap: 8px; }
.detail .close { position: absolute; top: 8px; right: 8px; padding: 0.2rem 0.55rem; }
.role { font-size: 0.72rem; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--text-2); margin-left: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head p { margin: 0; }
.trend { position: relative; }
.trend svg { display: block; width: 100%; height: 240px; overflow: visible; }
.subhead { font-size: 0.9rem; margin: 16px 0 6px; }
#rates + .subhead + .table-scroll { max-height: 380px; overflow-y: auto; }
#fixtures-table thead th { position: sticky; top: 0; background: var(--surface); cursor: default; }
#fixtures-table tbody tr { cursor: pointer; }
.trend .axis text { fill: var(--muted); font-size: 11px; }
.trend .gridline { stroke: var(--grid); stroke-width: 1; }
.trend .crosshair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.8rem; box-shadow: 0 2px 10px rgb(0 0 0 / 0.12); white-space: nowrap; z-index: 10; }
.tooltip .row { display: flex; align-items: center; gap: 6px; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th { text-align: left; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); padding: 8px; cursor: pointer; white-space: nowrap; user-select: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
th[aria-sort="ascending"]::after { content: " ▲"; font-size: 0.7em; }
th[aria-sort="descending"]::after { content: " ▼"; font-size: 0.7em; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.badge { display: inline-flex; align-items: center; gap: 6px; }
.dim { opacity: 0.55; }
footer { padding: 4px 2px; }

.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-tooltip { font-size: 0.8rem; }

@media (max-width: 640px) {
  #map { height: 55vh; }
  .tile .stats { grid-template-columns: repeat(2, 1fr); }
  .detail { top: auto; height: 60%; }
}

.earn-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 14px; }
.earn-tiles .stat { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.earn-tiles .stat .v { font-size: 1.6rem; }
#earnings-table td, #earnings-table th { vertical-align: top; cursor: default; }
#earnings-table .est { font-weight: 650; font-variant-numeric: tabular-nums; }
#earnings-table .sub { display: block; font-size: 0.76rem; color: var(--muted); white-space: nowrap; }

#activity .tile { background: var(--surface-2); border: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 0.84rem; margin-top: 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.legend-inline { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.75rem; color: var(--text-2); margin-top: 6px; }
.legend-inline span { display: inline-flex; align-items: center; gap: 5px; }

.pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; margin-top: 8px; }
.pair .subhead { margin-bottom: 2px; }
.pair p { margin: 0 0 6px; }
