/* ---------- World colors ---------- */
:root {
  --bg: linear-gradient(160deg, #3a1c71 0%, #5b3fa8 50%, #1f6fb2 100%);
  --panel: rgba(255, 255, 255, 0.12);
  --panel-strong: rgba(10, 10, 30, 0.55);
  --text: #fff;
  --muted: rgba(255, 255, 255, 0.75);
  --accent: #ffd23f;
  --accent-text: #2b1a00;
  --good: #3ddc84;
  --bad: #ff6b6b;
  --math: #ff9f1c;
  --spelling: #4dabf7;
  --science: #51cf66;
  --radius: 18px;
}
body[data-world="space"] {
  --bg: radial-gradient(2px 2px at 20% 30%, #fff 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 70% 20%, #fff 50%, transparent 51%),
        radial-gradient(2px 2px at 40% 80%, #cdf 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 85% 65%, #fff 50%, transparent 51%),
        radial-gradient(1px 1px at 10% 70%, #fff 50%, transparent 51%),
        linear-gradient(170deg, #0b0f2e 0%, #1b1d5c 55%, #3c1a6b 100%);
  --accent: #5ee0ff;
  --accent-text: #001b26;
}
body[data-world="fantasy"] {
  --bg: linear-gradient(170deg, #0f3b2e 0%, #1f6f4a 45%, #4b2a6e 100%);
  --accent: #ffd166;
  --accent-text: #2b1a00;
}
body[data-world="medieval"] {
  --bg: linear-gradient(170deg, #3b2a1a 0%, #6b4a2a 50%, #8a2c2c 100%);
  --accent: #f2c14e;
  --accent-text: #2b1a00;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Fredoka', 'Comic Sans MS', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-attachment: fixed;
  font-size: 20px;
  -webkit-tap-highlight-color: transparent;
}
#app { max-width: 780px; margin: 0 auto; padding: 16px; }
.screen { animation: fade 0.3s ease; }
h1, h2, h3 { margin: 0.4em 0; line-height: 1.15; }
h2 small { display: block; font-size: 0.6em; color: var(--muted); font-weight: 400; }
button { font-family: inherit; cursor: pointer; }
button:disabled { cursor: default; }

/* ---------- Buttons ---------- */
.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 20px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.1s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.btn.big { font-size: 24px; padding: 16px 32px; }
.btn.ghost { background: var(--panel); color: var(--text); box-shadow: none; border: 2px solid rgba(255, 255, 255, 0.3); }
.btn.danger { border-color: var(--bad); }
.btn:disabled { opacity: 0.5; }
.link { background: none; border: 0; color: var(--muted); font-size: 16px; margin-top: 12px; text-decoration: underline; }
.say {
  border: 0; background: var(--panel); color: var(--text);
  border-radius: 999px; width: 44px; height: 44px; font-size: 22px; vertical-align: middle;
}
.row { display: flex; gap: 12px; justify-content: center; align-items: center; margin-top: 16px; }
.row.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 14px; align-items: center; margin-top: 24px; }

/* ---------- Title ---------- */
.title { text-align: center; padding-top: 8vh; }
.title-art { font-size: 56px; letter-spacing: 12px; animation: bob 3s ease-in-out infinite; }
.logo { font-size: 54px; font-weight: 700; text-shadow: 0 5px 0 rgba(0, 0, 0, 0.3); }
.logo span { display: block; color: var(--accent); font-size: 1.2em; }
.tag { color: var(--muted); font-size: 22px; }

/* ---------- Create ---------- */
.create { text-align: center; }
.field { display: block; font-size: 20px; margin: 12px auto; max-width: 360px; }
.field input, .typed input {
  display: block; width: 100%; margin-top: 8px;
  font: inherit; font-size: 26px; text-align: center;
  padding: 12px; border-radius: var(--radius); border: 3px solid transparent; outline: none;
}
.field input:focus, .typed input:focus { border-color: var(--accent); }
.avatars { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.avatar {
  font-size: 42px; width: 72px; height: 72px; border-radius: 50%;
  background: var(--panel); border: 3px solid transparent;
}
.avatar.sel { border-color: var(--accent); background: rgba(255, 255, 255, 0.25); transform: scale(1.1); }
.worlds { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 8px 0 24px; }
.world-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 18px 12px; border-radius: var(--radius); border: 3px solid transparent; color: #fff; font-size: 20px;
}
.world-card.w-space { background: linear-gradient(160deg, #1b1d5c, #3c1a6b); }
.world-card.w-fantasy { background: linear-gradient(160deg, #1f6f4a, #4b2a6e); }
.world-card.w-medieval { background: linear-gradient(160deg, #6b4a2a, #8a2c2c); }
.world-card.sel { border-color: var(--accent); transform: scale(1.03); box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.15); }
.world-card em { font-size: 15px; color: var(--muted); }
.wicon { font-size: 48px; }
.wprog { font-size: 14px; }

/* ---------- HUD ---------- */
.hud {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--panel-strong); border-radius: 999px; padding: 8px 16px; font-size: 18px;
}
.who { display: flex; align-items: center; gap: 6px; font-weight: 600; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hud-avatar { font-size: 26px; }
.lv { display: flex; align-items: center; gap: 6px; }
.xpbar { display: inline-block; width: 70px; height: 10px; background: rgba(255, 255, 255, 0.2); border-radius: 99px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: var(--accent); }

/* ---------- Intro / results ---------- */
.intro, .result { text-align: center; }
.big-emoji { font-size: 90px; animation: bob 3s ease-in-out infinite; }
.story { background: var(--panel); border-radius: var(--radius); padding: 14px 20px; line-height: 1.5; text-align: left; }
.story p { margin: 0.5em 0; }
.result .story { text-align: center; }
.companion { font-size: 20px; }
.companion span { font-size: 34px; vertical-align: middle; }
.rewards { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.rewards span { background: var(--panel-strong); padding: 8px 16px; border-radius: 999px; font-weight: 600; animation: pop 0.4s ease backwards; }
.rewards span:nth-child(2) { animation-delay: 0.15s; }
.rewards span:nth-child(3) { animation-delay: 0.3s; }
.banner { background: var(--accent); color: var(--accent-text); border-radius: var(--radius); padding: 14px 18px; margin: 12px 0; font-weight: 600; line-height: 1.4; }

/* ---------- Map ---------- */
.map h2 { text-align: center; }
.path { list-style: none; padding: 0; margin: 16px 0; display: flex; flex-direction: column; gap: 12px; }
.path li:nth-child(even) { padding-left: 14%; }
.path li:nth-child(odd) { padding-right: 14%; }
.stage {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 12px 18px; border-radius: var(--radius); border: 3px solid transparent;
  background: var(--panel); color: var(--text); font-size: 20px;
}
.stage .semoji { font-size: 40px; }
.stage .sname { flex: 1; font-weight: 600; }
.stage .sname b { font-size: 12px; background: var(--bad); padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.stage .sstate { font-size: 16px; color: var(--muted); }
.stage.open { border-color: var(--accent); background: rgba(255, 255, 255, 0.2); animation: glow 1.6s ease-in-out infinite; }
.stage.open .sstate { color: var(--accent); font-weight: 600; }
.stage.locked { opacity: 0.45; }

/* ---------- Battle ---------- */
.place { text-align: center; color: var(--muted); margin-top: 8px; font-size: 16px; }
.arena { position: relative; height: 250px; margin: 4px 0 8px; }
.fighter { position: absolute; text-align: center; width: 45%; }
.fighter .emoji { font-size: 84px; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
.fighter .fname { font-weight: 600; font-size: 18px; }
.monster { right: 0; top: 0; }
.monster.boss .emoji { font-size: 110px; }
.hero { left: 0; bottom: 0; }
.hero .emoji { animation-delay: -1.2s; }
.buddy { font-size: 22px; }
.hpbar { height: 14px; background: rgba(0, 0, 0, 0.35); border-radius: 99px; overflow: hidden; margin: 4px auto 0; max-width: 180px; }
.hpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--bad), #ffa94d); transition: width 0.4s; }
.hptext { font-size: 14px; color: var(--muted); }
.hearts { font-size: 22px; letter-spacing: 2px; }
.hearts .lost { filter: grayscale(1); opacity: 0.3; }
.fighter.hit .emoji { animation: shake 0.5s; }
.monster.hit .emoji { filter: brightness(2) drop-shadow(0 0 12px #fff); }

.msg { background: var(--panel-strong); border-radius: var(--radius); padding: 10px 16px; text-align: center; line-height: 1.4; }
.panel { margin-top: 12px; }
.ask { text-align: center; font-size: 22px; font-weight: 600; margin: 8px 0; }
.powers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.power {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; border-radius: var(--radius); padding: 14px 6px; color: #fff; font-size: 18px; font-weight: 600;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
}
.power:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }
.power small { font-weight: 400; opacity: 0.9; font-size: 14px; }
.pemoji { font-size: 38px; }
.p-math { background: var(--math); }
.p-spelling { background: var(--spelling); }
.p-science { background: var(--science); }
.panel .link { display: block; margin: 12px auto 0; }

.question { background: var(--panel-strong); border-radius: var(--radius); padding: 14px; border-top: 6px solid var(--accent); }
.q-math { border-color: var(--math); }
.q-spelling { border-color: var(--spelling); }
.q-science { border-color: var(--science); }
.qhead { display: flex; justify-content: space-between; font-size: 16px; color: var(--muted); }
.lvl { background: var(--panel); padding: 2px 10px; border-radius: 99px; }
.prompt { font-size: 28px; font-weight: 600; text-align: center; margin: 14px 0; line-height: 1.35; }
.sentence { display: block; font-size: 22px; font-weight: 400; color: var(--muted); margin-top: 8px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices.n3 { grid-template-columns: 1fr 1fr 1fr; }
.choice {
  border: 3px solid transparent; border-radius: var(--radius); background: #fff; color: #222;
  font-size: 26px; font-weight: 600; padding: 14px 8px; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
}
.choice:not(:disabled):hover { border-color: var(--accent); }
.choice.right { background: var(--good); color: #fff; }
.choice.wrong { background: var(--bad); color: #fff; animation: shake 0.4s; }
.choice:disabled:not(.right):not(.wrong) { opacity: 0.5; }
.typed { display: flex; gap: 10px; align-items: center; }
.typed input { margin: 0; flex: 1; text-transform: lowercase; }
.typed input.right { background: var(--good); color: #fff; }
.typed input.wrong { background: var(--bad); color: #fff; }

.feedback { margin-top: 12px; border-radius: var(--radius); padding: 12px 16px; text-align: center; animation: pop 0.3s ease; }
.feedback p { margin: 0 0 10px; line-height: 1.4; }
.feedback.good { background: rgba(61, 220, 132, 0.25); border: 2px solid var(--good); }
.feedback.bad { background: rgba(255, 107, 107, 0.2); border: 2px solid var(--bad); }
.explain { display: block; font-size: 18px; margin-top: 6px; color: var(--text); }
.levelup { display: block; margin-top: 6px; color: var(--accent); font-weight: 700; }

/* Math visuals */
.clock { display: block; width: 170px; height: 170px; margin: 10px auto 0; }
.clock .face { fill: #fff; stroke: #333; stroke-width: 3; }
.clock text { font-size: 10px; fill: #222; font-family: inherit; font-weight: 600; }
.clock .hour-hand { stroke: #222; stroke-width: 4.5; stroke-linecap: round; }
.clock .minute-hand { stroke: #e03131; stroke-width: 2.5; stroke-linecap: round; }
.clock .pin { fill: #222; }
.coins-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 10px; }
.coin {
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%;
  font-size: 11px; font-weight: 600; color: #333; border: 3px solid rgba(0, 0, 0, 0.25);
}
.coin.quarter { width: 64px; height: 64px; background: #d9d9d9; }
.coin.dime { width: 46px; height: 46px; background: #e6e6e6; font-size: 10px; }
.coin.nickel { width: 54px; height: 54px; background: #c9c9c9; }
.coin.penny { width: 48px; height: 48px; background: #c8763a; color: #fff; }

/* ---------- Grown-ups ---------- */
.parents .note { color: var(--muted); font-size: 16px; line-height: 1.4; }
.stats { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; font-size: 18px; }
.stats th, .stats td { padding: 10px; text-align: left; border-bottom: 1px solid rgba(255, 255, 255, 0.1); vertical-align: top; }
.lvname { font-size: 13px; color: var(--muted); }
.mini { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-weight: 700; }
.missed { padding-left: 0; list-style: none; font-size: 16px; }
.missed li { padding: 6px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.tagx { font-size: 12px; background: var(--panel); padding: 2px 8px; border-radius: 99px; }

/* ---------- Animations ---------- */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-10px) rotate(-5deg); } 40% { transform: translateX(10px) rotate(5deg); } 60% { transform: translateX(-6px); } 80% { transform: translateX(6px); } }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.0); } 50% { box-shadow: 0 0 18px 2px rgba(255, 255, 255, 0.35); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* ---------- Phones ---------- */
@media (max-width: 520px) {
  body { font-size: 18px; }
  .logo { font-size: 42px; }
  .arena { height: 210px; }
  .fighter .emoji { font-size: 64px; }
  .monster.boss .emoji { font-size: 84px; }
  .prompt { font-size: 24px; }
  .choices.n3 { grid-template-columns: 1fr; }
  .power { font-size: 15px; }
  .pemoji { font-size: 30px; }
  .xpbar { width: 44px; }
  .hearts { font-size: 17px; letter-spacing: 0; white-space: nowrap; }
  .path li:nth-child(n) { padding: 0; }
}
