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

:root {
  --pink:       #ff6eb4;
  --pink-light: #ffb3d9;
  --pink-deep:  #e91e8c;
  --purple:     #c264fe;
  --purple-dark:#7c3aed;
  --lavender:   #f0e6ff;
  --gold:       #ffd700;
  --white:      #ffffff;
  --glass:      rgba(255,255,255,0.25);
  --glass-border: rgba(255,255,255,0.45);
  --shadow:     0 8px 32px rgba(180,60,180,0.18);
  --radius:     18px;
  --font-title: 'Fredoka One', cursive;
  --font-body:  'Nunito', sans-serif;
}

html, body {
  height: 100%;
  overflow-x: hidden;
  font-family: var(--font-body);
  background: linear-gradient(135deg, #fce4f3 0%, #e8d5ff 40%, #ffd6f0 70%, #d5eeff 100%);
  background-attachment: fixed;
  color: #5a2d6e;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* ===== GLITTER ===== */
#glitter-container {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
}
.glitter {
  position: absolute;
  border-radius: 50%;
  animation: glitter-float linear infinite;
  opacity: 0;
}
@keyframes glitter-float {
  0%   { transform: translateY(100vh) rotate(0deg);   opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 0.8; }
  100% { transform: translateY(-10vh) rotate(720deg); opacity: 0; }
}

/* ===== CONFETTI ===== */
#confetti-container {
  position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden;
}
.confetto {
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 2px;
  animation: confetti-fall 2.5s ease-in forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  min-height: 100vh;
  padding: 20px 16px 40px;
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
}
.screen.active { display: block; }

/* ===== TITLE ===== */
.title {
  font-family: var(--font-title);
  font-size: clamp(2rem, 10vw, 3rem);
  text-align: center;
  color: var(--pink-deep);
  text-shadow: 0 2px 12px rgba(233,30,140,0.3), 0 0 40px rgba(255,110,180,0.4);
  margin-bottom: 24px;
  line-height: 1.2;
  animation: title-pulse 3s ease-in-out infinite;
}
@keyframes title-pulse {
  0%, 100% { text-shadow: 0 2px 12px rgba(233,30,140,0.3), 0 0 40px rgba(255,110,180,0.4); }
  50%       { text-shadow: 0 2px 20px rgba(233,30,140,0.6), 0 0 60px rgba(194,100,254,0.6); }
}

/* ===== CARDS ===== */
.card {
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card h3 {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--purple-dark);
  margin-bottom: 10px;
  text-align: center;
}

/* ===== PLAYER SETUP ===== */
.setup-card { display: flex; flex-direction: column; gap: 16px; }
.player-setup { display: flex; flex-direction: column; gap: 8px; }
.player-setup h3 { text-align: left; font-size: 1rem; }

.name-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 2px solid var(--pink-light);
  background: rgba(255,255,255,0.6);
  font-family: var(--font-body);
  font-size: 1rem;
  color: #5a2d6e;
  outline: none;
  transition: border-color 0.2s;
}
.name-input:focus { border-color: var(--pink-deep); }

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.sym-btn {
  font-size: 1.4rem;
  width: 100%; aspect-ratio: 1;
  border-radius: 12px;
  border: 2.5px solid transparent;
  background: rgba(255,255,255,0.5);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.sym-btn:hover  { transform: scale(1.15); background: rgba(255,255,255,0.8); }
.sym-btn.active {
  border-color: var(--pink-deep);
  background: rgba(255,110,180,0.25);
  transform: scale(1.1);
  box-shadow: 0 0 12px rgba(233,30,140,0.4);
}
.sym-btn.taken  { opacity: 0.3; pointer-events: none; }

/* ===== MODE BUTTONS ===== */
.mode-buttons { display: flex; gap: 10px; }
.mode-btn {
  flex: 1;
  padding: 12px 8px;
  border-radius: 14px;
  border: 2px solid var(--pink-light);
  background: rgba(255,255,255,0.5);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--purple-dark);
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn.active {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(233,30,140,0.35);
}

/* ===== SIZE BUTTONS ===== */
.size-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 8px; }
.size-btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid var(--pink-light);
  background: rgba(255,255,255,0.5);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--purple-dark);
  cursor: pointer;
  transition: all 0.2s;
  min-width: 48px;
}
.size-btn.active {
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  color: white;
  border-color: transparent;
  box-shadow: 0 3px 12px rgba(124,58,237,0.35);
}
.win-hint {
  text-align: center;
  font-size: 0.85rem;
  color: var(--purple-dark);
  opacity: 0.75;
}

/* ===== STATS ===== */
#stats-display {
  display: flex; justify-content: space-around; margin-bottom: 10px;
}
.stat-item { text-align: center; }
.stat-item .stat-sym { font-size: 1.4rem; }
.stat-item .stat-name { font-size: 0.75rem; font-weight: 700; color: var(--purple-dark); }
.stat-item .stat-val  { font-size: 1.4rem; font-family: var(--font-title); color: var(--pink-deep); }

/* ===== BUTTONS ===== */
.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
  font-family: var(--font-title);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(233,30,140,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  margin-bottom: 14px;
}
.btn-primary:active { transform: scale(0.97); box-shadow: 0 3px 10px rgba(233,30,140,0.3); }

.btn-ghost {
  display: block;
  width: 100%;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid var(--pink-light);
  background: transparent;
  color: var(--purple-dark);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-ghost:active { background: rgba(255,110,180,0.1); }

.btn-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: none;
  background: var(--glass);
  backdrop-filter: blur(8px);
  font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.15s;
  border: 1.5px solid var(--glass-border);
}
.btn-icon:active { transform: scale(0.9); }

/* ===== GAME SCREEN ===== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.turn-indicator {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--purple-dark);
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1.5px solid var(--glass-border);
  padding: 8px 16px;
  border-radius: 12px;
  text-align: center;
  flex: 1;
  margin: 0 8px;
  animation: pulse-indicator 2s ease-in-out infinite;
}
@keyframes pulse-indicator {
  0%, 100% { box-shadow: 0 0 0 rgba(233,30,140,0); }
  50%       { box-shadow: 0 0 16px rgba(233,30,140,0.3); }
}

/* ===== SCOREBOARD ===== */
.scoreboard {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.score-box {
  flex: 1;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 10px 6px;
  text-align: center;
  box-shadow: var(--shadow);
}
.score-symbol { font-size: 1.5rem; line-height: 1; }
.score-name   { font-size: 0.7rem; font-weight: 700; color: var(--purple-dark); margin: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-val    { font-family: var(--font-title); font-size: 1.5rem; color: var(--pink-deep); }
.score-tie .score-symbol { font-size: 1.2rem; }

/* ===== BOARD ===== */
#board-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
}
#board {
  display: grid;
  gap: 8px;
  width: min(calc(100vw - 32px), 440px);
}
.cell {
  aspect-ratio: 1;
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 2px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 6vw, 2.8rem);
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, box-shadow 0.12s;
  box-shadow: 0 4px 12px rgba(180,60,180,0.1);
  position: relative;
  overflow: hidden;
}
.cell::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.4), transparent 70%);
  pointer-events: none;
}
.cell:not(.taken):hover {
  transform: scale(1.06);
  background: rgba(255,255,255,0.45);
  box-shadow: 0 6px 20px rgba(233,30,140,0.2);
}
.cell.taken { cursor: default; }
.cell.p1 { border-color: rgba(233,30,140,0.5); background: rgba(255,110,180,0.15); }
.cell.p2 { border-color: rgba(124,58,237,0.5); background: rgba(194,100,254,0.15); }
.cell.win-cell {
  animation: win-flash 0.5s ease-in-out 3;
  border-color: var(--gold) !important;
  background: rgba(255,215,0,0.25) !important;
}
@keyframes win-flash {
  0%, 100% { box-shadow: 0 0 0 rgba(255,215,0,0); }
  50%       { box-shadow: 0 0 24px rgba(255,215,0,0.7); }
}
.cell-enter {
  animation: cell-pop 0.2s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes cell-pop {
  0%   { transform: scale(0.3); opacity: 0.5; }
  100% { transform: scale(1);   opacity: 1; }
}

/* ===== MODAL ===== */
.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(100,20,120,0.5);
  backdrop-filter: blur(6px);
  z-index: 1000;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-content {
  background: linear-gradient(160deg, #fff0fa, #f0e6ff);
  border-radius: 24px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(150,20,180,0.3);
  max-width: 340px;
  width: 100%;
  animation: modal-in 0.35s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes modal-in {
  0%   { transform: scale(0.5) translateY(40px); opacity: 0; }
  100% { transform: scale(1)   translateY(0);    opacity: 1; }
}
.win-symbol { font-size: 4rem; margin-bottom: 8px; animation: bounce 0.6s cubic-bezier(0.34,1.56,0.64,1); }
@keyframes bounce { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.modal-content h2 {
  font-family: var(--font-title);
  font-size: 1.6rem;
  color: var(--pink-deep);
  margin-bottom: 20px;
}
.modal-buttons { display: flex; flex-direction: column; gap: 10px; }

/* ===== RAINBOW BAR ===== */
.rainbow-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 6px;
  background: linear-gradient(90deg, #ff6eb4, #ffd700, #7fff00, #00cfff, #c264fe, #ff6eb4);
  background-size: 200% 100%;
  animation: rainbow-slide 1.5s linear infinite;
  z-index: 9998;
}
@keyframes rainbow-slide {
  0%   { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 390px) {
  .title { font-size: 1.7rem; }
  .sym-btn { font-size: 1.1rem; }
  .cell  { border-radius: 10px; }
  .score-name { font-size: 0.6rem; }
}
@media (max-height: 700px) {
  .title { font-size: 1.8rem; margin-bottom: 10px; }
  .card  { padding: 10px; margin-bottom: 8px; }
  .sym-btn { font-size: 1.1rem; }
}
/* Prevent zoom on input focus iOS */
input[type="text"] { font-size: 16px; }
/* Better touch targets on small screens */
@media (hover: none) {
  .cell:not(.taken):active {
    transform: scale(0.95);
    background: rgba(255,255,255,0.55);
  }
}
