:root {
  --bg: #0f1117;
  --panel: #171a23;
  --panel-2: #1e2230;
  --line: #2a2f40;
  --text: #e8eaf1;
  --muted: #8a90a6;
  --accent: #6fbfdd;

  --t1: #f5c542;
  --t2: #c9d1e0;
  --t3: #d98a4a;
  --t4: #7aa7e8;
  --t5: #8c93a8;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 50% -200px, #1b2233 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  min-height: 100vh;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; text-align: left; }
a { color: inherit; text-decoration: none; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Top bar */
.topbar { border-bottom: 1px solid var(--line); background: rgba(15,17,23,.85); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; height: 68px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; letter-spacing: -.3px; white-space: nowrap; }
.brand img { width: 44px; height: 44px; border-radius: 50%; }
.brand b { color: var(--t1); }

.search { position: relative; width: 280px; max-width: 50vw; }
.search input {
  width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font: inherit; outline: none;
}
.search input:focus { border-color: var(--accent); }
.search-results { display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.search-results.open { display: block; }
.search-results button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; }
.search-results button:hover { background: var(--panel-2); }
.search-results .head { width: 24px; height: 24px; }
.search-results .none { padding: 10px 12px; color: var(--muted); }

/* Gamemode tabs */
.modes { display: flex; gap: 8px; overflow-x: auto; padding: 22px 0 18px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.mode {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-width: 86px; padding: 12px 10px 10px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  font-size: 13px; font-weight: 600; transition: .15s;
}
.mode img, .mode .trophy { width: 34px; height: 34px; font-size: 26px; line-height: 34px; text-align: center; }
.mode:hover { color: var(--text); border-color: #3a4157; }
.mode.active { color: var(--text); background: var(--panel-2); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* Heads */
.head { width: 32px; height: 32px; border-radius: 6px; image-rendering: pixelated; flex: 0 0 auto; }
.head-fallback { display: inline-grid; place-items: center; background: var(--panel-2); color: var(--muted); font-weight: 700; }

/* Region tags */
.region { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: #2a3045; color: #b9c0d6; }
.r-na { background: #3a2230; color: #ff8fb0; }
.r-nae { background: #3a2230; color: #ff8fb0; }
.r-nac { background: #3a2a1c; color: #ffad6b; }
.r-naw { background: #1c2b3a; color: #7cc4ff; }
.r-eu { background: #1f3326; color: #7fe0a0; }
.r-as { background: #33291a; color: #ffc067; }
.r-au { background: #2b2440; color: #c3a2ff; }
.r-sa { background: #1b3036; color: #6fd8e8; }

/* Tier badges */
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px 4px 5px;
  border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12px; font-weight: 800;
}
.badge img { width: 18px; height: 18px; }
.t1 { color: var(--t1); } .t2 { color: var(--t2); } .t3 { color: var(--t3); } .t4 { color: var(--t4); } .t5 { color: var(--t5); }

/* Overall leaderboard */
.board { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 40px; }
.board-head, .row { display: grid; grid-template-columns: 56px minmax(180px, 1.2fr) 90px 2fr; align-items: center; gap: 12px; padding: 12px 18px; }
.board-head { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; border-bottom: 1px solid var(--line); }
.row { width: 100%; border-bottom: 1px solid var(--line); transition: background .15s; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--panel-2); }
.rank { font-size: 20px; font-weight: 800; color: var(--muted); }
.top1 .rank { color: var(--t1); } .top2 .rank { color: var(--t2); } .top3 .rank { color: var(--t3); }
.top1 { background: linear-gradient(90deg, rgba(245,197,66,.10), transparent 40%); }
.top2 { background: linear-gradient(90deg, rgba(201,209,224,.08), transparent 40%); }
.top3 { background: linear-gradient(90deg, rgba(217,138,74,.08), transparent 40%); }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who .head { width: 44px; height: 44px; }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; }
.who-text small { color: var(--muted); font-size: 12px; }

/* Gamemode tier columns */
.tiers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 40px; }
.col { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; min-width: 0; }
.col-head { padding: 12px; text-align: center; font-weight: 800; font-size: 18px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.col-head.t1 { box-shadow: inset 0 -3px 0 var(--t1); }
.col-head.t2 { box-shadow: inset 0 -3px 0 var(--t2); }
.col-head.t3 { box-shadow: inset 0 -3px 0 var(--t3); }
.col-head.t4 { box-shadow: inset 0 -3px 0 var(--t4); }
.col-head.t5 { box-shadow: inset 0 -3px 0 var(--t5); }
.col-body { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.chip { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 9px; background: var(--panel-2); width: 100%; }
.chip:hover { outline: 1px solid var(--accent); }
.chip span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.chip .head { width: 26px; height: 26px; }
.none { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 4px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* Player modal */
.modal { position: fixed; inset: 0; background: rgba(5,6,10,.7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { position: relative; width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.modal-close { position: absolute; top: 10px; right: 14px; font-size: 26px; color: var(--muted); }
.modal-close:hover { color: var(--text); }
.pm-top { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.pm-body { height: 120px; image-rendering: pixelated; }
.pm-top h2 { margin: 4px 0 0; font-size: 24px; }
.pm-stats { display: flex; gap: 12px; margin-top: 6px; }
.pm-stats div { background: var(--panel-2); border-radius: 10px; padding: 8px 18px; display: flex; flex-direction: column; align-items: center; }
.pm-stats b { font-size: 20px; }
.pm-stats small { color: var(--muted); font-size: 12px; }
.pm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 20px; }
.pm-mode { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); font-size: 14px; font-weight: 600; }
.pm-mode img { width: 24px; height: 24px; }
.pm-mode span { flex: 1; }
.pm-mode b { font-weight: 800; }
.pm-mode.unranked { opacity: .45; }
.pm-mode:hover { outline: 1px solid var(--accent); }

/* Responsive */
@media (max-width: 900px) {
  .tiers { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .brand { font-size: 17px; }
  .search { width: 160px; }
  .hide-sm { display: none; }
  .board-head, .row { grid-template-columns: 36px 1fr; padding: 12px; }
  .board-head span:last-child { display: none; }
  .row .badges { grid-column: 1 / -1; }
  .tiers { grid-template-columns: 1fr; }
}
