:root {
  --bg: #f6efe6;
  --bg2: #eaf2f8;
  --ink: #3d3552;
  --soft: #7d7294;
  --pearl: #fffdf8;
  --lav: #c9b3dd;
  --lav-d: #9b7fbf;
  --sea: #7cc3d8;
  --gold: #f3c96b;
  --ok: #7fcfa6;
  --card: #ffffffee;
  --r: 22px;
  --tap: 84px;
  --font: "Avenir Next", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
button { font-family: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; background: radial-gradient(120% 80% at 50% 0%, #fffaf2 0%, var(--bg) 55%, var(--bg2) 100%); }

/* ---------- top bar ---------- */
#topbar { display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-top)) 10px 6px; min-height: 64px; }
.icon-btn { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--card); font-size: 28px; box-shadow: 0 3px 10px #7d729422; flex: 0 0 auto; display: grid; place-items: center; }
.icon-btn.small { width: 44px; height: 44px; font-size: 20px; opacity: .55; }
.icon-btn:active { transform: scale(.94); }
#meter { flex: 1; overflow: hidden; display: flex; align-items: center; gap: 8px; min-width: 0; background: var(--card); border-radius: 40px; padding: 5px 12px 5px 6px; box-shadow: 0 3px 10px #7d729422; }
#meterHeart { width: 46px; height: 42px; flex: 0 0 auto; }
#meterFill { transition: y .9s ease; }
#meterPearls { display: flex; flex: 1; justify-content: space-between; gap: 2px; min-width: 0; }
.mp { flex: 1 1 0; aspect-ratio: 1; max-width: 30px; min-width: 0; border-radius: 50%; border: 2px solid var(--lav); background: #fff; padding: 0; font-size: 0; position: relative; transition: transform .3s, background .5s, box-shadow .5s; }
.mp.done { background: radial-gradient(circle at 35% 30%, #fff 0 18%, #f6eefc 35%, #d9c5ea 100%); box-shadow: 0 0 10px #fff, 0 0 4px var(--lav-d); border-color: #fff; }
.mp.current { transform: scale(1.25); border-color: var(--lav-d); }

/* ---------- stage ---------- */
#stage { flex: 1; position: relative; overflow: hidden; }
.scene { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding: 8px 16px calc(14px + var(--safe-bot)); gap: 12px; animation: fadeIn .5s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: none; } }
.scene h1 { margin: 4px 0 0; font-size: clamp(26px, 6.5vw, 46px); text-align: center; letter-spacing: .5px; }
.scene h2 { margin: 2px 0; font-size: clamp(20px, 5vw, 34px); text-align: center; color: var(--soft); font-weight: 600; }
.grow { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 14px; overflow-y: auto; overflow-x: hidden; padding: 4px 2px 10px; -webkit-overflow-scrolling: touch; }
.grow > :first-child { margin-top: auto; }
.grow > :last-child { margin-bottom: auto; }
.grow > * { flex-shrink: 0; }

.caption { max-width: 720px; width: 100%; background: var(--card); border-radius: var(--r); padding: 14px 18px; font-size: clamp(18px, 4.6vw, 28px); line-height: 1.35; text-align: center; box-shadow: 0 4px 16px #7d729418; display: block; }
.caption.writings { font-family: Georgia, "Iowan Old Style", "Times New Roman", serif; font-size: clamp(20px, 5vw, 32px); color: #2f2745; }
.caption small { display: block; }
.attrib { font-size: 14px; color: var(--soft); text-align: center; margin-top: -4px; }
.word-hl { background: linear-gradient(transparent 55%, #f3c96b88 55%); border-radius: 4px; transition: background .3s; }
.speaking { background: #fff6d8; border-radius: 6px; box-shadow: 0 0 0 4px #fff6d8; }

.big-btn { min-width: 200px; min-height: var(--tap); border: 0; border-radius: 999px; padding: 12px 34px; font-size: clamp(22px, 5.5vw, 32px); font-weight: 700; background: linear-gradient(180deg, #fff, #efe4f8); box-shadow: 0 6px 0 #c9b3dd, 0 10px 20px #7d729433; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c9b3dd, 0 4px 10px #7d729433; }
.big-btn.gold { background: linear-gradient(180deg, #fff7df, #f7dc98); box-shadow: 0 6px 0 #d9ae4f, 0 10px 20px #7d729433; }
.row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; align-items: center; }
.next-pearl { width: 96px; height: 96px; border-radius: 50%; border: 0; font-size: 40px; background: radial-gradient(circle at 35% 30%, #fff 0 20%, #f6eefc 40%, #d6c1e8 100%); box-shadow: 0 0 0 6px #ffffffaa, 0 8px 22px #9b7fbf55; animation: breathe 2.4s ease-in-out infinite; }
.next-pearl:active { transform: scale(.94); }
@keyframes breathe { 50% { box-shadow: 0 0 0 12px #ffffff66, 0 8px 28px #9b7fbf77; } }
.again-btn { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--card); font-size: 32px; box-shadow: 0 3px 10px #7d729433; }

/* ---------- title ---------- */
.title-pearl { width: min(52vw, 280px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle at 34% 28%, #fff 0 14%, #fbf6ff 30%, #e6d6f2 70%, #cdb4e2 100%); box-shadow: 0 0 60px #fff, 0 20px 50px #9b7fbf55, inset -14px -18px 40px #b89cd455; animation: floaty 5s ease-in-out infinite; display: grid; place-items: center; font-size: min(22vw, 120px); }
@keyframes floaty { 50% { transform: translateY(-10px); } }

/* ---------- prayer moment ---------- */
.candle-light { position: absolute; inset: 0; pointer-events: none; background: radial-gradient(60% 45% at 50% 40%, #fff7da99, transparent 70%); animation: glow 4s ease-in-out infinite; }
@keyframes glow { 50% { opacity: .6; } }
.cues { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.cue { width: 104px; height: 118px; border-radius: 26px; border: 3px solid #fff; background: var(--card); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 44px; gap: 4px; box-shadow: 0 4px 12px #7d729422; transition: transform .3s, background .4s; }
.cue span { font-size: 15px; color: var(--soft); font-weight: 600; }
.cue.on { background: #fff6d8; transform: scale(1.06); border-color: var(--gold); }
.prayer-lines { max-width: 760px; width: 100%; display: flex; flex-direction: column; gap: 6px; }
.prayer-lines p { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(17px, 4.2vw, 26px); line-height: 1.35; text-align: center; opacity: .55; transition: opacity .5s; }
.prayer-lines p.on { opacity: 1; }

/* ---------- memorize pearls ---------- */
.strand { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; max-width: 760px; }
.part { min-height: 90px; max-width: 340px; border: 0; border-radius: 46px; padding: 10px 22px 10px 12px; display: flex; align-items: center; gap: 12px; font-family: Georgia, serif; font-size: clamp(18px, 4.6vw, 28px); text-align: left; background: #ffffffcc; box-shadow: 0 4px 12px #7d729422; opacity: .45; transition: opacity .4s, transform .3s, box-shadow .4s; }
.part .bead { width: 60px; height: 60px; flex: 0 0 auto; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff 0 15%, #efe6f7 45%, #cdb7e0 100%); box-shadow: inset -4px -6px 12px #a98cc955; }
.part.ready { opacity: 1; animation: nudge 2s ease-in-out infinite; }
.part.learned { opacity: 1; animation: none; box-shadow: 0 0 0 4px #fff, 0 0 22px #f3c96b; }
.part.learned .bead { background: radial-gradient(circle at 35% 30%, #fff 0 25%, #fdf7e6 50%, #f0d98f 100%); }
.part.speaking { transform: scale(1.04); background: #fff6d8; }
@keyframes nudge { 50% { transform: scale(1.03); } }
.echo { display: flex; align-items: center; gap: 14px; font-size: clamp(22px, 5.5vw, 34px); font-weight: 700; min-height: 90px; }
.echo .ring { width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; font-size: 38px; background: #fff; box-shadow: 0 0 0 0 #f3c96b88; animation: ring 1.4s ease-out infinite; }
@keyframes ring { to { box-shadow: 0 0 0 26px #f3c96b00; } }
.hidden-words { filter: blur(7px); opacity: .5; transition: filter .6s, opacity .6s; }
.hidden-words.peek { filter: none; opacity: 1; }

/* ---------- word cards ---------- */
.word-tabs { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.word-tab { min-height: 70px; padding: 8px 18px; border-radius: 36px; border: 3px solid #fff; background: var(--card); font-size: clamp(17px, 4.2vw, 24px); font-weight: 700; display: flex; align-items: center; gap: 8px; box-shadow: 0 3px 10px #7d729422; }
.word-tab.seen { border-color: var(--ok); }
.word-tab.active { background: #fff6d8; border-color: var(--gold); }
.story-cards { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 900px; }
.story-card { flex: 1 1 300px; max-width: 420px; min-height: 150px; border: 3px solid #fff; border-radius: var(--r); background: var(--card); padding: 12px 16px; display: flex; gap: 12px; align-items: center; text-align: left; font-size: clamp(16px, 4vw, 22px); line-height: 1.35; box-shadow: 0 4px 14px #7d729422; }
.story-card .art { font-size: 54px; flex: 0 0 auto; }
.story-card.heard { border-color: var(--ok); }

/* crayon scene */
.crayon-scene { flex-shrink: 0; position: relative; width: min(94vw, 640px); height: min(52vh, 420px); background: #fffaf0; border-radius: 28px; box-shadow: inset 0 0 0 4px #fff, 0 6px 18px #7d729422; overflow: hidden; }
.kid { position: absolute; bottom: 12%; width: 32%; text-align: center; font-size: clamp(18px, 4.5vw, 24px); font-weight: 700; }
.kid .face { font-size: clamp(70px, 18vw, 120px); line-height: 1; transition: transform .4s; }
.kid.mary { left: 6%; } .kid.gerard { right: 6%; }
.kid .paper { font-size: 36px; }
.crayon { position: absolute; width: 130px; height: 44px; border-radius: 10px 30px 30px 10px; background: linear-gradient(180deg, #ffe680, #f5c518); box-shadow: 0 4px 10px #0002; touch-action: none; z-index: 3; display: grid; place-items: center; font-weight: 800; color: #7a5b00; font-size: 14px; }
.crayon::after { content: ""; position: absolute; right: -18px; top: 8px; border-left: 20px solid #f5c518; border-top: 14px solid transparent; border-bottom: 14px solid transparent; }
.drop-zone { position: absolute; border-radius: 50%; border: 4px dashed #f3c96b; background: #fff6d855; animation: nudge 2s infinite; }
.choice-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ---------- mirror ---------- */
.mirror-wrap { position: relative; width: min(84vw, 56vh, 460px); aspect-ratio: 1 / 1.08; }
.mirror-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.mirror-reflects { position: absolute; inset: 0; pointer-events: none; }
.reflect { position: absolute; font-size: clamp(34px, 9vw, 54px); opacity: 0; transform: scale(.5); transition: opacity .8s, transform .8s; text-align: center; }
.reflect span { display: block; font-size: 15px; font-weight: 700; color: var(--ink); background: #fff; border-radius: 10px; padding: 1px 6px; }
.reflect.show { opacity: 1; transform: scale(1); }
.dust-labels { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.dust-label { background: #d8cfc4; color: #5d5347; border-radius: 16px; padding: 6px 12px; font-size: 16px; font-weight: 600; transition: opacity .6s, transform .6s; }
.dust-label.gone { opacity: .25; transform: scale(.9); text-decoration: line-through; }

/* ---------- song ---------- */
.lyrics { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 640px; }
.lyric { border: 0; border-radius: 30px; min-height: 58px; padding: 8px 18px; font-family: Georgia, serif; font-size: clamp(18px, 4.4vw, 26px); background: #ffffffcc; text-align: left; display: flex; align-items: center; gap: 10px; box-shadow: 0 2px 8px #7d729418; }
.lyric.child { background: #fff; box-shadow: 0 0 0 3px #e6d6f2, 0 2px 8px #7d729418; }
.lyric.teacher { opacity: .7; font-size: clamp(15px, 3.6vw, 21px); min-height: 46px; }
.lyric .note { font-size: 24px; }

/* ---------- story ---------- */
.story-stage { position: relative; width: min(94vw, 720px, 76vh); aspect-ratio: 2 / 1; background: #3a3352; border-radius: 30px; overflow: hidden; background: linear-gradient(180deg, #2f2a45, #4a4166); box-shadow: 0 8px 24px #3d355244; flex: 0 0 auto; }
.story-stage svg { width: 100%; height: 100%; display: block; }
.story-text { max-width: 760px; width: 100%; background: var(--card); border-radius: var(--r); padding: 14px 18px; font-size: clamp(17px, 4.2vw, 25px); line-height: 1.45; overflow-y: auto; min-height: 0; flex: 1 1 auto; }
.story-text .s { transition: background .3s; border-radius: 6px; }
.story-text .s.on { background: #fff6d8; }
.story-nav { display: flex; align-items: center; gap: 18px; flex: 0 0 auto; }
.story-dots { display: flex; gap: 8px; }
.story-dots i { width: 14px; height: 14px; border-radius: 50%; background: #d8cce6; }
.story-dots i.on { background: var(--lav-d); }
.adult-note { background: #eef6fb; border: 2px dashed #9ccbe0; border-radius: 16px; padding: 10px 14px; font-size: 16px; max-width: 720px; text-align: center; }

/* ---------- tire game ---------- */
.game-field { position: relative; width: min(96vw, 760px); flex: 1; min-height: 300px; border-radius: 30px; background: radial-gradient(circle at 50% 42%, #cfeac0 0 40%, #b7dca6 70%, #a4d192 100%); box-shadow: inset 0 0 0 4px #fff8; overflow: hidden; touch-action: none; }
.tire { position: absolute; border-radius: 50%; border: 22px solid #3f3d45; box-shadow: inset 0 0 0 4px #5e5b66, 0 0 0 4px #2d2b33, 0 10px 20px #0003; background: #c7b79a; }
.tire.happy { box-shadow: inset 0 0 0 4px #5e5b66, 0 0 0 4px #2d2b33, 0 0 40px #fff6, 0 0 0 16px #f3c96b55; }
.friend { position: absolute; width: 78px; height: 78px; margin: -39px 0 0 -39px; border-radius: 50%; display: grid; place-items: center; font-size: 50px; background: #ffffffcc; box-shadow: 0 5px 10px #0002; touch-action: none; transition: left .35s ease, top .35s ease, transform .2s; z-index: 2; }
.friend.drag { transition: none; transform: scale(1.15); z-index: 5; box-shadow: 0 12px 20px #0003; }
.friend.in { background: #fff; }
.friend.wobble { animation: wobble .6s ease-in-out infinite; background: #fff3e0; }
.friend.wobble::after { content: "🤲"; position: absolute; top: -26px; right: -14px; font-size: 26px; animation: nudge 1s infinite; }
@keyframes wobble { 25% { transform: rotate(-12deg) translateX(-3px);} 75% { transform: rotate(12deg) translateX(3px);} }
.friend.cheer { animation: hop .6s ease-in-out 3; }
@keyframes hop { 50% { transform: translateY(-16px); } }

/* ---------- coloring ---------- */
.color-wrap { position: relative; flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.color-page { position: relative; background: #fff; border-radius: 18px; box-shadow: 0 6px 20px #7d729433; touch-action: none; }
.color-page canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 18px; }
.palette { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; align-items: center; flex: 0 0 auto; }
.swatch { width: 56px; height: 56px; border-radius: 50%; border: 4px solid #fff; box-shadow: 0 3px 8px #0002; transition: transform .2s; }
.swatch.on { transform: scale(1.22); box-shadow: 0 0 0 4px var(--ink), 0 3px 8px #0002; }
.tool { width: 60px; height: 60px; border-radius: 18px; border: 3px solid #fff; background: var(--card); font-size: 28px; box-shadow: 0 3px 8px #0002; }
.tool.on { border-color: var(--ink); background: #fff6d8; }
.talk-bubble { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); background: #fff; border-radius: 20px; padding: 10px 16px; font-size: clamp(16px, 4vw, 22px); box-shadow: 0 4px 14px #0002; max-width: 90%; text-align: center; z-index: 4; animation: fadeIn .4s; }

/* ---------- pearl polishing ---------- */
.polish-wrap { position: relative; width: min(80vw, 52vh, 420px); aspect-ratio: 1; }
.polish-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

/* ---------- hint + sparkles ---------- */
#hintHand { position: fixed; z-index: 50; font-size: 64px; pointer-events: none; opacity: 0; transition: opacity .4s; filter: drop-shadow(0 4px 6px #0003); }
#hintHand.show { opacity: .95; animation: tapHint 1.3s ease-in-out infinite; }
@keyframes tapHint { 0%,100% { transform: translate(0, 0); } 50% { transform: translate(-8px, -14px) scale(.92); } }
#sparkles { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.spark { position: absolute; font-size: 26px; animation: sparkUp 1.3s ease-out forwards; }
@keyframes sparkUp { to { transform: translate(var(--dx), -90px) scale(.4); opacity: 0; } }

/* ---------- overlays (adult) ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: #2f2a45bb; display: grid; place-items: center; padding: 12px; }
.sheet { background: #fff; border-radius: 22px; padding: 18px 20px; width: min(420px, 96vw); max-height: 92vh; overflow: auto; -webkit-user-select: text; user-select: text; }
.sheet.wide { width: min(900px, 97vw); }
.sheet h2 { margin: 0 0 8px; font-size: 22px; }
.sheet h3 { margin: 16px 0 6px; font-size: 18px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; position: sticky; top: -18px; background: #fff; padding: 6px 0; z-index: 2; }
.text-btn { border: 0; background: #f1ecf7; border-radius: 12px; padding: 10px 14px; font-size: 16px; margin: 3px; }
.text-btn.on { background: #d9f2e5; }
.gate-answer { font-size: 32px; min-height: 44px; text-align: center; letter-spacing: 4px; border-bottom: 2px solid #ddd; margin-bottom: 10px; }
.gate-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.gate-pad button { height: 54px; font-size: 24px; border: 0; border-radius: 12px; background: #f1ecf7; }
.src { background: #faf7f0; border-left: 4px solid var(--gold); padding: 8px 12px; margin: 6px 0; font-family: Georgia, serif; font-size: 15px; line-height: 1.45; white-space: pre-wrap; }
.src .anchor { display: block; font-family: var(--font); font-size: 12px; color: var(--soft); margin-top: 4px; }
.review { background: #fff4f4; border-left: 4px solid #e39a9a; padding: 8px 12px; margin: 6px 0; font-size: 14px; }
.adult-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.setting-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; flex-wrap: wrap; font-size: 15px; }
.setting-row input[type=range] { width: 180px; }
.setting-row select { font-size: 15px; max-width: 240px; }
.log-stats { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: #f6f6f6; padding: 8px; border-radius: 8px; white-space: pre-wrap; }

@media (max-width: 520px) {
  #topbar { gap: 6px; padding-left: 6px; padding-right: 6px; }
  .icon-btn { width: 48px; height: 48px; font-size: 24px; }
  .icon-btn.small { width: 36px; height: 36px; font-size: 17px; }
  #meterHeart { width: 34px; height: 31px; }
  #meter { padding: 4px 8px 4px 4px; gap: 5px; }
  .swatch { width: 46px; height: 46px; }
  .tool { width: 50px; height: 50px; font-size: 24px; }
}
@media (max-height: 700px) {
  .cue { width: 86px; height: 96px; font-size: 36px; }
  .part { min-height: 72px; }
  .part .bead { width: 46px; height: 46px; }
  .next-pearl { width: 80px; height: 80px; }
}
@media (min-width: 900px) {
  .part { max-width: 420px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
