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

.hidden {
  display: none !important;
}

/* Prevent zoom on double-click */
html,
body {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  height: 100%;
}

body {
  font-family: "Open Sans", sans-serif;
  font-optical-sizing: auto;
  background: linear-gradient(160deg, #2d2a26 0%, #1f1d1a 40%, #252320 100%);
  min-height: 100vh;
  color: #e8e4df;
  letter-spacing: 0.03em;
  margin: 0;
  padding: 0;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Animated background - warm earth tones */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 15% 85%, rgba(139, 168, 134, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(194, 139, 115, 0.06) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(168, 162, 150, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
}

/* How to Play Screen */
.how-to-play-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.how-to-play-content {
  background: linear-gradient(145deg, rgba(55, 52, 48, 0.5) 0%, rgba(40, 38, 35, 0.7) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 32px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  border: 1px solid rgba(139, 168, 134, 0.12);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 0 60px rgba(139, 168, 134, 0.05),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.how-to-play-content h1 {
  font-size: 1.8rem;
  margin-bottom: 24px;
  color: #a8b5a0;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 20px rgba(168, 181, 160, 0.25);
}

.instructions {
  margin-bottom: 28px;
  text-align: left;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 14px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.instructions h2 {
  font-size: 0.9rem;
  margin-bottom: 16px;
  color: rgba(255, 255, 255, 0.8);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-weight: 600;
}

.instructions ul {
  list-style: none;
  padding: 0;
}

.instructions li {
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.65);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  border-left: 3px solid rgba(139, 168, 134, 0.4);
  transition: all 0.2s ease;
}

.instructions li:hover {
  background: rgba(255, 255, 255, 0.06);
  border-left-color: #8ba886;
}

.difficulty-selection {
  margin-bottom: 28px;
}

.difficulty-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.difficulty-btn {
  padding: 10px 22px;
  border: 1px solid rgba(139, 168, 134, 0.25);
  background: rgba(139, 168, 134, 0.08);
  color: rgba(255, 255, 255, 0.7);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.3s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.difficulty-btn:hover {
  background: rgba(139, 168, 134, 0.15);
  border-color: rgba(139, 168, 134, 0.4);
}

.difficulty-btn.active {
  background: linear-gradient(135deg, #8ba886 0%, #6b8f65 100%);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 20px rgba(107, 143, 101, 0.35);
}

.start-game-btn {
  padding: 14px 48px;
  background: linear-gradient(135deg, #8ba886 0%, #6b8f65 100%);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 24px rgba(107, 143, 101, 0.35);
  outline: none;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.start-game-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 30px rgba(107, 143, 101, 0.45);
}

/* Congratulations Modal */
.congratulations-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
  animation: fadeIn 0.3s ease-out;
}

.congratulations-content {
  background: linear-gradient(145deg, rgba(55, 52, 48, 0.6) 0%, rgba(40, 38, 35, 0.8) 100%);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  padding: 36px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  border: 1px solid rgba(139, 168, 134, 0.15);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  animation: scaleIn 0.4s ease;
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.congratulations-content h1 {
  font-size: 1.4rem;
  margin-bottom: 24px;
  color: #a8b5a0;
  text-shadow: 0 2px 20px rgba(168, 181, 160, 0.3);
}

/* Stats Display */
.stats-display {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-item {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
  padding: 14px 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-label {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
}

.stat-value.combo {
  color: #c28b73;
}

.difficulty-info {
  margin-bottom: 20px;
  padding: 12px;
  background: rgba(139, 168, 134, 0.08);
  border-radius: 10px;
  border: 1px solid rgba(139, 168, 134, 0.15);
}

.difficulty-info p {
  font-size: 0.9rem;
  margin: 0;
  color: #a8b5a0;
}

.play-again-btn {
  padding: 12px 40px;
  background: linear-gradient(135deg, #c28b73 0%, #a67260 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(166, 114, 96, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.play-again-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(166, 114, 96, 0.4);
}

/* Game Container */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  max-width: 500px;
  width: 100%;
  text-align: center;
  margin-inline: auto;
  min-height: 100vh;
  padding: 10px;
  position: relative;
  z-index: 1;
}

.game-info {
  margin-bottom: 10px;
  width: 100%;
  max-width: 400px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: linear-gradient(145deg, rgba(55, 52, 48, 0.4) 0%, rgba(40, 38, 35, 0.6) 100%);
  border-radius: 12px;
  border: 1px solid rgba(139, 168, 134, 0.1);
}

.game-info h1 {
  font-size: 0.95rem;
  margin: 0;
  color: #a8b5a0;
  font-weight: 600;
}

.game-info-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.collision-counters {
  display: flex;
  gap: 12px;
}

/* Mute Button */
.mute-btn {
  background: rgba(139, 168, 134, 0.15);
  border: 1px solid rgba(139, 168, 134, 0.3);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 34px;
}

.mute-btn:hover {
  background: rgba(139, 168, 134, 0.25);
  border-color: rgba(139, 168, 134, 0.5);
}

.mute-btn .sound-on,
.mute-btn .sound-off {
  display: block;
  filter: brightness(1.2);
}

.mute-btn .sound-off.hidden,
.mute-btn .sound-on.hidden {
  display: none;
}

.counter {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.2);
}

.counter-icon {
  font-size: 0.95rem;
}

.snake-counter {
  color: #c28b73;
  border: 1px solid rgba(194, 139, 115, 0.25);
}

.ladder-counter {
  color: #8ba886;
  border: 1px solid rgba(139, 168, 134, 0.25);
}

/* Combo Display */
.combo-display {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  background: linear-gradient(135deg, rgba(194, 139, 115, 0.2) 0%, rgba(166, 114, 96, 0.12) 100%);
  border-radius: 16px;
  border: 1px solid rgba(194, 139, 115, 0.3);
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 100;
}

.combo-display.active {
  opacity: 1;
  animation: comboPulse 0.5s ease-out;
}

@keyframes comboPulse {
  0% { transform: translateX(-50%) scale(0.8); }
  50% { transform: translateX(-50%) scale(1.1); }
  100% { transform: translateX(-50%) scale(1); }
}

.combo-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: #c28b73;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.combo-multiplier {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  margin-left: 6px;
}

/* Game Board */
.game-board {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  width: 100%;
  max-width: 400px;
}

#gameCanvas {
  background: rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(139, 168, 134, 0.12);
  border-radius: 14px;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.3),
    inset 0 0 40px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  flex: 1;
  width: 100%;
  max-width: 400px;
  height: auto;
  min-height: 200px;
  max-height: calc(100vh - 180px);
  outline: none;
}

/* Floating Numbers */
.floating-number {
  position: absolute;
  font-size: 1.4rem;
  font-weight: 800;
  pointer-events: none;
  animation: floatUp 1s ease-out forwards;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  z-index: 1000;
}

.floating-number.positive {
  color: #8ba886;
}

.floating-number.negative {
  color: #d4847a;
}

.floating-number.combo {
  color: #c28b73;
  font-size: 1.1rem;
}

@keyframes floatUp {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateY(-25px) scale(1.15);
  }
  100% {
    opacity: 0;
    transform: translateY(-50px) scale(0.9);
  }
}

/* Screen Flash */
.screen-flash {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0;
}

.screen-flash.snake {
  background: radial-gradient(circle, rgba(194, 139, 115, 0.2) 0%, transparent 65%);
  animation: flashOut 0.3s ease-out;
}

.screen-flash.ladder {
  background: radial-gradient(circle, rgba(139, 168, 134, 0.2) 0%, transparent 65%);
  animation: flashOut 0.3s ease-out;
}

@keyframes flashOut {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* Confetti */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1999;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  opacity: 0;
}

/* Bottom Controls */
.bottom-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-top: 8px;
}

.dice-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 400px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.dice-face {
  width: calc(100% / 6);
  height: 34px;
  background: transparent;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: rgba(255, 255, 255, 0.2);
  cursor: default;
  transition: all 0.25s ease;
  opacity: 0.4;
}

.dice-face.active {
  opacity: 1;
  color: #8ba886;
  background: rgba(139, 168, 134, 0.12);
}

/* Responsive */
@media (max-width: 768px) {
  .game-container {
    padding: 8px;
  }

  .game-info {
    padding: 8px 12px;
  }

  #gameCanvas {
    max-height: calc(100vh - 160px);
  }

  .dice-face {
    height: 30px;
    font-size: 1.4rem;
  }
}

@media (max-width: 375px) {
  .game-info h1 {
    font-size: 0.85rem;
  }

  .counter {
    font-size: 0.75rem;
    padding: 4px 8px;
  }

  #gameCanvas {
    max-height: calc(100vh - 140px);
  }

  .dice-face {
    height: 26px;
    font-size: 1.2rem;
  }

  .difficulty-btn {
    padding: 8px 14px;
    font-size: 0.7rem;
  }

  .start-game-btn {
    padding: 12px 32px;
    font-size: 0.9rem;
  }
}

@media (max-width: 320px) {
  #gameCanvas {
    max-height: calc(100vh - 120px);
  }

  .dice-face {
    height: 22px;
    font-size: 1rem;
  }
}
