:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #5d636e;
  --border: #e3e1db;
  --accent: #0b6b4f;
  --highlight: #e8f4ee;
  --highlight-border: #9fd0b8;
  --error: #a3261b;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141619;
    --surface: #1c1f23;
    --text: #e7e8ea;
    --muted: #9aa1ab;
    --border: #2e3238;
    --accent: #5fd0a4;
    --highlight: #16302a;
    --highlight-border: #2f6b55;
    --error: #ff8a7d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 16px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header, main, footer { max-width: 1200px; margin: 0 auto; }

header { padding-block: 28px 8px; }
h1 { margin: 0 0 4px; font-size: 1.6rem; letter-spacing: -0.01em; }
.asof { margin: 0; color: var(--muted); }
.asof strong { color: var(--text); }
.lede { margin: 8px 0 0; color: var(--muted); max-width: 70ch; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.filters label { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.filters select { font: inherit; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.filters .check { color: var(--text); }
.count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }

.status { color: var(--muted); }
.status.error { color: var(--error); }

.table-wrap { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; }
#rankings { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; }
#rankings thead th { cursor: pointer; user-select: none; position: sticky; top: env(safe-area-inset-top, 0px); background: var(--surface); }
#rankings thead th:hover, #rankings thead th:focus-visible { color: var(--text); }
th[aria-sort="ascending"]::after { content: " ▲"; color: var(--accent); }
th[aria-sort="descending"]::after { content: " ▼"; color: var(--accent); }

td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.key { font-weight: 600; }
td.name { font-weight: 500; }

tr.game { cursor: pointer; }
tr.game:hover td, tr.game:focus-visible td { background: color-mix(in srgb, var(--highlight) 50%, transparent); }
tr.game.above td { background: var(--highlight); }
tr.game.above td.rank { box-shadow: inset 3px 0 0 var(--accent); }
tr.game[aria-expanded="true"] td { border-bottom-color: transparent; }

tr.detail td { padding: 4px 16px 16px; background: var(--surface); }
tr.detail p { margin: 4px 0 8px; color: var(--muted); font-size: 0.9rem; }
table.tiers { max-width: 560px; font-size: 0.9rem; }
table.tiers th, table.tiers td { padding: 4px 10px; }
table.tiers th:not(:first-child) { text-align: right; }
td.zero { color: var(--muted); }

.unranked { margin: 20px 0; color: var(--muted); }
.unranked summary { cursor: pointer; }
.unranked ul { padding-left: 20px; }

footer { padding-block: 28px 40px; color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--border); margin-top: 28px; }
footer p { max-width: 80ch; }
footer strong { color: var(--text); }

/* Phones: each game becomes a card */
@media (max-width: 720px) {
  #rankings, #rankings > tbody, #rankings > tbody > tr, #rankings > tbody > tr > td { display: block; }
  #rankings { border: 0; background: none; }
  #rankings > thead { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 10px; }
  #rankings > thead > tr { display: contents; }
  #rankings > thead th { position: static; border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 0.7rem; }
  tr.game { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; padding: 8px 12px; background: var(--surface); }
  tr.game.above { background: var(--highlight); border-color: var(--highlight-border); }
  tr.game > td, tr.game.above > td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 2px 0; background: none; box-shadow: none; text-align: right; }
  tr.game > td::before { content: attr(data-label); color: var(--muted); text-align: left; }
  tr.game > td.name { font-size: 1.05rem; text-align: left; }
  tr.game > td.name::before { content: none; }
  tr.detail { margin: -6px 0 12px; }
  #rankings > tbody > tr.detail > td { padding: 8px 0; background: none; border: 0; }
  table.tiers { width: 100%; }
}
