:root {
  --bg-gradient-dark: linear-gradient(135deg, #0f0c1b 0%, #1a103c 40%, #2b0b3a 70%, #0d1b2a 100%);
  --bg-gradient-light: linear-gradient(135deg, #f0f4ff 0%, #e6eeff 40%, #f5e6ff 70%, #edf2f7 100%);
  --card-bg-dark: #ffffff0d;
  --card-bg-light: #ffffffbf;
  --card-border-dark: #ffffff1f;
  --card-border-light: #fff9;
  --text-primary-dark: #f8fafc;
  --text-secondary-dark: #cbd5e1;
  --text-primary-light: #1e293b;
  --text-secondary-light: #475569;
  --primary-accent: #8b5cf6;
  --primary-gradient: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
  --secondary-gradient: linear-gradient(135deg, #ec4899 0%, #f43f5e 100%);
  --gold-gradient: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  --emerald-gradient: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --cyan-gradient: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  --shadow-sm: 0 4px 6px -1px #0000001a, 0 2px 4px -1px #0000000f;
  --shadow-lg: 0 10px 25px -5px #00000040, 0 8px 10px -6px #0000001a;
  --shadow-glow: 0 0 25px #a855f759;
  --font-heading: "Fredoka", "Outfit", sans-serif;
  --font-body: "Plus Jakarta Sans", "Outfit", sans-serif;
}

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

html, body { min-height: 100%; }

body {
  font-family: var(--font-body);
  min-height: 100vh;
  transition: background 0.4s, color 0.4s;
  overflow-x: hidden;
}

body.dark {
  background: var(--bg-gradient-dark);
  color: var(--text-primary-dark);
}

body.light {
  background: var(--bg-gradient-light);
  color: var(--text-primary-light);
}

button, .game-card { -webkit-user-select: none; user-select: none; }

.story-text, .story-text *, .chat-bubble, input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

.glass-panel {
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-radius: 24px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark .glass-panel {
  background: var(--card-bg-dark);
  border: 1px solid var(--card-border-dark);
  box-shadow: 0 8px 32px #0000005e;
}

body.light .glass-panel {
  background: var(--card-bg-light);
  border: 1px solid var(--card-border-light);
  box-shadow: 0 8px 32px #1f268714;
}

.glass-button {
  cursor: pointer;
  font-family: var(--font-heading);
  border: none;
  border-radius: 16px;
  outline: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-weight: 600;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-flex;
  color: inherit;
}

.glass-button:hover { transform: translateY(-2px) scale(1.02); }
.glass-button:active { transform: translateY(1px) scale(0.98); }
.glass-button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary-gradient); color: #fff; box-shadow: 0 4px 15px #a855f766; }
.btn-secondary { background: var(--secondary-gradient); color: #fff; box-shadow: 0 4px 15px #ec489966; }
.btn-gold { background: var(--gold-gradient); color: #1e1b4b; box-shadow: 0 4px 15px #fbbf2466; }
.btn-emerald { background: var(--emerald-gradient); color: #fff; box-shadow: 0 4px 15px #10b98166; }
.btn-cyan { background: var(--cyan-gradient); color: #fff; box-shadow: 0 4px 15px #06b6d466; }
.btn-outline { color: inherit; background: #ffffff1a; border: 1px solid #fff3; }
body.light .btn-outline { background: #0000000d; border-color: #0000001a; }

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  padding: 0;
}

.app-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 24px 60px;
}

.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin: 12px 0 24px;
  padding: 14px 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
}

.brand img {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.4);
  border: 2px solid rgba(255, 255, 255, 0.4);
  object-fit: cover;
  background: #fff;
}

.brand h1 {
  font-family: var(--font-heading);
  font-size: 1.45rem;
  font-weight: 800;
}

.edition-pill {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--gold-gradient);
  color: #1e1b4b;
}

.brand p { font-size: 0.82rem; opacity: 0.8; margin-top: 2px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.xp-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 16px;
}

.xp-emoji { font-size: 1.6rem; }
.xp-meta { font-size: 0.78rem; font-weight: 700; }
.xp-bar {
  width: 90px;
  height: 7px;
  border-radius: 99px;
  background: #ffffff22;
  overflow: hidden;
  margin-top: 4px;
}
.xp-bar > span {
  display: block;
  height: 100%;
  background: var(--primary-gradient);
}

.hero {
  display: grid;
  grid-template-columns: 1.4fr 0.6fr;
  gap: 20px;
  margin-bottom: 28px;
}

.hero-copy h2 {
  font-family: var(--font-heading);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  margin: 8px 0 12px;
}

.hero-copy p { opacity: 0.85; line-height: 1.6; margin-bottom: 18px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-art {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5.5rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 8px 0 16px;
}
.section-head h3 { font-family: var(--font-heading); font-size: 1.25rem; }
.section-head span { font-size: 0.85rem; opacity: 0.7; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}

.game-card {
  padding: 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-height: 230px;
  border: 1px solid transparent;
}

.game-card:hover { transform: translateY(-4px); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.badge {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  color: #fff;
}

.badge-purple { background: var(--primary-gradient); }
.badge-gold { background: var(--gold-gradient); color: #1e1b4b; }
.badge-pink { background: var(--secondary-gradient); }
.badge-cyan { background: var(--cyan-gradient); }
.badge-green { background: var(--emerald-gradient); }

.xp-tag { font-size: 0.78rem; font-weight: 800; opacity: 0.8; }

.game-emoji { font-size: 2.4rem; margin-bottom: 8px; }
.game-card h4 { font-family: var(--font-heading); font-size: 1.2rem; margin-bottom: 6px; }
.game-card p { font-size: 0.9rem; opacity: 0.8; line-height: 1.45; flex: 1; }

.card-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  font-size: 0.78rem;
  opacity: 0.75;
}

.play-now {
  background: #ffffff22;
  color: #fff;
  padding: 6px 12px;
  border-radius: 14px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.88rem;
}

.panel { padding: 28px 32px; }
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.panel-head h2 { font-family: var(--font-heading); font-size: 1.55rem; }
.panel-head p { font-size: 0.88rem; opacity: 0.8; margin-top: 4px; }

.mode-tabs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 12px 0 22px;
}

.theme-card {
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  border-radius: 20px;
}
.theme-card .big { font-size: 2rem; display: block; margin-bottom: 8px; }
.theme-card strong { font-family: var(--font-heading); font-size: 0.95rem; }

.idea-row { display: flex; gap: 10px; flex-wrap: wrap; }
.idea-row input, .chat-form input, .answer-row input {
  flex: 1;
  min-width: 200px;
  padding: 14px 20px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.2);
  color: inherit;
  font-family: var(--font-body);
  font-size: 0.95rem;
  outline: none;
}
body.light .idea-row input,
body.light .chat-form input,
body.light .answer-row input {
  background: #fff;
  border-color: #00000022;
}

.story-card { padding: 24px; margin-bottom: 18px; }
.story-card h4 {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  color: #fbbf24;
  margin-bottom: 12px;
}
body.light .story-card h4 { color: #b45309; }

.story-text {
  font-size: 1.18rem;
  line-height: 1.75;
  margin-bottom: 16px;
}
.story-text .w {
  border-radius: 4px;
  padding: 0 1px;
  transition: background 0.12s, color 0.12s;
}
.story-text .w.on {
  background: #fbbf24;
  color: #1e1b4b;
}

.read-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

.voice-pick {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.voice-pick select {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid #fff3;
  background: #ffffff1a;
  color: inherit;
  outline: none;
}

body.light .voice-pick select {
  background: #fff;
  border-color: #00000022;
}

.choices { display: flex; flex-direction: column; gap: 10px; }
.choices .glass-button { justify-content: flex-start; text-align: left; width: 100%; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  margin-bottom: 14px;
  padding-right: 4px;
}

.chat-bubble {
  max-width: 82%;
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 0.98rem;
  line-height: 1.55;
  box-shadow: var(--shadow-sm);
}
.chat-bubble.sparky { align-self: flex-start; background: rgba(255,255,255,0.1); }
.chat-bubble.luella { align-self: flex-end; background: var(--primary-gradient); color: #fff; }
.chat-bubble .who { font-size: 0.75rem; font-weight: 800; color: #fbbf24; margin-bottom: 4px; }
.chat-form { display: flex; gap: 10px; }

.math-q {
  text-align: center;
  max-width: 520px;
  margin: 0 auto;
}
.math-q .eq {
  padding: 36px 20px;
  font-size: clamp(2.2rem, 6vw, 3.5rem);
  font-family: var(--font-heading);
  font-weight: 800;
  color: #fbbf24;
  margin: 10px 0 22px;
}
.answer-row { display: flex; gap: 10px; justify-content: center; }
.answer-row input { max-width: 180px; text-align: center; font-size: 1.4rem; font-weight: 800; }

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.option-grid .glass-button {
  padding: 22px 16px;
  font-size: 1.15rem;
  justify-content: center;
}

.letter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 16px 0;
}
.letter-tile {
  min-width: 48px;
  height: 56px;
  font-size: 1.4rem;
  font-family: var(--font-heading);
}

.simon-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 360px;
  margin: 16px auto;
}
.simon-pad {
  height: 110px;
  border-radius: 22px;
  border: none;
  cursor: pointer;
  opacity: 0.55;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: #fff;
}
.simon-pad.lit { opacity: 1; transform: scale(1.04); box-shadow: 0 0 24px #fff6; }

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  max-width: 420px;
  margin: 0 auto;
}
.mem-card {
  aspect-ratio: 1;
  border-radius: 16px;
  font-size: 1.8rem;
  background: #ffffff18;
  border: 1px solid #fff3;
  cursor: pointer;
}
.mem-card.up { background: #ffffff28; }
.mem-card.gone { visibility: hidden; }

.draw-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.draw-wrap {
  background: #1e1b4b22;
  border-radius: 20px;
  padding: 10px;
  margin: 8px 0 14px;
}

#drawPad {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  border-radius: 16px;
  background: #fffdf7;
  cursor: crosshair;
  touch-action: none;
  box-shadow: inset 0 0 0 1px #00000014;
}

.draw-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.tune-box {
  margin-top: 8px;
  padding: 10px 4px;
  opacity: 0.95;
}

.tune-box summary {
  cursor: pointer;
  font-family: var(--font-heading);
  font-weight: 700;
  margin-bottom: 10px;
}

.palette { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 10px; }
.swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #fff6;
  cursor: pointer;
}
.swatch.on { outline: 3px solid #fbbf24; }

.piano {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.note-cell {
  height: 54px;
  border-radius: 10px;
  border: 1px solid #fff3;
  background: #ffffff14;
  cursor: pointer;
  font-family: var(--font-heading);
}
.note-cell.on { background: var(--primary-gradient); color: #fff; }

.club-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.avatar-pick, .badge-card, .title-pick {
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  border-radius: 16px;
}
.avatar-pick .big { font-size: 2rem; }
.badge-card { opacity: 0.4; }
.badge-card.unlocked { opacity: 1; }
.badge-card .big { font-size: 1.6rem; }
.badge-card small, .avatar-pick small { display: block; font-size: 0.72rem; font-weight: 700; margin-top: 4px; }

.stat-row {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
  padding: 18px;
}
.stat-row div { text-align: center; }
.stat-row .n { font-family: var(--font-heading); font-size: 1.8rem; }

.feedback {
  text-align: center;
  margin-top: 14px;
  font-family: var(--font-heading);
  font-size: 1.1rem;
}
.feedback.ok { color: #34d399; }
.feedback.bad { color: #fb7185; }

.scoreline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  font-weight: 700;
}

footer {
  text-align: center;
  margin-top: 48px;
  opacity: 0.65;
  font-size: 0.85rem;
}

.modal-back {
  position: fixed;
  inset: 0;
  background: #0008;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow: auto;
  z-index: 40;
}
.modal { width: min(720px, 100%); padding: 28px; }

.hidden { display: none !important; }

@keyframes float {
  0%, to { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes bounceIn {
  0% { opacity: 0; transform: scale(0.3); }
  50% { opacity: 1; transform: scale(1.05); }
  70% { transform: scale(0.9); }
  to { transform: scale(1); }
}
.animate-float { animation: 4s ease-in-out infinite float; }
.animate-bounce-in { animation: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) bounceIn; }

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; }
  .hero-art { font-size: 4rem; }
  .option-grid, .memory-grid { grid-template-columns: 1fr 1fr; }
  .app-container { padding: 12px 14px 48px; }
  .panel { padding: 20px 16px; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #0000001a; }
::-webkit-scrollbar-thumb { background: #a855f780; border-radius: 4px; }
