:root {
  --bg: #0b0d12;
  --bg-elevated: #12151d;
  --bg-card: #171b26;
  --bg-card-hover: #1f2433;
  --border: #262c3b;
  --text: #e8eaf0;
  --text-dim: #9aa2b5;
  --text-faint: #5c6377;
  --accent: #6ea8ff;
  --accent-dim: #2f4570;
  --radius: 10px;

  /* Skill tier colors -- lowest to highest prestige. Names match
     classify_skill_tier_base()'s exact output strings from the processor
     script, so a tier string from players.json maps straight to a color
     with no translation table needed. */
  --tier-unranked: #5c6377;
  --tier-intermediate: #f28c28;
  --tier-competent: #4caf7d;
  --tier-advanced: #3aa0c9;
  --tier-expert: #7c6ee8;
  --tier-master: #e5484d;
  --tier-grandmaster: #e6b800;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5f8;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #eef1f8;
    --border: #dde1ea;
    --text: #191c24;
    --text-dim: #565f75;
    --text-faint: #8790a3;
    --accent: #2b62d9;
    --accent-dim: #dbe7ff;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.brand-dub { color: var(--text); }
.brand-rank { color: var(--accent); }

.search-wrap {
  position: relative;
  flex: 1 1 auto;
  max-width: 480px;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 10px 36px 10px 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
#search-input::placeholder { color: var(--text-faint); }

.search-clear {
  position: absolute;
  right: 8px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.search-clear:hover { background: var(--border); color: var(--text); }

.player-count {
  flex: 0 0 auto;
  color: var(--text-dim);
  font-size: 13px;
  white-space: nowrap;
}

/* ---------- Site navigation tiles (Events / H2Hs / Stats / About) ---------- */
.site-nav { display: flex; gap: 6px; flex: 0 0 auto; margin-left: auto; }
.nav-tile {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition: color 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}
.nav-tile svg {
  width: 16px; height: 16px;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-tile:hover { color: var(--text); border-color: var(--accent-dim); }
.nav-tile[aria-current="page"] {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-card));
}
.header-right { display: flex; justify-content: flex-end; min-width: 0; }
@media (max-width: 1240px) {
  .nav-tile span { display: none; }   /* icons only when space is tight */
  .nav-tile { padding: 7px 9px; }
}

/* ---------- Players / Teams tabs ---------- */
.view-tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  flex: 0 0 auto;
}
.view-tab {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.view-tab:hover { color: var(--text); }
.view-tab[aria-selected="true"] { background: var(--accent); color: #fff; }

/* ---------- Sort dials ---------- */
.sort-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.sort-label { color: var(--text-dim); font-size: 13px; margin-right: 2px; }
.sort-dial {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.1s ease, color 0.1s ease, background 0.1s ease;
}
.sort-dial:hover { color: var(--text); border-color: var(--accent-dim); }
.sort-dial.active {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-card));
}
.sort-arrow:empty { display: none; }

/* ---------- Year filter ---------- */
.year-bar {
  display: flex;
  gap: 6px;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: thin;
  max-width: 100%;
  padding: 2px 0;
}
.year-bar[hidden] { display: none; }
.year-pill {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.1s ease, color 0.1s ease, background 0.1s ease;
}
.year-pill:hover { color: var(--text); border-color: var(--accent-dim); }
.year-pill.active {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--bg-card));
}
@media (max-width: 900px) {
  .year-bar { margin-left: 0; flex-basis: 100%; }
}

/* ---------- Main / grid ---------- */
#main {
  flex: 1 1 auto;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
}

.status {
  color: var(--text-dim);
  font-size: 14px;
  padding: 40px 0;
  text-align: center;
}
.status:empty { display: none; }

.grid-viewport {
  /* The browser's own scroller does the scrolling; grid-spacer just
     reserves the correct total height so the scrollbar/thumb size is
     accurate for the FULL (unfiltered or filtered) player count, even
     though only a small window of cards is ever actually in the DOM. */
}

.grid-spacer {
  position: relative;
  width: 100%;
}

.grid-window {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 12px;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 0;
  font-size: 15px;
}

/* ---------- Player card ---------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: background 0.1s ease, transform 0.1s ease, border-color 0.1s ease;
}
.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-dim);
  transform: translateY(-1px);
}

.card-rank {
  position: absolute;
  top: 8px;
  left: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-faint);
}

.card-portrait {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  margin-top: 6px;
}
.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-tag {
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-tier {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
}

.card-elo {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Tier color coding -- data-tier holds the base tier name (the '+'
   suffix stripped); data-plus="true" marks the "+" variant, which uses the
   same color 40% darker. --tb = base tier color, --tc = the color shown.
   Shared by the leaderboard cards and the profile page's skill card. */
[data-tier="GrandMaster"]  { --tb: var(--tier-grandmaster); }
[data-tier="Master"]       { --tb: var(--tier-master); }
[data-tier="Expert"]       { --tb: var(--tier-expert); }
[data-tier="Advanced"]     { --tb: var(--tier-advanced); }
[data-tier="Competent"]    { --tb: var(--tier-competent); }
[data-tier="Intermediate"] { --tb: var(--tier-intermediate); }
[data-tier="Unranked"]     { --tb: var(--tier-unranked); }
[data-tier] { --tc: var(--tb); }
[data-tier][data-plus="true"] { --tc: color-mix(in srgb, var(--tb) 60%, #000); }
.card-tier[data-tier] { color: var(--tc); background: color-mix(in srgb, var(--tc) 15%, var(--bg-elevated)); }

/* ---------- Team card ---------- */
.team-portraits { display: flex; justify-content: center; margin-top: 6px; }
.team-portraits .team-portrait { width: 56px; height: 56px; margin-top: 0; }
.team-portraits .team-portrait + .team-portrait { margin-left: -12px; }
.team-names { font-size: 13px; }
.team-name:hover { color: var(--accent); }
.team-record {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.card.team-card:hover { transform: none; }

/* Ranks 1-3 get a small extra flourish since they're the most-looked-at
   cards on the whole site. */
.card:not(.team-card)[data-rank="1"] .card-portrait { border-color: var(--tier-grandmaster); box-shadow: 0 0 0 2px var(--tier-grandmaster); }
.card:not(.team-card)[data-rank="2"] .card-portrait,
.card:not(.team-card)[data-rank="3"] .card-portrait { border-color: var(--text-dim); box-shadow: 0 0 0 2px var(--text-dim); }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 20px 28px;
  text-align: center;
}
.site-footer p {
  margin: 0;
  color: var(--text-faint);
  font-size: 12px;
  max-width: 700px;
  margin: 0 auto;
}

@media (max-width: 480px) {
  .header-inner { flex-wrap: wrap; gap: 10px 12px; }
  .view-tabs { order: 1; }
  .site-nav { order: 4; width: 100%; justify-content: space-between; }
  .site-nav .nav-tile { flex: 1 1 0; justify-content: center; }
  .site-nav .nav-tile span { display: inline; }
  .search-wrap { order: 2; flex-basis: 100%; max-width: none; }
  .player-count { order: 3; width: 100%; text-align: right; }
  .grid-window { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
}

.team-card-link { cursor: pointer; }
.team-card-link:hover { border-color: var(--accent); }
