/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #1a6b3c;
  --green-dark: #145430;
  --yellow: #f5e642;
  --yellow-dim: #e6d83a;
  --white: #ffffff;
  --off-white: #f4f5f0;
  --gray-light: #e8e8e8;
  --gray: #999;
  --gray-dark: #555;
  --text: #1a1a1a;
  --red: #d32f2f;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--off-white);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

#app {
  max-width: 768px;
  margin: 0 auto;
  padding: 16px 16px 100px;
}

/* ===== Typography ===== */
.app-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--green);
  text-align: center;
  margin-bottom: 32px;
}

h2 { font-size: 1.25rem; font-weight: 700; }

.label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-dark);
  margin-bottom: 6px;
  margin-top: 16px;
}

.sub-note {
  font-size: 0.8rem;
  color: var(--gray);
  margin-bottom: 12px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn:active { opacity: 0.8; }

.btn-primary { background: var(--green); color: var(--white); }
.btn-primary:hover { background: var(--green-dark); }

.btn-secondary { background: var(--gray-light); color: var(--text); }

.btn-accent { background: var(--yellow); color: var(--text); }
.btn-accent:hover { background: var(--yellow-dim); }

.btn-full { width: 100%; margin-top: 12px; }

.btn-small {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
  background: var(--gray-light);
}

.btn-stepper {
  width: 48px;
  height: 48px;
  font-size: 1.5rem;
  border-radius: var(--radius);
  background: var(--gray-light);
}

.btn-back {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--green);
  -webkit-tap-highlight-color: transparent;
}

.game-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  padding: 12px 16px;
  z-index: 10;
}
.game-footer .btn {
  margin: 0 auto;
  max-width: 736px;
  display: block;
}

.score-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  padding: 12px 16px;
  z-index: 10;
}
.score-footer .btn {
  margin: 0 auto;
  max-width: 736px;
  display: block;
}

/* ===== Inputs ===== */
.input {
  width: 100%;
  min-height: 48px;
  padding: 12px;
  font-size: 16px;
  border: 2px solid var(--gray-light);
  border-radius: var(--radius);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus { border-color: var(--green); }
.input-full { width: 100%; }

.input.shake {
  animation: shake 0.35s;
  border-color: var(--red);
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ===== Layout helpers ===== */
.screen-header {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  margin-bottom: 12px;
}
.screen-header h2 { text-align: center; line-height: 1.3; }
.screen-header .btn-back { justify-self: start; }

.home-header { padding-top: 48px; }
.home-buttons { display: flex; flex-direction: column; gap: 0; }

.resume-expand { margin-top: 8px; }
.resume-input-row { display: flex; gap: 8px; }
.resume-input-row .input { flex: 1; text-transform: uppercase; }
.resume-input-row .btn { flex-shrink: 0; }

/* ===== Stepper ===== */
.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
}
.stepper-value {
  font-size: 1.5rem;
  font-weight: 700;
  min-width: 36px;
  text-align: center;
}

/* ===== Player list ===== */
.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.player-row .input { flex: 1; }
.player-row .btn-remove {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--gray);
  cursor: pointer;
  padding: 4px 8px;
  min-height: 48px;
}
.player-row .btn-remove:hover { color: var(--red); }
.player-row .input.duplicate { border-color: var(--red); }

/* ===== Game header ===== */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--white);
  text-align: center;
  padding: 16px 16px 8px;
  z-index: 10;
}
#rounds-list { padding-top: 110px; }
.game-code-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 4px; }
#game-name {
  font-size: 1.75rem;
  font-weight: 800;
}
.game-code {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--green);
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
}

/* ===== Round cards ===== */
.round-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.round-card { text-align: center; }
.round-card-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.round-card-header h3 { font-size: 1rem; font-weight: 700; }

.badge-complete {
  font-size: 0.75rem;
  background: #d4edda;
  color: #155724;
  padding: 2px 8px;
  border-radius: 99px;
}
.badge-partial {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ffc107;
}

.match-line {
  font-size: 0.85rem;
  padding: 4px 0;
  line-height: 1.4;
  color: var(--gray);
}
.match-player { font-weight: 700; font-size: 1.25rem; color: var(--text); }
.match-score { font-weight: 700; color: var(--green); font-size: 1.25rem; display: block; margin: 4px 0; }

.sitting-out {
  font-size: 0.8rem;
  color: var(--gray);
  margin-top: 6px;
}

.round-card .btn { margin-top: 8px; }

/* ===== Score entry ===== */
.score-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.score-teams {
  display: flex;
  gap: 12px;
}
.score-team {
  flex: 1;
  text-align: center;
}
.score-team-names {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 12px;
  min-height: 2.4em;
}
.score-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.score-stepper-value {
  font-size: 1.75rem;
  font-weight: 700;
  min-width: 48px;
  text-align: center;
}
.score-vs {
  display: flex;
  align-items: flex-end;
  padding-bottom: 18px;
  font-weight: 700;
  color: var(--gray);
  font-size: 0.9rem;
}

/* ===== Leaderboard header ===== */
.leaderboard-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--white);
  text-align: center;
  padding: 16px 16px 8px;
  z-index: 10;
}
.leaderboard-header .btn-back {
  position: absolute;
  left: 16px;
  top: 16px;
}
.leaderboard-header h2 {
  font-size: 1.75rem;
  font-weight: 800;
}
.leaderboard-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--green);
  margin-top: 2px;
}
#leaderboard-content { padding-top: 110px; }

/* ===== Leaderboard ===== */
.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.lb-table th {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 2px solid var(--green);
  font-size: 0.75rem;
  color: var(--gray-dark);
  white-space: nowrap;
}
.lb-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--gray-light);
  white-space: nowrap;
}
.lb-table tr:first-child td { font-weight: 700; }
.lb-rank { font-weight: 700; color: var(--green); }
.lb-player { font-weight: 600; }
.lb-empty { text-align: center; padding: 32px 16px; color: var(--gray); font-size: 1rem; }
.lb-legend {
  margin-top: 16px;
  padding: 14px 18px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-size: 0.8rem;
  color: var(--text);
  line-height: 1.8;
  list-style: none;
}

/* ===== Error / Toast ===== */
.error {
  color: var(--red);
  font-size: 0.875rem;
  margin-top: 8px;
}

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--white);
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 0.875rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

/* ===== Page content ===== */
.page-content { line-height: 1.6; }
.page-content p { margin-bottom: 1em; }

/* ===== Site footer ===== */
.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  text-align: center;
  padding: 10px 16px;
  font-size: 0.75rem;
  color: var(--gray);
  z-index: 5;
}
.site-footer a {
  color: var(--gray-dark);
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }
.footer-sep { margin: 0 6px; }

/* ===== Responsive ===== */
@media (min-width: 600px) {
  #app { padding: 24px 24px 100px; }
}
