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

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

:root {
  --purple: #7c3aed;
  --purple-dark: #4c1d95;
  --pink: #ec4899;
  --yellow: #fbbf24;
  --green: #10b981;
  --blue: #3b82f6;
  --red: #ef4444;
  --orange: #f97316;
  --dark: #0f0a1e;
  --dark2: #1a1035;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--dark);
  color: #fff;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== STAR BACKGROUND ===== */
#stars-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ===== HEADER ===== */
header {
  background: linear-gradient(160deg, var(--purple-dark) 0%, #2d1b69 50%, #1e1b4b 100%);
  padding: 70px 20px 50px;
  text-align: center;
  position: relative;
  z-index: 1;
  border-bottom: 3px solid rgba(124,58,237,0.4);
  overflow: hidden;
}

header::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 0; right: 0;
  height: 60px;
  background: linear-gradient(180deg, transparent, var(--dark));
}

.logo {
  font-family: 'Fredoka One', cursive;
  font-size: 4rem;
  color: var(--yellow);
  text-shadow: 3px 3px 0 #92400e, 0 0 40px rgba(251,191,36,0.5);
  animation: floatY 3s ease-in-out infinite;
  display: inline-block;
  margin-bottom: 10px;
}

.tagline {
  font-size: 1.25rem;
  color: rgba(255,255,255,0.85);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.header-badges {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.header-badge {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 30px;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
}

/* ===== SECTIONS ===== */
section {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 60px 24px;
}

section h2 {
  font-family: 'Fredoka One', cursive;
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 12px;
  color: var(--yellow);
  text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}

.section-subtitle {
  text-align: center;
  color: rgba(255,255,255,0.65);
  font-size: 1rem;
  margin-bottom: 48px;
}

/* ===== GAME CARDS ===== */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 24px;
}

.game-card {
  border-radius: 24px;
  padding: 32px 20px 24px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), box-shadow 0.3s;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 2px solid transparent;
  text-decoration: none;
  color: #fff;
}

.game-card:nth-child(1) { background: linear-gradient(145deg, #1a1035, #2d1b69); border-color: rgba(124,58,237,0.6); }
.game-card:nth-child(2) { background: linear-gradient(145deg, #0c1a2e, #0d3260); border-color: rgba(59,130,246,0.6); }
.game-card:nth-child(3) { background: linear-gradient(145deg, #0a2018, #0d4a2d); border-color: rgba(16,185,129,0.6); }
.game-card:nth-child(4) { background: linear-gradient(145deg, #2a1008, #7c2d12); border-color: rgba(249,115,22,0.6); }
.game-card:nth-child(5) { background: linear-gradient(145deg, #25082a, #701a75); border-color: rgba(236,72,153,0.6); }

.game-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 0%, rgba(255,255,255,0.08), transparent 70%);
  pointer-events: none;
}

.game-card:hover {
  transform: translateY(-10px) scale(1.03);
  box-shadow: 0 24px 48px rgba(0,0,0,0.5);
}

.game-card:hover.game-card:nth-child(1) { box-shadow: 0 24px 48px rgba(124,58,237,0.3); }
.game-card:hover.game-card:nth-child(2) { box-shadow: 0 24px 48px rgba(59,130,246,0.3); }
.game-card:hover.game-card:nth-child(3) { box-shadow: 0 24px 48px rgba(16,185,129,0.3); }
.game-card:hover.game-card:nth-child(4) { box-shadow: 0 24px 48px rgba(249,115,22,0.3); }
.game-card:hover.game-card:nth-child(5) { box-shadow: 0 24px 48px rgba(236,72,153,0.3); }

.game-icon {
  font-size: 64px;
  margin-bottom: 14px;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.game-card:nth-child(1) .game-icon { animation: floatY 2.8s ease-in-out infinite; }
.game-card:nth-child(2) .game-icon { animation: floatY 3.2s ease-in-out infinite 0.4s; }
.game-card:nth-child(3) .game-icon { animation: floatY 3.0s ease-in-out infinite 0.8s; }
.game-card:nth-child(4) .game-icon { animation: floatY 2.6s ease-in-out infinite 0.2s; }
.game-card:nth-child(5) .game-icon { animation: floatY 3.4s ease-in-out infinite 0.6s; }

.game-card h3 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.game-card p {
  font-size: 0.88rem;
  color: rgba(255,255,255,0.75);
  line-height: 1.5;
  margin-bottom: 16px;
  flex: 1;
}

.subjects {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge.math { background: #fbbf24; color: #78350f; }
.badge.spelling { background: #34d399; color: #064e3b; }

.age-range {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.5);
  margin-bottom: 20px;
}

.play-btn {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  color: #1a1a1a;
  border: none;
  padding: 11px 28px;
  border-radius: 30px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 15px rgba(251,191,36,0.35);
  width: 100%;
}

.play-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 24px rgba(251,191,36,0.55);
}

/* ===== FEATURES BAR ===== */
.features-bar {
  background: linear-gradient(135deg, rgba(124,58,237,0.15), rgba(59,130,246,0.15));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 32px 40px;
  display: flex;
  gap: 32px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 0;
}

.feature {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
}

.feature span:first-child { font-size: 1.8rem; }

/* ===== FAQ ===== */
#faq { padding-top: 20px; }

.faq-list {
  max-width: 800px;
  margin: 0 auto;
}

.faq-item {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  margin-bottom: 14px;
  overflow: hidden;
  transition: border-color 0.3s;
}

.faq-item:hover { border-color: rgba(124,58,237,0.4); }
.faq-item.open { border-color: rgba(124,58,237,0.6); }

.faq-question {
  padding: 20px 24px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1rem;
  user-select: none;
  color: #fff;
}

.faq-icon {
  width: 28px; height: 28px;
  background: rgba(124,58,237,0.3);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: transform 0.3s, background 0.3s;
  flex-shrink: 0;
  margin-left: 16px;
}

.faq-item.open .faq-icon {
  transform: rotate(45deg);
  background: rgba(124,58,237,0.6);
}

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, padding 0.3s;
  padding: 0 24px;
  color: rgba(255,255,255,0.75);
  line-height: 1.75;
  font-size: 0.95rem;
}

.faq-item.open .faq-answer {
  max-height: 400px;
  padding: 0 24px 20px;
}

/* ===== FOOTER ===== */
footer {
  text-align: center;
  padding: 40px 20px;
  color: rgba(255,255,255,0.3);
  font-size: 0.88rem;
  border-top: 1px solid rgba(255,255,255,0.05);
  position: relative;
  z-index: 1;
}

footer a { color: var(--yellow); text-decoration: none; }

/* ===== SHARED GAME PAGE STYLES ===== */
.game-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
}

.game-topbar {
  width: 100%;
  background: rgba(15,10,30,0.9);
  border-bottom: 2px solid rgba(124,58,237,0.3);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.back-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 8px 16px;
  border-radius: 10px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.back-btn:hover { background: rgba(255,255,255,0.18); }

.game-title-bar {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  color: var(--yellow);
}

.hud {
  display: flex;
  gap: 20px;
  margin-left: auto;
  align-items: center;
}

.hud-item {
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-item.score { color: var(--yellow); }
.hud-item.lives { color: #ff6b6b; }
.hud-item.streak { color: #34d399; }

/* ===== SETUP OVERLAY ===== */
.setup-overlay, .question-overlay, .gameover-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,5,25,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(6px);
  padding: 20px;
}

.setup-box, .question-box, .gameover-box {
  background: linear-gradient(145deg, #1a1035, #2d1b69);
  border: 2px solid rgba(124,58,237,0.5);
  border-radius: 28px;
  padding: 40px;
  max-width: 540px;
  width: 100%;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  position: relative;
}

.setup-box h2, .gameover-box h2 {
  font-family: 'Fredoka One', cursive;
  font-size: 2.2rem;
  color: var(--yellow);
  margin-bottom: 8px;
}

.setup-box p, .gameover-box p {
  color: rgba(255,255,255,0.7);
  margin-bottom: 28px;
  font-size: 0.95rem;
}

.option-label {
  font-weight: 800;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.5);
  margin-bottom: 10px;
  text-align: left;
}

.level-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 24px;
}

.level-btn {
  flex: 1;
  min-width: 90px;
  padding: 12px 8px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-family: 'Fredoka One', cursive;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.level-btn:hover, .level-btn.selected {
  background: var(--purple);
  border-color: var(--purple);
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(124,58,237,0.5);
}

.subject-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 28px;
}

.subject-btn {
  flex: 1;
  min-width: 110px;
  padding: 11px 8px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-family: 'Fredoka One', cursive;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}

.subject-btn:hover, .subject-btn.selected {
  border-color: var(--yellow);
  background: rgba(251,191,36,0.15);
  box-shadow: 0 4px 16px rgba(251,191,36,0.3);
}

.start-btn, .restart-btn {
  background: linear-gradient(135deg, var(--yellow), var(--orange));
  color: #1a1a1a;
  border: none;
  padding: 16px 40px;
  border-radius: 30px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 6px 20px rgba(251,191,36,0.4);
  width: 100%;
  margin-top: 8px;
}

.start-btn:hover, .restart-btn:hover {
  transform: scale(1.04);
  box-shadow: 0 10px 30px rgba(251,191,36,0.55);
}

/* ===== QUESTION OVERLAY ===== */
.question-box {
  max-width: 480px;
}

.question-label {
  font-family: 'Fredoka One', cursive;
  font-size: 1.2rem;
  color: var(--yellow);
  margin-bottom: 8px;
  animation: pulse 1s ease-in-out infinite;
}

.question-text {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  color: #fff;
  margin-bottom: 28px;
  line-height: 1.3;
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.answer-btn {
  padding: 18px 12px;
  border-radius: 16px;
  border: 2px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.07);
  color: #fff;
  font-family: 'Fredoka One', cursive;
  font-size: 1.15rem;
  cursor: pointer;
  transition: all 0.2s;
}

.answer-btn:hover { background: rgba(255,255,255,0.15); transform: scale(1.03); }
.answer-btn.correct { background: rgba(16,185,129,0.35); border-color: #10b981; color: #34d399; }
.answer-btn.wrong { background: rgba(239,68,68,0.35); border-color: #ef4444; color: #fc8181; }

.question-timer {
  position: absolute;
  top: 16px; right: 20px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  color: var(--yellow);
}

/* ===== CANVAS WRAPPER ===== */
.canvas-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 16px;
}

canvas {
  border-radius: 16px;
  box-shadow: 0 0 60px rgba(0,0,0,0.6);
  max-width: 100%;
  display: block;
}

/* ===== ANIMATIONS ===== */
@keyframes floatY {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

@keyframes popIn {
  0% { transform: scale(0.5); opacity: 0; }
  80% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.pop-in { animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1); }
.shake { animation: shake 0.3s ease; }

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  .logo { font-size: 2.5rem; }
  section h2 { font-size: 1.8rem; }
  .games-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .game-card { padding: 20px 14px 18px; }
  .game-icon { font-size: 44px; }
  .hud { gap: 8px; }
  .hud-item { padding: 4px 10px; font-size: 0.82rem; }
  .features-bar { flex-direction: column; align-items: center; gap: 16px; }
  .game-topbar { flex-wrap: wrap; }
  .answer-grid { grid-template-columns: 1fr 1fr; }
  .setup-box, .question-box { padding: 28px 20px; }
}

@media (max-width: 400px) {
  .games-grid { grid-template-columns: 1fr; }
}
