:root {
  --sky: #3bb6f5;
  --ink: #3a2a1a;
  --red: #ff5a5f;
  --yellow: #ffd23f;
  --green: #4cd37b;
  --purple: #9b6bff;
  --card: #fffdf6;
  --shadow: 0 0.6vmin 0 rgba(0,0,0,.18);
  --hz: "Kaiti SC", "STKaiti", "KaiTi", "BiauKai", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", sans-serif;
  --ui: "Baloo 2", "Chalkboard SE", "Comic Sans MS", "PingFang SC", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #2a9fe0;
  font-family: var(--ui); color: var(--ink);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none; touch-action: none;
}
img { -webkit-user-drag: none; user-select: none; pointer-events: none; }
button { font-family: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
#screen { position: absolute; inset: 0; }
.screen { position: absolute; inset: 0; background-size: cover; background-position: center; animation: screenIn .45s ease-out; }
@keyframes screenIn { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: none; } }

#fx { position: absolute; inset: 0; pointer-events: none; z-index: 50; width: 100%; height: 100%; }

/* ---------- HUD ---------- */
#hud { position: absolute; top: 0; left: 0; right: 0; height: calc(11vmin + env(safe-area-inset-top, 0px)); display: flex; align-items: center; gap: 2vmin; padding: 1.5vmin max(2vmin, env(safe-area-inset-right, 0px)) 1.5vmin max(2vmin, env(safe-area-inset-left, 0px)); padding-top: max(1.5vmin, calc(env(safe-area-inset-top, 0px) + 1vmin)); z-index: 30; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hudTitle { flex: 1; text-align: center; font-size: 4.2vmin; font-weight: 800; color: #fff; text-shadow: 0 .4vmin 0 rgba(0,0,0,.25); font-family: var(--hz); }
#starTotal { background: #fff; border-radius: 99px; padding: 1vmin 2.4vmin; font-size: 3.6vmin; font-weight: 800; box-shadow: var(--shadow); }
.round-btn { width: 9vmin; height: 9vmin; border-radius: 50%; background: #fff; font-size: 4.6vmin; box-shadow: var(--shadow); display: grid; place-items: center; transition: transform .1s; }
.round-btn:active, .big-btn:active, .tile:active { transform: scale(.92); }

/* ---------- Panda ---------- */
#pandaWrap { position: absolute; right: 1vmin; bottom: 0; width: 22vmin; z-index: 40; touch-action: none; }
#panda { width: 100%; display: block; transform-origin: 50% 100%; animation: breathe 2.6s ease-in-out infinite; pointer-events: auto; cursor: pointer; filter: drop-shadow(0 1vmin 1vmin rgba(0,0,0,.25)); }
@keyframes breathe { 0%,100% { transform: scale(1,1); } 50% { transform: scale(1.03,.97); } }
#panda.squish { animation: squish .5s ease; }
@keyframes squish { 0% { transform: scale(1,1); } 30% { transform: scale(1.25,.75); } 55% { transform: scale(.85,1.2) translateY(-8%); } 80% { transform: scale(1.05,.95); } 100% { transform: scale(1,1); } }
#panda.jump { animation: jump .7s ease; }
@keyframes jump { 0%,100% { transform: translateY(0) rotate(0); } 40% { transform: translateY(-35%) rotate(-8deg); } 60% { transform: translateY(-35%) rotate(8deg); } }
#panda.shake { animation: shake .5s ease; }
@keyframes shake { 0%,100% { transform: rotate(0); } 20% { transform: rotate(-10deg); } 40% { transform: rotate(10deg); } 60% { transform: rotate(-6deg); } 80% { transform: rotate(6deg); } }
#panda.chomp { animation: chomp .6s ease; }
@keyframes chomp { 0%,100% { transform: scale(1); } 25% { transform: scale(1.15,.9); } 50% { transform: scale(.95,1.08); } 75% { transform: scale(1.1,.92); } }

#bubble { position: absolute; bottom: 92%; right: 30%; width: max-content; min-width: 20vmin; max-width: 52vmin; background: #fff; border-radius: 3vmin; padding: 1.6vmin 2.4vmin; box-shadow: 0 .8vmin 2vmin rgba(0,0,0,.2); animation: pop .3s ease-out; pointer-events: none; }
#bubble::after { content: ""; position: absolute; right: 12%; bottom: -2.2vmin; border: 1.4vmin solid transparent; border-top: 2.2vmin solid #fff; }
#bubble .bt { font-family: var(--hz); font-size: 4vmin; font-weight: 700; }
#bubble .bp { font-size: 2.4vmin; color: #7a6a5a; margin-top: .4vmin; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } 70% { transform: scale(1.08); } to { transform: scale(1); opacity: 1; } }

/* ---------- Start ---------- */
.start { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vmin; }
.title { font-size: 9vmin; font-weight: 900; color: #fff; font-family: var(--hz); text-shadow: 0 .8vmin 0 #e0457b, 0 1.4vmin 2vmin rgba(0,0,0,.25); letter-spacing: .5vmin; animation: wobble 3s ease-in-out infinite; }
.subtitle { font-size: 4vmin; color: #fff; font-weight: 800; text-shadow: 0 .4vmin 0 rgba(0,0,0,.25); }
@keyframes wobble { 0%,100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg) scale(1.03); } }
.start-panda { width: 34vmin; animation: float 3s ease-in-out infinite; filter: drop-shadow(0 2vmin 2vmin rgba(0,0,0,.25)); }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3vmin); } }
.big-btn { background: var(--yellow); font-size: 6vmin; font-weight: 900; padding: 2vmin 8vmin; border-radius: 99px; box-shadow: 0 1.2vmin 0 #d9a400, 0 2vmin 3vmin rgba(0,0,0,.2); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.07); } }

/* ---------- Map ---------- */
.map { background: #39b3ef; display: grid; place-items: center; }
.map-board { position: relative; width: min(100vw, 150vh); aspect-ratio: 3 / 2; background: url(../assets/img/bg_map.webp) center / 100% 100% no-repeat; }
.pin { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: .6vmin; background: none; }
.pin .flag { background: #fff; border-radius: 3vmin; padding: 1vmin 2.4vmin; box-shadow: var(--shadow); text-align: center; border: .6vmin solid var(--yellow); animation: bob 2s ease-in-out infinite; }
.pin .flag b { display: block; white-space: nowrap; font-family: var(--hz); font-size: 4.2vmin; }
.pin .flag small { font-size: 2.2vmin; color: #7a6a5a; display: block; }
.pin .flag .pstars { font-size: 2.6vmin; }
.pin .num { width: 7vmin; height: 7vmin; border-radius: 50%; background: var(--red); color: #fff; font-size: 4vmin; font-weight: 900; display: grid; place-items: center; box-shadow: var(--shadow); }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-1vmin); } }
.map-panda { position: absolute; width: 13vmin; transform: translate(-50%, -85%); transition: left .9s ease-in-out, top .9s ease-in-out; animation: float 2s ease-in-out infinite; pointer-events: none; z-index: 5; }

/* ---------- Lesson hub ---------- */
.hub { display: flex; flex-direction: column; align-items: center; padding-top: 13vmin; }
.hub-head { background: rgba(255,255,255,.92); border-radius: 4vmin; padding: 1.5vmin 5vmin; text-align: center; box-shadow: var(--shadow); }
.hub-head .h { font-family: var(--hz); font-size: 7vmin; font-weight: 800; }
.hub-head .p { font-size: 2.8vmin; color: #7a6a5a; }
.tiles { display: grid; grid-template-columns: repeat(3, 24vmin); gap: 3vmin; margin-top: 4vmin; }
.tile { height: 24vmin; border-radius: 4vmin; background: var(--card); box-shadow: 0 1.2vmin 0 rgba(0,0,0,.18); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5vmin; transition: transform .1s; animation: tileIn .5s backwards ease-out; border: .8vmin solid #fff; }
.tile .ic { font-size: 9vmin; line-height: 1; }
.tile .nm { font-family: var(--hz); font-size: 4vmin; font-weight: 800; }
.tile .en { font-size: 2.1vmin; color: #7a6a5a; font-weight: 700; }
.tile .st { font-size: 2.6vmin; letter-spacing: .2vmin; }
.tile:nth-child(1) { background: #ffe9a8; } .tile:nth-child(2) { background: #ffd0e0; }
.tile:nth-child(3) { background: #c9f2d6; } .tile:nth-child(4) { background: #cfe6ff; }
.tile:nth-child(5) { background: #e6d8ff; } .tile:nth-child(6) { background: #ffdcc4; }
@keyframes tileIn { from { transform: translateY(6vmin) scale(.6); opacity: 0; } }
@media (orientation: portrait) { .tiles { grid-template-columns: repeat(2, 30vmin); } .tile { height: 26vmin; } }

/* ---------- Game common ---------- */
.game { overflow: hidden; }
.game .dim { position: absolute; inset: 0; background: rgba(255,255,255,.18); }
.prompt { position: absolute; top: 12vmin; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 2vmin; z-index: 5; }
.speak { width: 12vmin; height: 12vmin; border-radius: 50%; background: var(--red); color: #fff; font-size: 6vmin; box-shadow: 0 1vmin 0 #c93c41; animation: pulse 1.6s infinite; }
.progress { position: absolute; top: 12.5vmin; left: 2vmin; display: flex; gap: 1vmin; z-index: 5; }
.progress i { width: 3vmin; height: 3vmin; border-radius: 50%; background: rgba(255,255,255,.7); border: .4vmin solid #fff; }
.progress i.done { background: var(--green); }
.progress i.cur { background: var(--yellow); transform: scale(1.3); }
.card { background: var(--card); border-radius: 3vmin; box-shadow: 0 1vmin 0 rgba(0,0,0,.15), 0 1vmin 3vmin rgba(0,0,0,.15); }
.hz { font-family: var(--hz); font-weight: 700; }
.wiggle { animation: shake .5s ease; }
.boing { animation: boingAnim .6s ease; }
@keyframes boingAnim { 0%,100% { transform: scale(1); } 30% { transform: scale(1.3); } 60% { transform: scale(.9); } }

/* Balloons */
.balloon { position: absolute; width: 19vmin; height: 23vmin; touch-action: none; will-change: transform; }
.balloon .b { position: absolute; inset: 0 0 4vmin 0; border-radius: 50% 50% 48% 48% / 55% 55% 45% 45%; box-shadow: inset -2vmin -2vmin 0 rgba(0,0,0,.12), inset 2vmin 2vmin 0 rgba(255,255,255,.35); display: grid; place-items: center; font-family: var(--hz); font-size: 9vmin; font-weight: 800; color: #fff; text-shadow: 0 .4vmin 0 rgba(0,0,0,.25); }
.balloon .b::after { content: ""; position: absolute; bottom: -1.4vmin; left: 50%; transform: translateX(-50%); border: 1.2vmin solid transparent; border-bottom: 1.6vmin solid currentColor; color: inherit; }
.balloon .s { position: absolute; left: 50%; bottom: 0; height: 5vmin; border-left: .3vmin solid rgba(0,0,0,.4); }

/* Feed the panda */
.wish { position: absolute; top: 14vmin; left: 6vw; width: 34vmin; height: 34vmin; display: grid; place-items: center; padding: 2vmin; animation: float 3s ease-in-out infinite; }
.wish img { width: 100%; height: 100%; object-fit: contain; }
.wish .think { position: absolute; bottom: -3vmin; right: -2vmin; font-size: 6vmin; }
.big-panda { position: absolute; right: 8vw; bottom: 6vmin; width: 42vmin; filter: drop-shadow(0 1.5vmin 1.5vmin rgba(0,0,0,.25)); transform-origin: 50% 100%; }
.big-panda .mouth-target { position: absolute; left: 25%; right: 25%; top: 20%; height: 45%; border-radius: 50%; }
.big-panda img { width: 100%; display: block; }
.big-panda.hot img { filter: brightness(1.12) drop-shadow(0 0 3vmin #fff36b); }
.foods { position: absolute; left: 4vw; bottom: 5vmin; display: flex; gap: 3vmin; }
.food { width: 20vmin; height: 20vmin; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #ffe7b0 60%, #f5c56b); border: .6vmin solid #e0a43c; display: grid; place-items: center; font-family: var(--hz); font-size: 11vmin; font-weight: 800; box-shadow: 0 1vmin 0 rgba(0,0,0,.2); touch-action: none; position: relative; z-index: 3; }
.food.dragging { z-index: 20; box-shadow: 0 3vmin 3vmin rgba(0,0,0,.3); transform: scale(1.12); }
.food.home { transition: left .3s, top .3s, transform .3s; }
.num-dots { display: flex; flex-wrap: wrap; gap: 1vmin; justify-content: center; align-content: center; }
.num-dots img { width: 8vmin; height: 8vmin; }
.num-dots.few img { width: 18vmin; height: 18vmin; }

/* Sentence train */
.track { position: absolute; left: 0; right: 0; top: 52vh; height: 2vmin; background: repeating-linear-gradient(90deg, #8a5a2b 0 3vmin, transparent 3vmin 5vmin), #6b4423; border-radius: 1vmin; }
.train { position: absolute; left: 2vw; top: calc(52vh - 22vmin); display: flex; align-items: flex-end; gap: 1vmin; transition: transform 1.4s cubic-bezier(.2,.8,.3,1); }
.train.leave { transition: transform 2.2s cubic-bezier(.6,0,.9,.5); }
.engine { width: 24vmin; height: 22vmin; font-size: 18vmin; line-height: 22vmin; text-align: center; transform: scaleX(-1); }
.car { width: 18vmin; height: 18vmin; background: var(--red); border-radius: 2vmin 2vmin 1vmin 1vmin; position: relative; display: grid; place-items: center; box-shadow: inset 0 -2vmin 0 rgba(0,0,0,.15); }
.car::before, .car::after { content: ""; position: absolute; bottom: -2.5vmin; width: 5vmin; height: 5vmin; border-radius: 50%; background: #333; border: 1vmin solid #999; }
.car::before { left: 2vmin; } .car::after { right: 2vmin; }
.car .slot { width: 13vmin; height: 13vmin; background: rgba(255,255,255,.85); border-radius: 1.5vmin; border: .5vmin dashed #fff; display: grid; place-items: center; font-family: var(--hz); font-size: 10vmin; font-weight: 800; }
.car .slot.filled { background: #fff; border-style: solid; animation: pop .3s; }
.car .slot.lit { background: var(--yellow); }
.car:nth-child(3n) { background: var(--purple); } .car:nth-child(3n+1) { background: #2fb6ff; }
.tiles-row { position: absolute; left: 0; right: 24vmin; bottom: 6vmin; display: flex; justify-content: center; gap: 2.5vmin; flex-wrap: wrap; }
.ctile { width: 15vmin; height: 15vmin; border-radius: 2.5vmin; background: #fff; border: .6vmin solid var(--yellow); display: grid; place-items: center; font-family: var(--hz); font-size: 10vmin; font-weight: 800; box-shadow: 0 1vmin 0 rgba(0,0,0,.18); touch-action: none; position: relative; }
.ctile.used { visibility: hidden; }
.ctile.dragging { z-index: 20; transform: scale(1.12); }
.sent-pic { position: absolute; right: 6vw; top: 13vmin; width: 26vmin; height: 26vmin; padding: 1.5vmin; }
.sent-pic img { width: 100%; height: 100%; object-fit: contain; }
.smoke { position: absolute; font-size: 6vmin; animation: puff 1.2s ease-out forwards; pointer-events: none; }
@keyframes puff { from { opacity: .9; transform: translate(0,0) scale(.5); } to { opacity: 0; transform: translate(-6vmin,-14vmin) scale(2); } }

/* Writing */
.write-area { position: absolute; top: 12vmin; bottom: 2vmin; left: 0; right: 22vmin; display: flex; align-items: center; justify-content: center; gap: 4vmin; }
.write-side { display: flex; flex-direction: column; align-items: center; gap: 2vmin; }
.write-side .model { width: 22vmin; height: 22vmin; display: grid; place-items: center; font-family: var(--hz); font-size: 17vmin; font-weight: 700; color: var(--red); }
.write-side .py { font-size: 4.5vmin; font-weight: 800; }
.pad-wrap { position: relative; touch-action: none; }
.pad { width: min(68vmin, 62vw); height: min(68vmin, 62vw); background: #fff; border: .8vmin solid var(--red); border-radius: 2vmin; box-shadow: 0 1.2vmin 0 rgba(0,0,0,.18); touch-action: none; position: relative; }
.pad svg.grid { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tool-row { display: flex; gap: 2vmin; }
.write-queue { display: flex; gap: 1.2vmin; }
.write-queue span { width: 7vmin; height: 7vmin; border-radius: 1.5vmin; background: rgba(255,255,255,.85); display: grid; place-items: center; font-family: var(--hz); font-size: 5vmin; font-weight: 800; }
.write-queue span.done { background: var(--green); color: #fff; }
.write-queue span.cur { background: var(--yellow); transform: scale(1.15); }
@media (orientation: portrait) { .write-area { flex-direction: column; right: 0; bottom: 22vmin; } }

/* Picture pick / count */
.pick-row { position: absolute; left: 0; right: 22vmin; top: 30vmin; display: flex; justify-content: center; gap: 4vmin; flex-wrap: wrap; padding: 0 2vmin; }
.pick { width: 30vmin; height: 34vmin; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2vmin; transition: transform .15s; animation: tileIn .5s backwards; }
.pick img { width: 100%; height: 26vmin; object-fit: contain; }
.pick .lb { font-family: var(--hz); font-size: 4.5vmin; font-weight: 800; min-height: 5vmin; }
.pick.right { background: #d8ffe4; transform: scale(1.1) rotate(-3deg); }
.apples { position: absolute; top: 14vmin; left: 4vw; right: 26vmin; height: 40vmin; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 2vmin; padding: 2vmin; }
.apples img { width: 13vmin; height: 13vmin; animation: appleIn .45s backwards cubic-bezier(.3,1.6,.6,1); pointer-events: auto; }
.apples img.counted { filter: drop-shadow(0 0 1.5vmin #fff36b); transform: scale(1.1); }
@keyframes appleIn { from { transform: translateY(-30vmin) scale(.3); opacity: 0; } }
.choices { position: absolute; bottom: 6vmin; left: 0; right: 24vmin; display: flex; justify-content: center; gap: 4vmin; }
.choice { width: 18vmin; height: 18vmin; font-family: var(--hz); font-size: 12vmin; font-weight: 800; border-radius: 3vmin; background: #fff; border: .7vmin solid var(--purple); box-shadow: 0 1vmin 0 rgba(0,0,0,.2); }

/* Story */
.story-list { position: absolute; top: 12vmin; left: 3vw; right: 26vmin; bottom: 1vmin; display: flex; flex-direction: column; gap: 1.2vmin; overflow-y: auto; touch-action: pan-y; padding: 1vmin; }
.line { display: flex; align-items: center; gap: 2vmin; animation: tileIn .5s backwards; }
.line .who { width: 11vmin; height: 11vmin; flex: none; border-radius: 50%; background: #fff; box-shadow: var(--shadow); overflow: hidden; display: grid; place-items: center; }
.line .who img { width: 115%; height: 115%; object-fit: contain; margin-top: 2vmin; }
.line .say { background: #fff; border-radius: 3vmin; padding: 1vmin 2.4vmin; box-shadow: var(--shadow); text-align: left; border: .5vmin solid transparent; position: relative; }
.line .say .t { font-family: var(--hz); font-size: 4.2vmin; font-weight: 700; }
.line .say .t span.lit { color: var(--red); }
.line .say .p { font-size: 2.5vmin; color: #7a6a5a; }
.line.heard .say { border-color: var(--green); }
.line.heard .say::after { content: "✓"; position: absolute; right: -1.5vmin; top: -1.5vmin; width: 4.5vmin; height: 4.5vmin; border-radius: 50%; background: var(--green); color: #fff; font-size: 3vmin; display: grid; place-items: center; }
.line.playing .who { animation: jump .7s ease infinite; }

/* Result */
.result { position: absolute; inset: 0; background: rgba(30,40,80,.55); display: grid; place-items: center; z-index: 45; animation: screenIn .3s; }
.result .box { background: #fff; border-radius: 5vmin; padding: 4vmin 6vmin; text-align: center; box-shadow: 0 2vmin 4vmin rgba(0,0,0,.3); animation: pop .5s; }
.result .stars { font-size: 13vmin; letter-spacing: 1vmin; }
.result .stars span { display: inline-block; animation: starIn .6s backwards cubic-bezier(.3,1.8,.6,1); }
.result .stars span.off { filter: grayscale(1) opacity(.35); }
@keyframes starIn { from { transform: scale(0) rotate(-180deg); } }
.result h2 { font-family: var(--hz); font-size: 7vmin; margin: 1vmin 0; }
.result img { width: 24vmin; }
.result .row { display: flex; gap: 3vmin; justify-content: center; margin-top: 2vmin; }
.result .row button { font-size: 4vmin; font-weight: 900; padding: 1.6vmin 4vmin; border-radius: 99px; box-shadow: 0 .8vmin 0 rgba(0,0,0,.2); }
.btn-green { background: var(--green); color: #fff; } .btn-yellow { background: var(--yellow); }

.hint-hand { position: absolute; left: 0; top: 0; font-size: 10vmin; margin: -2vmin 0 0 -3vmin; pointer-events: none; z-index: 30; filter: drop-shadow(0 .6vmin .6vmin rgba(0,0,0,.3)); }
.feed-tip { position: absolute; left: 50%; top: 12vmin; transform: translateX(-10%); background: rgba(255,255,255,.92); border-radius: 3vmin; padding: 1vmin 2.4vmin; font-family: var(--hz); font-size: 3.6vmin; font-weight: 800; box-shadow: var(--shadow); text-align: center; }
.feed-tip small { display: block; font-family: var(--ui); font-size: 2.2vmin; color: #7a6a5a; }

.voice-switch { position: absolute; bottom: 2.5vmin; left: 50%; transform: translateX(-50%); background: rgba(255,255,255,.92); border-radius: 99px; padding: .9vmin 1.6vmin .9vmin 2.2vmin; font-size: 2.4vmin; font-weight: 800; display: flex; align-items: center; gap: 1.6vmin; box-shadow: var(--shadow); white-space: nowrap; }
.voice-switch .vs-grp { display: inline-flex; align-items: center; gap: .7vmin; cursor: pointer; }
.voice-switch b { padding: .5vmin 1.5vmin; border-radius: 99px; background: #eee; color: #888; }
.voice-switch b.on { background: var(--green); color: #fff; }
.voice-switch a { margin-left: .4vmin; color: #2d6cdf; font-size: 2.3vmin; }
