:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --green: #238636;
  --green-fg: #3fb950;
  --red: #da3633;
  --red-fg: #f85149;
  --yellow-fg: #d29922;
  --radius: 8px;
}

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

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

a { color: inherit; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem 4rem;
}

/* ── Header ── */
header { text-align: center; margin-bottom: 2rem; }

header h1 {
  font-size: 2.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, #7c3aed 0%, #ec4899 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.subtitle { color: var(--text-muted); margin-top: 0.4rem; font-size: 0.95rem; }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.card h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1.25rem; }

/* ── Forms ── */
.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.form-group small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

input[type="text"],
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

textarea { resize: vertical; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; margin-top: 0.5rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Utilities ── */
.hidden { display: none !important; }

.error-msg {
  color: var(--red-fg);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.success-msg {
  color: var(--green-fg);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.muted { color: var(--text-muted); }

/* ── Nav bar ── */
.nav { margin-bottom: 1rem; }

/* ── User bar ── */
.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.user-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ── Player list ── */
.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--surface-2);
  transition: border-color 0.15s;
}

.player-item:hover { border-color: var(--accent); }
.player-item .player-name-text { font-weight: 500; }

/* ── Loading spinner ── */
.spinner-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Game header ── */
.game-matchup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.matchup-name {
  font-size: 1.4rem;
  font-weight: 700;
}

.matchup-vs {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
}

.score-block { text-align: center; }

.score-num {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
}

.score-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.score-sep { font-size: 2rem; color: var(--border); }

/* ── Round cards ── */
.round-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  background: var(--surface-2);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.round-card.visible { opacity: 1; transform: translateY(0); }

.round-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.875rem;
}

.round-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.badge {
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-p1-win  { background: rgba(35,134,54,.18);  color: var(--green-fg); }
.badge-p2-win  { background: rgba(218,54,51,.18);  color: var(--red-fg);   }
.badge-draw    { background: rgba(158,106,3,.18);  color: var(--yellow-fg);}

.round-actions {
  display: flex;
  align-items: center;
  justify-content: space-around;
  gap: 0.75rem;
}

.action-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  flex: 1;
}

.action-col.is-winner .action-emoji { filter: drop-shadow(0 0 8px rgba(124,58,237,.7)); }

.action-emoji { font-size: 2.25rem; line-height: 1; }
.action-word  { font-weight: 600; font-size: 0.9rem; }
.action-who   { font-size: 0.75rem; color: var(--text-muted); }

.round-divider { color: var(--text-muted); font-size: 1.1rem; }

/* ── Winner banner ── */
.winner-banner {
  text-align: center;
  padding: 1.25rem;
  border-radius: var(--radius);
  margin-top: 0.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.winner-banner.visible { opacity: 1; }

.banner-p1  { background: rgba(35,134,54,.12);  border: 1px solid rgba(35,134,54,.3);  color: var(--green-fg); }
.banner-p2  { background: rgba(218,54,51,.12);  border: 1px solid rgba(218,54,51,.3);  color: var(--red-fg);   }
.banner-draw{ background: rgba(158,106,3,.12);  border: 1px solid rgba(158,106,3,.3);  color: var(--yellow-fg);}

.play-again { text-align: center; margin-top: 1.5rem; }

/* ── Profile page value display ── */
.value-display {
  padding: 0.5rem 0;
  font-weight: 600;
  font-size: 1rem;
}

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.3rem;
}

/* ── Leaderboard table ── */
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.lb-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.lb-table th.num,
.lb-table td.num { text-align: right; }

.lb-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.lb-table tr:last-child td { border-bottom: none; }

.lb-table tr:hover td { background: var(--surface-2); }

.lb-table tr.is-me td { background: rgba(124,58,237,.08); }

.rank-cell { font-weight: 700; color: var(--text-muted); min-width: 2rem; }
.rank-medal { font-size: 1.1rem; }

.lb-score { font-weight: 700; font-size: 1rem; }

.lb-username a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}
.lb-username a:hover { color: var(--accent); text-decoration: underline; }

/* ── Game history entries ── */
.gh-entry {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.gh-entry:last-child { border-bottom: none; }

/* Names header: "you  vs  opponent" */
.gh-names {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.gh-name {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gh-name.me  { text-align: left;  }
.gh-name.opp { text-align: right; }
.gh-name a   { color: var(--text); text-decoration: none; }
.gh-name a:hover { color: var(--accent); text-decoration: underline; }

.gh-vs-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

/* Per-round rows */
.gh-round-row {
  display: grid;
  grid-template-columns: 1.8rem 1fr 2rem 1fr;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  font-size: 0.85rem;
  margin-bottom: 0.15rem;
}

.gh-round-row.rr-win  { border-left-color: var(--green-fg); background: rgba(35,134,54,.06); }
.gh-round-row.rr-loss { border-left-color: var(--red-fg);   background: rgba(218,54,51,.06); }
.gh-round-row.rr-draw { border-left-color: var(--yellow-fg);background: rgba(158,106,3,.06); }

.gh-rnum {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gh-action {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
}

.gh-action.me-action  { justify-content: flex-start; }
.gh-action.opp-action { justify-content: flex-end;   }

.gh-action.winner { font-weight: 700; }
.gh-action.winner .gh-emoji { filter: drop-shadow(0 0 4px currentColor); }

.gh-emoji { font-size: 1.1rem; line-height: 1; }
.gh-word  { font-size: 0.8rem; }

.gh-round-vs {
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Footer: result badge + score + date */
.gh-footer {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.gh-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  flex-shrink: 0;
}

.gh-badge.win  { background: rgba(35,134,54,.18);  color: var(--green-fg); }
.gh-badge.loss { background: rgba(218,54,51,.18);  color: var(--red-fg);   }
.gh-badge.draw { background: rgba(158,106,3,.18);  color: var(--yellow-fg);}

.gh-score { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.gh-date  { color: var(--text-muted); font-size: 0.78rem; margin-left: auto; }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s;
}

.page-btn:hover:not(:disabled):not(.active) { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.page-btn:disabled { opacity: 0.35; cursor: not-allowed; }
