:root {
  --bg: #f1f5f9;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0d9488;
  --accent2: #2563eb;
  --accent-soft: #e6fffa;
  --chip-bg: #f1f5f9;
  --danger: #ef4444;
  --success: #22c55e;
  --winner: #fef3c7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #111a2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --border: #1e293b;
    --accent: #14b8a6;
    --accent2: #60a5fa;
    --accent-soft: #0d2b2e;
    --chip-bg: #1a2332;
    --danger: #f87171;
    --success: #4ade80;
    --winner: #2d1f0a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.header h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.header .back {
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ── Sections / Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 10px;
}

/* ── Inputs ── */
textarea, input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  resize: vertical;
  -webkit-appearance: none;
}
textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}
textarea { min-height: 80px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
  min-height: 44px;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--accent); color: #fff; width: 100%; }
.btn-primary:disabled { opacity: 0.4; }
.btn-secondary { background: var(--chip-bg); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { font-size: 13px; padding: 6px 12px; min-height: 32px; border-radius: 8px; }

/* ── Player Chips ── */
.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
}
.player-chip .remove {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  padding: 0;
  line-height: 1;
}

/* ── Rounds selector ── */
.rounds-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.rounds-row .val {
  font-size: 28px;
  font-weight: 800;
  min-width: 40px;
  text-align: center;
  color: var(--accent);
}
.round-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
}

/* ── Match Card ── */
.match-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.match-card:active { border-color: var(--accent); }
.match-card.scored { border-color: var(--success); opacity: 0.85; }
.match-card .versus {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.match-card .team {
  flex: 1;
  text-align: center;
  padding: 10px 6px;
  border-radius: 10px;
  background: var(--chip-bg);
  font-weight: 700;
  font-size: 15px;
}
.match-card .team.winner { background: var(--winner); border: 2px solid var(--accent); }
.match-card .vs {
  font-size: 13px;
  font-weight: 800;
  color: var(--muted);
  padding: 0 4px;
}
.match-card .score-line {
  text-align: center;
  margin-top: 8px;
  font-size: 14px;
  color: var(--muted);
}
.match-card .score-line strong { color: var(--accent); font-size: 18px; }

/* ── Scoring Overlay ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.overlay-card {
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 20px 16px 28px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}
.overlay-card h3 {
  margin: 0 0 14px;
  font-size: 17px;
  text-align: center;
}

/* Score matchup (teams side by side) */
.score-matchup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}
.score-team {
  flex: 1;
  text-align: center;
}
.score-names {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.4;
}
.score-circle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--chip-bg);
  border: 3px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  margin: 0 auto;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.score-circle:active { border-color: var(--accent); }
.score-circle.editing { border-color: var(--accent); background: var(--accent-soft); }
.score-circle.winner { border-color: var(--accent); background: var(--accent-soft); }
.score-vs {
  font-size: 14px;
  font-weight: 800;
  color: var(--muted);
  padding: 0 4px;
}

/* Number pad grid */
.num-pad {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.num-pad.open {
  display: grid;
}
.num-key {
  padding: 12px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--chip-bg);
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  text-align: center;
  min-height: 44px;
}
.num-key:active { background: var(--accent-soft); border-color: var(--accent); }

/* ── Leaderboard ── */
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.lb-row:last-child { border: none; }
.lb-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--chip-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}
.lb-rank.top1 { background: #fbbf24; color: #000; }
.lb-rank.top2 { background: #94a3b8; color: #fff; }
.lb-rank.top3 { background: #d97706; color: #fff; }
.lb-name { flex: 1; font-weight: 600; font-size: 15px; }
.lb-pts { font-size: 18px; font-weight: 800; color: var(--accent); }
.lb-detail {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.lb-rd {
  font-size: 11px;
  background: var(--chip-bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--muted);
}

/* ── Round nav ── */
.round-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.round-tabs::-webkit-scrollbar { display: none; }
.round-tab {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.round-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Misc ── */
.empty { text-align: center; color: var(--muted); padding: 24px 0; font-size: 14px; }
.fade { opacity: 0.5; pointer-events: none; }
.mt8 { margin-top: 8px; }
.mb12 { margin-bottom: 12px; }
.gap8 { display: flex; gap: 8px; }
.flex1 { flex: 1; }
.text-center { text-align: center; }
.text-sm { font-size: 13px; color: var(--muted); }