: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: #6b7a8f;
  --tier-competent: #4caf7d;
  --tier-advanced: #3aa0c9;
  --tier-expert: #7c6ee8;
  --tier-master: #d857c4;
  --tier-grandmaster: #f2a93c;
}

@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;
}

/* ---------- 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 -- applied via data-tier on .card-tier, matching the
   base tier name (the '+' suffix, if any, is stripped before lookup). */
.card-tier[data-tier="GrandMaster"] { color: var(--tier-grandmaster); background: color-mix(in srgb, var(--tier-grandmaster) 15%, var(--bg-elevated)); }
.card-tier[data-tier="Master"]      { color: var(--tier-master);      background: color-mix(in srgb, var(--tier-master) 15%, var(--bg-elevated)); }
.card-tier[data-tier="Expert"]      { color: var(--tier-expert);      background: color-mix(in srgb, var(--tier-expert) 15%, var(--bg-elevated)); }
.card-tier[data-tier="Advanced"]    { color: var(--tier-advanced);    background: color-mix(in srgb, var(--tier-advanced) 15%, var(--bg-elevated)); }
.card-tier[data-tier="Competent"]   { color: var(--tier-competent);   background: color-mix(in srgb, var(--tier-competent) 15%, var(--bg-elevated)); }
.card-tier[data-tier="Intermediate"]{ color: var(--tier-intermediate);background: color-mix(in srgb, var(--tier-intermediate) 15%, var(--bg-elevated)); }
.card-tier[data-tier="Unranked"]    { color: var(--tier-unranked);    background: color-mix(in srgb, var(--tier-unranked) 15%, var(--bg-elevated)); }

/* Ranks 1-3 get a small extra flourish since they're the most-looked-at
   cards on the whole site. */
.card[data-rank="1"] .card-portrait { border-color: var(--tier-grandmaster); box-shadow: 0 0 0 2px var(--tier-grandmaster); }
.card[data-rank="2"] .card-portrait,
.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; }
  .player-count { order: 3; width: 100%; text-align: right; }
  .grid-window { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
}
