:root {
  --bg-0: #05070d;
  --bg-1: #0a0f1e;
  --bg-2: #0e1526;
  --panel: rgba(255, 255, 255, 0.035);
  --panel-strong: rgba(255, 255, 255, 0.055);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #f2f5ff;
  --text-dim: #8993b0;
  --text-faint: #5b6580;

  --lime: #d4ff3f;
  --lime-soft: rgba(212, 255, 63, 0.14);
  --teal: #2ee6c9;
  --teal-soft: rgba(46, 230, 201, 0.14);

  --win: #4ade80;
  --win-soft: rgba(74, 222, 128, 0.14);
  --loss: #ff5d7a;
  --loss-soft: rgba(255, 93, 122, 0.14);
  --draw: #9aa5c4;
  --draw-soft: rgba(154, 165, 196, 0.14);
  --pending: #ffb84d;
  --pending-soft: rgba(255, 184, 77, 0.14);

  --radius: 16px;
  --radius-sm: 10px;
  --font-display: "Rajdhani", "Segoe UI", sans-serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg-0);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background: radial-gradient(1200px 600px at 15% -10%, rgba(46, 230, 201, 0.1), transparent 60%),
    radial-gradient(1000px 500px at 90% 0%, rgba(212, 255, 63, 0.08), transparent 55%), var(--bg-0);
  position: relative;
}

/* Faint padel-court line motif behind everything */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image: linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(900px 500px at 50% 0%, black, transparent 75%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: rgba(6, 9, 18, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--panel-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--lime), var(--teal));
  font-size: 20px;
  box-shadow: 0 0 24px rgba(212, 255, 63, 0.35);
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1;
}

.brand-text .tagline {
  margin-top: 3px;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.03em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.sync-status {
  color: var(--text-dim);
  font-size: 13px;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-body);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.btn-primary {
  background: linear-gradient(120deg, var(--lime), var(--teal));
  color: #06120c;
  box-shadow: 0 0 0 rgba(212, 255, 63, 0);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(212, 255, 63, 0.35);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn-ghost {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.2);
}

main {
  position: relative;
  z-index: 1;
  padding: 28px 28px 60px;
  max-width: 1240px;
  margin: 0 auto;
}

/* Stats -------------------------------------------------------------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px 18px;
  text-align: center;
  overflow: hidden;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--lime), var(--teal));
  opacity: 0.8;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 255, 63, 0.35);
}

.stat-icon {
  font-size: 15px;
  margin-bottom: 4px;
  opacity: 0.85;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.stat-label {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-card--rate .stat-value {
  background: linear-gradient(120deg, var(--lime), var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat-card--filter {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.segmented-btn {
  border: 1px solid var(--panel-border);
  background: var(--panel-strong);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-body);
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.segmented-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.25);
}

.segmented-btn.active {
  background: linear-gradient(120deg, var(--lime), var(--teal));
  color: #06120c;
  border-color: transparent;
}

.ring-wrap {
  position: relative;
  width: 74px;
  height: 74px;
  margin: 0 auto;
}

.ring-wrap svg {
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 8;
}

.ring-fill {
  fill: none;
  stroke: url(#ringGradient);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s ease;
}

.ring-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
}

/* Breakdown panels ----------------------------------------------------- */

.breakdowns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
}

.panel h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel h2::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(135deg, var(--lime), var(--teal));
  display: inline-block;
}

.rank-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rank-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.rank-row-link {
  color: inherit;
  text-decoration: none;
  border-radius: 8px;
  padding: 6px 8px;
  margin: 0 -8px;
  transition: background 0.12s ease;
}

.rank-row-link:hover {
  background: var(--lime-soft);
}

.rank-row-link:hover .rank-name {
  color: var(--lime);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: #06120c;
}

.rank-main {
  min-width: 0;
}

.rank-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.rank-bar {
  margin-top: 5px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.rank-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--teal), var(--lime));
}

.rank-meta {
  color: var(--text-dim);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Games section ---------------------------------------------------------- */

.games-section {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.filters input,
.filters select {
  background: var(--panel-strong);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.filters input:focus,
.filters select:focus {
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(212, 255, 63, 0.15);
}

#searchInput {
  flex: 1;
  min-width: 200px;
}

.table-scroll {
  overflow-x: auto;
}

.games-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.games-table th {
  text-align: left;
  color: var(--text-dim);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 14px;
  border-bottom: 2px solid rgba(212, 255, 63, 0.25);
  white-space: nowrap;
}

.games-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--panel-border);
  white-space: nowrap;
}

.games-table tbody tr {
  transition: background 0.12s ease;
}

.games-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.015);
}

.games-table tbody tr:hover {
  background: var(--lime-soft);
}

.set-chips {
  display: inline-flex;
  gap: 4px;
}

.set-chip {
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text-dim);
}

.set-chip.set-won {
  background: var(--win-soft);
  color: var(--win);
}

.set-chip.set-lost {
  background: var(--loss-soft);
  color: var(--loss);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-win {
  background: var(--win-soft);
  color: var(--win);
}

.badge-loss {
  background: var(--loss-soft);
  color: var(--loss);
}

.badge-draw {
  background: var(--draw-soft);
  color: var(--draw);
}

.badge-pending {
  background: var(--pending-soft);
  color: var(--pending);
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 28px;
  font-size: 14px;
}

/* Admin: full-database view --------------------------------------------- */

.summary-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.summary-chip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: center;
}

.summary-chip .chip-value {
  display: block;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
}

.summary-chip .chip-label {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.summary-chip.chip-played .chip-value {
  color: var(--teal);
}

.summary-chip.chip-win .chip-value {
  color: var(--win);
}

.summary-chip.chip-loss .chip-value {
  color: var(--loss);
}

.summary-chip.chip-pending .chip-value {
  color: var(--pending);
}

.summary-chip.chip-draw .chip-value {
  color: var(--draw);
}

.games-section h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-note {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 16px;
  max-width: 800px;
  line-height: 1.5;
}

.row-count {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.admin-table {
  font-size: 12.5px;
}

.admin-table th,
.admin-table td {
  padding: 7px 10px;
}

.admin-table th[data-sort]:hover {
  color: var(--lime);
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  color: var(--text-faint);
}

/* Find a Game --------------------------------------------------------- */

.quickpicks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.quickpick-btn {
  font-weight: 600;
}

.venue-search-wrap {
  position: relative;
  margin-bottom: 10px;
}

#venueSearch {
  width: 100%;
  background: var(--panel-strong);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 14px;
  font-family: var(--font-body);
  outline: none;
}

#venueSearch:focus {
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(212, 255, 63, 0.15);
}

.venue-suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: #0d1322;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.venue-suggestion {
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--panel-border);
}

.venue-suggestion:last-child {
  border-bottom: none;
}

.venue-suggestion:hover {
  background: var(--lime-soft);
}

.venue-suggestion span {
  font-size: 12px;
  color: var(--text-dim);
}

.venue-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  min-height: 0;
}

.venue-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--lime-soft);
  color: var(--lime);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-size: 13px;
  font-weight: 600;
}

.venue-chip button {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
}

.filter-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.filter-label input {
  background: var(--panel-strong);
  border: 1px solid var(--panel-border);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  font-family: var(--font-body);
}

.match-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.match-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.match-card:hover {
  transform: translateY(-2px);
  border-color: rgba(212, 255, 63, 0.35);
}

/* 1 open spot = closest to a ready game, so it gets the strongest pull */
.match-card--hot {
  background: linear-gradient(160deg, rgba(212, 255, 63, 0.09), var(--panel) 55%);
  border-color: rgba(212, 255, 63, 0.55);
  box-shadow: 0 0 0 1px rgba(212, 255, 63, 0.12), 0 8px 28px rgba(212, 255, 63, 0.14);
}

.match-card--hot:hover {
  border-color: var(--lime);
  box-shadow: 0 0 0 1px rgba(212, 255, 63, 0.25), 0 10px 32px rgba(212, 255, 63, 0.25);
}

.match-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.match-date {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
}

.match-venue {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.match-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.match-players {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Scoreboard: one row per team, one column per set */
.score-table {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
}

.score-row + .score-row {
  border-top: 1px solid var(--panel-border);
}

.score-team-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-cells {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.score-cell {
  min-width: 26px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-dim);
}

.score-cell.score-win {
  color: var(--lime);
}

.player-chip {
  font-size: 12px;
  background: var(--panel-strong);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--text);
}

.player-chip em {
  font-style: normal;
  color: var(--teal);
  font-weight: 600;
}

.match-card-join {
  display: block;
  text-align: center;
  margin-top: 14px;
  font-size: 13px;
  background: #25d366;
  color: #06120c;
  font-weight: 700;
}

.match-card-join:hover {
  filter: brightness(1.08);
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  main {
    padding: 20px 16px 48px;
  }
}
