:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --sunken: #ebe6db;
  --text: #22262a;
  --muted: #646a6f;
  --line: #d8d1c3;
  --accent: #b5521c;
  --gun: #2f6fb3;
  --artillery: #b5651d;
  --barracks: #b33a3a;
  --leash: #6a8a2a;
  --sprite-bg: #d9d2c2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17191b;
    --surface: #202326;
    --sunken: #2a2e32;
    --text: #e6e3dc;
    --muted: #9aa0a5;
    --line: #363b40;
    --accent: #e98a4f;
    --gun: #6aa8ec;
    --artillery: #e8a35e;
    --barracks: #ec7a7a;
    --leash: #a9c86a;
    --sprite-bg: #3a3d38;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17191b;
  --surface: #202326;
  --sunken: #2a2e32;
  --text: #e6e3dc;
  --muted: #9aa0a5;
  --line: #363b40;
  --accent: #e98a4f;
  --gun: #6aa8ec;
  --artillery: #e8a35e;
  --barracks: #ec7a7a;
  --leash: #a9c86a;
  --sprite-bg: #3a3d38;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}
.top, main { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 20px; }
.title-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px 24px; justify-content: space-between; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0; }
.muted, .note, .build { color: var(--muted); }
.build { margin: 4px 0 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.build .dirty { color: var(--accent); }
.note { font-size: 13px; margin: 8px 0 0; max-width: 80ch; }
section { margin: 28px 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.levels { display: flex; gap: 6px; flex-wrap: wrap; }
.levels button, .chip {
  font: inherit; font-size: 13px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 4px 12px; border-radius: 999px; cursor: pointer;
}
.levels button[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.facts { margin: 12px 0 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.facts summary { cursor: pointer; width: fit-content; }
.facts p { margin: 4px 0 0 1.1em; }

.section-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; }
.toggles { border: 0; padding: 0; margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.toggles label { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.map { position: relative; margin: 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--sunken); }
.map img { display: block; width: 100%; height: auto; }
.map svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map .slot-label { font: 600 34px ui-sans-serif, system-ui, sans-serif; fill: #fff; paint-order: stroke; stroke: #1b1f22; stroke-width: 8px; }
.map .slot-name { font: 500 22px ui-sans-serif, system-ui, sans-serif; fill: #fff; paint-order: stroke; stroke: #1b1f22; stroke-width: 6px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.entry { display: inline-flex; align-items: center; gap: 4px; margin-right: 12px; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-head code { font-size: 12px; color: var(--muted); }
.stats { display: grid; grid-template-columns: auto auto; gap: 2px 16px; margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; }

.rig-player { display: flex; flex-direction: column; gap: 6px; }
canvas.rig { display: block; width: 100%; background: var(--sprite-bg); border-radius: 6px; }
.icon canvas.rig { width: 40px; background: none; }
.anim-select {
  font: inherit; font-size: 13px; width: 100%;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
.caption { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.ladders { display: grid; gap: 12px; }
.ladder .levels-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tier { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tier h4 { margin: 0; font-size: 14px; }
.tier .stats { grid-template-columns: 1fr auto; }

@media (max-width: 640px) {
  .ladder .levels-row { grid-template-columns: 1fr; }
}

.badge { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.role { margin: 0; font-size: 13px; }
.group { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.card .stats dd { text-align: right; overflow-wrap: anywhere; }
.card .stats code { font-size: 12px; }

.milestones { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.milestone details { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.milestone summary { cursor: pointer; padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.milestone summary .status { color: var(--muted); font-size: 13px; }
.milestone-body { padding: 0 12px 12px; font-size: 14px; max-width: 90ch; }
.milestone-body ul { padding-left: 20px; margin: 8px 0; }
.milestone-body li { margin: 4px 0; }
.milestone-body code { font-size: 12px; }
.state { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; border-radius: 4px; padding: 1px 6px; border: 1px solid var(--line); color: var(--muted); }
.state-published { color: var(--leash); border-color: currentColor; }
.state-built { color: var(--post); border-color: currentColor; }
.state-planned { color: var(--accent); border-color: currentColor; }
