:root {
  --bg: #0b0e14;
  --bg-soft: #11151f;
  --card: #161b27;
  --card-hover: #1b2231;
  --border: #232b3d;
  --text: #e6e9f0;
  --text-dim: #8b93a7;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --gold: #f5c518;
  --silver: #c0c8d4;
  --bronze: #cd8a4e;
  --good: #34d399;
  --ok: #fbbf24;
  --bad: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; scroll-behavior: smooth; }

body {
  margin: 0;
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(124, 92, 255, 0.14), transparent 60%),
    radial-gradient(900px 400px at 10% 110%, rgba(34, 211, 238, 0.08), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { width: min(1240px, 94vw); margin: 0 auto; }

/* ---------- header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  background: rgba(11, 14, 20, 0.75);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.15rem;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.brand b { color: var(--accent-2); font-weight: 700; }
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.tabs { display: flex; gap: 4px; background: var(--bg-soft); padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
/* CSS-only mobile nav toggle (checkbox hack — no JS). Hidden on desktop. */
.nav-toggle {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.nav-burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  cursor: pointer;
  flex: 0 0 auto;
}
.nav-burger span {
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}
.tab {
  padding: 8px 18px;
  border-radius: 9px;
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--text); background: var(--card-hover); }
.tab.active { color: #fff; background: linear-gradient(135deg, var(--accent), #5b3fd4); box-shadow: 0 4px 14px rgba(124, 92, 255, 0.35); }

/* ---------- layout ---------- */
main { flex: 1; padding: 28px 0 48px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
h1 { font-size: 1.6rem; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; font-weight: 650; }

.controls { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.segmented {
  display: flex;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
}
.seg {
  padding: 7px 16px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.88rem;
  transition: all 0.15s ease;
}
.seg:hover { color: var(--text); }
.seg.active { background: linear-gradient(135deg, var(--accent), #5b3fd4); color: #fff; box-shadow: 0 3px 10px rgba(124, 92, 255, 0.3); }

.month-form select {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}
.month-form select:hover { border-color: var(--accent); }

.muted { color: var(--text-dim); margin: 0 0 16px; font-size: 0.92rem; }

/* ---------- cards ---------- */
.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.015), transparent 40%), var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------- tables ---------- */
.table-wrap {
  padding: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}
/* Leaderboards have sticky left columns: drop the wrapper's horizontal
   padding so the stuck columns sit flush with the card edge instead of
   leaving a 6px gap when scrolled horizontally. */
.table-wrap:has(> .leaderboard) { padding-left: 0; padding-right: 0; }

table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }

thead th {
  position: sticky;
  top: 0;
  background: var(--card);
  color: var(--text-dim);
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.th-sort { color: inherit; text-decoration: none; transition: color 0.12s ease; }
.th-sort:hover { color: var(--accent-2); }
.th-sort.sorted-desc::after { content: " ↓"; color: var(--accent-2); }
.th-sort.sorted-asc::after { content: " ↑"; color: var(--accent-2); }
.th-num .th-sort { display: inline-block; width: 100%; text-align: left; }

tbody td { padding: 10px; border-bottom: 1px solid rgba(35, 43, 61, 0.55); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.12s ease; }
tbody tr:hover { background: var(--card-hover); }

/* leaderboard */
.leaderboard {
  --sticky-place: 52px;
  --sticky-player: 200px;
  --sticky-score: 130px;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 100%;
}
.col-place { width: var(--sticky-place); text-align: center; }
.leaderboard .col-place { min-width: var(--sticky-place); max-width: var(--sticky-place); }
.leaderboard .col-player { width: var(--sticky-player); min-width: var(--sticky-player); max-width: var(--sticky-player); }
.leaderboard .col-score { width: var(--sticky-score); }
.leaderboard .col-score { min-width: var(--sticky-score); max-width: var(--sticky-score); }
.col-day { text-align: center; min-width: 46px; }

/* Sticky first three columns (place / player / score) so they stay visible
   when scrolling the leaderboard horizontally. */
.leaderboard thead th { z-index: 3; }
.leaderboard thead th.col-place,
.leaderboard thead th.col-player,
.leaderboard thead th.col-score {
  position: sticky;
  z-index: 5;
  background: var(--card);
}
.leaderboard thead th.col-place { left: 0; }
.leaderboard thead th.col-player { left: var(--sticky-place); }
.leaderboard thead th.col-score {
  left: calc(var(--sticky-place) + var(--sticky-player));
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.6);
}
.leaderboard thead th.col-place,
.leaderboard thead th.col-player { border-right: 1px solid var(--border); }
.leaderboard tbody td.col-place,
.leaderboard tbody td.col-player,
.leaderboard tbody td.col-score {
  position: sticky;
  z-index: 2;
  background: var(--card);
}
.leaderboard tbody td.col-place { left: 0; }
.leaderboard tbody td.col-player { left: var(--sticky-place); }
.leaderboard tbody td.col-score {
  left: calc(var(--sticky-place) + var(--sticky-player));
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.6);
}
.leaderboard tbody td.col-place,
.leaderboard tbody td.col-player { border-right: 1px solid rgba(35, 43, 61, 0.55); }
.leaderboard tbody tr:hover td.col-place,
.leaderboard tbody tr:hover td.col-player,
.leaderboard tbody tr:hover td.col-score { background: var(--card-hover); }
.leaderboard tbody tr.row-highlight td.col-place,
.leaderboard tbody tr.row-highlight td.col-player,
.leaderboard tbody tr.row-highlight td.col-score { background: #1a2334; }
.leaderboard .col-player .player-link { min-width: 0; }
.leaderboard .col-player .nick {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.row-gold td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.row-silver td:first-child { box-shadow: inset 3px 0 0 var(--silver); }
.row-bronze td:first-child { box-shadow: inset 3px 0 0 var(--bronze); }

.place-badge { font-weight: 700; color: var(--text-dim); }

.player-link { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.player-link:hover .nick { color: var(--accent-2); }
.player-link:visited { color: var(--text); }
.nick { font-weight: 600; }

/* Avatar rail (mobile-only behavior, see media queries): wrapper anchors the
   rank chip over the avatar corner. Chip hidden on desktop. */
.avatar-wrap { position: relative; display: inline-flex; flex: 0 0 auto; }
.place-chip { display: none; }
/* Mobile avatar rail (flex sibling of the leaderboard table). Hidden on
   desktop, where the table's own sticky columns do the job. */
.avatar-rail { display: none; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--bg-soft);
}
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 0.85rem;
}
.avatar-xl { width: 84px; height: 84px; font-size: 2rem; }

.score-cell { display: flex; flex-direction: column; gap: 4px; }
.score-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.score-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.score-played { font-size: 0.72rem; font-weight: 600; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.score-bar { height: 5px; border-radius: 3px; background: var(--bg-soft); overflow: hidden; }
/* Leader-relative gradient: the fill is painted at full track width, then
   clipped to the score fraction (--f: points/max, 0..1). 1st place (f=1)
   shows the full purple->blue gradient, lower places show only the left
   slice of it (last place ~purple only). The width declaration is the
   fallback for browsers without clip-path/var(): correct length, but with
   the gradient compressed into the bar (old behavior). */
.score-fill { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); background-repeat: no-repeat; width: calc(var(--f, 1) * 100%); }
@supports (clip-path: inset(0 0 0 0)) {
  .score-fill { width: 100%; clip-path: inset(0 calc((1 - var(--f, 1)) * 100%) 0 0 round 3px); }
}

.row-highlight td { background: rgba(34, 211, 238, 0.07); }
.row-highlight td:first-child { box-shadow: inset 3px 0 0 var(--accent-2); }
.row-highlight { animation: row-glow 1.6s ease-out; }
@keyframes row-glow {
  0% { background: rgba(34, 211, 238, 0.28); }
  100% { background: transparent; }
}

.day-cell {
  border-radius: 8px;
  cursor: default;
  font-variant-numeric: tabular-nums;
}
.day-link,
.day-link:link,
.day-link:visited,
.day-link:hover,
.day-link:active {
  display: block;
  color: inherit;
  text-decoration: none;
  padding: 6px 4px;
  border-radius: 6px;
}
tbody tr:hover .day-link:hover { background: rgba(255, 255, 255, 0.06); }
.back-link { color: var(--text-dim); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.back-link:hover { color: var(--accent-2); }
.back-link,
.back-link:visited { text-decoration: none; }

.gg-button-sm {
  padding: 8px 18px;
  font-size: 0.88rem;
  border-radius: 10px;
}
.gg-button-sm:hover { transform: translateY(-1px); }
.gg-button {
  display: inline-block;
  padding: 12px 26px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #5b3fd4);
  color: #fff;
  font-weight: 750;
  font-size: 1rem;
  text-decoration: none;
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.gg-button,
.gg-button:link,
.gg-button:visited,
.gg-button:hover,
.gg-button:active { text-decoration: none; }
.gg-button:hover {
  transform: translateY(-2px);
  filter: brightness(1.12);
  box-shadow: 0 10px 26px rgba(124, 92, 255, 0.45);
}
.day-cell .day-points { font-weight: 700; display: block; }
.day-cell .day-sub { font-size: 0.7rem; color: var(--text-dim); display: block; }

.day-cell.place-1 { background: rgba(245, 197, 24, 0.16); box-shadow: inset 0 0 0 1px rgba(245, 197, 24, 0.45); }
.day-cell.place-1 .day-points { color: var(--gold); }
.day-cell.place-2 { background: rgba(192, 200, 212, 0.10); box-shadow: inset 0 0 0 1px rgba(192, 200, 212, 0.30); }
.day-cell.place-3 { background: rgba(205, 138, 78, 0.13); box-shadow: inset 0 0 0 1px rgba(205, 138, 78, 0.35); }
.day-cell.place-3 .day-points { color: var(--bronze); }
.day-cell.place-4, .day-cell.place-5 { background: rgba(124, 92, 255, 0.10); }
.day-cell:not([class*="place-"]) { color: var(--text-dim); }
.day-empty { color: #3a4257; text-align: center; }

/* countries */
.flag {
  font-size: 1.15rem;
  margin-right: 4px;
  /* Country flags (regional-indicator emoji) only render as real flags when an
     emoji-capable font is used. The default sans-serif stack on Windows falls
     back to Segoe UI Symbol, which shows letters (e.g. "UA") instead of the
     flag. Force emoji fonts + emoji presentation so they display correctly. */
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji",
               "Twemoji Mozilla", "Segoe UI Symbol", sans-serif;
  font-variant-emoji: emoji;
}
.pct-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.pct-pill.good { background: rgba(52, 211, 153, 0.14); color: var(--good); }
.pct-pill.ok { background: rgba(251, 191, 36, 0.14); color: var(--ok); }
.pct-pill.bad { background: rgba(248, 113, 113, 0.14); color: var(--bad); }
.stat-inline { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Wide data tables: guarantee a sensible minimum so columns don't crush,
   the .table-wrap scrolls instead. Countries keeps its first column stuck
   (separate borders are required for sticky to work reliably). */
.countries {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 620px;
}
.table-wrap:has(> .countries) { padding-left: 0; padding-right: 0; }
.countries thead th:first-child,
.countries tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--card);
  border-right: 1px solid var(--border);
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.countries tbody tr:hover td:first-child { background: var(--card-hover); }
.recent-games { min-width: 540px; }
.recent-games td { white-space: nowrap; }
.recent-games tr.clickable-row { cursor: pointer; }
.row-link,
.row-link:link,
.row-link:visited,
.row-link:hover,
.row-link:active {
  display: block;
  color: inherit;
  text-decoration: none;
  padding: 2px 0;
}
tbody tr:hover .row-link:hover { color: var(--accent-2); }
.challenge-table { min-width: 560px; }

/* ---------- empty state ---------- */
.empty-state { text-align: center; padding: 56px 20px; }
.empty-icon { font-size: 2.6rem; margin-bottom: 10px; }
.empty-state p { color: var(--text-dim); }

/* ---------- profile ---------- */
.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  background:
    radial-gradient(600px 200px at 0% 0%, rgba(124, 92, 255, 0.18), transparent 60%),
    linear-gradient(180deg, rgba(255,255,255,0.02), transparent 40%),
    var(--card);
}
.profile-id { display: flex; align-items: center; gap: 18px; }
.profile-id h1 { font-size: 1.8rem; }
.profile-meta { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.meta-pill {
  display: inline-flex;
  align-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text-dim);
}
.meta-pill.rating { color: var(--accent-2); border-color: rgba(34, 211, 238, 0.35); }

.rewards { text-align: right; }
.rewards-title { color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; }
.reward-badges {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  max-width: 620px;
}
.reward-badges.collapsed {
  /* 3 full rows + a sliver of the next one, fading out */
  max-height: 130px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 62%, transparent 97%);
  mask-image: linear-gradient(to bottom, #000 62%, transparent 97%);
}
.reward-badge {
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reward-badge.reward-1 { background: rgba(245, 197, 24, 0.12); border: 1px solid rgba(245, 197, 24, 0.4); color: var(--gold); }
.reward-badge.reward-2 { background: rgba(192, 200, 212, 0.10); border: 1px solid rgba(192, 200, 212, 0.35); color: var(--silver); }
.reward-badge.reward-3 { background: rgba(205, 138, 78, 0.12); border: 1px solid rgba(205, 138, 78, 0.4); color: var(--bronze); }
.reward-badge:hover { filter: brightness(1.25); }

.rewards-toggle {
  margin-top: 10px;
  background: var(--bg-soft);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 14px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}
.rewards-toggle:hover { color: var(--text); border-color: var(--accent); }

.mode-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.mode-pill.mode-nm { color: var(--accent-2); border-color: rgba(34, 211, 238, 0.35); }
.mode-pill.mode-nmpz { color: var(--accent); border-color: rgba(124, 92, 255, 0.4); }
.mode-pill.mode-move { color: var(--good); border-color: rgba(52, 211, 153, 0.35); }
.mode-pill.mode-ukraine { color: var(--ok); border-color: rgba(251, 191, 36, 0.35); }
.mode-pill.mode-bonus { color: var(--gold); border-color: rgba(245, 197, 24, 0.4); }

/* stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.stat-card:hover { transform: translateY(-2px); border-color: rgba(124, 92, 255, 0.5); }
.stat-value { font-size: 1.45rem; font-weight: 750; font-variant-numeric: tabular-nums; }
/* Occurrence frequency in the card's top-right corner (e.g. "1 in 92.7").
   Absolutely positioned, so it never affects card layout at any width. */
.stat-share {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stat-label { color: var(--text-dim); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }
.stat-pct { font-size: 0.72rem; font-weight: 600; margin-top: 2px; }
.stat-pct.good { color: var(--good); }
.stat-pct.bad { color: var(--bad); }
.stat-pct.top { color: var(--good); }

/* history chart */
.history-card { margin-bottom: 20px; }
.history-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 180px;
  padding-top: 10px;
}
.history-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
  min-width: 0;
}
.history-value { font-size: 0.75rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.history-bar {
  width: 100%;
  max-width: 46px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--accent), rgba(124, 92, 255, 0.25));
  min-height: 3px;
  transition: filter 0.12s ease;
}
.history-col:hover .history-bar { filter: brightness(1.3); }
.history-month { font-size: 0.68rem; color: var(--text-dim); white-space: nowrap; }

/* about */
.about-card { text-align: center; padding: 70px 24px; }
.about-text { font-size: 1.15rem; color: var(--text-dim); }

/* challenge detail */
.rounds-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.round-card { padding: 14px 16px; }
.round-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.round-number { font-weight: 700; white-space: nowrap; }
.round-country {
  flex: 1;
  min-width: 0;
  color: var(--text-dim);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}
.round-stats { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.round-stats > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.round-stats .stat-label { font-size: 0.72rem; }
.stat-value-sm { font-weight: 700; font-variant-numeric: tabular-nums; }
.round-closest { color: var(--text-dim); font-size: 0.85rem; border-top: 1px solid var(--border); padding-top: 8px; }
.round-closest a { color: var(--accent-2); text-decoration: none; }

/* footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 18px 0;
  color: var(--text-dim);
  font-size: 0.85rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ---------- join form ---------- */
.form-card { max-width: 640px; margin: 0 auto; }
.form-card h1 { margin-bottom: 8px; }
.form-field { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; }
.form-field label { font-weight: 650; font-size: 0.92rem; }
.form-field input[type="text"],
.form-field input[type="url"],
.form-field input:not([type]) {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 14px;
  font: inherit;
  outline: none;
  width: 100%;
}
.form-field input:focus { border-color: var(--accent); }
.form-help { color: var(--text-dim); font-size: 0.85rem; }
.form-error { color: var(--bad); font-size: 0.88rem; font-weight: 600; }
.form-error ul { margin: 6px 0; padding-left: 18px; }
.form-success {
  background: rgba(52, 211, 153, 0.10);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: var(--good);
  border-radius: 11px;
  padding: 12px 14px;
  font-weight: 600;
}
.form-success a { color: var(--accent-2); }

@media (max-width: 720px) {
  /* ----- base ----- */
  .container { width: min(1240px, 100% - 24px); }
  main { padding: 18px 0 32px; }
  h1 { font-size: 1.3rem; }
  .card { padding: 14px; }
  tbody td { padding: 8px 6px; }
  thead th { padding: 10px 8px; }

  /* ----- header: CSS-only hamburger ----- */
  .header-inner {
    flex-wrap: nowrap;
    gap: 12px;
    padding: 10px 0;
    position: relative;
  }
  .brand { font-size: 1.05rem; margin-right: auto; }
  .nav-burger { display: flex; }
  .tabs {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 6px;
    z-index: 60;
    background: var(--bg-soft);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
  .nav-toggle:checked ~ .tabs { display: flex; }
  .nav-toggle:focus-visible ~ .nav-burger { outline: 2px solid var(--accent-2); outline-offset: 2px; }
  .tab { padding: 12px 16px; font-size: 1rem; }

  /* ----- leaderboard: identity lives in the avatar rail,
         score + days scroll beside it ----- */
  .leaderboard {
    --sticky-score: 96px;
    --lb-row-h: 49px;
    --lb-head-h: 36px;
    --rail-w: 178px;
    --rail-shrink: 126px;
  }
  .leaderboard thead th.col-score,
  .leaderboard tbody td.col-score {
    position: static;
    box-shadow: none;
    border-right: none;
  }
  .leaderboard .col-score { min-width: 84px; max-width: none; width: auto; }
  /* The table's own identity columns are replaced by the rail on mobile
     (display:none also drops them from the accessibility tree). */
  .leaderboard .col-place,
  .leaderboard .col-player { display: none; }
  .col-day { min-width: 44px; }
  .day-link,
  .day-link:link,
  .day-link:visited,
  .day-link:hover,
  .day-link:active { padding: 8px 4px; }

  /* ----- avatar rail: sticky flex sibling of the table -----
     Collapse is *scrubbed* by the finger: leaderboard.js sets --p
     (0..1 over ~80px of sideways scroll) and every animated value is a
     calc() of --p with NO transition — so partial drags show partial
     states instead of replaying a canned animation. Row/header heights
     lock to the table's via --lb-row-h / --lb-head-h (refined to exact
     pixels by leaderboard.js; the CSS values are the no-JS fallback). */
  .table-wrap { --p: 0; }
  .table-wrap:has(> .leaderboard) { display: flex; align-items: flex-start; }
  .table-wrap:has(> .leaderboard) > table.leaderboard { flex: 0 0 auto; }
  .avatar-rail {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    position: sticky;
    left: 0;
    z-index: 6;
    width: calc(var(--rail-w) - (var(--rail-shrink) * var(--p, 0)));
    background: var(--card);
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.6);
    overflow: hidden;
  }
  .rail-head { height: var(--lb-head-h); flex: 0 0 auto; border-bottom: 1px solid var(--border); }
  .rail-row {
    height: var(--lb-row-h);
    flex: 0 0 auto;
    padding: 0 10px 0 8px;
    border-bottom: 1px solid rgba(35, 43, 61, 0.55);
    overflow: hidden;
  }
  .rail-row:last-child { border-bottom: none; }
  .avatar-rail .player-link { gap: calc(10px * (1 - var(--p, 0))); }
  /* Rank gutter: the place column, moved into the rail. Crossfades into
     the avatar corner chip as the rail collapses. */
  .rail-place {
    flex: 0 0 auto;
    min-width: calc(30px * (1 - var(--p, 0)));
    max-width: calc(30px * (1 - var(--p, 0)));
    overflow: hidden;
    text-align: center;
    font-weight: 700;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    opacity: calc(1 - var(--p, 0));
  }
  .avatar-rail .nick {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: calc(160px * (1 - var(--p, 0)));
    opacity: calc(1 - var(--p, 0));
  }
  .place-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: -5px;
    bottom: -5px;
    min-width: 18px;
    height: 18px;
    padding: 0 3px;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    opacity: var(--p, 0);
    transform: scale(calc(0.5 + (0.5 * var(--p, 0))));
  }
  .rail-row:hover, .rail-row.sync-hover { background: var(--card-hover); }
  .leaderboard tbody tr.sync-hover { background: var(--card-hover); }
  .rail-row.row-gold { box-shadow: inset 3px 0 0 var(--gold); }
  .rail-row.row-silver { box-shadow: inset 3px 0 0 var(--silver); }
  .rail-row.row-bronze { box-shadow: inset 3px 0 0 var(--bronze); }
  .rail-row.row-highlight {
    background: rgba(34, 211, 238, 0.07);
    box-shadow: inset 3px 0 0 var(--accent-2);
    animation: row-glow 1.6s ease-out;
  }

  /* ----- controls ----- */
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .controls { width: 100%; }
  .segmented { overflow-x: auto; max-width: 100%; }
  .seg { flex: 0 0 auto; padding: 10px 16px; }
  .month-form { width: 100%; }
  .month-form select { width: 100%; min-height: 44px; }

  /* ----- profile / cards ----- */
  .profile-header { gap: 16px; }
  .profile-id { gap: 12px; }
  .profile-id h1 { font-size: 1.4rem; }
  .avatar-xl { width: 64px; height: 64px; font-size: 1.5rem; }
  .rewards { width: 100%; text-align: left; }
  .rewards-toggle { padding: 10px 16px; min-height: 44px; }
  .reward-badges { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reward-badges.collapsed { max-height: 122px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-value { font-size: 1.2rem; }
  .history-chart { gap: 6px; overflow-x: auto; }
  .history-col { min-width: 34px; }
  .history-month { font-size: 0.6rem; }

  /* ----- misc ----- */
  .hide-sm { display: none; }
  .countries thead th:first-child,
  .countries tbody td:first-child { max-width: 140px; }
  .about-card { padding: 40px 20px; }
  .form-card .gg-button,
  .page-head .gg-button { width: 100%; text-align: center; }
  .form-field input[type="text"],
  .form-field input[type="url"],
  .form-field input:not([type]) { padding: 12px 14px; font-size: 16px; }
}

@media (max-width: 480px) {
  .leaderboard { --rail-w: 150px; --rail-shrink: 106px; --lb-row-h: 45px; }
  .avatar-rail .player-link { gap: calc(8px * (1 - var(--p, 0))); }
  .rail-row { padding: 0 6px; }
  .col-day { min-width: 40px; }
  .player-link { gap: 8px; }
  .nick { font-size: 0.85rem; }
  .avatar { width: 28px; height: 28px; }
}

@media (max-width: 380px) {
  .leaderboard { --rail-w: 132px; --rail-shrink: 88px; }
  .leaderboard .col-score { min-width: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  .avatar-rail,
  .avatar-rail .nick,
  .place-chip { transition: none; }
}
