:root {
  --bg: #E8F4F1;
  --surface: #FFFFFF;
  --ink: #17324D;
  --muted: #5A7184;
  --line: #CFE0E4;
  --sun: #FFC93C;
  --sun-ink: #3A2A00;
  --coral: #FF6B57;
  --leaf: #2FA876;
  --leaf-bg: #DDF3E8;
  --warn-bg: #FFE8E3;
  --violet: #7B61FF;
  --r: 18px;
  --f-display: "Baloo 2", "Trebuchet MS", system-ui, sans-serif;
  --f-body: "Nunito", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 17px; line-height: 1.45;
  min-height: 100vh; min-height: 100dvh;
  padding-top: env(safe-area-inset-top, 0); padding-bottom: env(safe-area-inset-bottom, 0);
}
h1, h2, h3 { font-family: var(--f-display); font-weight: 800; line-height: 1.1; margin: 0; text-wrap: balance; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--ink); }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

#app { max-width: 520px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
.screen { display: flex; flex-direction: column; gap: 14px; padding: 12px max(16px, env(safe-area-inset-left, 0)) 24px max(16px, env(safe-area-inset-right, 0)); }

/* ---------- Buttons ---------- */
.btn { border: 0; border-radius: 16px; min-height: 52px; padding: 0 22px; font-family: var(--f-display); font-weight: 800; font-size: 19px; background: var(--surface); color: var(--ink); border: 2px solid var(--line); display: inline-flex; align-items: center; justify-content: center; gap: 10px; transition: transform .08s; }
.btn:active { transform: translateY(2px) scale(.99); }
.btn.primary { background: var(--sun); border-color: #E8AE1A; color: var(--sun-ink); box-shadow: 0 4px 0 #E8AE1A; }
.btn.primary:active { box-shadow: 0 1px 0 #E8AE1A; }
.btn.go { background: var(--leaf); border-color: #228A5F; color: #fff; box-shadow: 0 4px 0 #228A5F; }
.btn.block { width: 100%; }
.btn.small { min-height: 42px; font-size: 16px; padding: 0 16px; border-radius: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }
.chip { border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 15px; min-height: 40px; }
.chip:active { background: var(--bg); }
.ico { width: 22px; height: 22px; flex: none; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.topbar .back { width: 44px; height: 44px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); display: grid; place-items: center; flex: none; }
.topbar .title { font-family: var(--f-display); font-weight: 800; font-size: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dots { display: flex; gap: 6px; align-items: center; }
.dots i { width: 22px; height: 8px; border-radius: 999px; background: #CBDDE2; display: block; }
.dots i.on { background: var(--leaf); }
.dots i.now { background: var(--sun); }
.tools { display: flex; gap: 8px; }
.tool { width: 44px; height: 44px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 15px; }
.tool[aria-pressed="true"] { background: var(--sun); border-color: #E8AE1A; }

/* ---------- Stage ---------- */
.stage { position: relative; width: 100%; aspect-ratio: 360 / 300; border-radius: 22px; overflow: hidden; border: 3px solid #fff; box-shadow: 0 6px 18px rgba(23, 50, 77, .14); background: #cde; isolation: isolate; }
.stage .layer { position: absolute; inset: 0; }
.stage .layer svg { display: block; width: 100%; height: 100%; }
.stage .layer.back { z-index: 1; }
.stage .layer.front { z-index: 3; pointer-events: none; }
.actor { position: absolute; bottom: 5%; width: 34%; z-index: 2; transform-origin: 50% 100%; }
.actor.you { left: 4%; z-index: 4; }
.actor.npc { right: 4%; }
.actor.flip .char-svg { transform: scaleX(-1); }
.char-svg { display: block; width: 100%; height: auto; overflow: visible; animation: bob 2.6s ease-in-out infinite; }
.actor.you .char-svg { animation-delay: -1.2s; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.08); } }
.mouth-open { opacity: 0; transform-box: fill-box; transform-origin: center; }
.actor.talking .mouth-closed { opacity: 0; }
.actor.talking .mouth-open { animation: talk .26s ease-in-out infinite alternate; }
@keyframes talk { from { opacity: 1; transform: scaleY(.3); } to { opacity: 1; transform: scaleY(1); } }
.actor.talking { animation: nod .5s ease-in-out infinite alternate; }
@keyframes nod { from { transform: translateY(0); } to { transform: translateY(-2px); } }
.actor.happy { animation: hop .7s ease-out; }
@keyframes hop { 0% { transform: translateY(0); } 30% { transform: translateY(-14px) rotate(-2deg); } 55% { transform: translateY(0); } 75% { transform: translateY(-6px) rotate(2deg); } 100% { transform: translateY(0); } }
.actor.oops { animation: wobble .6s ease-in-out; }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
.actor.enter-l { animation: slideL .6s ease-out both; }
.actor.enter-r { animation: slideR .6s ease-out both; }
@keyframes slideL { from { transform: translateX(-60%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideR { from { transform: translateX(60%); opacity: 0; } to { transform: none; opacity: 1; } }
.spark { position: absolute; z-index: 6; width: 14px; height: 14px; background: var(--sun); clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%); animation: spark .9s ease-out forwards; pointer-events: none; }
@keyframes spark { from { transform: translate(0, 0) scale(.4); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(1.2) rotate(90deg); opacity: 0; } }

.bubble { position: absolute; z-index: 5; top: 5%; left: 5%; right: 5%; background: #fff; border-radius: 18px; padding: 10px 14px; box-shadow: 0 4px 14px rgba(23, 50, 77, .18); max-height: 52%; overflow: hidden; }
.bubble::after { content: ""; position: absolute; bottom: -10px; width: 20px; height: 20px; background: #fff; transform: rotate(45deg); border-radius: 4px; }
.bubble[data-side="npc"]::after { right: 17%; }
.bubble[data-side="you"]::after { left: 17%; }
.bubble[data-side="you"] { background: #FFF6D6; }
.bubble[data-side="you"]::after { background: #FFF6D6; }
.bubble .en { font-family: var(--f-display); font-weight: 800; font-size: 20px; line-height: 1.15; }
.bubble .vi { margin-top: 4px; font-size: 14px; color: var(--muted); line-height: 1.25; }
.bubble .dotty::after { content: "..."; animation: dots 1s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 33% { content: "."; } 66% { content: ".."; } 100% { content: "..."; } }

/* ---------- Panels, cards ---------- */
.panel { background: var(--surface); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; border: 2px solid var(--line); }
.panel .hint { color: var(--muted); font-size: 15px; }
.card { background: var(--surface); border: 2px solid var(--line); border-radius: 22px; padding: 18px; }
.label { font-weight: 800; font-size: 15px; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.center { justify-content: center; }
.row.between { justify-content: space-between; }
.options { display: flex; flex-direction: column; gap: 10px; }
.opt { text-align: left; border: 2px solid var(--line); background: #fff; border-radius: 16px; padding: 13px 16px; font-weight: 800; font-size: 18px; min-height: 56px; }
.opt:active { background: var(--bg); }
.opt.right { border-color: var(--leaf); background: var(--leaf-bg); }
.opt.wrong { border-color: var(--coral); background: var(--warn-bg); animation: wobble .4s; }
.opt[disabled] { cursor: default; }
.say { font-family: var(--f-display); font-weight: 800; font-size: 26px; line-height: 1.15; }
.say-vi { color: var(--muted); font-size: 16px; }
.note { border-radius: 14px; padding: 10px 14px; font-size: 16px; }
.note.ok { background: var(--leaf-bg); }
.note.fix { background: var(--warn-bg); }
.note b { font-weight: 800; }
.err { color: #C2392B; font-weight: 700; min-height: 22px; font-size: 15px; }
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 14px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 999px; font-family: var(--f-display); font-weight: 800; z-index: 50; animation: toast 1.8s ease-out forwards; }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -10px); } 12% { opacity: 1; transform: translate(-50%, 0); } 80% { opacity: 1; } 100% { opacity: 0; } }
.stars { display: flex; gap: 4px; }
.stars svg { width: 24px; height: 24px; }
.stars.big svg { width: 44px; height: 44px; }
.stars .off path { fill: #D6E3E7; }
.stars .on path { fill: var(--sun); stroke: #E8AE1A; }
.bar { height: 12px; border-radius: 999px; background: #CFE3E8; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--leaf); border-radius: 999px; transition: width .5s; }

/* ---------- Login ---------- */
.hero { position: relative; border-radius: 0 0 28px 28px; overflow: hidden; margin: 0 -16px; aspect-ratio: 360 / 215; background: #cde; }
.hero svg.sc { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero .a { position: absolute; bottom: 4%; width: 22%; }
.hero .a.l { left: 22%; } .hero .a.r { right: 22%; }
.brand { text-align: center; display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.brand h1 { font-size: 40px; color: var(--ink); }
.brand h1 span { color: var(--coral); }
.brand p { margin: 0; color: var(--muted); }
.login-card { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 800; }
.input { width: 100%; border: 2px solid var(--line); border-radius: 16px; padding: 0 16px; min-height: 54px; font-size: 19px; font-weight: 700; background: #fff; }
.input:focus { border-color: var(--sun); outline: none; box-shadow: 0 0 0 4px rgba(255, 201, 60, .35); }
textarea.input { padding: 12px 16px; min-height: 76px; resize: none; line-height: 1.3; }
.guest { background: #FFF3D1; border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.guest .label { color: #6B5200; }
.tiny { font-size: 14px; color: var(--muted); text-align: center; }

/* ---------- Story ---------- */
.levels { display: flex; flex-direction: column; gap: 10px; }
.lv { display: flex; gap: 14px; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 12px 14px; animation: rise .5s ease-out both; }
.lv:nth-child(2) { animation-delay: .15s; } .lv:nth-child(3) { animation-delay: .3s; } .lv:nth-child(4) { animation-delay: .45s; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.lv .n { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-family: var(--f-display); font-weight: 800; font-size: 22px; color: #fff; flex: none; }
.lv .t { display: flex; flex-direction: column; min-width: 0; }
.lv .t b { font-family: var(--f-display); font-size: 19px; }
.lv .t span { color: var(--muted); font-size: 15px; }
.avatars { display: flex; gap: 10px; justify-content: center; }
.avatars button { width: 64px; height: 76px; border-radius: 16px; border: 3px solid var(--line); background: #fff; padding: 4px; overflow: hidden; }
.avatars button[aria-pressed="true"] { border-color: var(--sun); background: #FFF6D6; }
.avatars svg { width: 100%; height: 100%; display: block; }

/* ---------- Map ---------- */
.me { display: flex; align-items: center; gap: 12px; }
.me .face { width: 56px; height: 56px; border-radius: 50%; background: #FFF6D6; border: 3px solid var(--sun); overflow: hidden; flex: none; }
.me .face svg { width: 150%; margin: -4px 0 0 -25%; display: block; }
.me .who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.me .who b { font-family: var(--f-display); font-size: 20px; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .who span { color: var(--muted); font-size: 14px; }
.lvl { display: inline-block; background: var(--sun); color: var(--sun-ink); font-family: var(--f-display); font-weight: 800; padding: 2px 12px; border-radius: 999px; font-size: 15px; }
.prog { display: flex; flex-direction: column; gap: 6px; }
.prog .row { font-weight: 800; font-size: 15px; }
.place { position: relative; border: 3px solid #fff; border-radius: 20px; overflow: hidden; padding: 0; text-align: left; background: #fff; box-shadow: 0 4px 12px rgba(23, 50, 77, .12); display: block; width: 100%; }
.place:active { transform: scale(.985); }
.place .art { display: block; width: 100%; aspect-ratio: 360 / 150; position: relative; background: #cde; }
.place .art > svg, .place .art > span > svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.place .art .a svg { position: static; height: auto; }
.place .art .a { position: absolute; bottom: 2%; width: 34%; display: block; }
.place .meta { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px 10px; gap: 8px; }
.places .place .meta { flex-direction: column; align-items: flex-start; }
.place .meta b { font-family: var(--f-display); font-size: 19px; line-height: 1.1; }
.place .meta small { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.places { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.place.wide { grid-column: 1 / -1; }
.place.wide .art { aspect-ratio: 360 / 130; }
.locked { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.locked .lk { background: #DCE7EA; border-radius: 16px; padding: 10px 8px; text-align: center; color: var(--muted); font-weight: 800; font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.locked .lk b { font-family: var(--f-display); font-size: 16px; color: #43606F; line-height: 1.1; }
.badge { background: var(--leaf-bg); color: #145236; font-weight: 800; font-size: 13px; padding: 2px 10px; border-radius: 999px; }

/* ---------- Hall ---------- */
.missions { display: flex; flex-direction: column; gap: 6px; }
.mi { display: flex; gap: 10px; align-items: center; font-size: 15px; background: var(--bg); border-radius: 12px; padding: 8px 10px; }
.mi .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #B5CBD2; flex: none; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px; }
.mi.done { background: var(--leaf-bg); }
.mi.done .tick { background: var(--leaf); border-color: var(--leaf); }
.mi small { color: var(--muted); display: block; }
.phrases { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
.phrases .chip { white-space: nowrap; flex: none; }
.result h2 { font-size: 28px; }
.result p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
