/* MathQuest 2 — older-kid feel: deeper colors, more text, but still playful */
:root {
  --bg-1: #1d2545;
  --bg-2: #2e3a72;
  --paper: #fdf6e3;
  --paper-dark: #ede4c5;
  --ink: #1a1f3a;
  --accent: #ffb84d;
  --accent-2: #ff7b6b;
  --good: #4eb86b;
  --bad: #e85a4f;
  --info: #5aa9e6;
  --gold: #ffc83d;
  --shadow: 0 4px 0 rgba(0,0,0,0.25);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Baloo 2", "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  color: var(--ink);
  background: radial-gradient(ellipse at top, var(--bg-2) 0%, var(--bg-1) 80%);
  overflow: hidden; user-select: none;
  touch-action: manipulation;
}
#app {
  height: 100%; display: flex; flex-direction: column;
  max-width: 920px; margin: 0 auto; position: relative;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
}

/* HUD */
.hud {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: rgba(20,28,60,0.85);
  border-bottom: 2px solid rgba(255,255,255,0.08);
  z-index: 10;
}
.hud.hidden { display: none; }
.hud-stats { display: flex; gap: 10px; font-size: 18px; font-weight: 700; color: white; }
.stat { background: rgba(255,255,255,0.12); padding: 5px 12px; border-radius: 999px; }
.icon-btn {
  background: var(--accent); border: none;
  font-size: 20px; width: 44px; height: 44px;
  border-radius: 12px; box-shadow: var(--shadow);
  cursor: pointer; color: var(--ink);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.25); }

/* Screens */
#screens { flex: 1; position: relative; overflow: hidden; }
.screen {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  padding: 16px;
  overflow-y: auto;
  color: white;
}
.screen.active { display: flex; }
.screen-title {
  text-align: center; font-size: 28px;
  margin: 4px 0 16px; color: var(--accent);
  text-shadow: 0 2px 0 rgba(0,0,0,0.3);
}

/* Welcome */
.welcome-card {
  margin: auto; text-align: center;
  background: var(--paper); color: var(--ink);
  padding: 32px 24px; border-radius: 24px;
  box-shadow: var(--shadow);
  border: 3px solid var(--accent);
  max-width: 400px;
}
.big-mascot { font-size: 80px; }
.welcome-card h1 { font-size: 42px; margin: 6px 0; color: var(--bg-1); }
.subtitle { font-size: 18px; margin: 0 0 12px; color: var(--bg-2); }
.lore { font-size: 16px; font-style: italic; margin: 16px 0; color: #555; }

.primary-btn {
  background: var(--accent-2); color: white;
  border: none; font-size: 22px; font-weight: 700;
  padding: 14px 32px; border-radius: 14px;
  box-shadow: 0 5px 0 #b54a3e;
  cursor: pointer; font-family: inherit;
  margin: 8px;
}
.primary-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #b54a3e; }
.text-btn {
  background: transparent; border: none;
  color: var(--bg-2); font-size: 14px;
  text-decoration: underline; cursor: pointer; font-family: inherit;
  margin-top: 10px;
}

/* Realm list */
.realm-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.realm-card {
  background: linear-gradient(135deg, var(--paper), var(--paper-dark));
  color: var(--ink);
  border-radius: 18px; padding: 18px;
  box-shadow: var(--shadow);
  border: 3px solid var(--accent);
  cursor: pointer;
  transition: transform 0.15s;
}
.realm-card:active { transform: scale(0.98); }
.realm-card.locked { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.5); border-color: #888; }
.realm-card .realm-emoji { font-size: 44px; }
.realm-card .realm-name { font-size: 22px; font-weight: 700; margin: 6px 0 2px; }
.realm-card .realm-desc { font-size: 14px; color: #555; margin: 0 0 8px; }
.realm-card .realm-progress {
  height: 8px; background: rgba(0,0,0,0.1); border-radius: 4px; overflow: hidden;
  margin-top: 8px;
}
.realm-card .realm-progress-fill {
  height: 100%; background: var(--good); transition: width 0.4s;
}
.realm-card .realm-meta {
  font-size: 12px; color: #666; margin-top: 6px;
  display: flex; justify-content: space-between;
}
.codex-hint { text-align: center; margin-top: 14px; opacity: 0.6; font-size: 14px; }

/* Quest list */
.quest-list {
  display: flex; flex-direction: column; gap: 10px;
  max-width: 600px; width: 100%; margin: 0 auto;
}
.quest-item {
  background: var(--paper); color: var(--ink);
  padding: 14px 18px;
  border-radius: 14px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
  cursor: pointer; border: 2px solid transparent;
}
.quest-item:active { transform: translateY(2px); }
.quest-item.locked { opacity: 0.5; cursor: not-allowed; }
.quest-item.completed { border-color: var(--good); }
.quest-item .quest-num {
  font-size: 22px; font-weight: 700; color: var(--accent-2);
  min-width: 36px;
}
.quest-item .quest-info { flex: 1; }
.quest-item .quest-title { font-weight: 700; font-size: 16px; }
.quest-item .quest-sub { font-size: 12px; color: #666; }
.quest-item .quest-stars { color: var(--gold); font-size: 18px; }

/* Play */
.play-header {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.progress-bar {
  flex: 1; height: 14px;
  background: rgba(255,255,255,0.15);
  border-radius: 7px; overflow: hidden;
  border: 1px solid rgba(255,255,255,0.25);
}
#progressFill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--good), #6dd285);
  transition: width 0.4s;
}
.play-tools { display: flex; gap: 6px; }
.tool-btn {
  width: 36px; height: 36px;
  border-radius: 10px; border: none;
  background: rgba(255,255,255,0.15); color: white;
  font-size: 16px; cursor: pointer;
}
.tool-btn.active { background: var(--accent); color: var(--ink); }

.scene-container {
  background: rgba(255,255,255,0.07);
  border-radius: 16px;
  min-height: 160px; max-height: 220px;
  margin-bottom: 12px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}
.scene-container svg { max-width: 100%; max-height: 200px; }

.story-text {
  background: var(--paper); color: var(--ink);
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 17px; line-height: 1.5;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.story-text .num-highlight {
  background: var(--accent); padding: 1px 6px; border-radius: 6px; font-weight: 700;
}
.story-text .keyword-highlight {
  color: var(--accent-2); font-weight: 700;
}
.story-text .vocab {
  border-bottom: 2px dotted var(--info);
  cursor: help;
}

.question-text {
  text-align: center;
  font-size: 20px; font-weight: 700;
  color: var(--accent);
  margin-bottom: 14px;
}

.choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 500px; width: 100%;
  margin: 0 auto;
}
.choice-btn {
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--paper);
  border-radius: 14px;
  padding: 18px;
  font-size: 22px; font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  box-shadow: var(--shadow);
  min-height: 70px;
  transition: transform 0.1s;
}
.choice-btn:active:not(:disabled) { transform: translateY(2px); }
.choice-btn:disabled { cursor: not-allowed; }
.choice-btn.correct { background: var(--good); color: white; border-color: #2e8b50; animation: pulse 0.4s; }
.choice-btn.wrong { background: var(--bad); color: white; border-color: #a83e36; animation: shake 0.4s; }
.choice-btn.faded { opacity: 0.35; }

.explain-box {
  background: rgba(255, 184, 77, 0.18);
  border-left: 4px solid var(--accent);
  padding: 12px 14px;
  border-radius: 8px;
  margin-top: 14px;
  font-size: 15px;
  color: white;
}
.explain-box.hidden { display: none; }
.explain-box.good { background: rgba(78, 184, 107, 0.18); border-color: var(--good); }

.story-unfurl {
  margin-top: 12px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  font-style: italic;
  font-size: 15px;
  color: rgba(255,255,255,0.85);
  min-height: 0;
  display: none;
}
.story-unfurl.show {
  display: block;
  animation: unfurl 0.6s ease-out;
}
@keyframes unfurl {
  0% { opacity: 0; transform: translateY(-6px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Reward */
.reward-card {
  margin: auto;
  background: var(--paper); color: var(--ink);
  padding: 28px;
  border-radius: 24px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 3px solid var(--accent);
  max-width: 500px; width: 100%;
}
.reward-card h2 { color: var(--accent-2); margin: 0 0 12px; font-size: 28px; }
.comic-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
}
.comic-panel {
  background: white;
  border: 2px solid var(--ink);
  border-radius: 8px;
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  position: relative;
}
.comic-panel .panel-num {
  position: absolute; top: 2px; left: 4px;
  font-size: 10px; color: #888;
}

.reward-items {
  text-align: left;
  background: rgba(0,0,0,0.05);
  padding: 12px 16px;
  border-radius: 10px;
  margin: 12px 0;
}
.reward-items div { margin: 4px 0; font-size: 15px; }

/* Codex */
.codex-content {
  flex: 1;
  background: var(--paper); color: var(--ink);
  padding: 16px;
  border-radius: 16px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.codex-chapter {
  border-bottom: 1px dashed #aaa;
  padding: 10px 0;
}
.codex-chapter:last-child { border-bottom: none; }
.codex-chapter h3 { margin: 0 0 6px; color: var(--accent-2); }
.codex-chapter .chapter-text { font-size: 14px; line-height: 1.5; color: #444; }

/* Parent */
.parent-content {
  flex: 1;
  background: var(--paper); color: var(--ink);
  padding: 16px;
  border-radius: 16px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.parent-section { margin-bottom: 16px; }
.parent-section h3 { margin: 0 0 8px; color: var(--bg-2); border-bottom: 2px solid var(--accent); padding-bottom: 4px; }
.skill-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0;
}
.skill-bar-wrap {
  flex: 1; max-width: 180px;
  height: 8px; background: #ddd; border-radius: 4px; overflow: hidden;
  margin: 0 10px;
}
.skill-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--info), var(--good));
}
.misconception-row {
  padding: 8px 10px;
  background: rgba(232, 90, 79, 0.1);
  border-left: 3px solid var(--bad);
  margin: 4px 0;
  border-radius: 6px;
  font-size: 14px;
}
.misconception-row b { color: var(--bad); }

/* Animations */
@keyframes pulse {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Promotion cutscene */
.promotion {
  position: fixed; inset: 0;
  background: rgba(20, 25, 50, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.4s;
}
.promotion-card {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  max-width: 360px;
  box-shadow: 0 0 80px rgba(255, 184, 77, 0.5);
  animation: scaleIn 0.5s ease-out;
}
.promotion-card .promo-icon { font-size: 80px; }
.promotion-card h2 { font-size: 30px; margin: 8px 0; }
.promotion-card p { font-size: 18px; margin: 10px 0 20px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn {
  0% { transform: scale(0.5) rotate(-10deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Sparkles on correct */
.sparkle {
  position: absolute; pointer-events: none;
  font-size: 24px; opacity: 0;
  animation: sparkle 1.2s ease-out forwards;
}
@keyframes sparkle {
  0% { opacity: 0; transform: scale(0) rotate(0); }
  30% { opacity: 1; transform: scale(1.4) rotate(180deg); }
  100% { opacity: 0; transform: scale(0.5) translateY(-40px) rotate(360deg); }
}
