:root {
  --bg: #0f2a1d;
  --bg2: #133622;
  --card: #17402a;
  --card-border: #235339;
  --accent: #c8f169;
  --accent-dim: #8fb84a;
  --text: #eef7ea;
  --text-dim: #a9c4ac;
  --danger: #ff6b6b;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1, h2, h3 { margin: 0; }

h1.title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}
h1.title .ball { font-size: 22px; }

.subtitle { color: var(--text-dim); font-size: 14px; margin-top: -8px; }

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

.section-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 700;
  margin-bottom: 10px;
}

/* Buttons */
button {
  font-family: inherit;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-appearance: none;
  transition: transform 0.05s ease, opacity 0.15s ease;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #0f2a1d; width: 100%; }
.btn-secondary { background: var(--card-border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--card-border); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > button { flex: 1; }

/* Inputs */
input[type=text], input[type=number] {
  font-family: inherit;
  background: var(--bg2);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 16px;
  width: 100%;
}
input[type=text]:focus, input[type=number]:focus {
  outline: none;
  border-color: var(--accent-dim);
}

/* Player list (setup) */
.player-add-row { display: flex; gap: 8px; }
.player-add-row input { flex: 1; }
.player-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}
.player-list li .remove { color: var(--danger); font-size: 13px; font-weight: 700; padding: 4px 8px; background: none; }

.player-count { color: var(--text-dim); font-size: 13px; margin-top: 8px; }

/* Segmented control */
.segmented {
  display: flex;
  background: var(--bg2);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.segmented button {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  padding: 10px 8px;
  font-size: 14px;
  border-radius: 9px;
}
.segmented button.active { background: var(--accent); color: #0f2a1d; }

.stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg2);
  border-radius: 12px;
  padding: 6px 6px 6px 16px;
}
.stepper .stepper-value { font-size: 18px; font-weight: 800; }
.stepper .stepper-btns { display: flex; gap: 6px; }
.stepper button {
  width: 40px; height: 40px; padding: 0;
  background: var(--card-border); color: var(--text);
  font-size: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}

.field-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.field-group:last-child { margin-bottom: 0; }

.error-banner {
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}

/* Tab bar */
.tabbar {
  display: flex;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 4px;
  gap: 4px;
  position: sticky;
  top: max(8px, env(safe-area-inset-top));
  z-index: 5;
}
.tabbar button {
  flex: 1;
  background: transparent;
  color: var(--text-dim);
  padding: 10px 6px;
  font-size: 14px;
  border-radius: 10px;
}
.tabbar button.active { background: var(--accent); color: #0f2a1d; }

/* Round header */
.round-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.round-header .round-num { font-size: 20px; font-weight: 800; }
.round-nav { display: flex; gap: 8px; align-items: center; }
.round-nav button { width: 36px; height: 36px; padding: 0; background: var(--card-border); border-radius: 10px; font-size: 16px; }

.sitting-out {
  font-size: 13px;
  color: var(--text-dim);
  background: var(--bg2);
  border-radius: 10px;
  padding: 8px 12px;
}
.sitting-out b { color: var(--text); }

/* Match card */
.match-card { display: flex; flex-direction: column; gap: 12px; }
.match-court-label {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-dim);
}
.team-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.team-names {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}
.team-names .plus { color: var(--text-dim); font-weight: 400; }
.score-btn {
  width: 72px;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  padding: 12px 4px;
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 12px;
}
.score-btn.winner { border-color: var(--accent); color: var(--accent); }
.vs-divider {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

/* Score picker modal */
.picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.picker-sheet {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  max-height: 80vh;
  overflow-y: auto;
}
.picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.picker-title { font-size: 15px; font-weight: 800; }
.picker-actions { display: flex; gap: 8px; }
.picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.picker-num {
  background: var(--bg2);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 10px;
  padding: 14px 0;
  font-size: 17px;
  font-weight: 700;
}
.picker-num.selected { background: var(--accent); color: #0f2a1d; border-color: var(--accent); }

/* Standings table */
table.standings { width: 100%; border-collapse: collapse; font-size: 14px; }
table.standings th, table.standings td {
  text-align: left;
  padding: 10px 6px;
  border-bottom: 1px solid var(--card-border);
}
table.standings th { color: var(--text-dim); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
table.standings td.num, table.standings th.num { text-align: center; }
table.standings tr:last-child td { border-bottom: none; }
table.standings td.rank { font-weight: 800; color: var(--accent); width: 24px; }
table.standings td.name { font-weight: 600; }
table.standings td.diff.positive { color: var(--accent); }
table.standings td.diff.negative { color: var(--danger); }

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

.history-round { margin-bottom: 14px; }
.history-round:last-child { margin-bottom: 0; }
.history-round-title { font-size: 13px; font-weight: 700; color: var(--text-dim); margin-bottom: 8px; }
.history-match { font-size: 14px; padding: 8px 0; border-bottom: 1px solid var(--card-border); display: flex; justify-content: space-between; gap: 8px; }
.history-match:last-child { border-bottom: none; }
.history-score { font-weight: 800; color: var(--accent); white-space: nowrap; }

.footer-actions { display: flex; flex-direction: column; gap: 10px; }
