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

body {
  font-family: 'Fredoka One', 'Comic Sans MS', cursive;
  background: linear-gradient(135deg, #a8edea, #fed6e3, #d4a1f7);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
}

/* ── START SCREEN ── */
#start-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.start-card {
  background: white;
  border-radius: 32px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 380px; width: 90%;
}
.start-title {
  font-size: clamp(28px, 6vw, 42px);
  color: #5a2d82;
  margin-bottom: 8px;
}
.start-subtitle {
  font-size: 20px;
  color: #888;
  margin-bottom: 32px;
}
.mode-btn {
  display: block; width: 100%;
  padding: 22px;
  font-family: 'Fredoka One', cursive;
  font-size: 24px;
  border: none; border-radius: 20px;
  cursor: pointer;
  margin-bottom: 16px;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 6px 0 rgba(0,0,0,0.15);
}
.mode-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,0.15); }
.btn-2p  { background: #4caf50; color: white; }
.btn-cpu { background: #2196f3; color: white; }

/* ── GAME LAYOUT ── */
#game {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.hidden { display: none !important; }

.game-title {
  font-size: clamp(24px, 5vw, 36px);
  color: #5a2d82;
  text-shadow: 2px 2px 0 rgba(255,255,255,0.6);
  text-align: center;
}

/* ── TURN BANNER ── */
#turn-banner {
  background: white;
  border-radius: 50px;
  padding: 10px 30px;
  font-size: clamp(18px, 4vw, 26px);
  color: #333;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transition: background 0.4s;
}

/* ── SCORE ── */
#scores {
  display: flex; gap: 12px; width: 100%;
}
.score-box {
  flex: 1;
  background: white;
  border-radius: 16px;
  padding: 10px 16px;
  display: flex; flex-direction: column; align-items: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  border-top: 6px solid transparent;
}
.p1-box { border-top-color: #f44336; }
.p2-box { border-top-color: #2196f3; }
.score-label { font-size: clamp(14px, 3vw, 18px); color: #555; }
.score-pos   { font-size: clamp(20px, 4vw, 28px); color: #333; margin-top: 2px; }

/* ── BOARD ── */
#board-wrapper {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 1;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  border: 4px solid #fff;
}
#board-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: 100%; height: 100%;
  position: absolute; inset: 0;
}
.cell {
  border: 1px solid rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2px;
  position: relative;
  font-size: clamp(8px, 1.6vw, 14px);
  color: rgba(0,0,0,0.5);
  font-weight: bold;
  user-select: none;
}
/* Alternating pastel colors */
.cell:nth-child(odd)  { background: #fff9c4; }
.cell:nth-child(even) { background: #e8f5e9; }
.cell.snake-head { background: #ffccbc !important; }
.cell.snake-tail { background: #ffe0b2 !important; }
.cell.ladder-bot { background: #c8e6c9 !important; }
.cell.ladder-top { background: #b3e5fc !important; }
.cell.highlight  { outline: 3px solid #ffeb3b; z-index: 5; }

.cell-num { line-height: 1; margin-top: 1px; }

#tokens-layer {
  position: absolute; inset: 0;
  z-index: 10;
  pointer-events: none;
}

.token {
  position: absolute;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(10px, 2vw, 16px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.token.p1 { background: #f44336; }
.token.p2 { background: #2196f3; }
.token.pop { animation: pop 0.25s ease; }

@keyframes pop {
  0%   { transform: scale(0.6); }
  60%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

#overlay-svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* ── DICE ── */
#dice-area {
  display: flex; align-items: center; gap: 16px;
}
.dice {
  width: clamp(60px, 12vw, 90px);
  height: clamp(60px, 12vw, 90px);
  background: white;
  border-radius: 16px;
  box-shadow: 0 6px 0 #aaa, 0 0 0 2px #ccc;
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
  transition: transform 0.1s;
}
.dice.rolling {
  animation: diceRoll 0.7s ease;
}
@keyframes diceRoll {
  0%   { transform: rotate(0deg)   scale(1); }
  20%  { transform: rotate(25deg)  scale(1.1); }
  40%  { transform: rotate(-20deg) scale(0.95); }
  60%  { transform: rotate(15deg)  scale(1.05); }
  80%  { transform: rotate(-10deg) scale(1); }
  100% { transform: rotate(0deg)   scale(1); }
}
.dot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  width: 100%; height: 100%;
  gap: 2px;
}
.dot {
  background: #333;
  border-radius: 50%;
  width: 100%; height: 100%;
}
.dot.empty { background: transparent; }
#dice-result {
  font-size: clamp(20px, 5vw, 34px);
  color: #5a2d82;
  min-width: 60px;
}

/* ── MESSAGE BOX ── */
#message-box {
  background: white;
  border-radius: 20px;
  padding: 14px 24px;
  font-size: clamp(16px, 3.5vw, 24px);
  color: #333;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  min-height: 60px;
  display: flex; align-items: center; justify-content: center;
  width: 100%;
  transition: background 0.4s;
}
#message-box.snake-msg { background: #ffcdd2; }
#message-box.ladder-msg { background: #c8e6c9; }
#message-box.win-msg   { background: #fff9c4; }

/* ── BUTTONS ── */
#btn-row {
  display: flex; gap: 12px; width: 100%;
}
.action-btn {
  flex: 1;
  padding: 18px;
  font-family: 'Fredoka One', cursive;
  font-size: clamp(18px, 4vw, 26px);
  border: none; border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0,0,0,0.2);
  transition: transform 0.1s, box-shadow 0.1s;
}
.action-btn:active { transform: translateY(3px); box-shadow: 0 3px 0 rgba(0,0,0,0.2); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: 0 6px 0 rgba(0,0,0,0.2); }
.roll-btn { background: #4caf50; color: white; }
.new-btn  { background: #ff9800; color: white; flex: 0 0 auto; padding: 18px 24px; }

/* ── WIN OVERLAY ── */
#win-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
#win-card {
  background: white;
  border-radius: 32px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  max-width: 360px; width: 90%;
  animation: bounceIn 0.5s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes bounceIn {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
#win-emoji { font-size: 72px; margin-bottom: 12px; }
#win-text  { font-size: 32px; color: #5a2d82; margin-bottom: 24px; }
#win-card .action-btn { font-size: 24px; }

/* ── CONFETTI ── */
#confetti-container {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 150;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  width: 12px; height: 12px;
  border-radius: 2px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { transform: translateY(-20px) rotate(0deg);   opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0.3; }
}

/* ── AUTH SCREEN ── */
#auth-screen {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.auth-card {
  background: white;
  border-radius: 32px;
  padding: 40px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  max-width: 380px; width: 90%;
}
.auth-title {
  font-size: clamp(22px, 5vw, 32px);
  color: #5a2d82;
  margin-bottom: 4px;
}
.auth-subtitle {
  font-size: 18px;
  color: #888;
  margin-bottom: 24px;
}
.auth-tabs {
  display: flex;
  background: #f0f0f0;
  border-radius: 16px;
  padding: 4px;
  margin-bottom: 20px;
  gap: 4px;
}
.auth-tab {
  flex: 1;
  padding: 12px;
  font-family: 'Fredoka One', cursive;
  font-size: 18px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #999;
  cursor: pointer;
  transition: all 0.2s;
}
.auth-tab.active {
  background: white;
  color: #5a2d82;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.auth-input {
  display: block;
  width: 100%;
  padding: 14px 16px;
  font-family: 'Fredoka One', cursive;
  font-size: 17px;
  border: 2px solid #e0e0e0;
  border-radius: 14px;
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
  color: #333;
  background: #fafafa;
}
.auth-input:focus { border-color: #764ba2; background: white; }
.auth-error {
  color: #f44336;
  font-size: 15px;
  min-height: 20px;
  margin-bottom: 8px;
  text-align: left;
}
.auth-btn {
  display: block;
  width: 100%;
  padding: 16px;
  font-family: 'Fredoka One', cursive;
  font-size: 20px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 5px 0 rgba(0,0,0,0.15);
}
.auth-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }
.btn-primary { background: #764ba2; color: white; }
.btn-guest   { background: #f0f0f0; color: #555; }
.auth-divider {
  color: #ccc;
  font-size: 15px;
  margin: 16px 0 12px;
}

/* ── USER BAR ── */
#user-bar {
  position: fixed;
  top: 12px; right: 16px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-radius: 50px;
  padding: 8px 16px;
  box-shadow: 0 2px 14px rgba(0,0,0,0.15);
}
#user-name-display {
  font-size: clamp(13px, 2.5vw, 17px);
  color: #5a2d82;
}
.logout-btn {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(12px, 2vw, 15px);
  background: #f5f5f5;
  color: #888;
  border: none;
  border-radius: 20px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.logout-btn:hover { background: #ffcdd2; color: #e53935; }
.stats-btn {
  font-family: 'Fredoka One', cursive;
  font-size: clamp(12px, 2vw, 15px);
  background: #ede7f6;
  color: #5a2d82;
  border: none;
  border-radius: 20px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.stats-btn:hover { background: #d1c4e9; }

/* ── STATS OVERLAY ── */
#stats-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  animation: fadeIn 0.2s ease;
}
#stats-card {
  position: relative;
  background: white;
  border-radius: 28px;
  padding: 36px 32px 28px;
  max-width: 400px; width: 92%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: bounceIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
}
.stats-close-btn {
  position: absolute; top: 16px; right: 20px;
  background: #f5f5f5; border: none; border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 18px; cursor: pointer; color: #888;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.stats-close-btn:hover { background: #ffcdd2; color: #e53935; }
#stats-title {
  font-size: 26px; color: #5a2d82;
  margin-bottom: 20px; text-align: center;
}
#stats-summary {
  display: flex; gap: 12px; justify-content: center;
  margin-bottom: 24px;
}
.stat-item {
  flex: 1;
  background: #f3e5f5;
  border-radius: 16px;
  padding: 14px 8px;
  text-align: center;
}
.stat-num {
  font-size: 32px; color: #5a2d82; line-height: 1;
}
.stat-lbl {
  font-size: 13px; color: #888; margin-top: 4px;
}
.history-title {
  font-size: 17px; color: #888;
  margin-bottom: 10px; text-align: center;
  border-top: 1px solid #f0f0f0; padding-top: 14px;
}
#history-list {
  display: flex; flex-direction: column; gap: 6px;
  max-height: 220px; overflow-y: auto;
}
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 15px;
}
.history-item.win  { background: #e8f5e9; }
.history-item.loss { background: #ffebee; }
.h-date  { color: #aaa; font-size: 13px; flex: 0 0 auto; }
.h-mode  { color: #666; flex: 1; text-align: center; }
.h-result { font-size: 15px; flex: 0 0 auto; }
.no-history { color: #bbb; text-align: center; padding: 20px 0; font-size: 17px; }

/* ── WIN STATS ── */
.win-stats {
  font-size: 17px; color: #888;
  margin-bottom: 16px; text-align: center;
  min-height: 24px;
}
