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

body {
  font-family: 'Comic Sans MS', 'Trebuchet MS', 'Segoe UI', sans-serif;
  min-height: 100vh;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='700'%3E%3Ccircle cx='60' cy='45' r='1.6' fill='%23fff' opacity='0.8'/%3E%3Ccircle cx='180' cy='120' r='1.2' fill='%23fff' opacity='0.5'/%3E%3Ccircle cx='320' cy='40' r='1.8' fill='%23fff' opacity='0.9'/%3E%3Ccircle cx='500' cy='90' r='1.3' fill='%23fff' opacity='0.6'/%3E%3Ccircle cx='620' cy='30' r='1.5' fill='%23fff' opacity='0.7'/%3E%3Ccircle cx='860' cy='70' r='1.2' fill='%23fff' opacity='0.5'/%3E%3Ccircle cx='90' cy='260' r='1.4' fill='%23fff' opacity='0.6'/%3E%3Ccircle cx='250' cy='330' r='1.2' fill='%23fff' opacity='0.45'/%3E%3Ccircle cx='430' cy='250' r='1.7' fill='%23fff' opacity='0.75'/%3E%3Ccircle cx='560' cy='380' r='1.2' fill='%23fff' opacity='0.5'/%3E%3Ccircle cx='700' cy='300' r='1.5' fill='%23fff' opacity='0.65'/%3E%3Ccircle cx='840' cy='420' r='1.3' fill='%23fff' opacity='0.55'/%3E%3Ccircle cx='60' cy='470' r='1.2' fill='%23fff' opacity='0.5'/%3E%3Ccircle cx='300' cy='520' r='1.6' fill='%23fff' opacity='0.7'/%3E%3Ccircle cx='480' cy='620' r='1.3' fill='%23fff' opacity='0.55'/%3E%3Ccircle cx='740' cy='560' r='1.4' fill='%23fff' opacity='0.6'/%3E%3Ccircle cx='880' cy='650' r='1.2' fill='%23fff' opacity='0.5'/%3E%3Ccircle cx='200' cy='640' r='1.5' fill='%23fff' opacity='0.65'/%3E%3Cpath d='M 380 160 l 0 -14 M 380 160 l 0 14 M 380 160 l -10 0 M 380 160 l 10 0' stroke='%23fff' stroke-width='1.4' opacity='0.6'/%3E%3Cpath d='M 790 490 l 0 -10 M 790 490 l 0 10 M 790 490 l -8 0 M 790 490 l 8 0' stroke='%23fff' stroke-width='1.2' opacity='0.5'/%3E%3Cline x1='150' y1='190' x2='215' y2='158' stroke='%23fff' stroke-width='1.6' opacity='0.4' stroke-linecap='round'/%3E%3Ccircle cx='218' cy='156' r='2.6' fill='%23fff' opacity='0.75'/%3E%3Cellipse cx='760' cy='120' rx='88' ry='20' fill='none' stroke='%23ed8936' stroke-width='6' opacity='0.8' transform='rotate(-16 760 120)'/%3E%3Ccircle cx='760' cy='120' r='50' fill='%23f6ad55' opacity='0.95'/%3E%3Ccircle cx='742' cy='106' r='9' fill='%23dd8b1e' opacity='0.6'/%3E%3Ccircle cx='778' cy='134' r='6' fill='%23dd8b1e' opacity='0.6'/%3E%3Ccircle cx='120' cy='565' r='42' fill='%234fd1c5' opacity='0.9'/%3E%3Ccircle cx='104' cy='550' r='8' fill='%2338b2ac' opacity='0.8'/%3E%3Ccircle cx='138' cy='580' r='6' fill='%2338b2ac' opacity='0.8'/%3E%3Ccircle cx='428' cy='72' r='15' fill='%23cbd5e0' opacity='0.9'/%3E%3Ccircle cx='422' cy='66' r='4' fill='%23a0aec0' opacity='0.9'/%3E%3Ccircle cx='434' cy='78' r='2.6' fill='%23a0aec0' opacity='0.9'/%3E%3Cg transform='rotate(32 650 560)'%3E%3Cellipse cx='650' cy='560' rx='16' ry='34' fill='%23e2e8f0'/%3E%3Cpath d='M 650 512 L 663 534 L 637 534 Z' fill='%23e53e3e'/%3E%3Ccircle cx='650' cy='550' r='7' fill='%2390cdf4' stroke='%232b6cb0' stroke-width='2'/%3E%3Cpath d='M 636 580 L 624 600 L 640 592 Z' fill='%23e53e3e'/%3E%3Cpath d='M 664 580 L 676 600 L 660 592 Z' fill='%23e53e3e'/%3E%3Cpath d='M 650 594 Q 655 610 650 622 Q 645 610 650 594' fill='%23f6ad55'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(160deg, #0f172a 0%, #1e3a8a 50%, #312e81 100%);
  background-size: cover, cover;
  background-position: center, center;
  background-attachment: fixed, fixed;
  color: #f7fafc;
}

.hidden { display: none !important; }

#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
}
#btn-to-dashboard {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: bold;
  color: #1a202c;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 10px;
  text-decoration: none;
}
#btn-mute {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mute-icon-svg { width: 22px; height: 22px; }

#screen-setup, #screen-game { padding: 16px 20px 32px; }

h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
#screen-setup > p { text-align: center; opacity: 0.85; margin-bottom: 16px; }
.game-intro { max-width: 560px; margin: 20px auto 4px; padding-top: 16px; border-top: 1px dashed rgba(255, 255, 255, 0.25); font-size: 13px; line-height: 1.7; opacity: 0.8; text-align: center; }

#mode-choice { display: flex; gap: 12px; justify-content: center; margin-bottom: 16px; }
.mode-btn, .count-btn {
  padding: 12px 20px;
  font-size: 15px;
  font-weight: bold;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  color: #f7fafc;
  cursor: pointer;
}
.mode-btn.mode-selected, .count-btn.count-selected {
  background: linear-gradient(135deg, #48bb78, #38a169);
  box-shadow: 0 3px 0 #2f855a;
}

#player-count-choice { text-align: center; margin-bottom: 16px; }
.setup-label { font-size: 14px; font-weight: bold; margin-bottom: 8px; }
#count-buttons { display: flex; gap: 10px; justify-content: center; }

#player-name-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
  margin: 0 auto 20px;
}
.player-name-input {
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
}
.player-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 10px;
}
.char-picker { display: flex; gap: 6px; justify-content: center; }
.char-btn {
  width: 48px;
  height: 48px;
  padding: 3px;
  border-radius: 10px;
  border: 3px solid transparent;
  background: rgba(255, 255, 255, 0.15);
  cursor: pointer;
  flex-shrink: 0;
}
.char-btn svg { width: 100%; height: 100%; display: block; }
.char-btn.char-selected { background: rgba(255, 255, 255, 0.85); }

#btn-start {
  display: block;
  margin: 0 auto;
  padding: 14px 32px;
  font-size: 18px;
  font-weight: bold;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #f6ad55, #dd6b20);
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 0 #9c4221;
}
#btn-start:disabled { background: #718096; box-shadow: 0 4px 0 #4a5568; cursor: not-allowed; }

#scoreboard { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 12px; }
.score-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
}
.score-row-active { background: rgba(255, 255, 255, 0.3); }
.score-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.score-name { font-weight: bold; white-space: nowrap; }

#board-wrap {
  position: relative;
  max-width: 100%;
  max-height: 60vh;
  overflow: auto;
  margin: 0 auto 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.08);
  padding: 8px;
  width: fit-content;
}
#board {
  display: grid;
  grid-template-columns: repeat(10, 48px);
  grid-template-rows: repeat(10, 48px);
  gap: 2px;
  position: relative;
}
.cell {
  border-radius: 6px;
  background: #e2e8f0;
  padding: 3px;
  position: relative;
}
.cell-number { font-size: 10px; font-weight: bold; color: rgba(26, 32, 44, 0.6); }
.cell-start { background: linear-gradient(135deg, #48bb78, #38a169); }
.cell-finish { background: linear-gradient(135deg, #f6ad55, #dd6b20); }
.cell-ladder-foot { background: linear-gradient(135deg, #9ae6b4, #48bb78); }
.cell-ladder-head { background: linear-gradient(135deg, #38a169, #276749); }
.cell-snake-head { background: linear-gradient(135deg, #feb2b2, #f56565); }
.cell-snake-tail { background: linear-gradient(135deg, #c53030, #822727); }
.cell-destination { position: absolute; bottom: 2px; right: 3px; font-size: 9px; font-weight: bold; color: rgba(26, 32, 44, 0.75); }

#paths-layer {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 498px;
  height: 498px;
  pointer-events: none;
}
#pawns-layer {
  position: absolute;
  top: 8px;
  left: 8px;
  pointer-events: none;
}
.pawn-svg {
  position: absolute;
  width: 44px;
  height: 44px;
  transition: transform 0.3s ease;
}
.pawn-svg.no-transition { transition: none; }

#dice-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 4px;
  justify-content: center;
}
.dice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  opacity: 0.5;
  cursor: not-allowed;
  flex-shrink: 0;
}
.dice-btn.dice-btn-active { opacity: 1; cursor: pointer; background: rgba(255, 255, 255, 0.25); box-shadow: 0 0 0 3px #f6ad55; }
.dice-btn:disabled { pointer-events: none; }
.dice-owner { font-size: 11px; font-weight: bold; }
.dice-face-svg { width: 36px; height: 36px; }
.dice-face-svg.rolling { animation: dice-shake 0.16s linear infinite; }
@keyframes dice-shake {
  0% { transform: rotate(-14deg) scale(1.06) translateY(-1px); }
  25% { transform: rotate(0deg) scale(1.12) translateY(1px); }
  50% { transform: rotate(14deg) scale(1.06) translateY(-1px); }
  75% { transform: rotate(0deg) scale(1.12) translateY(1px); }
  100% { transform: rotate(-14deg) scale(1.06) translateY(-1px); }
}

.overlay { display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); align-items: center; justify-content: center; padding: 20px; z-index: 100; }
.overlay:not(.hidden) { display: flex; }
.modal { background: white; color: #1a202c; border-radius: 20px; padding: 24px; max-width: 420px; width: 100%; text-align: center; }
#question-text { font-size: 18px; font-weight: bold; margin-bottom: 16px; }
#question-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.opt-btn { padding: 14px 8px; font-size: 15px; font-weight: bold; border: 2px solid #e2e8f0; border-radius: 12px; background: #f7fafc; cursor: pointer; min-height: 52px; }
.opt-btn:disabled { cursor: not-allowed; }
.opt-btn.opt-correct { background: #c6f6d5; border-color: #38a169; }
.opt-btn.opt-wrong { background: #fed7d7; border-color: #e53e3e; }
#question-feedback { font-weight: bold; min-height: 20px; }

#winner-name { font-size: 22px; margin-bottom: 8px; }
#winner-stats { margin-bottom: 16px; font-size: 14px; color: #4a5568; }
#btn-play-again { padding: 12px 28px; font-size: 16px; font-weight: bold; border: none; border-radius: 12px; background: linear-gradient(135deg, #4299e1, #3182ce); color: white; cursor: pointer; }

@keyframes celebrate-bounce {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.05) rotate(-1deg); }
  50% { transform: scale(1.08) rotate(1deg); }
  75% { transform: scale(1.05) rotate(-1deg); }
}
#modal-winner .modal { animation: celebrate-bounce 0.8s ease; }

.ad-slot {
  max-width: 500px;
  min-height: 90px;
  margin: 160px auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.12);
  border: 2px dashed rgba(255, 255, 255, 0.5);
  border-radius: 14px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  font-weight: bold;
}
