/* Google Fonts: Fredoka for kid-friendly bubbly UI */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

:root {
  --font-family: 'Fredoka', sans-serif;
  --bg-gradient: linear-gradient(135deg, #FFDEE9 0%, #B5FFFC 100%);
  --color-primary: #FF5252;
  --color-primary-dark: #D32F2F;
  --color-secondary: #FFD740;
  --color-secondary-dark: #FFC400;
  --color-accent: #40C4FF;
  --color-success: #69F0AE;
  --color-dark: #37474F;
  --color-light: #FFFFFF;
  --board-light: #FFF9C4;
  --board-dark: #FFE0B2;
  --card-shadow: 0 10px 0 rgba(0, 0, 0, 0.1);
  --border-radius: 20px;
  --border-width: 4px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
}

body {
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--color-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* Site header bar — consistent with the other Cubs Play games */
.site-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 30px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.site-header .sh-brand { display: inline-flex; align-items: center; gap: 14px; text-decoration: none; }
.site-header .sh-brand img { height: 60px; width: auto; transition: transform .3s ease; }
.site-header .sh-brand:hover img { transform: scale(1.12); }
.site-header .sh-brand span { font-weight: 800; font-size: 28px; color: #b8860b; letter-spacing: .5px; }
.site-header .sh-back {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 16px; color: #4a3a16; background: #f5b921;
  text-decoration: none; padding: 11px 24px; border-radius: 30px;
  box-shadow: 0 4px 10px rgba(245, 185, 33, .4); transition: transform .2s ease, box-shadow .2s ease;
}
.site-header .sh-back:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 6px 16px rgba(245, 185, 33, .5); }
@media (max-width: 600px) {
  .site-header { padding: 10px 16px; }
  .site-header .sh-brand img { height: 44px; }
  .site-header .sh-brand span { font-size: 22px; }
  .site-header .sh-back { font-size: 14px; padding: 9px 18px; }
}

/* App Containers */
.app-container {
  width: 100%;
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 20px 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

header {
  text-align: center;
  margin-bottom: 10px;
}

header h1 {
  font-size: 3rem;
  color: #FF5252;
  text-shadow: 
    3px 3px 0px #FFF, 
    6px 6px 0px var(--color-dark);
  letter-spacing: 2px;
  animation: bounce 2s infinite alternate;
}

@keyframes bounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-10px); }
}

/* Card layout wrapper */
.card-wrapper {
  background: var(--color-light);
  border: var(--border-width) solid var(--color-dark);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  padding: 30px;
  width: 100%;
}

/* Setup Screen */
#setup-screen {
  max-width: 850px;
  text-align: center;
  width: 100%;
}

#setup-screen h2 {
  font-size: 2rem;
  margin-bottom: 25px;
  color: var(--color-dark);
}

.player-count-selector {
  display: flex;
  justify-content: center;
  gap: 15px;
  margin-bottom: 30px;
}

.count-btn {
  background: var(--color-light);
  border: var(--border-width) solid var(--color-dark);
  border-radius: 15px;
  padding: 12px 25px;
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--color-dark);
  transition: all 0.1s ease;
}

.count-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 0 var(--color-dark);
}

.count-btn.active {
  background: var(--color-secondary);
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--color-dark);
}

.player-inputs-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
  max-height: 450px;
  overflow-y: auto;
  padding-right: 5px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 15px;
  background: #F5F7FA;
  padding: 15px;
  border-radius: var(--border-radius);
  border: 3px solid var(--color-dark);
}

.player-token-preview {
  width: 55px;
  height: 55px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 3px solid var(--color-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 700;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  background-color: var(--color-light);
}

.player-details {
  flex-grow: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
}

.player-details label {
  font-weight: 700;
  font-size: 1.1rem;
}

.player-details input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 3px solid var(--color-dark);
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  background: var(--color-light);
}

.player-details input:focus {
  border-color: var(--color-accent);
}

.color-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.color-option {
  width: 40px;
  height: 40px;
  border: 2px solid var(--color-dark);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.45), 0 3px 0 rgba(55, 71, 79, 0.25);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.color-option:hover {
  transform: scale(1.1);
}

.color-option.selected {
  border-color: var(--color-primary);
  box-shadow: inset 0 3px 0 rgba(255,255,255,0.45), 0 0 0 4px var(--color-secondary), 0 5px 0 rgba(55, 71, 79, 0.25);
  transform: scale(1.12);
}

/* Play Game Button */
.play-btn {
  background: var(--color-success);
  border: var(--border-width) solid var(--color-dark);
  border-radius: var(--border-radius);
  color: var(--color-dark);
  padding: 15px 40px;
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 0 var(--color-dark);
  transition: all 0.15s ease;
}

.play-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 11px 0 var(--color-dark);
}

.play-btn:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 var(--color-dark);
}

/* Main Game Interface */
#game-screen {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 30px;
  width: 100%;
}

@media (max-width: 900px) {
  #game-screen {
    grid-template-columns: 1fr;
  }
}

/* Game Board wrapper */
.board-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--color-light);
  border: var(--border-width) solid var(--color-dark);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  user-select: none;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  width: 100%;
  height: 100%;
}

/* Grid Cell Styles */
.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: clamp(0.7rem, 2vw, 1.2rem);
  border: 1px dashed rgba(55, 71, 79, 0.15);
  box-sizing: border-box;
}

.cell-bg-1 { background-color: var(--board-light); }
.cell-bg-2 { background-color: var(--board-dark); }
.cell-bg-3 { background-color: #E8F5E9; }
.cell-bg-4 { background-color: #E1F5FE; }
.cell-bg-5 { background-color: #F3E5F5; }

.cell-number {
  position: absolute;
  top: 5px;
  left: 5px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid var(--color-dark);
  border-radius: 8px;
  width: clamp(16px, 3.5vw, 26px);
  height: clamp(16px, 3.5vw, 26px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.6rem, 1.5vw, 0.9rem);
  color: var(--color-dark);
}

/* SVG Overlay for Snakes and Ladders */
.board-svg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* Snake and Ladder SVG elements */
.svg-snake-body {
  fill: none;
  stroke: #4CAF50;
  stroke-linecap: round;
  filter: drop-shadow(0px 4px 4px rgba(0,0,0,0.15));
  animation: snakeWiggle 3s infinite ease-in-out;
}

.svg-snake-belly {
  fill: none;
  stroke: #81C784;
  stroke-dasharray: 8 12;
  stroke-linecap: round;
}

.svg-snake-head {
  fill: #388E3C;
}

.svg-snake-eyes {
  fill: white;
}

.svg-snake-pupils {
  fill: black;
}

.svg-snake-tongue {
  fill: none;
  stroke: #FF1744;
  stroke-width: 3;
  stroke-linecap: round;
}

.svg-ladder-rail {
  stroke: #A1887F;
  stroke-linecap: round;
  filter: drop-shadow(0px 3px 3px rgba(0,0,0,0.2));
}

.svg-ladder-rail-highlight {
  stroke: #D7CCC8;
  stroke-linecap: round;
}

.svg-ladder-rung {
  stroke: #8D6E63;
  stroke-linecap: round;
}

/* Tokens overlay container */
.tokens-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

/* Player Tokens */
.player-token {
  position: absolute;
  width: 5.8%;
  height: 5.8%;
  border-radius: 50%;
  border: 2px solid var(--color-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.75rem, 1.35vw, 1.2rem);
  font-weight: 700;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
  transform: translate(-50%, -50%);
  transition: left 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
              top 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 25;
  background-color: var(--color-light);
}

.player-token.active-bounce {
  animation: pulseToken 1s infinite alternate;
  z-index: 30;
}

@keyframes pulseToken {
  0% { transform: translate(-50%, -50%) scale(1); }
  100% { transform: translate(-50%, -50%) scale(1.2); }
}

/* Game Info Sidebar */
.game-info-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.turn-card {
  background: var(--color-light);
  border: var(--border-width) solid var(--color-dark);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  padding: 20px;
  text-align: center;
}

.turn-title {
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #78909C;
  margin-bottom: 10px;
}

.turn-player {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  font-size: 1.8rem;
  font-weight: 700;
  min-width: 0;
}

.turn-avatar {
  width: 50px;
  height: 50px;
  flex: 0 0 50px;
  border-radius: 50%;
  border: 3px solid var(--color-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  background-color: var(--color-light);
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
}

#turn-player-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Dice Roller Card */
.dice-card {
  background: var(--color-light);
  border: var(--border-width) solid var(--color-dark);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  padding: 25px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* 3D Dice styling */
.dice-scene {
  width: 100px;
  height: 100px;
  perspective: 400px;
  margin: 10px 0;
}

.dice-cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: translateZ(-50px) rotateX(0deg) rotateY(0deg);
  transition: transform 0.6s cubic-bezier(0.2, 0.8, 0.3, 1.1);
}

.dice-face {
  position: absolute;
  width: 100px;
  height: 100px;
  border: 4px solid var(--color-dark);
  background: #FFF;
  border-radius: 18px;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 8px;
  box-sizing: border-box;
}

.dot {
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--color-dark);
  align-self: center;
  justify-self: center;
}

/* Specific face rotations */
.face-1  { transform: rotateY(  0deg) translateZ(50px); }
.face-6  { transform: rotateY(180deg) translateZ(50px); }
.face-3  { transform: rotateY( -90deg) translateZ(50px); }
.face-4  { transform: rotateY(  90deg) translateZ(50px); }
.face-5  { transform: rotateX(  90deg) translateZ(50px); }
.face-2  { transform: rotateX( -90deg) translateZ(50px); }

/* Face pips placements */
.face-1 .dot { grid-area: 2 / 2; background-color: var(--color-primary); width: 20px; height: 20px;} /* Big red dot */

.face-2 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-2 .dot:nth-child(2) { grid-area: 3 / 3; }

.face-3 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-3 .dot:nth-child(2) { grid-area: 2 / 2; }
.face-3 .dot:nth-child(3) { grid-area: 3 / 3; }

.face-4 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-4 .dot:nth-child(2) { grid-area: 1 / 3; }
.face-4 .dot:nth-child(3) { grid-area: 3 / 1; }
.face-4 .dot:nth-child(4) { grid-area: 3 / 3; }

.face-5 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-5 .dot:nth-child(2) { grid-area: 1 / 3; }
.face-5 .dot:nth-child(3) { grid-area: 2 / 2; }
.face-5 .dot:nth-child(4) { grid-area: 3 / 1; }
.face-5 .dot:nth-child(5) { grid-area: 3 / 3; }

.face-6 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-6 .dot:nth-child(2) { grid-area: 1 / 3; }
.face-6 .dot:nth-child(3) { grid-area: 2 / 1; }
.face-6 .dot:nth-child(4) { grid-area: 2 / 3; }
.face-6 .dot:nth-child(5) { grid-area: 3 / 1; }
.face-6 .dot:nth-child(6) { grid-area: 3 / 3; }

/* Rolling keyframe animation */
.dice-cube.rolling {
  animation: spinDice 0.6s linear;
}

@keyframes spinDice {
  0%   { transform: translateZ(-50px) rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
  100% { transform: translateZ(-50px) rotateX(720deg) rotateY(360deg) rotateZ(180deg); }
}

/* Button & Action styling */
.action-btn {
  background: var(--color-primary);
  border: 3px solid var(--color-dark);
  border-radius: 15px;
  color: var(--color-light);
  padding: 10px 24px;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--color-dark);
  transition: all 0.1s ease;
  width: 100%;
}

.action-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 0 var(--color-dark);
}

.action-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--color-dark);
}

.action-btn.disabled {
  background: #B0BEC5 !important;
  color: #78909C !important;
  box-shadow: 0 4px 0 #78909C !important;
  cursor: not-allowed;
  transform: none !important;
}

.roll-instructions {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  color: #546E7A;
}

/* Players list summary */
.players-card {
  background: var(--color-light);
  border: var(--border-width) solid var(--color-dark);
  border-radius: var(--border-radius);
  box-shadow: var(--card-shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.players-card-title {
  font-weight: 700;
  font-size: 1.2rem;
  border-bottom: 2px dashed #CFD8DC;
  padding-bottom: 8px;
  color: var(--color-dark);
}

.player-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 12px;
  border: 2px solid transparent;
}

.player-list-item.active {
  background: #FFFDE7;
  border-color: var(--color-secondary);
}

.player-item-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}

.player-item-avatar {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 50%;
  border: 2px solid var(--color-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  background-color: var(--color-light);
}

.player-item-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.player-item-position {
  flex: 0 0 auto;
  font-weight: 700;
  background: #ECEFF1;
  padding: 3px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
  border: 1px solid #CFD8DC;
}

/* Sound Button and Controls bar */
.top-controls {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 10px;
}

.sound-toggle {
  background: var(--color-light);
  border: 3px solid var(--color-dark);
  border-radius: 50%;
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--color-dark);
  font-size: 1.4rem;
  transition: all 0.1s ease;
}

.sound-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--color-dark);
}

.sound-toggle:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--color-dark);
}

.home-btn {
  background: var(--color-light);
  border: 3px solid var(--color-dark);
  border-radius: 15px;
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--color-dark);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.1s ease;
}

.home-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--color-dark);
}

.home-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--color-dark);
}

/* Winner Overlay/Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(55, 71, 79, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.winner-modal {
  background: var(--color-light);
  border: var(--border-width) solid var(--color-dark);
  border-radius: var(--border-radius);
  box-shadow: 0 15px 0 var(--color-dark);
  width: 90%;
  max-width: 450px;
  padding: 40px 30px;
  text-align: center;
  transform: scale(0.7) rotate(-5deg);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .winner-modal {
  transform: scale(1) rotate(0deg);
}

.winner-crown {
  font-size: 4rem;
  animation: pulseCrown 1.5s infinite ease-in-out;
  display: inline-block;
  margin-bottom: 10px;
}

@keyframes pulseCrown {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.2) rotate(10deg); }
}

.winner-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 4px solid var(--color-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4.5rem;
  margin: 10px auto 20px;
  background: var(--color-secondary);
  box-shadow: 0 6px 0 rgba(0,0,0,0.15);
}

.winner-modal h2 {
  font-size: 2.2rem;
  color: var(--color-primary);
  margin-bottom: 10px;
  text-shadow: 2px 2px 0px #FFF, 4px 4px 0px var(--color-dark);
}

.winner-modal p {
  font-size: 1.2rem;
  font-weight: 600;
  color: #546E7A;
  margin-bottom: 25px;
}

/* Wiggle animation for snakes path */
@keyframes snakeWiggle {
  0%, 100% { stroke-dashoffset: 0; }
  50% { stroke-dashoffset: 6; }
}

/* Utility visibility classes */
.hidden {
  display: none !important;
}
