:root {
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ee;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);

  --accent: #d95926;
  --accent-ink: #ffffff;

  /* Tier badge gradient endpoints: --tier-t (0..1, set per-badge) blends
     between these. Low tiers read as neutral/muted, high tiers as bold. */
  --tier-low: #898781;
  --tier-high: #0d366b;

  --win: #0ca30c;
  --loss: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --surface-2: #222221;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);

    --accent: #d95926;
    --tier-low: #898781;
    --tier-high: #3987e5;

    --win: #0ca30c;
    --loss: #e66767;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---- Header ---- */
.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.site-logo {
  height: 56px;
  width: auto;
  flex: none;
}

.eyebrow {
  display: block;
  font: 600 12px/1 ui-monospace, "SF Mono", monospace;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 8px;
}

.hero h1 {
  margin: 0;
  font-family: "Anton", "Arial Narrow Bold", system-ui, sans-serif;
  font-weight: 400;
  text-transform: uppercase;
  font-size: clamp(30px, 4.4vw, 44px);
  letter-spacing: 0.01em;
  color: var(--accent);
  overflow-wrap: break-word;
  text-shadow:
    2px 2px 0 rgba(0, 0, 0, 0.75),
    -1px -1px 0 rgba(0, 0, 0, 0.35);
}

.hero-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

#refreshBtn {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

#refreshBtn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.error-box {
  border: 1px solid var(--loss);
  color: var(--loss);
  background: var(--surface-1);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
}

.error-box[hidden] {
  display: none;
}

/* ---- Stat row ---- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat-subvalue {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
}

.stat-label {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- Layout grid ---- */
.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  align-items: start;
  min-width: 0;
}

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

@media (max-width: 800px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

.main-col,
.side-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Panels ---- */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  min-width: 0;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

/* ---- Tables ---- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--gridline);
  padding: 8px 6px;
}

td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

.col-rank {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  width: 36px;
}

.player-name {
  font-weight: 600;
}

.player-callsign {
  font: 12px ui-monospace, "SF Mono", monospace;
  color: var(--text-muted);
}

.col-record,
.col-score,
.col-cbills {
  font-variant-numeric: tabular-nums;
}

.col-score {
  font-weight: 700;
}

/* ---- Tier badges ---- */
.tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.tier-badge {
  --tier-color: color-mix(in srgb, var(--tier-high) calc(var(--tier-t, 0) * 100%), var(--tier-low));
  background: color-mix(in srgb, var(--tier-color) 18%, transparent);
  color: var(--tier-color);
}

/* ---- Ranked lists (entertainment / fan favorite) ---- */
ol,
ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

ol li,
.tier-key li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--gridline);
  font-size: 14px;
}

ol li:last-child,
.tier-key li:last-child {
  border-bottom: none;
}

.li-name {
  font-weight: 500;
}

.li-val {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.li-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 0;
}

.tier-key li {
  align-items: center;
}

/* ---- Result badges ---- */
.result-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.result-win {
  background: color-mix(in srgb, var(--win) 18%, transparent);
  color: var(--win);
}

.result-loss {
  background: color-mix(in srgb, var(--loss) 18%, transparent);
  color: var(--loss);
}

footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding-top: 12px;
}

/* ---- Mobile ---- */
@media (max-width: 640px) {
  .app {
    padding: 16px 12px 48px;
    gap: 16px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
    padding-bottom: 16px;
  }

  .brand {
    gap: 12px;
  }

  .site-logo {
    height: 40px;
  }

  .hero h1 {
    font-size: clamp(22px, 8vw, 30px);
  }

  .hero-meta {
    justify-content: space-between;
  }

  .panel {
    padding: 14px;
  }

  table {
    min-width: 420px;
    font-size: 13px;
  }
}
