:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --border: #dde2ee;
  --text: #1b2033;
  --muted: #646b84;
  --primary: #3b5bdb;
  --primary-soft: #e4e9fd;
  --ens: #b8860b;
  --ens-soft: #fdf3d3;
  --discord: #5865f2;
  --gold: #f5c518;
  --error: #c92a2a;
  --error-soft: #fde8e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(20 30 60 / 6%), 0 4px 16px rgb(20 30 60 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131c;
    --surface: #1a1d29;
    --surface-2: #232736;
    --border: #2e3346;
    --text: #e8eaf3;
    --muted: #9298b0;
    --primary: #7d95ff;
    --primary-soft: #262e52;
    --ens: #f2c94c;
    --ens-soft: #3a3118;
    --error: #ff8787;
    --error-soft: #3d1f22;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, .brand, .stat-value {
  font-family: "Fredoka", system-ui, sans-serif;
  font-weight: 600;
  letter-spacing: 0.01em;
}
h1 { font-size: 2rem; margin: 0; }
h2 { font-size: 1.35rem; margin: 2rem 0 0.25rem; }
a { color: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.strong { font-weight: 700; }

/* top bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.4rem;
  color: var(--text);
  text-decoration: none;
}
.brand img { width: 36px; height: 36px; object-fit: contain; }
.nav { display: flex; gap: 4px; }
.nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.account form { margin: 0; }
.account-name { font-weight: 600; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 999px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn-discord { background: var(--discord); color: #fff; }
.btn-discord:hover { filter: brightness(1.1); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* layout */
.container {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 0 16px 48px;
  flex: 1;
}
.hero { padding: 32px 0 20px; }
.hero p { margin: 4px 0 0; }
.hero-profile { display: flex; align-items: center; gap: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.footer { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 24px 16px; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; margin: 0; }

/* avatars */
.avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; background: var(--surface-2); }
.avatar-sm { width: 22px; height: 22px; }
.avatar-lg { width: 72px; height: 72px; }

/* tables */
.table-card { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.is-me td { background: var(--primary-soft); }
.table tr.separator td { text-align: center; color: var(--muted); padding: 4px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.rank { width: 48px; text-align: center !important; font-weight: 700; font-size: 1.05rem; }

.player { display: flex; align-items: center; gap: 10px; }
.player-name { font-weight: 600; }
.player-link { color: inherit; text-decoration: none; }
.player-link:hover { color: var(--primary); text-decoration: underline; }
.player-link::after { content: ""; position: absolute; inset: 0; }  /* the whole row is clickable */
.table tr:has(.player-link) { position: relative; cursor: pointer; }
.ball-icon { width: 36px; height: 36px; object-fit: contain; flex-shrink: 0; }

.progress-cell { display: flex; align-items: center; gap: 10px; }
.complete-sets {
  font-family: "Fredoka", system-ui, sans-serif;
  font-weight: 700;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--primary);
  min-width: 2.6em;
}
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; flex: 1; min-width: 80px; }
.progress-bar { height: 100%; background: var(--primary); border-radius: inherit; }

/* badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
}
.badge-ens { background: var(--ens-soft); color: var(--ens); }
.badge-old { background: var(--surface-2); color: var(--muted); }
.ens-text { color: var(--ens); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.stat-value { font-size: 2rem; line-height: 1; }
.stat-value .muted { font-size: 1.2rem; }
.stat-value .complete-sets { font-size: 1.6rem; margin-left: 4px; }
.stat-label { color: var(--muted); font-weight: 600; font-size: 0.9rem; }
.stat-ens { color: var(--ens); }

/* ball grid */
.ball-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.ball-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.ball-tile:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--primary); }
.ball-tile img { width: 64px; height: 64px; object-fit: contain; }
.ball-tile.is-missing { cursor: default; }
.ball-tile.is-missing img { filter: grayscale(1) brightness(0.4); opacity: 0.35; }
.ball-tile.is-missing .ball-name { color: var(--muted); }
.ball-name { font-size: 0.78rem; font-weight: 600; text-align: center; line-height: 1.2; }
.ball-count {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
}

/* filters */
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select {
  font: inherit;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .stats { grid-template-columns: 1fr; }
  .account-name { display: none; }
  .topbar-inner { gap: 12px; }
  h1 { font-size: 1.6rem; }
  .ball-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
}

.amount { color: var(--muted); font-weight: 600; font-size: 0.85rem; }

/* flash messages */
.flash { margin-top: 20px; padding: 12px 16px; border-radius: var(--radius); font-weight: 600; }
.flash-success { background: var(--primary-soft); color: var(--primary); }
.flash-error { background: var(--error-soft); color: var(--error); }

/* gifts */
.select-col { width: 72px; text-align: center !important; }
.gift-amount {
  width: 60px;
  font: inherit;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: center;
}
.gift-check { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.table tr.is-selected td { background: var(--primary-soft); }
.gift-bar {
  position: sticky;
  bottom: 16px;
  margin-top: 16px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  z-index: 5;
  box-shadow: 0 8px 30px rgb(20 30 60 / 18%);
}
.gift-bar[hidden] { display: none; }
.gift-count { white-space: nowrap; }
.gift-bar input[type="text"] {
  flex: 1;
  min-width: 200px;
  font: inherit;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
