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

:root {
  --bg:       #0f1c28;
  --surface:  #1a2f45;
  --accent:   #c59a4a;
  --fire:     #e07030;
  --heat:     #e7b34d;
  --make:     #7dcea0;
  --miss:     #c23b22;
  --text:     #f4efe3;
  --muted:    #a8b4c0;
  --card:     rgba(255,255,255,0.07);
  --card-active: rgba(197,154,74,0.20);
  --navy:     #142f4b;
  --rust:     #9b4529;
  --gold:     #c59a4a;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  touch-action: none;
  user-select: none;
}

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.hidden { display: none !important; }

/* ── Setup screen ────────────────────────────────────────── */
#setup-screen {
  background:
    radial-gradient(ellipse at 20% 0%, rgba(197,154,74,0.18), transparent 50%),
    linear-gradient(165deg, #0c1824 0%, #142f4b 55%, #1a2430 100%);
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(16px, env(safe-area-inset-top)) 12px max(24px, env(safe-area-inset-bottom));
}

.setup-card {
  background: var(--surface);
  border: 1px solid rgba(197,154,74,0.35);
  border-radius: 18px;
  padding: 32px 28px;
  width: min(460px, 96vw);
  margin: auto 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
  flex-shrink: 0;
}

.setup-card h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 2.1rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--gold), #e8d5a3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline {
  text-align: center;
  margin: -8px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}
.back-link {
  position: fixed;
  top: 12px;
  left: 14px;
  z-index: 40;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  pointer-events: all;
}
.back-link:hover { color: var(--gold); }

.setup-card h1 .emoji {
  font-size: 1.6rem;
  -webkit-text-fill-color: initial;
  cursor: pointer;
  display: inline-block;
}
.setup-card h1 .emoji:active { transform: scale(1.18) rotate(-12deg); }

.section-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

/* Player input rows */
.player-input-row {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 8px;
}

.prow-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-num {
  font-size: 0.95rem;
  font-weight: 800;
  min-width: 32px;
}

.player-input-row input {
  flex: 1;
  min-width: 0;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.player-input-row input:focus { border-color: var(--accent); }

/* Human / CPU toggle */
.ai-toggle {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.ai-toggle.cpu { background: rgba(255,179,0,0.2); border-color: var(--heat); }

.parrot-vibe {
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
  padding: 0 2px 2px;
}
.parrot-vibe b { color: var(--text); font-weight: 700; }

/* Parrot swatches */
.flavor-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding-left: 42px;
}
.flavor-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  cursor: pointer;
  padding: 0;
  transition: transform 0.12s, border-color 0.12s;
}
.flavor-swatch:hover { transform: scale(1.12); }
.flavor-swatch.selected {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.4), 0 0 10px rgba(255,255,255,0.5);
  transform: scale(1.15);
}
/* Soft "already taken by another player" hint (not a hard block) */
.flavor-swatch.taken:not(.selected) { opacity: 0.3; }

.remove-player-btn {
  background: rgba(255,82,82,0.15);
  border: none;
  color: var(--miss);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.85rem;
}
.remove-player-btn:hover { background: rgba(255,82,82,0.3); }

#add-player-btn {
  background: rgba(79,195,247,0.1);
  border: 1px dashed rgba(79,195,247,0.4);
  color: var(--accent);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  width: 100%;
}
#add-player-btn:hover { background: rgba(79,195,247,0.2); }
#add-player-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Direction radio */
.direction-options {
  display: flex;
  gap: 10px;
}

.direction-options label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s, border-color 0.2s;
}
.direction-options input[type="radio"] { accent-color: var(--accent); }
.direction-options label:has(input:checked) {
  background: var(--card-active);
  border-color: var(--accent);
}

/* Checkbox row (e.g. flick feedback toggle) */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.checkbox-row input { accent-color: var(--accent); }

#start-btn {
  background: linear-gradient(135deg, #9b4529, #c59a4a);
  border: none;
  color: #fff;
  border-radius: 10px;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: opacity 0.2s, transform 0.1s;
}
#start-btn:hover  { opacity: 0.9; }
#start-btn:active { transform: scale(0.98); }

#practice-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: var(--text);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
#practice-btn:hover  { background: rgba(255,255,255,0.12); }
#practice-btn:active { transform: scale(0.98); }

/* Practice stats panel (replaces player cards in solo practice) */
.practice-stats {
  flex: 1;
  display: flex;
  justify-content: center;
  gap: 28px;
}
.ps-item { display: flex; flex-direction: column; align-items: center; }
.ps-num {
  font-size: clamp(2rem, 6vh, 3.4rem);
  font-weight: 900;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.ps-label {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── Game screen ─────────────────────────────────────────── */
#game-screen {
  pointer-events: none;
}

#game-canvas {
  position: fixed;
  inset: 0;
  display: block;
  pointer-events: all;
  cursor: crosshair;
}

/* HUD */
#hud {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
}

#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 16px 0;
  gap: 10px;
}

#turn-banner {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 1px 8px rgba(0,0,0,0.6);
}

#top-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#point-count {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--fire);
  text-shadow: 0 0 16px var(--fire);
  min-width: 60px;
  text-align: right;
  white-space: nowrap;
}

/* HUD buttons (mute, etc.) — re-enable pointer events (#hud disables them) */
.hud-btn {
  pointer-events: all;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}
.hud-btn:active { transform: scale(0.95); }

#streak-banner {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  padding: 4px 0;
  letter-spacing: 0.03em;
  min-height: 1.6em;
}
#streak-banner.heating-up  { color: var(--heat); }
#streak-banner.on-fire     { color: var(--fire); text-shadow: 0 0 12px var(--fire); }
#streak-banner.miss-penalty { color: var(--miss); }

#flip-hint {
  position: fixed;
  bottom: 140px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.88rem;
  color: rgba(255,255,255,0.45);
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50%       { opacity: 0.9;  }
}

/* Player cards */
#player-list {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 6px;
  padding: 8px 10px 12px;
  overflow-x: auto;
  pointer-events: none;
}

.player-card {
  flex: 1;
  min-width: 96px;
  background: rgba(255,255,255,0.13);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.3s, border-color 0.3s, transform 0.3s;
}

.player-card.active {
  background: var(--card-active);
  border-color: var(--accent);
  box-shadow: 0 0 22px rgba(197,154,74,0.45);
  transform: scale(1.06);
}

.player-card.heating-up {
  border-color: var(--heat);
  box-shadow: 0 0 10px rgba(255,179,0,0.35);
}

.player-card.on-fire {
  border-color: var(--fire);
  background: rgba(255,102,0,0.15);
  box-shadow: 0 0 16px rgba(255,102,0,0.4);
  animation: fire-pulse 0.8s ease-in-out infinite;
}

.player-card.eliminated {
  opacity: 0.35;
  text-decoration: line-through;
  filter: grayscale(1);
}

/* One-shot flash when a player is knocked out */
.player-card.just-out { animation: card-out 0.9s ease; }
@keyframes card-out {
  0%   { background: rgba(255,82,82,0.55); transform: scale(1.14); filter: none; opacity: 1; }
  100% { }
}

@keyframes fire-pulse {
  0%, 100% { box-shadow: 0 0 16px rgba(255,102,0,0.4); }
  50%       { box-shadow: 0 0 28px rgba(255,102,0,0.7); }
}

.p-name {
  font-size: clamp(1rem, 2.2vh, 1.6rem);
  font-weight: 700;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The lives count — the #1 thing that must read across a classroom */
.p-lives-num {
  font-size: clamp(2.6rem, 7vh, 4.5rem);
  font-weight: 900;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.p-lives-label {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.player-card.low-lives .p-lives-num { color: var(--miss); }
.player-card.on-fire   .p-lives-num { color: var(--fire); }

/* ── Turn-handoff gate ───────────────────────────────────── */
#handoff-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 12, 22, 0.82);
  backdrop-filter: blur(4px);
  pointer-events: all;                 /* re-enable: #game-screen disables them */
  cursor: pointer;
  animation: handoff-in 0.18s ease-out;
}
@keyframes handoff-in { from { opacity: 0; } to { opacity: 1; } }

.handoff-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 36px 48px;
  text-align: center;
}
.handoff-label {
  font-size: 1rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.handoff-name {
  font-size: clamp(2.6rem, 11vw, 6rem);
  font-weight: 900;
  line-height: 1;
  /* color set inline to the player's flavor in JS */
  text-shadow: 0 0 32px currentColor;
}
.handoff-tap {
  margin-top: 14px;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.6);
  animation: pulse 1.6s ease-in-out infinite;
}

/* ── First-launch tutorial ───────────────────────────────── */
#tutorial-overlay {
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(6px);
  z-index: 30;
}
.tutorial-card { gap: 14px; }
.tutorial-card h2 { font-size: 1.4rem; font-weight: 800; text-align: center; }
.tut-list { display: flex; flex-direction: column; gap: 10px; padding-left: 18px; }
.tut-list li { font-size: 0.98rem; line-height: 1.35; }
#tutorial-done-btn {
  margin-top: 4px;
  background: linear-gradient(135deg, #9b4529, #c59a4a);
  border: none; color: #fff; border-radius: 10px; padding: 12px;
  font-size: 1rem; font-weight: 700; cursor: pointer;
}
#tutorial-done-btn:active { transform: scale(0.98); }

/* ── Game Over screen ────────────────────────────────────── */
#game-over {
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(6px);
  flex-direction: column;
  gap: 24px;
  text-align: center;
}

.game-over-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  border: 1px solid rgba(197,154,74,0.35);
  border-radius: 18px;
  padding: 40px 32px;
  width: min(420px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Match summary rows */
#match-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}
#match-summary:empty { display: none; }
.ms-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 0.9rem;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 7px 10px;
}
.ms-row.ms-winner {
  background: rgba(255,204,0,0.10);
  border: 1px solid rgba(255,204,0,0.35);
}
.ms-name {
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ms-stats {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.game-over-card h2 {
  font-size: 1.4rem;
  color: var(--muted);
  font-weight: 600;
}

#winner-name {
  font-size: 2.4rem;
  font-weight: 900;
  background: linear-gradient(90deg, #e8d5a3, #c59a4a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#play-again-btn {
  background: linear-gradient(135deg, #9b4529, #c0592b);
  border: none;
  color: #fff;
  border-radius: 10px;
  padding: 14px 32px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}
#play-again-btn:hover { opacity: 0.88; }

.secondary-btn {
  background: transparent;
  border: 1px solid rgba(197,154,74,0.45);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 28px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
.secondary-btn:hover { border-color: var(--gold); color: var(--gold); }
.secondary-btn:active { transform: scale(0.98); }

/* ── Practice strength meter ─────────────────────────────── */
#practice-meter {
  position: fixed;
  bottom: 132px;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 72vw);
  pointer-events: none;
  text-align: center;
}
.pm-track {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: rgba(255,255,255,0.12);
}
.pm-band {
  /* make window 1800–2400 on a 1000–3200 scale */
  position: absolute;
  left: 36.4%;
  width: 27.2%;
  top: 0;
  bottom: 0;
  background: rgba(105,240,170,0.45);
  border-radius: 5px;
}
.pm-marker {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 18px;
  margin-left: -2px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 0 8px rgba(255,255,255,0.8);
  transition: left 0.15s ease;
}
.pm-label {
  margin-top: 6px;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#egg-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 50;
  pointer-events: none;
  background: rgba(20, 47, 75, 0.92);
  border: 1px solid rgba(197, 154, 74, 0.55);
  color: #f4efe3;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  white-space: nowrap;
}
#egg-toast.hidden { display: none !important; }

/* ── Reduced motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .player-card.on-fire { animation: none; }
  #flip-hint { animation: none; opacity: 0.7; }
  .handoff-tap { animation: none; }
  #handoff-overlay { animation: none; }
  .player-card.just-out { animation: none; }
}
