/* ========== VIBRANT/GRADIENT THEME ========== */
:root {
  --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  --card-bg: #1f2937;
  --card-border: rgba(255,255,255,0.1);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-gradient: linear-gradient(90deg, #06b6d4, #8b5cf6);
  --btn-gradient: linear-gradient(135deg, #06b6d4 0%, #8b5cf6 100%);
  --table-header-bg: rgba(255,255,255,0.05);
  --table-border: rgba(255,255,255,0.05);
  --input-bg: #111827;
  --input-border: rgba(255,255,255,0.15);
  --hover-bg: rgba(255,255,255,0.08);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  margin: 0;
  padding: 20px;
  background: var(--bg-gradient);
  min-height: 100vh;
  color: var(--text-primary);
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Subtle glow on leaderboard card */
#leaderboardCard {
  box-shadow: 0 4px 30px rgba(6, 182, 212, 0.1), 0 4px 20px rgba(0, 0, 0, 0.3);
}

h1, h2 > span:first-child, h3 {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 { margin: 0 0 16px; font-size: 20px; color: var(--text-primary); }

table { border-collapse: collapse; width: 100%; }

th, td {
  border-bottom: 1px solid var(--table-border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--table-header-bg);
  position: sticky;
  top: 0;
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display:flex; gap:8px; flex-wrap: wrap; }

button {
  cursor:pointer;
  padding:10px 16px;
  border-radius:10px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
  font-weight: 500;
  transition: all 0.2s ease;
}

button:hover {
  background: rgba(255,255,255,0.15);
  transform: translateY(-1px);
}

button.primary {
  background: var(--btn-gradient);
  color: white;
  font-weight: 600;
}

button.primary:hover {
  filter: brightness(1.1);
  transform: scale(1.02);
}

select, input[type=text] {
  padding:10px 12px;
  border-radius:10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
  width:100%;
}

select:focus, input[type=text]:focus {
  outline: none;
  border-color: #06b6d4;
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.2);
}

label {
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  display: block;
}

.muted { color: var(--text-muted); font-size: 12px; }
.delta-pos { color: #34d399; font-weight: bold; }
.delta-neg { color: #f87171; font-weight: bold; }
.pending { font-size: 13px; }
.mode { margin-bottom: 12px; }
.mode label { display: inline; margin-right: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 6px; }
.small { font-size: 12px; color: var(--text-secondary); }

/* Modal for charts */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); display:none; z-index: 2000; }
.modal { position: fixed; top: 8vh; left: 50%; transform: translateX(-50%); width: min(900px, 92vw); background: var(--card-bg); border:1px solid var(--card-border); border-radius:16px; box-shadow: 0 20px 50px rgba(0,0,0,0.4); display:none; z-index: 2001; }
.modal header { display:flex; justify-content:space-between; align-items:center; padding:14px 18px; border-bottom:1px solid var(--table-border); }
.modal header h3 { margin:0; font-size:16px; }
.modal .content { padding:14px 18px; }
.close-btn { border: none; background: rgba(255,255,255,0.1); border-radius:8px; padding:8px 14px; cursor:pointer; color: var(--text-primary); transition: all 0.2s; }
.close-btn:hover { background: rgba(255,255,255,0.15); }

.container {
  max-width: 1100px;
  margin: 0 auto;
}

.icon-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  width: 28px;
  height: 28px;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.25);
  transform: scale(1.05);
}

/* Player column visuals (avatar only in Player col, not in # col) */
.name-cell { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.name-cell .name-with-trophy { display: inline-flex; align-items: center; gap: 4px; }
.name-cell .trophy-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
  border: 2px solid rgba(6, 182, 212, 0.3);
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.2);
}

/* Avatar picker UI in menu */
#avatarChoices { display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.avatar-choice {
  width:36px; height:36px; border:1px solid rgba(255,255,255,0.15); border-radius:10px;
  display:flex; align-items:center; justify-content:center; cursor:pointer; background: rgba(255,255,255,0.05);
  transition: all 0.2s;
}
.avatar-choice:hover { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.25); }
.avatar-choice.selected { outline:2px solid #06b6d4; border-color: #06b6d4; }

/* small avatar for compact contexts (Recent Matches) */
.avatar.small {
  width: 22px; height: 22px;
  font-size: 11px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid rgba(6, 182, 212, 0.2);
  vertical-align: -3px;
  margin-right: 4px;
}

/* Touch-friendly selects */
.big-select {
  font-size: 18px;
  padding: 14px 16px;
  min-height: 48px;
  line-height: 1.3;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text-primary);
  border-radius: 12px;
}
.big-select:focus {
  border-color: #06b6d4;
  box-shadow: 0 0 0 2px rgba(6, 182, 212, 0.2);
  outline: none;
}
@media (max-width: 1024px) {
  .big-select { font-size: 19px; padding: 16px 18px; }
}

/* === Emoji Avatars === */

/* Emoji avatars: show the emoji itself (no circle, no border) */
.avatar.emoji {
  background: transparent !important;
  border: 0 !important;
  color: inherit;
  font-size: 20px;
  width: auto !important;
  height: auto !important;
  padding: 0;
  line-height: 1;
  display: inline-block;
  vertical-align: middle;
}

/* Compact emoji for small contexts */
.avatar.emoji.small {
  background: transparent !important;
  border: 0 !important;
  font-size: 16px;
  width: auto !important;
  height: auto !important;
  padding: 0;
  line-height: 1;
}

/* ---- Context-specific sizing ---- */

/* Leaderboard player emoji */
#lb .name-cell .avatar.emoji {
  font-size: 20px !important;
  line-height: 1 !important;
  display: inline-block !important;
  vertical-align: middle !important;
}

/* Recent Matches: a bit smaller so rows stay compact */
#matches .avatar.emoji {
  font-size: 18px !important;
  line-height: 1 !important;
  display: inline-block !important;
}

/* Pending table, register selects, and peek modal */
#pendingTbl .avatar.emoji,
#singlesForm .avatar.emoji,
#doublesForm .avatar.emoji,
.peek-modal .avatar.emoji {
  font-size: 18px !important;
  line-height: 1 !important;
  display: inline-block !important;
}

/* Slight padding for match rows to breathe */
#lb tbody td,
#matches tbody td {
  padding-top: 10px;
  padding-bottom: 10px;
}

/* Leaderboard menu button */
.lb-menu-btn {
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
  width: 38px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  transition: all 0.2s;
}
.lb-menu-btn:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.25);
}

/* Leaderboard menu panel — compact popover */
.lb-menu-panel{
  position: fixed;
  left: 16px; top: 60px;
  background: var(--card-bg);
  border:1px solid var(--card-border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  padding: 14px;
  display:none;
  width: 340px;
  max-width: 92vw;
  max-height: 70vh;
  overflow:auto;
  z-index: 2002;
}

/* Hide "Add player" section in avatar-only mode */
.lb-menu-panel.avatar-only #lbAddWrap { display:none; }

.lb-menu-panel hr {
  border: none;
  border-top: 1px solid var(--table-border);
  margin: 12px 0;
}

/* ===== Leaderboard medal accents ===== */
.leaderboard-row.gold {
  background: linear-gradient(90deg, rgba(255,215,0,0.15) 0%, transparent 50%);
  box-shadow: inset 4px 0 0 rgba(255,215,0,.8);
  font-weight:600;
}
.leaderboard-row.silver {
  background: linear-gradient(90deg, rgba(192,192,192,0.1) 0%, transparent 50%);
  box-shadow: inset 4px 0 0 rgba(192,192,192,.7);
  font-weight:600;
}
.leaderboard-row.bronze {
  background: linear-gradient(90deg, rgba(205,127,50,0.1) 0%, transparent 50%);
  box-shadow: inset 4px 0 0 rgba(205,127,50,.7);
  font-weight:600;
}

.qualifying-row {
  background: rgba(255,255,255,0.02);
}
.qual-note {
  margin-left: 8px;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(6, 182, 212, 0.15);
  padding: 2px 8px;
  border-radius: 10px;
}
.qual-rating {
  color: var(--text-muted);
}

.inactive {
  opacity: 0.5;
}
.inactive .name-cell::after {
  content: 'Inactive';
  font-size: 0.7em;
  color: var(--text-muted);
  margin-left: 8px;
  background: rgba(255,255,255,0.08);
  padding: 3px 8px;
  border-radius: 10px;
}

/* ===== Player Peek panel ===== */
.player-peek-panel {
  position: fixed;
  left: 16px; top: 60px;
  background: var(--card-bg);
  border:1px solid var(--card-border);
  border-radius:14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  padding:14px;
  display:none;
  width: 400px;
  max-width: 95vw;
  z-index: 2003;
}

.player-peek-head { font-weight:700; margin-bottom:8px; display:flex; align-items:center; gap:8px; }
.player-peek-stats { margin-bottom:10px; font-size:14px; color: var(--text-secondary); }

.player-peek-matches { display:grid; grid-template-columns: 1fr 1fr; gap:6px 12px; font-size:14px; }
.player-peek-matches div { white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.player-peek-close {
  position:absolute; top:8px; right:8px;
  border: none; background: rgba(255,255,255,0.1); border-radius:8px; padding:4px 10px; cursor:pointer;
  color: var(--text-primary);
  transition: all 0.2s;
}
.player-peek-close:hover { background: rgba(255,255,255,0.15); }

/* Zero-game players: greyed out with a "No games" pill */
.zero {
  opacity: 0.45;
}
.zero .name-cell::after {
  content: 'No games';
  font-size: 0.7em;
  color: var(--text-muted);
  margin-left: 8px;
  background: rgba(255,255,255,0.08);
  padding: 3px 8px;
  border-radius: 10px;
}

/* Separator row before zero-game block */
.lb-sep td {
  padding-top: 14px;
  border-bottom: none;
}
.lb-sep .sep-pill {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  background: rgba(139, 92, 246, 0.15);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

/* Two equal columns for doubles rows so partner 2 aligns across lines */
.match-pair-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}

.match-team-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}
.match-team-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Stack each team's two players */
.match-team-grid .team {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Keep icon + name + delta on one line */
.playerline {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  white-space: nowrap;
}

.match-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Bigger, touch-friendly buttons */
.big-btn {
  font-size: 17px;
  padding: 14px 20px;
  min-height: 48px;
  line-height: 1.2;
  border-radius: 12px;
  font-weight: 600;
}

/* Row-level remove buttons in Pending */
#pendingCard .remove-btn {
  font-size: 15px;
  padding: 10px 14px;
  min-height: 40px;
  line-height: 1;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
  border: 1px solid rgba(248, 113, 113, 0.3);
}
#pendingCard .remove-btn:hover {
  background: rgba(248, 113, 113, 0.25);
}

/* Optional: scale up on tablets */
@media (max-width: 1024px) {
  .big-btn { font-size: 18px; padding: 16px 22px; }
  #pendingCard .remove-btn { font-size: 16px; }
}

/* Slightly larger text for table content */
#lb td,
#matches td,
#pendingTbl td {
  font-size: 15px;
}

#lb th,
#matches th,
#pendingTbl th {
  font-size: 14px;
}

/* Slightly larger text for table contents in Leaderboard, Recent Matches, and Pending Matches */
#lb tbody td,
#matches tbody td,
#pendingTbl tbody td {
  font-size: 15px;
}

/* Pending matches doubles formatting */
.pending-team {
  display: block;
  line-height: 1.6;
}
.pending-team.winners {
  color: #4ade80;
}
.pending-team.losers {
  color: #f87171;
}
.pending-vs {
  font-size: 12px;
  color: var(--text-muted);
  margin: 2px 0;
}

/* History doubles formatting */
.history-team {
  display: block;
  line-height: 1.5;
}
.history-vs {
  font-size: 11px;
  color: var(--text-muted);
  margin: 1px 0;
}

/* Daily summary rows in Recent Matches */
#matches th {
  font-size: 14px;
  line-height: 1.4;
  text-transform: none;
}

/* --- Mini player panel --- */
.mini-modal { width: min(560px, 92vw); }

/* Clear stats row with divider */
.mini-statsbar {
  padding: 10px 0;
  border-bottom: 1px solid var(--table-border);
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 600;
}

/* Peek list layout */
.mini-list  { display: grid; gap: 8px; max-height: 320px; overflow: auto; }
.mini-row   { display: grid; grid-template-columns: 1fr auto 1fr; column-gap: 12px; align-items: center; }

/* One line per side, no wrapping */
.mini-row .team,
.mini-row .opp {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Center "vs" */
.mini-row .vs {
  font-size: 12px;
  opacity: .6;
  padding: 0 6px;
  color: var(--text-muted);
}

/* Color ONLY the selected player's side (both names in doubles) */
.me-win  { color: #34d399; font-weight: 700; }
.me-loss { color: #f87171; font-weight: 700; }

/* Clickable name in leaderboard */
.lb-name-btn {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 10px;
  transition: all 0.2s;
  background: rgba(255,255,255,0.05);
  border: 1px solid transparent;
}
.lb-name-btn:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
}

/* Player peek modal */
.peek-modal {
  position: fixed;
  top: 10vh;
  left: 50%;
  transform: translateX(-50%);
  width: min(540px, 92vw);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.4);
  z-index: 2001;
  display: none;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.peek-header {
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--table-border);
}
.peek-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
/* Reset gradient styling for avatar inside h3 */
.peek-header h3 .avatar {
  -webkit-background-clip: border-box !important;
  -webkit-text-fill-color: initial !important;
  background-clip: border-box !important;
  background: none !important;
}
.peek-header h3 .avatar.emoji {
  background: none !important;
}
.peek-title-actions {
  display: inline-flex;
  gap: 6px;
  margin-left: auto;
}
.peek-title-actions .icon-btn {
  width: 36px;
  height: 36px;
  font-size: 18px;
  background: rgba(255,255,255,0.08) !important;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  /* Reset gradient text styling inherited from h3 */
  -webkit-background-clip: border-box !important;
  -webkit-text-fill-color: initial !important;
  background-clip: border-box !important;
  color: inherit;
}
.peek-content {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

.peek-load-more {
  align-self: flex-start;
}

/* Compact utility button (matches "Show more days" styling) */
.show-more-btn,
.peek-load-more {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(6, 182, 212, 0.3);
  background: rgba(6, 182, 212, 0.1);
  color: #06b6d4;
  cursor: pointer;
  line-height: 1.2;
  transition: all 0.2s;
}
.show-more-btn:hover,
.peek-load-more:hover {
  background: rgba(6, 182, 212, 0.2);
  border-color: rgba(6, 182, 212, 0.5);
}

.peek-stats-row {
  font-weight: 600;
  display: flex; gap: 16px; flex-wrap: wrap;
  padding: 10px 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--table-border);
  border-radius: 12px;
}
.peek-list { display: grid; gap: 8px; }

/* Each match row – single line, no wrapping */
.peek-match {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--table-border);
  border-radius: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background 0.2s;
}
.peek-match:hover {
  background: rgba(255,255,255,0.06);
}
.peek-vs { opacity: 0.5; color: var(--text-muted); }

/* Name coloring: left team colored by win/loss */
.opp-win  { color: #34d399; font-weight: 600; }
.opp-loss { color: #f87171; font-weight: 600; }

/* Small avatars inside peek */
.peek-match .avatar.small { margin-right: 6px; }

/* Leaderboard action buttons (stats + chart) */
.lb-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Bigger medal emojis for top 3 ranks in leaderboard */
#lb .rank-cell {
  font-size: 22px !important;
  line-height: 1.2 !important;
}

/* ===== Vibrant theme is now the default ===== */
:root { color-scheme: dark; }

.no-scroll {
  overflow: hidden;
  height: 100vh;
}

/* Table zebra striping */
#lb tbody tr:nth-child(even):not(.leaderboard-row) { background: rgba(255,255,255,0.02); }
#lb tbody tr:hover { background: rgba(255,255,255,0.05); }

/* Leaderboard mode toggle */
.lb-toggle { display:flex; gap:8px; align-items:center; }
.lb-toggle button {
  padding:8px 14px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary);
  border-radius:10px;
  font-size:13px;
  cursor:pointer;
  transition: all .2s ease;
  font-weight: 500;
}
.lb-toggle button:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.25);
}

/* Selected toggle button */
.lb-toggle button.on,
.lb-toggle button[aria-selected="true"] {
  background: var(--btn-gradient);
  color: white !important;
  -webkit-text-fill-color: white !important;
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

/* Focus outline (keyboard) */
.lb-toggle button:focus-visible {
  outline: 2px solid #06b6d4;
  outline-offset: 2px;
}

/* --- Leaderboard row divider: make it one continuous line --- */

/* turn off cell borders in the body; keep header as-is */
#lb tbody td { border-bottom: none !important; }

/* draw one line per row that spans the full width */
#lb tbody tr { position: relative; }
#lb tbody tr::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: var(--table-border);
  pointer-events: none;
}

/* if you have zebra/medal backgrounds, keep the line visible on top */
#lb tbody tr.leaderboard-row::after { opacity: 0.8; }

/* === Fix: align rank medals (1–3) with numeric ranks below — table-safe version === */

/* same width for the whole rank column */
#lb th:nth-child(1),
#lb td:nth-child(1){
  width: var(--lb-rank-w) !important;
  min-width: var(--lb-rank-w) !important;
  max-width: var(--lb-rank-w) !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  text-align: center;
}

/* keep classic table layout and center everything vertically */
#lb tbody td{
  vertical-align: middle;
  line-height: 1.1;
}

/* normalize font sizing for the rank column so emoji ≈ numbers */
#lb tbody td:nth-child(1){
  font-size: var(--lb-rank-fs);
}

/* if top-3 rows had custom padding/height, enforce same padding as the rest */
#lb tbody tr:nth-child(-n+3) td{
  padding-top: 10px;
  padding-bottom: 10px;
}

/* optional: if your numeric ranks look slightly low, nudge them up a hair */
#lb tbody td:nth-child(1) {
  transform: translateY(0);
}

.champ-badge { margin-left: 6px; font-size: 14px; vertical-align: middle; }

/* Rating bar visual enhancement */
.rating-bar {
  height: 4px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}
.rating-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Radio button styling for mode selection */
input[type="radio"] {
  accent-color: #06b6d4;
  transform: scale(1.1);
}

/* Checkbox styling */
input[type="checkbox"] {
  accent-color: #06b6d4;
}

/* Add subtle animation to buttons */
button {
  transition: all 0.2s ease;
}

/* Make the form labels more visible */
.mode label {
  color: var(--text-primary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}
.mode label:hover {
  background: rgba(255,255,255,0.05);
}

/* Style the scrollbar for a modern look */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}

/* ========== NEW LAYOUT: PODIUM + DRAWER ========== */

/* Page header */
.page-header {
  text-align: center;
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0 0 4px 0;
  font-size: 32px;
}
.page-tagline {
  color: var(--text-muted);
  font-size: 13px;
  margin: 0;
}

/* Top bar with mode toggle and action buttons */
.top-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 10px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

.mode-pills {
  display: flex;
  background: rgba(255,255,255,0.05);
  border-radius: 10px;
  padding: 3px;
}
.mode-pills button {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  -webkit-text-fill-color: var(--text-secondary);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.mode-pills button:hover {
  background: rgba(255,255,255,0.05);
}
.mode-pills button.on {
  background: var(--btn-gradient);
  color: white;
  -webkit-text-fill-color: white;
  font-weight: 600;
}

.action-btns {
  display: flex;
  gap: 6px;
}
.action-btns button {
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.action-btns button:hover {
  background: rgba(255,255,255,0.12);
}
.action-btns button.primary {
  background: var(--btn-gradient);
  border-color: transparent;
  font-weight: 600;
}

/* Main leaderboard card */
.leaderboard-main {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  overflow: hidden;
  box-shadow:
    0 0 60px rgba(6, 182, 212, 0.1),
    0 8px 32px rgba(0,0,0,0.4);
  max-width: 480px;
  margin: 0 auto;
}

/* Podium for top 3 */
.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  padding: 30px 30px 20px;
  background: linear-gradient(180deg, rgba(6,182,212,0.1) 0%, transparent 100%);
}

.podium-spot {
  text-align: center;
  padding: 16px 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.05);
  min-width: 90px;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
}
.podium-spot:hover {
  background: rgba(255,255,255,0.08);
  transform: translateY(-2px);
}

.podium-spot.first {
  order: 2;
  transform: scale(1.1);
  background: linear-gradient(135deg, rgba(255,215,0,0.2), rgba(255,215,0,0.05));
  border: 1px solid rgba(255,215,0,0.3);
  min-width: 110px;
}
.podium-spot.first:hover {
  transform: scale(1.12) translateY(-2px);
}
.podium-spot.second {
  order: 1;
  background: linear-gradient(135deg, rgba(192,192,192,0.15), rgba(192,192,192,0.05));
  border: 1px solid rgba(192,192,192,0.2);
}
.podium-spot.third {
  order: 3;
  background: linear-gradient(135deg, rgba(205,127,50,0.15), rgba(205,127,50,0.05));
  border: 1px solid rgba(205,127,50,0.2);
}

.podium-medal { font-size: 32px; }
.podium-avatar { margin: 4px 0; font-size: 24px; }
.podium-name { font-weight: 700; font-size: 14px; margin: 6px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.podium-rating { color: var(--text-secondary); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Rest of leaderboard (positions 4+) */
.rest-list {
  padding: 8px 20px 20px;
}
.rest-item {
  display: grid;
  grid-template-columns: 32px 28px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 2px;
  cursor: pointer;
  transition: background 0.2s;
  background: rgba(255,255,255,0.02);
}
.rest-item:hover {
  background: rgba(255,255,255,0.06);
}
.rest-item:last-child {
  margin-bottom: 0;
}
.rest-rank {
  text-align: center;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
}
.rest-avatar {
  font-size: 20px;
  line-height: 1;
  text-align: center;
}
.rest-player {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.rest-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rest-rating {
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 14px;
  text-align: right;
  min-width: 45px;
}

/* Qualifying and inactive item styling */
.rest-item.qualifying-item {
  opacity: 0.7;
}
.rest-item.qualifying-item .rest-rating {
  color: var(--text-muted);
}
.rest-item.inactive-item {
  opacity: 0.5;
}
.rest-item.inactive-item .rest-rating {
  color: var(--text-muted);
}
.qual-badge {
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(6, 182, 212, 0.15);
  padding: 2px 6px;
  border-radius: 8px;
  margin-left: 6px;
}

/* Separator for qualifying/inactive */
.rest-separator {
  padding: 12px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.rest-separator span {
  background: rgba(139, 92, 246, 0.15);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

/* Inactive toggle button */
.inactive-toggle-wrap {
  display: flex;
  justify-content: center;
  padding: 16px 0 8px;
}
.inactive-toggle-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.inactive-toggle-btn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-secondary);
}
.inactive-toggle-arrow {
  font-size: 10px;
  transition: transform 0.2s;
}
.inactive-toggle-btn.open .inactive-toggle-arrow {
  transform: rotate(180deg);
}
.inactive-section {
  animation: fadeIn 0.2s ease;
}
.inactive-item {
  opacity: 0.5;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Loading state for leaderboard */
.leaderboard-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.leaderboard-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: #06b6d4;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Slide-out drawer */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 2000;
}
.drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  right: -420px;
  top: 0;
  bottom: 0;
  width: 400px;
  max-width: 92vw;
  background: var(--card-bg);
  border-left: 1px solid var(--card-border);
  box-shadow: -10px 0 40px rgba(0,0,0,0.4);
  transition: right 0.3s ease;
  z-index: 2001;
  display: flex;
  flex-direction: column;
}
.drawer.open {
  right: 0;
}

.drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--card-border);
  background: rgba(255,255,255,0.02);
}
.drawer-tab {
  flex: 1;
  padding: 14px;
  border: none;
  background: none;
  color: var(--text-secondary);
  -webkit-text-fill-color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}
.drawer-tab:hover {
  background: rgba(255,255,255,0.03);
}
.drawer-tab.active {
  color: #06b6d4;
  -webkit-text-fill-color: #06b6d4;
  border-bottom-color: #06b6d4;
  font-weight: 600;
}

.drawer-header {
  display: flex;
  justify-content: flex-end;
  padding: 8px 12px;
  border-bottom: 1px solid var(--card-border);
}
.drawer-close {
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 8px;
}
.drawer-close:hover {
  background: rgba(255,255,255,0.12);
}

.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.drawer-panel {
  display: none;
}
.drawer-panel.active {
  display: block;
}

/* Form styles in drawer */
.drawer-form-group {
  margin-bottom: 16px;
}
.drawer-form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.drawer-form-group select,
.drawer-form-group input {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text-primary);
  font-size: 15px;
}

.drawer-submit-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--btn-gradient);
  color: white;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  margin-top: 8px;
}
.drawer-submit-btn:hover {
  filter: brightness(1.1);
}

/* Recent matches in drawer */
.drawer-match-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 8px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--table-border);
  transition: all 0.2s;
}
.drawer-match-item:hover {
  background: rgba(255,255,255,0.05);
}
.drawer-match-item.deletable {
  cursor: pointer;
}
.drawer-match-item.show-delete {
  background: rgba(248, 113, 113, 0.08);
  border-color: rgba(248, 113, 113, 0.25);
}
.drawer-match-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.drawer-match-players {
  font-size: 14px;
}
.drawer-match-time {
  font-size: 12px;
  color: var(--text-muted);
}
.match-delete-btn {
  display: none;
  padding: 4px 8px;
  background: rgba(248, 113, 113, 0.2);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.match-delete-btn:hover {
  background: rgba(248, 113, 113, 0.35);
}
.drawer-match-item.show-delete .match-delete-btn {
  display: inline-flex;
}

/* Day header in drawer matches */
.drawer-day-header {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  padding: 14px 0 8px;
  margin-top: 20px;
}
.drawer-day-header:first-child {
  margin-top: 0;
}

/* Daily summary in drawer - stands out */
.drawer-day-summary {
  font-size: 13px;
  font-weight: 600;
  padding: 12px 14px;
  margin: 0 0 12px;
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
  border-radius: 12px;
  border: 1px solid rgba(6, 182, 212, 0.2);
  color: var(--text-primary);
}
.summary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 4px 0;
  align-items: center;
}
.summary-icon {
  font-size: 16px;
  margin-right: 4px;
  flex-shrink: 0;
}
.winners-row {
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 8px;
  margin-bottom: 6px;
}
.losers-row {
  padding-top: 2px;
}

/* Mode toggle in drawer */
.drawer-mode-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.drawer-mode-toggle label {
  flex: 1;
  text-align: center;
  padding: 8px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
.drawer-mode-toggle input {
  display: none;
}
.drawer-mode-toggle input:checked + span {
  display: block;
  background: var(--btn-gradient);
  margin: -8px;
  padding: 8px;
  border-radius: 8px;
  color: white;
  font-weight: 600;
}

/* Hide old layout elements */
.old-layout { display: none !important; }

/* Win/loss colors in drawer */
.drawer-match-players .win { color: #34d399; font-weight: 600; }
.drawer-match-players .loss { color: #f87171; }

/* Avatars in history */
.history-avatar {
  display: inline-block;
  vertical-align: middle;
  margin-right: 3px;
  font-size: 14px;
  line-height: 1;
}
.summary-player {
  display: inline-flex;
  align-items: center;
}
.summary-player .history-avatar {
  margin-right: 4px;
}
.summary-player.winner {
  color: #34d399;
}
.summary-player.loser {
  color: #f87171;
}

/* Settings button in top bar */
.settings-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.settings-btn:hover {
  background: rgba(255,255,255,0.12);
}

/* Responsive adjustments */
@media (max-width: 500px) {
  .top-bar {
    flex-direction: column;
    gap: 8px;
  }
  .action-btns {
    justify-content: center;
    width: 100%;
  }
  .action-btns button {
    flex: 1;
    justify-content: center;
  }
  .podium {
    gap: 8px;
    padding: 20px 12px 16px;
  }
  .podium-spot {
    min-width: 80px;
    padding: 12px 8px;
  }
  .podium-spot.first {
    min-width: 95px;
  }
  .podium-name {
    font-size: 13px;
  }
}
