:root {
  --primary-color: #8A2BE2;
  --success-color: #00FF99;
  --error-color: #FF4081;
  --background-color: #1a1a2e;
}

body {
  font-family: 'Nunito', 'Comic Sans MS', sans-serif;
  text-align: center;
  background: linear-gradient(45deg, #1a1a2e, #2a1b3d, #1a1a2e);
  background-size: 400% 400%;
  animation: galaxyShift 15s ease infinite;
  color: white;
  padding: 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 3px),
    radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 2px);
  background-size: 50px 50px, 30px 30px;
  background-position: 0 0, 25px 25px;
  animation: twinkle 4s ease-in-out infinite alternate;
  z-index: -1;
}

h1 {
  color: transparent;
  background: linear-gradient(90deg, #FF9AA2, #FFB7B2, #FFDAC1, #E2F0CB, #B5EAD7, #C7CEEA);
  -webkit-background-clip: text;
  background-clip: text;
  font-size: clamp(1.8rem, 5vw, 3rem);
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
  margin-bottom: 30px;
  padding: 0 10px;
  text-align: center;
}

h1::before {
  content: '🚀';
  margin-right: 10px;
}

h1::after {
  content: '✨';
  margin-left: 10px;
}
  
  .grid {
    width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    grid-gap: 1px;
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px;
    border-radius: 8px;
    overflow-x: auto;
  }

  /* Animations */
  @keyframes galaxyShift {
    0% { background-position: 0% 50% }
    50% { background-position: 100% 50% }
    100% { background-position: 0% 50% }
  }

  @keyframes twinkle {
    from { opacity: 0.5; }
    to { opacity: 1; }
  }

  @keyframes rainbow {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
  }

  /* Floating emojis */
  .floating-emoji {
    position: fixed;
    font-size: 1.2rem; /* smaller size */
    opacity: 0.5; /* make them more subtle */
    pointer-events: none;
    animation: float 8s ease-in-out infinite; /* slower animation */
  }

  .floating-emoji:nth-child(1) { top: 10%; left: 10%; animation-delay: 0s; }
  .floating-emoji:nth-child(2) { top: 20%; right: 10%; animation-delay: -2s; }
  .floating-emoji:nth-child(3) { bottom: 10%; left: 20%; animation-delay: -4s; }

  @keyframes float {
    0% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-10px) rotate(5deg); }
    50% { transform: translateY(-20px) rotate(10deg); }
    75% { transform: translateY(-10px) rotate(5deg); }
    100% { transform: translateY(0) rotate(0deg); }
  }
  
  .grid div {
    width: 100%;
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-weight: bold;
    font-size: clamp(0.6rem, 1.2vw, 0.9rem);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
  }

  .grid div:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.2);
  }
  
  .quiz-container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 20px rgba(138, 43, 226, 0.4);
    color: white;
    padding: clamp(0.8rem, 2vw, 2rem);
    border-radius: 15px;
    width: min(90vw, 400px);
    margin: 1rem auto;
    box-sizing: border-box;
  }

  .quiz-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
  }

  @media (max-width: 480px) {
    .quiz-container {
      width: 85vw;
      padding: 0.8rem;
    }

    .quiz-question {
      font-size: 1.1rem;
    }

    .quiz-form {
      gap: 5px;
    }

    #quizAnswer {
      width: 80px;
      padding: 8px;
    }

    #submitAnswer {
      padding: 8px 15px;
      font-size: 1rem;
    }

    .grid {
      grid-gap: 1px;
      padding: 5px;
    }
    
    .grid div {
      border-radius: 4px;
    }
  }

  .quiz-question::before {
    content: '🤔';
    margin-right: 10px;
  }
  
  .quiz-question {
    font-size: 1.2rem;
    margin-bottom: 10px;
  }
  
  #quizAnswer {
    width: 100px;
    padding: 10px;
    border: 2px solid #eee;
    border-radius: 8px;
    font-size: 1.2rem;
    text-align: center;
    transition: border-color 0.3s;
  }
  
  #quizAnswer:focus {
    border-color: var(--primary-color);
    outline: none;
  }
  
  #submitAnswer {
    margin-left: 10px;
    background: linear-gradient(45deg, #8A2BE2, #9400D3);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 0 10px rgba(138, 43, 226, 0.4);
  }
  
  #submitAnswer:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 0 15px rgba(138, 43, 226, 0.6);
  }
  
  .feedback {
    font-size: 1.4rem;
    height: 2em;
    margin-bottom: 20px;
    transition: all 0.3s ease;
    text-shadow: 0 0 5px rgba(255,255,255,0.5);
  }

  .feedback.correct::before {
    content: '🎉 ';
  }

  .feedback.wrong::before {
    content: '💫 ';
  }
  
  .correct {
    color: green;
    animation: pop 0.4s ease forwards;
  }
  
  .wrong {
    color: red;
    animation: shake 0.4s ease forwards;
  }
  
  /* Color levels for mastery */
  .level-0 { background: rgba(255, 255, 255, 0.15) !important; /* White/transparent for unanswered */ }
  .level-1 { background: rgba(138, 43, 226, 0.2) !important; /* Light purple */ }
  .level-2 { background: rgba(138, 43, 226, 0.4) !important; /* Medium purple */ }
  .level-3 { background: rgba(138, 43, 226, 0.6) !important; /* Stronger purple */ }
  .level-4 { background: rgba(138, 43, 226, 0.8) !important; /* Deep purple */ }
  
  @keyframes pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.25); }
    80% { transform: scale(0.95); }
    100% { transform: scale(1); }
  }
  
  @keyframes shake {
    0% { transform: translateX(0); }
    20% { transform: translateX(-8px) rotate(-2deg); }
    40% { transform: translateX(8px) rotate(2deg); }
    60% { transform: translateX(-4px) rotate(-1deg); }
    80% { transform: translateX(4px) rotate(1deg); }
    100% { transform: translateX(0); }
  }

  @media (max-width: 768px) {
    .floating-emoji {
      font-size: 1.5rem;
    }
  }
  
  @media (max-width: 480px) {
    .floating-emoji:nth-child(3) {
      display: none;
    }
  }

  .number-pad {
    display: grid; /* Always show number pad */
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    width: min(95vw, 300px);
    margin: 20px auto;
  }

  /* Grid toggle button styles */
  .grid-toggle {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.1rem;
    margin-bottom: 0;
    transition: all 0.2s;
  }

  .header-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
  }

  .grid-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
  }

  .grid-icon {
    font-size: 1.2em;
    vertical-align: middle;
  }

  .num-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 15px;
    font-size: 1.2rem;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.1s ease;
  }

  .num-btn.pressed {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
  }

  .num-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
  }

  .num-btn.clear {
    color: #FF4081;
  }

  .num-btn.delete {
    color: #FFD600;
  }

  /* Grid container styles */
  .grid-container {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    padding: 20px;
    box-sizing: border-box;
    overflow: auto;
  }

  .grid-container.visible {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  /* Close button for grid */
  .close-grid {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 10px;
  }

  .close-grid:hover {
    transform: scale(1.1);
  }

  /* Highlight current question */
  .grid div.current-question {
    animation: pulse 1.5s infinite;
    box-shadow: 0 0 15px var(--primary-color);
    transform: scale(1.1);
  }

  @keyframes pulse {
    0% { box-shadow: 0 0 15px var(--primary-color); }
    50% { box-shadow: 0 0 25px var(--primary-color); }
    100% { box-shadow: 0 0 15px var(--primary-color); }
  }

  .streak-container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 10px 20px;
    border-radius: 15px;
    margin: 0;
    font-size: 1.2rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
  }

  /* Make buttons more compact on mobile */
  @media (max-width: 480px) {
    .header-controls {
      gap: 10px;
    }
    
    .grid-toggle, .streak-container {
      padding: 8px 15px;
      font-size: 1rem;
    }
  }

  .streak-count {
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.5);
  }

  .streak-flame {
    animation: flicker 1s ease-in-out infinite alternate;
  }

  @keyframes flicker {
    0% { opacity: 0.8; transform: scale(0.95); }
    100% { opacity: 1; transform: scale(1.05); }
  }

  /* Rocket progress */
  .rocket-container {
    position: fixed;
    left: 0;
    bottom: 30px; /* give it some space from bottom */
    width: 80vw; /* horizontal space to move */
    height: 60px; /* container height */
    pointer-events: none;
    z-index: 99; /* ensure it stays below interactive elements */
}

.rocket {
    position: absolute;
    left: 0;
    font-size: 3.5rem;
    transition: left 1s ease;
    filter: drop-shadow(0 0 10px rgba(255,255,255,0.3));
    transform: rotate(45deg); /* adjust from default NE to point right */
}

@keyframes rocketShake {
    0% { transform: rotate(42deg) translateX(2px); }
    50% { transform: rotate(48deg) translateX(-2px); }
    100% { transform: rotate(42deg) translateX(2px); }
}

.rocket.flying {
    animation: rocketShake 0.5s infinite;
}
  
