/* Layout: a scoreboard. Dark arena by default. Each of the six modes is a stone
   on the Gauntlet and keeps its stone's color everywhere it appears (tabs, tags,
   charts); the brand mark is the six stones in a row. */
:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e2230;
  --line: #2a2f3e;
  --fg: #ece8de;
  --muted: #9095a6;
  --ember: #ff6b3d;
  --ember-ink: #1a0d07;
  --good: #4cc38a;
  --bad: #f06a6a;

  --uhc: #4fcf76;
  --sword: #4f9ff5;
  --diasmp: #f28a3c;
  --crystal: #bb80f7;
  --mace: #f05a5a;
  --speedrun: #f0d43a;
  --overall: #ece8de;
  --gauntlet: #d9ad4a;

  --div-wood: #a8774a;
  --div-stone: #9a9ea6;
  --div-iron: #dfe2e7;
  --div-gold: #f2c540;
  --div-diamond: #52dbd5;
  --div-netherite: #b39a92;

  --display: "Saira Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --body: "Barlow", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --radius: 6px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #edeff3; --panel: #ffffff; --panel-2: #f4f5f8; --line: #d8dbe3;
    --fg: #161921; --muted: #5b6070; --ember: #d4461a; --ember-ink: #ffffff;
    --good: #1f8a57; --bad: #c43c3c;
    --uhc: #1f8f45; --sword: #2471d1; --diasmp: #c25a12; --crystal: #8a4fd0; --mace: #cc3434; --speedrun: #9a7b00; --overall: #161921; --gauntlet: #9c7414;
    --div-wood: #8a5a2e; --div-stone: #6c7078; --div-iron: #8a9099; --div-gold: #b08508;
    --div-diamond: #138f8a; --div-netherite: #6b534b;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #edeff3; --panel: #ffffff; --panel-2: #f4f5f8; --line: #d8dbe3;
  --fg: #161921; --muted: #5b6070; --ember: #d4461a; --ember-ink: #ffffff;
  --good: #1f8a57; --bad: #c43c3c;
  --uhc: #1f8f45; --sword: #2471d1; --diasmp: #c25a12; --crystal: #8a4fd0; --mace: #cc3434; --speedrun: #9a7b00; --overall: #161921; --gauntlet: #9c7414;
  --div-wood: #8a5a2e; --div-stone: #6c7078; --div-iron: #8a9099; --div-gold: #b08508;
  --div-diamond: #138f8a; --div-netherite: #6b534b;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.5 var(--body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gauntlet); outline-offset: 2px; border-radius: 3px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, td.n, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Top bar ---------- */
.sample-strip {
  background: var(--panel-2);
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  text-align: center;
  padding: 6px 16px;
}
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-inner, .page, .footer-inner {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 20px;
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 8px 24px;
  flex-wrap: wrap;
  padding-block: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font: 800 22px/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stones { display: inline-flex; gap: 3px; }
.stones i { width: 7px; height: 7px; background: var(--mode); transform: rotate(45deg); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius);
}
.nav a:hover { color: var(--fg); background: var(--panel); }
.nav a[aria-current="page"] { color: var(--fg); background: var(--panel-2); }
.search { margin-left: auto; flex: 0 1 220px; min-width: 0; }
.search input, .control select, .control input {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
}
.search input::placeholder, .control input::placeholder { color: var(--muted); }

/* ---------- Page ---------- */
.page { flex: 1; padding-block: 28px 56px; display: flex; flex-direction: column; gap: 36px; outline: none; }
.loading, .empty { color: var(--muted); }
h1, h2, h3 { font-family: var(--display); text-transform: uppercase; letter-spacing: 0.02em; line-height: 1.05; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(34px, 6vw, 56px); font-weight: 800; }
h2 { font-size: 26px; font-weight: 700; }
h3 { font-size: 19px; font-weight: 700; }
.eyebrow { font: 600 12px/1 var(--body); text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.section { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head a { color: var(--muted); font-size: 14px; }
.section-head a:hover { color: var(--fg); }
.lede { color: var(--muted); max-width: 62ch; margin: 0; }
.prose { max-width: 66ch; display: flex; flex-direction: column; gap: 12px; }
.prose p { margin: 0; }

/* ---------- Home hero ---------- */
.hero { display: flex; flex-direction: column; gap: 16px; padding-block: 8px 4px; }
.hero h1 .accent { color: var(--gauntlet); }
.hero-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.ip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--fg);
  color: var(--bg);
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  font: 600 15px/1 var(--body);
  cursor: pointer;
}
.ip .mono { font-weight: 500; }
.ip:hover { filter: brightness(1.08); }
.season-note { color: var(--muted); font-size: 14px; }
.totals { display: flex; gap: 10px 32px; flex-wrap: wrap; margin: 0; }
.totals div { display: flex; flex-direction: column; }
.totals dt { order: 2; color: var(--muted); font-size: 13px; }
.totals dd { order: 1; margin: 0; font: 500 24px/1.2 var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- Mode colors ---------- */
[data-mode="uhc"] { --mode: var(--uhc); }
[data-mode="sword"] { --mode: var(--sword); }
[data-mode="diasmp"] { --mode: var(--diasmp); }
[data-mode="crystal"] { --mode: var(--crystal); }
[data-mode="mace"] { --mode: var(--mace); }
[data-mode="speedrun"] { --mode: var(--speedrun); }
[data-mode="overall"] { --mode: var(--overall); }
.mode-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 700 13px/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--mode);
  white-space: nowrap;
}
.mode-tag::before { content: ""; width: 8px; height: 8px; background: var(--mode); transform: rotate(45deg); }

/* ---------- Ladder cards on home ---------- */
.ladders { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.ladder-link { font-size: 13px; color: var(--muted); }
.ladder-link:hover { color: var(--fg); }
.stone { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap; }
.format-tag { color: var(--muted); margin-left: 6px; }
.tab-note { display: block; font: 500 11px/1.2 var(--body); text-transform: none; letter-spacing: 0; opacity: 0.75; margin-top: 3px; }
td.wrap { white-space: normal; min-width: 220px; }
tr.team-start { border-top: 2px solid var(--line); }
table.mini { font-size: 14px; background: transparent; }
table.mini td { padding: 5px 0; border: 0; }
table.mini td + td { padding-left: 10px; }
table.mini tr { border: 0; }
table.mini tr:hover { background: transparent; }
.ladder {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--mode);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}
.ladder-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ladder-head h3 { color: var(--mode); }
.ladder-head a { font-size: 13px; color: var(--muted); }
.ladder ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ladder li { display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.ladder li:first-child { border-top: 0; }
.ladder .pos { font: 500 13px var(--mono); color: var(--muted); }
.ladder li:first-child .pos { color: var(--mode); }

/* ---------- Player chip ---------- */
.player { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; min-width: 0; }
.player:hover .player-name { text-decoration: underline; text-underline-offset: 3px; }
.player-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.head {
  width: 24px; height: 24px; flex: none;
  border-radius: 3px;
  image-rendering: pixelated;
  background: var(--panel-2);
  display: inline-grid;
  place-items: center;
  font: 700 13px/1 var(--display);
  color: var(--muted);
  overflow: hidden;
}
.head.big { width: 72px; height: 72px; font-size: 34px; border-radius: 6px; }
.rank-badge {
  font: 700 11px/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 5px;
  border-radius: 3px;
  border: 1px solid currentColor;
  color: var(--muted);
  white-space: nowrap;
}
.rank-badge.owner { color: var(--gauntlet); }
.rank-badge.creator { color: var(--crystal); }
.rank-badge.media { color: var(--sword); }
.rank-badge.vip { color: var(--uhc); }

/* ---------- Divisions ---------- */
.div-badge { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 600; font-size: 14px; }
.div-badge::before { content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--div); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.25); }
[data-div="wood"] { --div: var(--div-wood); }
[data-div="stone"] { --div: var(--div-stone); }
[data-div="iron"] { --div: var(--div-iron); }
[data-div="gold"] { --div: var(--div-gold); }
[data-div="diamond"] { --div: var(--div-diamond); }
[data-div="netherite"] { --div: var(--div-netherite); }

/* ---------- Tabs and controls ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  text-decoration: none;
  font: 700 16px/1 var(--display);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 9px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.tab:hover { color: var(--fg); border-color: var(--mode, var(--muted)); }
.tab[aria-current="true"], .tab[aria-pressed="true"] { color: var(--bg); background: var(--mode, var(--fg)); border-color: var(--mode, var(--fg)); }
.tab.small { font-size: 13px; padding: 6px 10px; }
.controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.control { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; flex: 1 1 140px; max-width: 220px; }
.control.grow { flex: 2 1 200px; max-width: 300px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 12px; text-align: left; white-space: nowrap; }
td.n, th.n { text-align: right; }
thead th {
  font: 600 12px/1 var(--body);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th button:hover { color: var(--fg); }
th button:focus-visible { outline: 2px solid var(--gauntlet); outline-offset: 2px; }
th[aria-sort] button { color: var(--fg); }
th[aria-sort="descending"] button::after { content: "▼"; font-size: 9px; }
th[aria-sort="ascending"] button::after { content: "▲"; font-size: 9px; }
tbody tr { border-top: 1px solid var(--line); }
tbody tr:first-child { border-top: 0; }
tbody tr:hover { background: var(--panel-2); }
tr.me { background: color-mix(in srgb, var(--ember) 9%, transparent); }
td.pos { font-family: var(--mono); color: var(--muted); width: 1%; }
tr.top1 td.pos { color: var(--div-gold); }
tr.top2 td.pos { color: var(--div-iron); }
tr.top3 td.pos { color: var(--div-wood); }
.elo { font-weight: 500; color: var(--fg); }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.dim { color: var(--muted); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.pager-buttons { display: flex; gap: 6px; }
.btn {
  font: 600 14px/1 var(--body);
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- Match list ---------- */
.match-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.match-row {
  display: grid;
  grid-template-columns: 170px minmax(0, 1.2fr) minmax(0, 1.2fr) auto;
  gap: 4px 16px;
  align-items: center;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  text-decoration: none;
}
.match-list li:first-child .match-row { border-top: 0; }
.match-row:hover { background: var(--panel-2); }
.match-row .winner { display: flex; gap: 8px; align-items: center; min-width: 0; }
.match-row .crown { color: var(--div-gold); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.match-row .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-row .when { color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }

/* ---------- Player profile ---------- */
.profile-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.profile-head > div { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.profile-title { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.profile-title h1 { text-transform: none; letter-spacing: 0; overflow-wrap: anywhere; }
.profile-meta { color: var(--muted); font-size: 14px; }
.mode-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.mode-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--mode);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mode-card.unplayed { border-top-color: var(--line); color: var(--muted); }
.mode-card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.mode-card .big-elo { font: 500 34px/1 var(--mono); font-variant-numeric: tabular-nums; }
.mode-card .big-elo small { font-size: 13px; color: var(--muted); margin-left: 6px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 8px; margin: 0; }
.stat-grid div { display: flex; flex-direction: column; min-width: 0; }
.stat-grid dt { order: 2; font-size: 12px; color: var(--muted); }
.stat-grid dd { order: 1; margin: 0; font: 500 16px/1.3 var(--mono); font-variant-numeric: tabular-nums; }
.ladder-place { font-size: 13px; color: var(--muted); }

.chart-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.chart-panel svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-label { fill: var(--muted); font: 11px var(--mono); }
.chart-div-label { font: 600 11px var(--body); text-transform: uppercase; letter-spacing: 0.06em; }
.chart-line { fill: none; stroke: var(--mode); stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: var(--mode); opacity: 0.12; }
.chart-dot { fill: var(--mode); stroke: var(--panel); stroke-width: 2; }
.two-col { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 14px; }
.placements { display: flex; flex-direction: column; gap: 6px; }
.place-bar { display: grid; grid-template-columns: 52px 1fr 34px; gap: 8px; align-items: center; font-size: 13px; }
.place-bar .track { height: 10px; background: var(--panel-2); border-radius: 2px; overflow: hidden; }
.place-bar .fill { height: 100%; background: var(--mode); border-radius: 2px; }
.place-bar .label { color: var(--muted); }

/* ---------- Ranked page ---------- */
.div-table td:first-child { width: 1%; }
.rule-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* ---------- Footer ---------- */
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.footer-inner { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding-block: 16px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 14px;
  z-index: 20;
}

@media (max-width: 980px) {
  .ladders, .mode-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .ladders, .mode-cards { grid-template-columns: minmax(0, 1fr); }
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .match-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "mode when" "winner winner" "meta meta"; }
  .match-row .mode-tag { grid-area: mode; }
  .match-row .when { grid-area: when; }
  .match-row .winner { grid-area: winner; }
  .match-row .meta { grid-area: meta; }
  .topbar { position: static; }
  .search { margin-left: 0; flex: 1 1 100%; }
  td .rank-badge { display: none; }
  .opt { display: none; }
  th, td { padding: 8px 9px; }
  .control { max-width: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .fill { transition: width 0.4s ease-out; }
}
