/* NumberBlocks Game - Kid-Friendly Styles */

@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@700;900&display=swap');

:root {
  --bg-gradient-start: #1a0533;
  --bg-gradient-mid: #2d1b4e;
  --bg-gradient-end: #0f2847;
  --game-bg: rgba(20, 10, 40, 0.85);
  --button-glow: #ff66aa;
  --star-color: #ffe066;
  --one-color: #ff4444;
  --two-color: #ff9933;
  --three-color: #ffee44;
  --four-color: #44dd44;
  --five-color: #44bbff;
  --six-color: #9966ff;
  --seven-rainbow: linear-gradient(180deg, #ff4444, #ff9933, #ffee44, #44dd44, #44bbff, #4466ff, #9944ff);
  --eight-color: #ff66bb;
  --nine-color: #778899;
  --ten-color: #ffffff;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: 'Fredoka One', 'Nunito', sans-serif;
  background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 50%, var(--bg-gradient-end) 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Animated starfield background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(2px 2px at 20px 30px, white, transparent),
    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.8), transparent),
    radial-gradient(3px 3px at 50px 160px, rgba(255,230,100,0.9), transparent),
    radial-gradient(2px 2px at 90px 40px, white, transparent),
    radial-gradient(2px 2px at 130px 80px, rgba(255,255,255,0.7), transparent),
    radial-gradient(3px 3px at 160px 120px, rgba(255,200,100,0.8), transparent);
  background-repeat: repeat;
  background-size: 200px 200px;
  animation: twinkle 4s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}

@keyframes twinkle {
  0% { opacity: 0.5; }
  100% { opacity: 1; }
}

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

/* Top Bar with Score and Exit */
#top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 15px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 20px;
  margin-bottom: 10px;
}

#score-display {
  font-size: 28px;
  color: var(--star-color);
  text-shadow: 0 0 10px rgba(255, 224, 102, 0.7);
  display: flex;
  align-items: center;
  gap: 10px;
}

#score-display .star {
  font-size: 32px;
  animation: pulse 1.5s ease-in-out infinite;
}

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

/* Parent Exit Button - small and subtle */
#exit-btn {
  background: rgba(100, 100, 100, 0.5);
  border: 2px solid rgba(150, 150, 150, 0.5);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  color: rgba(200, 200, 200, 0.7);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#exit-btn:hover {
  background: rgba(150, 50, 50, 0.8);
  color: white;
}

/* Fullscreen Button */
#fullscreen-btn {
  background: linear-gradient(145deg, #6644aa, #4422aa);
  border: 3px solid #9966ff;
  border-radius: 50%;
  width: 45px;
  height: 45px;
  color: white;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 4px 15px rgba(102, 68, 170, 0.5);
}

#fullscreen-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(102, 68, 170, 0.7);
}

/* Game Board */
#game-board {
  width: 100%;
  aspect-ratio: 8/12;
  max-height: calc(100vh - 280px);
  background: var(--game-bg);
  border-radius: 20px;
  border: 4px solid rgba(150, 100, 200, 0.5);
  box-shadow: 
    0 0 30px rgba(150, 100, 200, 0.3),
    inset 0 0 60px rgba(0, 0, 0, 0.5);
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(12, 1fr);
  gap: 2px;
  padding: 5px;
}

/* Grid cells */
.cell {
  background: rgba(50, 30, 80, 0.4);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* NumberBlock in cell */
.numberblock {
  width: 90%;
  height: 90%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: blockAppear 0.3s ease-out;
  position: relative;
}

.numberblock img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@keyframes blockAppear {
  0% { transform: scale(0) rotate(-10deg); opacity: 0; }
  70% { transform: scale(1.1) rotate(5deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* Active falling block highlight */
.numberblock.active {
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  animation: glow 0.8s ease-in-out infinite alternate;
}

@keyframes glow {
  0% { filter: brightness(1); }
  100% { filter: brightness(1.3); }
}

/* Combining animation */
.numberblock.combining {
  animation: combine 0.5s ease-in-out;
}

@keyframes combine {
  0% { transform: scale(1); }
  30% { transform: scale(1.3); }
  60% { transform: scale(0.8); }
  100% { transform: scale(1); }
}

/* Celebration effect */
.celebration {
  position: absolute;
  pointer-events: none;
  font-size: 40px;
  animation: celebrationFloat 1s ease-out forwards;
  z-index: 100;
}

@keyframes celebrationFloat {
  0% { transform: scale(0) translateY(0); opacity: 1; }
  50% { transform: scale(1.5) translateY(-20px); opacity: 1; }
  100% { transform: scale(1) translateY(-60px); opacity: 0; }
}

/* Next Block Preview */
#next-preview {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 15px;
  padding: 10px;
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 15px;
}

#next-preview-label {
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
}

#next-block {
  width: 60px;
  height: 60px;
  background: rgba(50, 30, 80, 0.6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(150, 100, 200, 0.5);
}

#next-block img {
  width: 80%;
  height: 80%;
  object-fit: contain;
}

/* Control Buttons */
#controls {
  display: flex;
  justify-content: center;
  gap: 30px;
  width: 100%;
  padding: 20px;
  margin-top: auto;
}

.control-btn {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: none;
  font-size: 50px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.control-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.3s, height 0.3s;
}

.control-btn:active::before {
  width: 150%;
  height: 150%;
}

#left-btn {
  background: linear-gradient(145deg, #ff7799, #ff4477);
  box-shadow: 
    0 8px 0 #cc2255,
    0 12px 20px rgba(255, 68, 119, 0.4);
  color: white;
}

#left-btn:active {
  transform: translateY(4px);
  box-shadow: 
    0 4px 0 #cc2255,
    0 6px 10px rgba(255, 68, 119, 0.4);
}

#right-btn {
  background: linear-gradient(145deg, #66ddff, #44aaff);
  box-shadow: 
    0 8px 0 #2288dd,
    0 12px 20px rgba(68, 170, 255, 0.4);
  color: white;
}

#right-btn:active {
  transform: translateY(4px);
  box-shadow: 
    0 4px 0 #2288dd,
    0 6px 10px rgba(68, 170, 255, 0.4);
}

/* Start Screen */
#start-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-mid), var(--bg-gradient-end));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 30px;
}

#start-screen h1 {
  font-size: clamp(36px, 10vw, 72px);
  background: linear-gradient(45deg, #ff4444, #ff9933, #ffee44, #44dd44, #44bbff, #9966ff, #ff66bb);
  background-size: 300% 300%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: rainbowText 5s ease infinite;
  text-shadow: none;
  text-align: center;
}

@keyframes rainbowText {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

#character-parade {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 90%;
}

#character-parade img {
  width: 50px;
  height: 60px;
  object-fit: contain;
  animation: bounce 1s ease-in-out infinite;
}

#character-parade img:nth-child(1) { animation-delay: 0s; }
#character-parade img:nth-child(2) { animation-delay: 0.1s; }
#character-parade img:nth-child(3) { animation-delay: 0.2s; }
#character-parade img:nth-child(4) { animation-delay: 0.3s; }
#character-parade img:nth-child(5) { animation-delay: 0.4s; }
#character-parade img:nth-child(6) { animation-delay: 0.5s; }
#character-parade img:nth-child(7) { animation-delay: 0.6s; }
#character-parade img:nth-child(8) { animation-delay: 0.7s; }
#character-parade img:nth-child(9) { animation-delay: 0.8s; }
#character-parade img:nth-child(10) { animation-delay: 0.9s; }

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

#play-btn {
  padding: 25px 80px;
  font-size: 36px;
  font-family: 'Fredoka One', sans-serif;
  background: linear-gradient(145deg, #44dd44, #22aa22);
  border: none;
  border-radius: 50px;
  color: white;
  cursor: pointer;
  box-shadow: 
    0 8px 0 #117711,
    0 15px 30px rgba(34, 170, 34, 0.4);
  transition: all 0.2s;
  animation: playPulse 2s ease-in-out infinite;
}

@keyframes playPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

#play-btn:hover {
  background: linear-gradient(145deg, #55ee55, #33bb33);
}

#play-btn:active {
  transform: translateY(4px) scale(1);
  box-shadow: 
    0 4px 0 #117711,
    0 8px 15px rgba(34, 170, 34, 0.4);
}

/* Game Over Screen */
#game-over {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 20px;
}

#game-over.show {
  display: flex;
  animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#game-over h2 {
  font-size: 48px;
  color: var(--star-color);
  text-shadow: 0 0 20px rgba(255, 224, 102, 0.5);
}

#final-score {
  font-size: 36px;
  color: white;
}

#final-score span {
  color: var(--star-color);
  font-size: 48px;
}

/* Hidden class */
.hidden {
  display: none !important;
}

/* Mobile optimizations */
@media (max-width: 600px) {
  #game-container {
    padding: 5px;
  }
  
  .control-btn {
    width: 100px;
    height: 100px;
    font-size: 40px;
  }
  
  #controls {
    gap: 20px;
    padding: 15px;
  }
  
  #score-display {
    font-size: 22px;
  }
}

@media (max-height: 700px) {
  .control-btn {
    width: 80px;
    height: 80px;
    font-size: 35px;
  }
  
  #next-preview {
    padding: 5px;
    margin: 5px 0;
  }
  
  #next-block {
    width: 45px;
    height: 45px;
  }
}

/* Level indicator */
#level-display {
  color: rgba(255, 255, 255, 0.8);
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#level-display .level-icon {
  font-size: 22px;
}

/* Combo indicator */
#combo-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 60px;
  color: var(--star-color);
  text-shadow: 0 0 30px rgba(255, 224, 102, 0.8);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
}

#combo-display.show {
  animation: comboShow 1s ease-out forwards;
}

@keyframes comboShow {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1.3); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1) translateY(-50px); }
}

/* Sound toggle */
#sound-btn {
  background: rgba(100, 100, 100, 0.5);
  border: 2px solid rgba(150, 150, 150, 0.5);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  color: rgba(200, 200, 200, 0.9);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}

#sound-btn:hover, #music-btn:hover {
  background: rgba(100, 150, 100, 0.6);
}

#sound-btn.muted, #music-btn.muted {
  color: rgba(200, 100, 100, 0.9);
  text-decoration: line-through;
}

/* Music button */
#music-btn {
  background: rgba(100, 100, 100, 0.5);
  border: 2px solid rgba(150, 150, 150, 0.5);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  color: rgba(200, 200, 200, 0.9);
  font-size: 20px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
}
