:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --card: #ffffff;
  --bg: #f8fafc;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.05);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --r: 8px;
  --r-lg: 14px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
}

/* ── SIDEBAR ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 { font-size: 17px; font-weight: 800; color: var(--primary); }
.sidebar-logo p  { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px; font-weight: 500;
  border-left: 3px solid transparent;
  transition: all .15s;
  user-select: none;
}
.nav-item:hover { background: #f1f5f9; color: var(--text-primary); }
.nav-item.active { background: #ede9fe; color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.nav-icon { width: 20px; text-align: center; font-size: 16px; }

/* ── MAIN ─────────────────────────────────────────────────────────────────── */
.main { margin-left: 220px; flex: 1; padding: 28px 32px; min-height: 100vh; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }

/* ── PAGE HEADER ──────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 22px; }
.page-header h2 { font-size: 22px; font-weight: 800; }
.page-header p  { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }

/* ── GRID ─────────────────────────────────────────────────────────────────── */
.g2      { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.g3      { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.g-games { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 16px; }

/* ── CARD ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

/* ── STAT CARD ────────────────────────────────────────────────────────────── */
.stat-card  { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 18px 22px; box-shadow: var(--shadow); }
.stat-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); }
.stat-value { font-size: 34px; font-weight: 800; margin-top: 4px; }

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 16px;
  border-radius: var(--r);
  font-size: 13px; font-weight: 600;
  cursor: pointer; border: none;
  transition: all .15s; line-height: 1;
}
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover   { background: var(--primary-dark); }
.btn-secondary { background: #f1f5f9; color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover   { background: #059669; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover    { background: #dc2626; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-warning:hover   { background: #d97706; }
.btn-pink      { background: #ec4899; color: #fff; }
.btn-pink:hover      { background: #db2777; }
.btn-sm   { padding: 5px 11px; font-size: 12px; }
.btn-lg   { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 7px; border-radius: 6px; }

/* ── FORM ─────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block; font-size: 12px; font-weight: 700;
  color: var(--text-primary); margin-bottom: 5px;
  text-transform: uppercase; letter-spacing: .04em;
}
.input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--r);
  font-size: 14px; background: var(--card); color: var(--text-primary);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }

/* ── TOGGLE ───────────────────────────────────────────────────────────────── */
.toggle-group { display: flex; background: #f1f5f9; border-radius: var(--r); padding: 3px; gap: 2px; }
.toggle-btn {
  flex: 1; padding: 6px 10px;
  border: none; border-radius: 6px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  background: transparent; color: var(--text-secondary); transition: all .15s;
}
.toggle-btn.active { background: var(--card); color: var(--primary); box-shadow: var(--shadow); }

/* ── BRACKET ──────────────────────────────────────────────────────────────── */
.bracket-match {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: var(--r); margin-bottom: 8px;
  background: var(--bg); border: 1px solid var(--border); flex-wrap: wrap;
}
.bracket-match.match-active { border-color: var(--primary); background: #f5f3ff; }
.bracket-match.match-done { opacity: .75; }
.bm-player  { flex: 1; font-weight: 600; min-width: 80px; }
.bm-vs      { color: var(--text-secondary); font-size: 12px; font-weight: 700; padding: 0 4px; }
.bm-winner  { color: var(--success); }
.bm-loser   { color: var(--text-secondary); text-decoration: line-through; font-weight: 400; }
.bm-tbd     { color: var(--text-secondary); font-style: italic; font-weight: 400; }
.bm-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── BADGE ────────────────────────────────────────────────────────────────── */
.badge    { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.b-purple { background: #ede9fe; color: var(--primary); }
.b-green  { background: #d1fae5; color: #065f46; }
.b-orange { background: #ffedd5; color: #9a3412; }
.b-blue   { background: #dbeafe; color: #1e40af; }
.b-gray   { background: #f1f5f9; color: var(--text-secondary); }

/* ── TABLE ────────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-secondary); padding: 8px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* ── PLAYER ───────────────────────────────────────────────────────────────── */
.player-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r); border: 1px solid var(--border); margin-bottom: 7px; background: var(--card); }
.avatar    { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 800; flex-shrink: 0; }
.avatar-sm { width: 26px; height: 26px; font-size: 10px; }

/* ── GAME CARD ────────────────────────────────────────────────────────────── */
.game-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 18px;
  box-shadow: var(--shadow); cursor: pointer; transition: all .15s;
}
.game-card:hover    { box-shadow: var(--shadow-md); border-color: var(--primary-light); transform: translateY(-1px); }
.game-card.is-active { border-color: var(--primary); border-width: 2px; }
.game-num      { font-size: 30px; font-weight: 900; color: var(--primary); line-height: 1; }
.game-pts-badge { background: #ede9fe; color: var(--primary); padding: 4px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }

/* ── KOTH ARENA ───────────────────────────────────────────────────────────── */
.koth-arena {
  background: linear-gradient(135deg, #f8fafc 0%, #ede9fe 100%);
  border: 1px solid #c7d2fe;
  border-radius: var(--r-lg); padding: 28px; text-align: center;
  margin-bottom: 20px;
}
.koth-arena.draw-state { background: linear-gradient(135deg, #fffbeb, #ffedd5); border-color: #fcd34d; }
.crown      { font-size: 40px; }
.king-name  { font-size: 26px; font-weight: 900; color: var(--primary); }
.chall-name { font-size: 20px; font-weight: 700; color: var(--accent); }
.vs-divider { font-size: 18px; font-weight: 800; color: var(--text-secondary); margin: 10px 0; }
.koth-queue { margin-top: 18px; }
.q-item {
  display: inline-flex; align-items: center; gap: 5px;
  background: white; border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 11px;
  font-size: 12px; font-weight: 600; margin: 3px;
}

/* ── TEAM BOX ─────────────────────────────────────────────────────────────── */
.team-display { display: grid; grid-template-columns: 1fr 56px 1fr; gap: 12px; align-items: center; }
.team-box     { border-radius: var(--r-lg); padding: 18px; text-align: center; }
.team-a       { background: #dbeafe; border: 2px solid #93c5fd; }
.team-b       { background: #fce7f3; border: 2px solid #f9a8d4; }
.team-box.champion { box-shadow: 0 0 0 3px var(--accent); }
.team-score   { font-size: 36px; font-weight: 900; margin-top: 8px; }
.team-member  { background: white; border-radius: var(--r); padding: 4px 9px; margin: 3px; font-size: 12px; font-weight: 600; display: inline-block; }

/* ── ROUND HISTORY ────────────────────────────────────────────────────────── */
.round-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--r); border: 1px solid var(--border); margin-bottom: 5px; font-size: 13px; }
.round-num { width: 22px; height: 22px; background: #f1f5f9; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; flex-shrink: 0; }

/* ── LEADERBOARD ──────────────────────────────────────────────────────────── */
.lb-item { display: flex; align-items: center; gap: 14px; padding: 13px 14px; border-radius: var(--r); border: 1px solid var(--border); margin-bottom: 7px; background: var(--card); transition: box-shadow .15s; }
.lb-item:hover { box-shadow: var(--shadow); }
.rank { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.r1 { background: #fef3c7; color: #92400e; font-size: 16px; }
.r2 { background: #f1f5f9; color: #334155; }
.r3 { background: #ffedd5; color: #9a3412; }
.rN { background: #f8fafc; color: var(--text-secondary); }
.progress-bar  { height: 5px; background: #e2e8f0; border-radius: 999px; overflow: hidden; margin-top: 5px; max-width: 180px; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s; }

/* ── MODAL ────────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
}
.overlay.hidden { display: none; }
.modal { background: var(--card); border-radius: var(--r-lg); padding: 32px; max-width: 460px; width: 100%; box-shadow: var(--shadow-lg); }
.modal h3     { font-size: 20px; font-weight: 800; margin-bottom: 6px; }
.modal .sub   { color: var(--text-secondary); font-size: 14px; margin-bottom: 22px; }
.modal-btns   { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── GAME OVERLAY ─────────────────────────────────────────────────────────── */
.game-overlay {
  display: none; position: fixed; inset: 0; background: var(--bg);
  z-index: 200; overflow-y: auto; padding: 28px 32px;
}
.go-inner { max-width: 860px; margin: 0 auto; }

/* ── WINNER BANNER ────────────────────────────────────────────────────────── */
.winner-banner {
  background: linear-gradient(135deg, #fef3c7, #ede9fe);
  border: 2px solid var(--accent);
  border-radius: var(--r-lg); padding: 24px; text-align: center; margin-bottom: 20px;
}
.winner-banner h3 { font-size: 22px; font-weight: 900; }

/* ── DRAW BOX ─────────────────────────────────────────────────────────────── */
.draw-box {
  background: linear-gradient(135deg, #fffbeb, #ffedd5);
  border: 2px solid #fcd34d; border-radius: var(--r-lg);
  padding: 22px; text-align: center; margin-bottom: 20px;
}

/* ── UTILITIES ────────────────────────────────────────────────────────────── */
.flex       { display: flex; }
.flex-c     { display: flex; align-items: center; }
.flex-b     { display: flex; justify-content: space-between; align-items: center; }
.gap-2      { gap: 8px; }
.gap-3      { gap: 12px; }
.mt-1       { margin-top: 4px; }
.mt-2       { margin-top: 8px; }
.mt-3       { margin-top: 12px; }
.mt-4       { margin-top: 16px; }
.mt-6       { margin-top: 24px; }
.mb-2       { margin-bottom: 8px; }
.mb-3       { margin-bottom: 12px; }
.mb-4       { margin-bottom: 16px; }
.mb-6       { margin-bottom: 24px; }
.w100       { width: 100%; }
.text-sm    { font-size: 13px; }
.text-xs    { font-size: 11px; }
.text-muted { color: var(--text-secondary); }
.text-center { text-align: center; }
.fw-700     { font-weight: 700; }
.fw-800     { font-weight: 800; }
.c-primary  { color: var(--primary); }
.section-title { font-size: 14px; font-weight: 700; margin-bottom: 10px; color: var(--text-primary); }
.divider    { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.empty-state { text-align: center; padding: 44px 20px; }
.empty-icon  { font-size: 44px; margin-bottom: 10px; }
.empty-state h3 { font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.empty-state p  { color: var(--text-secondary); font-size: 13px; }
.pts-chip   { background: #ede9fe; color: var(--primary); padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }

@media (max-width: 700px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 16px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .team-display { grid-template-columns: 1fr; }
}
