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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #1e2a47;
  --bg-input: #243251;
  --accent: #e94560;
  --accent-hover: #d63851;
  --text-primary: #eeeeee;
  --text-secondary: #aaaaaa;
  --text-muted: #777777;
  --border: #2a3a5c;
  --success: #4ECDC4;
  --warning: #FFE66D;
  --danger: #FF6B6B;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 200ms ease;
}

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

/* === Login Page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  width: 100%;
  max-width: 360px;
  padding: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  transition: transform var(--transition);
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 24px;
}

.login-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color var(--transition);
}

.login-card input:focus {
  border-color: var(--accent);
}

.login-card button {
  width: 100%;
  margin-top: 16px;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.login-card button:hover {
  background: var(--accent-hover);
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
}

.hidden {
  display: none;
}

.shake {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-10px); }
  80% { transform: translateX(10px); }
}

/* === App Layout === */
main {
  padding: 16px;
  padding-bottom: 80px; /* space for bottom nav */
  max-width: 600px;
  margin: 0 auto;
}

/* === Bottom Navigation === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  font-size: 12px;
  min-width: 64px;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 20px;
}

.nav-label {
  font-size: 11px;
  font-weight: 500;
}

/* === Cards === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-title {
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* === Section Headers === */
.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
}

/* === Game Card === */
.game-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  transition: background var(--transition);
}

.game-card.deleted {
  opacity: 0.5;
}

.game-date {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.game-matchup {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 15px;
}

.game-team {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.game-team.winner {
  font-weight: 700;
}

.game-vs {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}

.game-score {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin-top: 8px;
  color: var(--accent);
}

.player-name {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
}

/* === Add Game Form === */
.add-game-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-label {
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.date-input {
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  width: 100%;
}

.date-input:focus {
  border-color: var(--accent);
}

/* Team Picker */
.team-picker {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: start;
}

.team-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.team-label {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding-bottom: 4px;
  border-bottom: 2px solid var(--border);
}

.team-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 600;
  padding-top: 28px;
}

.player-btn {
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  min-height: 44px;
}

.player-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.15);
}

.player-btn.disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Score Input */
.score-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.score-input {
  width: 64px;
  padding: 12px;
  text-align: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 24px;
  font-weight: 700;
  outline: none;
}

.score-input:focus {
  border-color: var(--accent);
}

.score-separator {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-muted);
}

.add-set-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
  width: 100%;
  transition: all var(--transition);
}

.add-set-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.mode-toggle input {
  accent-color: var(--accent);
}

/* Submit Button */
.btn-primary {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition);
  min-height: 52px;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  padding: 10px 16px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-secondary:hover {
  background: var(--bg-card);
}

.btn-danger {
  padding: 10px 16px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-danger:hover {
  background: rgba(255, 107, 107, 0.1);
}

.btn-success {
  padding: 10px 16px;
  background: transparent;
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
}

/* === Standings Table === */
.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.standings-table th {
  text-align: left;
  padding: 10px 8px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.standings-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

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

.standings-table tr:first-child td {
  color: var(--accent);
  font-weight: 600;
}

/* === Stats === */
.stats-section {
  margin-bottom: 24px;
}

.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.chart-container canvas {
  max-height: 300px;
}

.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
}

/* Streak indicators */
.streak {
  display: flex;
  gap: 4px;
  justify-content: center;
  margin-top: 8px;
}

.streak-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.streak-dot.win {
  background: var(--success);
}

.streak-dot.loss {
  background: var(--danger);
}

/* H2H selector */
.h2h-selector {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.h2h-selector select {
  flex: 1;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
}

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
}

.modal h3 {
  margin-bottom: 12px;
}

.modal p {
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* === Loading === */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

/* === Toast === */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 14px;
  z-index: 300;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.7s;
  pointer-events: none;
}

.toast.success {
  border-color: var(--success);
  color: var(--success);
}

.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* === Pairing Heatmap === */
.heatmap-grid {
  display: grid;
  gap: 4px;
}

.heatmap-cell {
  padding: 10px 6px;
  text-align: center;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
}

.heatmap-header {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* === Utility === */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

/* === Remove Set Button === */
.remove-set-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  transition: color var(--transition);
}

.remove-set-btn:hover {
  color: var(--danger);
}

/* === Game Actions === */
.game-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
