:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #666;
  --accent: #e63946;
  --accent-2: #457b9d;
  --border: #ddd;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #e63946;
  --accent-2: #5a9ec9;
  --border: #2a2a3e;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
  transition: background 0.2s, color 0.2s;
}

.view { display: none; width: 100%; max-width: 480px; flex-direction: column; gap: 1rem; }
.view.active { display: flex; }

.logo { font-size: 2rem; font-weight: 800; text-align: center; margin: 1.5rem 0; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input, select {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus, select:focus { border-color: var(--accent); }

.btn {
  width: 100%;
  padding: 0.875rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--accent-2); color: #fff; }
.btn-big { padding: 1.25rem; font-size: 1.25rem; }

.divider { text-align: center; color: var(--text-muted); font-size: 0.875rem; }

.error { color: var(--accent); font-size: 0.9rem; text-align: center; }
.hidden { display: none !important; }

/* Lobby */
.room-code-display { font-size: 1.1rem; text-align: center; }
.code-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.25rem;
  padding: 0.25rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  user-select: all;
}
.hint { text-align: center; color: var(--text-muted); font-size: 0.9rem; }

.player-list { display: flex; flex-direction: column; gap: 0.5rem; }
.player-chip {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-weight: 600;
}
.player-chip.host::after { content: ' 👑'; }

.settings-panel { display: flex; flex-direction: column; gap: 0.75rem; }
.settings-panel label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--text-muted); }

/* Game view */
.players-row { display: flex; gap: 0.75rem; }
.player-card {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  text-align: center;
  border: 3px solid transparent;
  transition: border-color 0.2s;
  min-width: 0;
}
.player-card.active { border-color: var(--accent); }
.player-card .p-name { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 0.25rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-card .p-score { font-size: 2.5rem; font-weight: 900; line-height: 1; }
.player-card .p-legs { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.25rem; }

.turn-info { text-align: center; }
.turn-label { font-size: 1.1rem; font-weight: 700; }
.checkout-hint { font-size: 0.9rem; color: var(--accent-2); margin-top: 0.25rem; min-height: 1.2em; font-weight: 600; }

.numpad-wrap { display: flex; flex-direction: column; gap: 0.5rem; }

.numpad-display {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 10px;
  text-align: right;
  padding: 0.75rem 1rem;
  font-size: 2.5rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: var(--text);
  min-height: 4rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.numpad-display.disabled { opacity: 0.4; }

.numpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.num-btn {
  padding: 1rem;
  font-size: 1.5rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s, background 0.1s;
  touch-action: manipulation;
}
.num-btn:active { transform: scale(0.93); background: var(--border); }
.num-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.del-btn { background: var(--border); }
.ok-btn { background: var(--accent); color: #fff; }

.bust-msg {
  text-align: center;
  font-size: 2rem;
  font-weight: 900;
  color: var(--accent);
  animation: pop 0.4s ease;
}
@keyframes pop { 0% { transform: scale(0.8); opacity: 0; } 60% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }

.averages { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.avg-chip {
  background: var(--surface);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Game over */
.winner-banner { font-size: 1.75rem; font-weight: 900; text-align: center; padding: 1rem; }
.stats-list { display: flex; flex-direction: column; gap: 0.5rem; }
.stat-row {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  font-size: 0.95rem;
}

/* Training mode */
.btn-training { background: #2a9d8f; color: #fff; }

.training-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-back {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.5rem 0;
  font-weight: 600;
}
.training-streak {
  font-size: 1.1rem;
  font-weight: 700;
}

.training-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1rem;
  text-align: center;
}
.training-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.training-target {
  font-size: 4rem;
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.btn-hit { background: #2a9d8f; color: #fff; font-size: 1.25rem; padding: 1.1rem; }
.btn-miss { background: var(--border); color: var(--text); }

.training-stats {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  justify-content: space-around;
  font-size: 0.95rem;
}
.stat-item { text-align: center; }
.stat-item .stat-val { font-size: 1.5rem; font-weight: 900; }
.stat-item .stat-key { font-size: 0.8rem; color: var(--text-muted); }

/* Camera */
.camera-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  cursor: pointer;
}
.camera-label input { accent-color: var(--accent); width: 1.1rem; height: 1.1rem; cursor: pointer; }

.game-video {
  width: 100%;
  border-radius: var(--radius);
  background: #000;
  aspect-ratio: 4/3;
  object-fit: cover;
  display: block;
}

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
