*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Login overlay ── */
.login-overlay {
  position: fixed; inset: 0; z-index: 999;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.login-overlay.hidden { display: none; }
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.login-logo { font-size: 24px; font-weight: 700; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-box input[type="password"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
  text-align: center;
}
.login-box input[type="password"]:focus { border-color: var(--accent); }
.login-box button[type="submit"] {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
.login-box button[type="submit"]:hover { opacity: .85; }
.login-error { color: var(--red); font-size: 13px; }
.login-error.hidden { display: none; }
.reset-ok { color: #00FF88; font-size: 13px; }

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 20px 24px;
}
.header-inner { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.header-titles { display: flex; flex-direction: row; align-items: center; gap: 12px; }
.province-shape { height: 72px; width: auto; }
.logo { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.subtitle { color: var(--muted); margin-top: 4px; font-size: 13px; }
.logout-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 6px 12px;
  transition: color .2s, border-color .2s;
  white-space: nowrap;
}
.logout-btn:hover { color: var(--text); border-color: var(--text); }

/* ── Main ── */
main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Search ── */
.search-section { display: flex; flex-direction: column; gap: 12px; }
.search-box { display: flex; gap: 8px; }
.search-box input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 14px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.search-box input:focus { border-color: var(--accent); }
.search-box button {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
}
.search-box button:hover { opacity: .85; }

.player-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
}
.player-card.hidden { display: none; }
.player-card h3 { font-size: 16px; margin-bottom: 10px; color: var(--accent); }
.player-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.stat-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  text-align: center;
}
.stat-chip .val { font-size: 20px; font-weight: 700; }
.stat-chip .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Tables grid ── */
.tables-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .tables-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 580px) { .tables-grid { grid-template-columns: 1fr; } }

/* ── Table sections ── */
.table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.table-section h2 {
  padding: 14px 18px;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.full-table { width: 100%; overflow-x: auto; }
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; }
.section-header h2 { padding: 0; }
.season-select { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.ranking-tabs { display: flex; border-bottom: 1px solid var(--border); }
.ranking-tab-btn { background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 600; padding: 12px 18px; display: flex; align-items: center; gap: 6px; transition: color .2s, border-color .2s; }
.ranking-tab-btn:hover { color: var(--text); }
.ranking-tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.season-tab { user-select: none; }
.season-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.season-select-inline { background: transparent; color: inherit; border: none; font-size: 13px; font-weight: 600; cursor: pointer; outline: none; padding: 0; }

table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
tbody tr { transition: background .15s; }
tbody tr:hover { background: rgba(255,255,255,.03); }
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
tbody tr:last-child td { border-bottom: none; }

.rank-1 .username { color: #ffd700; font-weight: 700; }
.rank-2 .username { color: #c0c0c0; font-weight: 600; }
.rank-3 .username { color: #cd7f32; font-weight: 600; }

.medal { font-size: 16px; }
.loading { text-align: center; color: var(--muted); padding: 20px; }
.empty   { text-align: center; color: var(--muted); padding: 20px; }

.win-pct { color: var(--green); font-weight: 600; }

/* ── Pagination ── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.page-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; font-size: 13px; padding: 6px 14px; transition: border-color .2s; }
.page-btn:hover:not([disabled]) { border-color: var(--accent); color: var(--accent); }
.page-btn[disabled] { opacity: 0.35; cursor: default; }
.page-info { color: var(--muted); font-size: 13px; }

/* ── Room link banner ── */
.room-link-section {
  max-width: 1100px;
  width: 100%;
  margin: 24px auto 0;
  padding: 0 16px;
}
.room-link-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #1a2a1a, #0d1f0d);
  border: 2px solid var(--green);
  border-radius: 14px;
  padding: 28px 24px;
  text-decoration: none;
  color: var(--text);
  transition: border-color .2s, box-shadow .2s, transform .15s;
  box-shadow: 0 0 20px rgba(63, 185, 80, 0.15);
}
.room-link-btn:hover {
  border-color: #5fdd70;
  box-shadow: 0 0 32px rgba(63, 185, 80, 0.35);
  transform: translateY(-2px);
}
.room-link-label {
  font-size: 18px;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.5px;
}
.room-link-url {
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  word-break: break-all;
  text-align: center;
}
@media (max-width: 580px) {
  .room-link-url { font-size: 16px; }
}

/* ── Contact ── */
.contact-section { text-align: center; padding: 28px 16px; }
.contact-section h2 { font-size: 16px; margin-bottom: 8px; }
.contact-section p { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.contact-btn { display: inline-block; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 20px; color: var(--accent); font-size: 14px; text-decoration: none; transition: border-color .2s; }
.contact-btn:hover { border-color: var(--accent); }

/* ── Footer ── */
footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 20px;
}

/* ── Tabs ── */
.tabs { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; max-width: 1100px; width: 100%; margin: 0 auto; padding: 0 16px; }
.tab-btn { background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-size: 14px; font-weight: 600; padding: 12px 18px; transition: color .2s, border-color .2s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-panel { display: flex; flex-direction: column; gap: 28px; }
.tab-panel.hidden { display: none; }

/* ── Joins ── */
.joins-header { display: flex; align-items: center; gap: 16px; }
.stat-chip.big .val { font-size: 48px; font-weight: 700; }
.stat-chip.big .lbl { font-size: 14px; color: var(--muted); }
.bar-chart { padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.bar-item { display: grid; grid-template-columns: 48px 1fr 40px; align-items: center; gap: 10px; }
.bar-label { font-size: 12px; color: var(--muted); text-align: right; }
.bar-track { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width .4s ease; min-width: 2px; }
.bar-count { font-size: 12px; color: var(--muted); }
