:root {
  --bg1: #2a1b5c; --bg2: #5b2a86; --bg3: #ff7a59;
  --card: #fffaf0; --ink: #2b2140; --muted: #6b5d80;
  --accent: #ff7a1a; --accent2: #7c4dff; --good: #22b573; --gold: #ffc233;
  --radius: 28px;
  font-size: 18px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Nunito', system-ui, sans-serif; color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2) 60%, var(--bg3));
  background-attachment: fixed; overflow-x: hidden;
}
.sky { position: fixed; inset: 0; pointer-events: none;
  background-image: radial-gradient(2px 2px at 20% 30%, #fff8, transparent), radial-gradient(2px 2px at 70% 20%, #fff9, transparent),
    radial-gradient(1.5px 1.5px at 40% 70%, #fff7, transparent), radial-gradient(2px 2px at 85% 60%, #fff8, transparent),
    radial-gradient(1.5px 1.5px at 10% 85%, #fff6, transparent), radial-gradient(2px 2px at 55% 45%, #fff5, transparent);
  animation: twinkle 6s ease-in-out infinite alternate; }
@keyframes twinkle { to { opacity: .5; } }

#app { position: relative; max-width: 760px; margin: 0 auto; min-height: 100dvh; padding: 20px 16px 40px; }
h1, h2, h3, .title { font-family: 'Baloo 2', cursive; margin: 0; line-height: 1.1; }
h1 { font-size: 2.6rem; color: #fff; text-shadow: 0 4px 0 #0003; }
h2 { font-size: 1.7rem; }
p { line-height: 1.5; }
.center { text-align: center; }
.white { color: #fff; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.card { background: var(--card); border-radius: var(--radius); padding: 24px; box-shadow: 0 12px 0 #0002, 0 20px 50px #0004; }

button, .btn {
  font-family: 'Baloo 2', cursive; font-weight: 800; font-size: 1.25rem; border: 0; cursor: pointer;
  border-radius: 999px; padding: 14px 26px; color: #fff; background: var(--accent);
  box-shadow: 0 6px 0 #b8500d; transition: transform .1s, box-shadow .1s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
button:active { transform: translateY(4px); box-shadow: 0 2px 0 #b8500d; }
button.secondary { background: var(--accent2); box-shadow: 0 6px 0 #4a28a8; }
button.ghost { background: #ffffff22; box-shadow: none; color: #fff; font-size: 1rem; padding: 10px 18px; }
button.ghost.dark { background: #2b214012; color: var(--ink); }
button.gold { background: var(--gold); color: #5a3b00; box-shadow: 0 6px 0 #c48a00; }
button:disabled { opacity: .5; cursor: default; }
button.big { font-size: 1.6rem; padding: 18px 34px; }

label { font-weight: 700; display: block; margin-bottom: 6px; }
input, select {
  width: 100%; font: inherit; font-size: 1.15rem; padding: 14px 18px; border-radius: 18px; border: 3px solid #e7dcc8; background: #fff; color: var(--ink);
}
input:focus { outline: none; border-color: var(--accent2); }
input.pin { letter-spacing: .6em; text-align: center; font-size: 1.6rem; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: .95rem; }
.check input { width: 26px; height: 26px; flex: none; }
.error { color: #d0342c; font-weight: 700; min-height: 1.2em; }

/* Grades de escolha com emoji */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); }
.tile {
  background: #fff; color: var(--ink); box-shadow: 0 6px 0 #e2d4bd; border: 4px solid transparent;
  border-radius: 24px; padding: 14px 8px; flex-direction: column; font-size: 1rem; gap: 4px; min-height: 120px;
}
.grid.small .tile { min-height: 70px; padding: 8px; }
.tile .emoji { font-size: 3rem; line-height: 1; }
.grid.small .tile .emoji { font-size: 2.2rem; }
.tile.selected { border-color: var(--accent2); background: #f1ebff; }
.tile:active { box-shadow: 0 2px 0 #e2d4bd; }

/* Home */
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; color: #fff; }
.badge { font-family: 'Baloo 2'; font-weight: 800; border-radius: 999px; padding: 4px 12px; font-size: .9rem; background: #ffffff26; color: #fff; }
.badge.premium { background: var(--gold); color: #5a3b00; }
.hero-card { display: flex; gap: 14px; align-items: center; background: #fff; border-radius: 22px; padding: 14px; box-shadow: 0 6px 0 #e2d4bd; }
.hero-card .avatar { font-size: 3rem; width: 70px; height: 70px; display: grid; place-items: center; background: #f1ebff; border-radius: 50%; flex: none; }
.hero-card .info { flex: 1; min-width: 0; }
.hero-card .name { font-family: 'Baloo 2'; font-weight: 800; font-size: 1.3rem; }
.hero-card .epithet { color: var(--accent2); font-weight: 700; font-size: .95rem; }
.hero-card .items { font-size: .85rem; color: var(--muted); }
.section-title { color: #fff; font-family: 'Baloo 2'; font-weight: 800; font-size: 1.4rem; margin: 26px 0 10px; }

/* Palco da história: só o trecho atual fica na tela */
.story-screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.story-top { display: flex; align-items: center; gap: 8px; padding: 12px 16px; color: #fff; max-width: 800px; width: 100%; margin: 0 auto; }
.story-top .title { font-size: 1.2rem; flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress { display: flex; gap: 4px; justify-content: center; padding-bottom: 6px; }
.progress span { width: 12px; height: 12px; border-radius: 50%; background: #ffffff40; }
.progress span.done { background: var(--gold); }
.progress span.now { background: #fff; transform: scale(1.3); }
.stage { position: relative; flex: 1; overflow: hidden; }
.segment {
  position: absolute; inset: 0; overflow-y: auto; padding: 8px 16px 32px;
  display: flex; flex-direction: column; align-items: center;
  transition: transform .7s cubic-bezier(.6,-0.2,.3,1.2), opacity .6s;
}
.segment.enter { transform: translateY(100%); opacity: 0; }
.segment.leave { transform: translateY(-110%); opacity: 0; }
.segment .card { width: 100%; max-width: 720px; margin: auto 0; }
.story-text { font-size: 1.45rem; line-height: 1.6; font-family: 'Nunito'; margin: 0; }
.age-small .story-text { font-size: 1.7rem; }
.story-text .w { transition: background .2s; border-radius: 6px; }
.story-text .w.on { background: #ffe38a; }
.illustration { width: 100%; aspect-ratio: 1; border-radius: 22px; object-fit: cover; margin-bottom: 16px; animation: pop .6s; }
.illustration-wait { width: 100%; aspect-ratio: 3/1; border-radius: 22px; margin-bottom: 16px; display: grid; place-items: center;
  background: linear-gradient(90deg, #f1ebff, #fff1d6, #f1ebff); background-size: 200% 100%; animation: shimmer 2s linear infinite; color: var(--accent2); font-weight: 700; }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }

.choices { display: grid; gap: 14px; margin-top: 22px; }
.choices.symbols { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
.choice {
  background: #fff; color: var(--ink); border: 4px solid #e7dcc8; box-shadow: 0 6px 0 #e2d4bd; border-radius: 26px;
  font-size: 1.25rem; padding: 14px 18px; justify-content: flex-start; text-align: left;
}
.choice .emoji { font-size: 2.2rem; line-height: 1; }
.choices.symbols .choice { flex-direction: column; justify-content: center; min-height: 150px; }
.choices.symbols .choice .emoji { font-size: 5rem; }
.choices.symbols.no-text .choice .label { display: none; }
.choice.armed { border-color: var(--good); background: #e8fbf1; animation: wiggle .5s ease-in-out infinite alternate; }
.choice.armed::after { content: '✔ toque de novo'; font-size: .85rem; color: var(--good); }
@keyframes wiggle { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }

.story-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.listen { background: #f1ebff; color: var(--accent2); box-shadow: 0 4px 0 #d8c9ff; font-size: 1.05rem; padding: 10px 18px; }
.listen.playing { background: var(--accent2); color: #fff; }

.writing { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-align: center; pointer-events: none; }
.writing[hidden] { display: none; }
.writing .quill { font-size: 4rem; animation: float 1.2s ease-in-out infinite alternate; }
@keyframes float { to { transform: translateY(-14px) rotate(-8deg); } }

.ending-banner { font-family: 'Baloo 2'; font-weight: 800; font-size: 2.2rem; text-align: center; color: var(--accent); margin-top: 10px; }
.confetti { position: fixed; top: -20px; font-size: 1.6rem; animation: fall linear forwards; pointer-events: none; z-index: 20; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.modal-back { position: fixed; inset: 0; background: #1a0f3acc; display: grid; place-items: center; padding: 16px; z-index: 30; }
.modal-back .card { width: 100%; max-width: 460px; max-height: 90dvh; overflow: auto; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(120px); background: #2b2140; color: #fff;
  padding: 12px 20px; border-radius: 999px; font-weight: 700; transition: transform .3s; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }

.logo { font-size: 6rem; text-align: center; animation: float 2s ease-in-out infinite alternate; }
.steps { display: flex; justify-content: center; gap: 8px; margin-bottom: 14px; }
.steps span { width: 36px; height: 8px; border-radius: 8px; background: #ffffff40; }
.steps span.on { background: var(--gold); }

@media (max-width: 480px) {
  :root { font-size: 16px; }
  h1 { font-size: 2.1rem; }
  .story-text { font-size: 1.3rem; }
}
