* { 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='800' cy='90' r='50' fill='%23fbd38d'/%3E%3Ccircle cx='800' cy='90' r='36' fill='%23f6ad55'/%3E%3Cline x1='800' y1='20' x2='800' y2='2' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cline x1='800' y1='160' x2='800' y2='178' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cline x1='730' y1='90' x2='712' y2='90' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cline x1='870' y1='90' x2='888' y2='90' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cline x1='750' y1='40' x2='737' y2='27' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cline x1='850' y1='140' x2='863' y2='153' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cline x1='850' y1='40' x2='863' y2='27' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cline x1='750' y1='140' x2='737' y2='153' stroke='%23f6ad55' stroke-width='5' stroke-linecap='round'/%3E%3Cg fill='%23ffffff' opacity='0.9'%3E%3Cellipse cx='150' cy='90' rx='55' ry='26'/%3E%3Cellipse cx='195' cy='78' rx='38' ry='22'/%3E%3Cellipse cx='108' cy='80' rx='34' ry='20'/%3E%3Cellipse cx='560' cy='150' rx='48' ry='22'/%3E%3Cellipse cx='598' cy='140' rx='32' ry='18'/%3E%3Cellipse cx='524' cy='142' rx='30' ry='17'/%3E%3Cellipse cx='320' cy='260' rx='50' ry='24'/%3E%3Cellipse cx='362' cy='250' rx='34' ry='19'/%3E%3Cellipse cx='284' cy='252' rx='32' ry='18'/%3E%3Cellipse cx='700' cy='300' rx='46' ry='22'/%3E%3Cellipse cx='735' cy='292' rx='30' ry='17'/%3E%3Cellipse cx='667' cy='294' rx='28' ry='16'/%3E%3Cellipse cx='120' cy='400' rx='42' ry='20'/%3E%3Cellipse cx='152' cy='392' rx='28' ry='15'/%3E%3Cellipse cx='90' cy='394' rx='26' ry='14'/%3E%3C/g%3E%3Cpath d='M 420 60 Q 430 50 440 60 Q 450 50 460 60' fill='none' stroke='%234a5568' stroke-width='2.5' stroke-linecap='round' opacity='0.6'/%3E%3Cpath d='M 500 110 Q 508 102 516 110 Q 524 102 532 110' fill='none' stroke='%234a5568' stroke-width='2.2' stroke-linecap='round' opacity='0.5'/%3E%3Cg fill='none' stroke-linecap='round'%3E%3Cpath d='M -20 700 A 170 170 0 0 1 320 700' stroke='%23e53e3e' stroke-width='15'/%3E%3Cpath d='M -4 700 A 154 154 0 0 1 304 700' stroke='%23dd6b20' stroke-width='15'/%3E%3Cpath d='M 12 700 A 138 138 0 0 1 288 700' stroke='%23ecc94b' stroke-width='15'/%3E%3Cpath d='M 28 700 A 122 122 0 0 1 272 700' stroke='%2348bb78' stroke-width='15'/%3E%3Cpath d='M 44 700 A 106 106 0 0 1 256 700' stroke='%234299e1' stroke-width='15'/%3E%3Cpath d='M 60 700 A 90 90 0 0 1 240 700' stroke='%23805ad5' stroke-width='15'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(160deg, #bee3f8 0%, #ebf8ff 55%, #fefcbf 100%);
  background-size: cover, cover;
  background-position: center, center;
  background-attachment: fixed, fixed;
  color: #2d3748;
}

.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; color: #2b6cb0; }
#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(0, 0, 0, 0.12); font-size: 13px; line-height: 1.7; color: #4a5568; 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.6);
  color: #2d3748;
  cursor: pointer;
}
.mode-btn.mode-selected, .count-btn.count-selected {
  background: linear-gradient(135deg, #48bb78, #38a169);
  color: white;
  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.55);
  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.45);
  cursor: pointer;
  flex-shrink: 0;
}
.char-btn svg { width: 100%; height: 100%; display: block; }
.char-btn.char-selected { background: #fff; }

#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: #a0aec0; box-shadow: 0 4px 0 #718096; 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.55);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
}
.score-row-active { background: rgba(255, 255, 255, 0.9); }
.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.5);
  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.45);
  opacity: 0.5;
  cursor: not-allowed;
  flex-shrink: 0;
}
.dice-btn.dice-btn-active { opacity: 1; cursor: pointer; background: rgba(255, 255, 255, 0.9); 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.5); 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; color: #2b6cb0; }
#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(45, 55, 72, 0.05);
  border: 2px dashed rgba(45, 55, 72, 0.25);
  border-radius: 14px;
  color: rgba(45, 55, 72, 0.6);
  font-size: 13px;
  font-weight: bold;
}
