/* ============================================
   MABEL STEM - Kid-Friendly STEM Games
   ============================================ */

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

:root {
  --pink: #FF6B9D;
  --purple: #C084FC;
  --blue: #60A5FA;
  --green: #34D399;
  --yellow: #FBBF24;
  --orange: #FB923C;
  --red: #F87171;
  --dark: #1E1B4B;
  --light: #F8FAFC;
  --unicorn-bg: linear-gradient(135deg, #fce4ec, #f3e5f5, #e8eaf6);
  --orca-bg: linear-gradient(135deg, #e0f7fa, #e1f5fe, #e8eaf6);
  --cheetah-bg: linear-gradient(135deg, #fff8e1, #fff3e0, #fce4ec);
  --butterfly-bg: linear-gradient(135deg, #e8f5e9, #f1f8e9, #fffde7);
}

body {
  font-family: 'Fredoka', 'Baloo 2', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================
   SCREENS
   ============================================ */
.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ============================================
   HOME SCREEN
   ============================================ */
#home-screen {
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stars-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.stars-bg::before,
.stars-bg::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  animation: twinkle 3s ease-in-out infinite alternate;
}

.stars-bg::before {
  width: 6px; height: 6px;
  top: 10%; left: 20%;
  animation-delay: 0s;
}

.stars-bg::after {
  width: 4px; height: 4px;
  top: 30%; right: 15%;
  animation-delay: 1.5s;
}

@keyframes twinkle {
  0% { opacity: 0.3; transform: scale(1); }
  100% { opacity: 1; transform: scale(1.5); }
}

.home-header {
  text-align: center;
  margin: 12px 0 20px;
  z-index: 1;
}

.title-bounce {
  font-family: 'Bubblegum Sans', 'Baloo 2', cursive;
  font-size: clamp(2rem, 7vw, 3.5rem);
  font-weight: 800;
  display: inline-flex;
  gap: 2px;
}

.title-letter {
  display: inline-block;
  animation: letterBounce 2s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.1s);
  text-shadow: 3px 3px 0 rgba(0,0,0,0.1);
}

@keyframes letterBounce {
  0%, 100% { transform: translateY(0); }
  25% { transform: translateY(-10px); }
  50% { transform: translateY(0); }
}

.subtitle {
  font-size: clamp(1rem, 3vw, 1.5rem);
  color: rgba(255,255,255,0.9);
  margin-top: 8px;
  font-weight: 500;
}

/* ============================================
   GAME CARDS
   ============================================ */
.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  width: 100%;
  max-width: 460px;
  z-index: 1;
  padding-bottom: 40px;
}

.game-card {
  background: white;
  border: none;
  border-radius: 22px;
  padding: 16px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow:
    0 6px 0 rgba(0,0,0,0.08),
    0 10px 30px rgba(0,0,0,0.12);
  position: relative;
  overflow: hidden;
  text-align: center;
  aspect-ratio: 1;
}

.game-card:hover,
.game-card:focus {
  transform: scale(1.06) translateY(-4px);
  box-shadow:
    0 10px 0 rgba(0,0,0,0.06),
    0 16px 40px rgba(0,0,0,0.2);
  outline: none;
}

.game-card:active {
  transform: scale(0.96) translateY(2px);
  box-shadow:
    0 2px 0 rgba(0,0,0,0.1),
    0 4px 10px rgba(0,0,0,0.15);
}

.unicorn-card { border-bottom: 5px solid var(--pink); }
.orca-card { border-bottom: 5px solid var(--blue); }
.cheetah-card { border-bottom: 5px solid var(--orange); }
.butterfly-card { border-bottom: 5px solid var(--green); }

.unicorn-card::before { content: ''; position: absolute; inset: 0; background: var(--unicorn-bg); opacity: 0.4; }
.orca-card::before { content: ''; position: absolute; inset: 0; background: var(--orca-bg); opacity: 0.4; }
.cheetah-card::before { content: ''; position: absolute; inset: 0; background: var(--cheetah-bg); opacity: 0.4; }
.butterfly-card::before { content: ''; position: absolute; inset: 0; background: var(--butterfly-bg); opacity: 0.4; }

.card-emoji {
  font-size: 2.8rem;
  z-index: 1;
  animation: gentleFloat 3s ease-in-out infinite;
  flex-shrink: 0;
}

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

.card-info {
  z-index: 1;
}

.card-info h2 {
  font-family: 'Bubblegum Sans', 'Baloo 2', cursive;
  font-size: 0.95rem;
  color: var(--dark);
  line-height: 1.2;
}

.card-subject {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 2px 8px;
  border-radius: 20px;
  margin: 4px 0;
}

.unicorn-card .card-subject { background: #fce4ec; color: #c2185b; }
.orca-card .card-subject { background: #e1f5fe; color: #0277bd; }
.cheetah-card .card-subject { background: #fff3e0; color: #e65100; }
.butterfly-card .card-subject { background: #e8f5e9; color: #2e7d32; }

.card-desc {
  font-size: 0.8rem;
  color: #64748B;
  line-height: 1.2;
}

/* ============================================
   GAME SCREEN
   ============================================ */
#game-screen {
  background: white;
  flex-direction: column;
}

.game-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: white;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
}

.back-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--purple);
  background: #F3E8FF;
  border: none;
  border-radius: 16px;
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.back-btn:hover {
  background: #E9D5FF;
  transform: scale(1.05);
}

.back-arrow {
  font-size: 0.9rem;
}

.score-display {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--dark);
  display: flex;
  align-items: center;
  gap: 6px;
  background: #FFFBEB;
  padding: 8px 16px;
  border-radius: 16px;
}

.score-stars {
  font-size: 1.4rem;
}

#game-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: calc(100vh - 70px);
}

/* ============================================
   SHARED GAME STYLES
   ============================================ */
.game-prompt {
  font-family: 'Baloo 2', cursive;
  font-size: clamp(1.3rem, 4vw, 2rem);
  color: var(--dark);
  text-align: center;
  margin-bottom: 20px;
  line-height: 1.3;
}

.game-emoji-big {
  font-size: clamp(3rem, 10vw, 5rem);
  text-align: center;
  margin-bottom: 16px;
  animation: gentleFloat 3s ease-in-out infinite;
}

.game-scene {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Answer Buttons */
.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 500px;
}

.answer-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 600;
  padding: 18px 16px;
  border: 3px solid transparent;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  overflow: hidden;
  color: white;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.15);
}

.answer-btn:hover {
  transform: scale(1.05);
}

.answer-btn:active {
  transform: scale(0.95);
}

.answer-btn.pink-btn { background: var(--pink); }
.answer-btn.purple-btn { background: var(--purple); }
.answer-btn.blue-btn { background: var(--blue); }
.answer-btn.green-btn { background: var(--green); }
.answer-btn.orange-btn { background: var(--orange); }
.answer-btn.yellow-btn { background: var(--yellow); color: var(--dark); text-shadow: none; }

.answer-btn.correct {
  animation: correctPop 0.5s ease;
  border-color: #22C55E;
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.4);
}

.answer-btn.wrong {
  animation: wrongShake 0.5s ease;
  opacity: 0.5;
}

@keyframes correctPop {
  0% { transform: scale(1); }
  30% { transform: scale(1.15); }
  60% { transform: scale(0.95); }
  100% { transform: scale(1.05); }
}

@keyframes wrongShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

/* Stars display area */
.stars-area {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  background: linear-gradient(135deg, #fce4ec, #f3e5f5);
  border-radius: 24px;
  min-height: 100px;
  width: 100%;
  max-width: 500px;
}

.star-item {
  font-size: 2.5rem;
  animation: starAppear 0.4s ease backwards;
}

@keyframes starAppear {
  from { transform: scale(0) rotate(-180deg); opacity: 0; }
  to { transform: scale(1) rotate(0deg); opacity: 1; }
}

/* ============================================
   ORCA SCIENCE GAME
   ============================================ */
.ocean-scene {
  width: 100%;
  max-width: 500px;
  position: relative;
}

.water-tank {
  background: linear-gradient(180deg, #E0F7FA 0%, #4FC3F7 30%, #0288D1 100%);
  border-radius: 20px;
  height: 280px;
  position: relative;
  overflow: hidden;
  border: 4px solid #0277BD;
  margin-bottom: 20px;
}

.water-line {
  position: absolute;
  top: 30%;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(255,255,255,0.5);
  z-index: 2;
}

.water-label-float {
  position: absolute;
  top: 10%;
  right: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #01579B;
  background: rgba(255,255,255,0.7);
  padding: 4px 10px;
  border-radius: 10px;
}

.water-label-sink {
  position: absolute;
  bottom: 10%;
  right: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: white;
  background: rgba(0,0,0,0.2);
  padding: 4px 10px;
  border-radius: 10px;
}

.test-object {
  position: absolute;
  font-size: 3.5rem;
  left: 50%;
  transform: translateX(-50%);
  top: 5%;
  z-index: 5;
  transition: all 1s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
}

.test-object.floating {
  top: 10%;
  animation: bobbing 2s ease-in-out infinite;
}

.test-object.sinking {
  top: 65%;
}

@keyframes bobbing {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-10px); }
}

.sink-float-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.sf-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.3rem;
  font-weight: 600;
  padding: 16px 24px;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  transition: all 0.15s;
  color: white;
}

.sf-btn:hover { transform: scale(1.05); }
.sf-btn:active { transform: scale(0.95); }

.sf-btn.float-btn {
  background: linear-gradient(135deg, #4FC3F7, #29B6F6);
}

.sf-btn.sink-btn {
  background: linear-gradient(135deg, #5C6BC0, #3949AB);
}

.sf-btn.correct { box-shadow: 0 0 20px rgba(34, 197, 94, 0.5); border: 3px solid #22C55E; }
.sf-btn.wrong { opacity: 0.5; }

.fun-fact {
  background: #FFF9C4;
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 1rem;
  color: #5D4037;
  text-align: center;
  margin-top: 12px;
  animation: fadeSlideUp 0.4s ease;
  line-height: 1.4;
}

.fun-fact strong {
  color: #E65100;
}

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

/* ============================================
   CHEETAH ENGLISH GAME
   ============================================ */
.word-scene {
  width: 100%;
  max-width: 500px;
}

.picture-card {
  background: linear-gradient(135deg, #FFF8E1, #FFECB3);
  border-radius: 24px;
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
  border: 3px solid #FFD54F;
}

.picture-emoji {
  font-size: 5rem;
  margin-bottom: 8px;
}

.letter-hint {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--dark);
  letter-spacing: 6px;
  font-family: 'Baloo 2', cursive;
}

.letter-blank {
  color: var(--orange);
}

/* ============================================
   BUTTERFLY CODE GAME
   ============================================ */
.code-scene {
  width: 100%;
  max-width: 600px;
}

.code-garden {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: #E8F5E9;
  border-radius: 20px;
  padding: 12px;
  margin-bottom: 16px;
  aspect-ratio: 1;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

.garden-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  background: #C8E6C9;
  border-radius: 10px;
  position: relative;
}

.garden-cell.path {
  background: #A5D6A7;
}

.garden-cell.butterfly-here {
  background: #81C784;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(129, 199, 132, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(129, 199, 132, 0); }
}

.code-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

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

.arrow-btn {
  font-size: 1.8rem;
  width: 60px;
  height: 60px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  background: var(--green);
  box-shadow: 0 4px 0 #16A34A;
}

.arrow-btn:hover { transform: translateY(-2px); }
.arrow-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #16A34A; }

.code-queue {
  display: flex;
  gap: 6px;
  padding: 10px 16px;
  background: #F1F8E9;
  border-radius: 14px;
  min-height: 50px;
  flex-wrap: wrap;
  justify-content: center;
  min-width: 200px;
}

.code-step {
  font-size: 1.5rem;
  background: white;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 2px solid #A5D6A7;
  animation: starAppear 0.3s ease backwards;
}

.code-action-btns {
  display: flex;
  gap: 10px;
}

.run-btn, .clear-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 12px 24px;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.15s;
  color: white;
}

.run-btn {
  background: linear-gradient(135deg, #66BB6A, #43A047);
  box-shadow: 0 4px 0 #2E7D32;
}

.run-btn:hover { transform: translateY(-2px); }
.run-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #2E7D32; }

.clear-btn {
  background: linear-gradient(135deg, #EF5350, #E53935);
  box-shadow: 0 4px 0 #C62828;
}

.clear-btn:hover { transform: translateY(-2px); }
.clear-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #C62828; }

.move-counter {
  font-size: 0.95rem;
  color: #558B2F;
  font-weight: 600;
}

/* ============================================
   CELEBRATION OVERLAY
   ============================================ */
.celebration {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
  animation: fadeIn 0.3s ease;
}

.celebration.hidden {
  display: none;
}

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

.celebration-content {
  background: white;
  border-radius: 30px;
  padding: 40px;
  text-align: center;
  z-index: 2;
  animation: celebrationPop 0.5s ease;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

@keyframes celebrationPop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); }
  100% { transform: scale(1); opacity: 1; }
}

.celebration-emoji {
  font-size: 5rem;
  margin-bottom: 12px;
  animation: celebrationSpin 1s ease;
}

@keyframes celebrationSpin {
  0% { transform: rotate(0deg) scale(0); }
  50% { transform: rotate(180deg) scale(1.3); }
  100% { transform: rotate(360deg) scale(1); }
}

.celebration h2 {
  font-family: 'Baloo 2', cursive;
  font-size: 2rem;
  color: var(--dark);
  margin-bottom: 20px;
}

.play-again-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 1.2rem;
  font-weight: 600;
  padding: 14px 32px;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 15px rgba(192, 132, 252, 0.4);
}

.play-again-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(192, 132, 252, 0.5);
}

.go-home-btn {
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 10px 24px;
  background: transparent;
  color: #64748B;
  border: 2px solid #E2E8F0;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 12px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.go-home-btn:hover {
  background: #F1F5F9;
  border-color: #CBD5E1;
}

/* Music toggle */
.music-toggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 500;
  font-size: 1.8rem;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.9);
  box-shadow: 0 4px 15px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.music-toggle:hover {
  transform: scale(1.1);
}

.music-toggle.muted {
  opacity: 0.5;
}

/* Confetti */
.confetti-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 600px) {
  .game-grid {
    grid-template-columns: repeat(2, 1fr);
    max-width: 340px;
    gap: 12px;
  }

  .game-card {
    padding: 12px 8px 10px;
  }

  .card-emoji {
    font-size: 2.8rem;
  }

  .code-garden {
    max-width: 260px;
  }

  .arrow-btn {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
  }

  .answer-grid {
    gap: 10px;
  }

  .answer-btn {
    padding: 14px 12px;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.game-card:focus-visible,
.answer-btn:focus-visible,
.sf-btn:focus-visible,
.arrow-btn:focus-visible,
.run-btn:focus-visible,
.clear-btn:focus-visible {
  outline: 3px solid var(--purple);
  outline-offset: 3px;
}
