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

:root {
  --bg: #1a1a2e;
  --bg-panel: #16213e;
  --bg-card: #1a1a2e;
  --border: #2a2a4a;
  --text: #e0e0e0;
  --text-muted: #888;
  --text-dim: #444;
  --text-placeholder: #555;
  --accent: #f0c040;
  --accent-glow: rgba(240, 192, 64, 0.3);
  --bust: #e74c3c;
  --bust-inactive-bg: #555;
  --bust-inactive-text: #aaa;
  --modifier-bg: #2a2a4a;
  --modifier-text: #c0a0f0;
  --modifier-border: #4a3a6a;
  --modifier-badge-bg: #3a2a5a;
  --modifier-active: #5a3a8a;
  --flip7-bg: #2a5a2a;
  --flip7-text: #80e080;
  --special-dot: #c0a0f0;
  --overlay-backdrop: rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f0f0f5;
    --bg-panel: #ffffff;
    --bg-card: #e8e8f0;
    --border: #d0d0dd;
    --text: #1a1a2e;
    --text-muted: #777;
    --text-dim: #aaa;
    --text-placeholder: #999;
    --accent: #c8960a;
    --accent-glow: rgba(200, 150, 10, 0.2);
    --bust: #d63031;
    --bust-inactive-bg: #ccc;
    --bust-inactive-text: #888;
    --modifier-bg: #e8e0f8;
    --modifier-text: #6a3aaa;
    --modifier-border: #c8b8e8;
    --modifier-badge-bg: #e0d4f5;
    --modifier-active: #c8b8e8;
    --flip7-bg: #d4f0d4;
    --flip7-text: #2a7a2a;
    --special-dot: #8a5ad0;
    --overlay-backdrop: rgba(0, 0, 0, 0.4);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
}

.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

/* ── Select Screen ── */
#screen-select {
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  gap: 32px;
}

.logo { text-align: center; }
.logo h1 { font-size: 2.5rem; color: var(--accent); letter-spacing: 0.08em; }
.logo p { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; }

.mode-buttons { display: flex; flex-direction: column; gap: 16px; width: 100%; max-width: 340px; }

.mode-btn {
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, transform 0.1s;
}
.mode-btn:active { transform: scale(0.98); }
.mode-btn:hover { border-color: var(--accent); }
.mode-btn h2 { font-size: 1.2rem; color: var(--accent); margin-bottom: 6px; }
.mode-btn p { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }

/* ── Players Screen ── */
#screen-players {
  min-height: 100dvh;
  padding: 24px;
  align-items: center;
}

.players-setup { width: 100%; max-width: 400px; }
.players-setup h2 { color: var(--accent); font-size: 1.3rem; margin-bottom: 20px; text-align: center; }

.player-input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.player-input-row input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
.player-input-row input:focus { border-color: var(--accent); }
.player-input-row input::placeholder { color: var(--text-placeholder); }

.btn-add {
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
  min-height: 48px;
}

.player-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-panel);
  padding: 12px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.player-list .remove-btn {
  background: none;
  border: none;
  color: var(--bust);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: var(--bg);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-start { font-size: 1.1rem; padding: 16px; }
.btn-start:disabled { background: var(--border); color: var(--text-muted); cursor: default; }

.btn-back {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  margin-top: 16px;
}

/* ── Game Screen ── */
#screen-game {
  min-height: 100dvh;
  padding: 0 0 100px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.game-header .round-label { font-weight: 700; color: var(--accent); font-size: 1rem; }
.game-header .mode-label { font-size: 0.75rem; color: var(--text-muted); }

.header-actions { display: flex; gap: 12px; align-items: center; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-icon:hover { color: var(--text); }

.players-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 640px) {
  .players-container { max-width: 620px; }
}

.player-panel {
  background: var(--bg-panel);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  transition: opacity 0.3s;
}

.player-panel.busted { opacity: 0.35; }

.player-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.player-panel-name { font-weight: 600; font-size: 1rem; }

.player-panel-scores { display: flex; align-items: baseline; gap: 8px; }
.score-round { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
.score-total { font-size: 0.8rem; color: var(--text-muted); }

.cards-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.card {
  width: 38px;
  height: 52px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  -webkit-tap-highlight-color: transparent;
}

.text-outline,
.card.selected,
.special-btn.active {
  text-shadow: -1px -1px 0 rgba(0,0,0,0.4), 1px -1px 0 rgba(0,0,0,0.4), -1px 1px 0 rgba(0,0,0,0.4), 1px 1px 0 rgba(0,0,0,0.4);
}

.card.selected {
  background: var(--card-color, var(--accent));
  color: #fff;
  border-color: var(--card-color, var(--accent));
  box-shadow: 0 0 8px rgba(0,0,0,0.2);
}

.card.maxed {
  opacity: 0.3;
  cursor: default;
}

.specials-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.special-btn {
  min-height: 34px;
  padding: 4px 10px;
  line-height: 1.1;
  text-align: center;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
  border: 2px solid var(--modifier-border);
  background: var(--bg-card);
  color: var(--text-dim);
  -webkit-tap-highlight-color: transparent;
}

.special-btn.active {
  background: var(--modifier-color);
  color: #fff;
  border-color: var(--modifier-color);
}

.player-panel-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.btn-bust { background: var(--bust); color: white; }
.btn-bust.active { background: var(--bust-inactive-bg); color: var(--bust-inactive-text); }

.flip7-badge {
  display: inline-flex;
  align-items: center;
  background: var(--flip7-bg);
  color: var(--flip7-text);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
}

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  z-index: 5;
}

.bottom-bar .btn-end-round {
  max-width: 480px;
}

@media (min-width: 640px) {
  .bottom-bar .btn-end-round { max-width: 620px; }
}

.btn-end-round {
  flex: 1;
}

/* ── Overlays ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay-backdrop);
  z-index: 20;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.overlay.visible { display: flex; }

.overlay-sheet {
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 480px;
}

.overlay-sheet h3 { margin-bottom: 16px; color: var(--modifier-text); font-size: 1rem; }

.overlay-close {
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: none;
  background: var(--modifier-bg);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

/* Winner overlay */
.winner-content {
  text-align: center;
  padding: 32px 24px;
}
.winner-content h2 { color: var(--accent); font-size: 1.6rem; margin-bottom: 8px; }
.winner-content .winner-score { font-size: 2rem; font-weight: 700; color: var(--accent); margin-bottom: 24px; }
.winner-content .final-scores { text-align: left; margin-bottom: 24px; }
.winner-content .final-scores div {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

/* ── Round Summary Overlay ── */
.summary-scores { margin-bottom: 20px; }
.summary-scores div {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.summary-scores .bust-label { color: var(--bust); }

.btn-confirm-round {
  margin-bottom: 8px;
}
