/* ===== โทนสีและค่าพื้นฐาน ===== */
:root {
  --ink: #2b2d42;
  --ink-soft: #5c607e;
  --sky-1: #74c4f5;
  --sky-2: #cdeeff;
  --sea-1: #4fb6e8;
  --sea-2: #2f93cc;
  --sand: #ffe3a1;
  --grass: #8fd47e;
  --sun: #ffd166;
  --coral: #ff7f6e;
  --good: #4fc463;
  --shadow: rgba(43, 45, 66, .18);
  --tap: 84px;
  --radius: 28px;
  --font: "Mali", "Sukhumvit Set", "Thonburi", "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
}
@media (max-height: 560px), (max-width: 480px) { :root { --tap: 64px; --radius: 22px; } }
@media (max-width: 420px) { :root { --tap: 56px; } }

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font); font-weight: 500; color: var(--ink); background: var(--sky-2);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; -webkit-appearance: none; appearance: none; }
h1, h2, h3, p { margin: 0; }
#app { position: fixed; inset: 0; }

.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

/* ===== ปุ่มแบบของเล่น (กดแล้วยุบ) ===== */
.btn3d {
  --c: #fff;
  background: var(--c); border-radius: var(--radius);
  box-shadow: 0 7px 0 rgba(0, 0, 0, .16), 0 12px 22px var(--shadow);
  box-shadow: 0 7px 0 color-mix(in srgb, var(--c) 72%, #000), 0 12px 22px var(--shadow);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn3d:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, .16), 0 5px 10px var(--shadow);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--c) 72%, #000), 0 5px 10px var(--shadow);
}
.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: calc(var(--tap) * .46); line-height: 1;
}

/* ภาพไอคอนและภาพประกอบ (มี emoji สำรองถ้าโหลดภาพไม่ได้) */
img.ico, img.art { display: block; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.icon-btn img.ico { width: 68%; height: 68%; }
.parent-btn { display: inline-flex; align-items: center; gap: 6px; }
img.lock-ico { width: 18px; height: 18px; }

/* ===== ตุ้บตั้บ: ภาพ 4 ท่าซ้อนกัน แสดงทีละท่าตาม class ===== */
.mascot { height: var(--m, 260px); aspect-ratio: 484 / 693; flex: none; position: relative; }
.mascot .m-body { position: absolute; inset: 0; transform-origin: 50% 100%; animation: breathe 3s ease-in-out infinite; }
.mascot .pose {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%;
  display: none; pointer-events: none; -webkit-user-drag: none; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .15));
}
.mascot .pose-wave { display: block; }
.mascot.happy .pose-wave, .mascot.open .pose-wave, .mascot.sleepy .pose-wave { display: none; }
.mascot.happy .pose-jump, .mascot.open .pose-eat, .mascot.sleepy .pose-sleep { display: block; }
.mascot.happy .m-body { animation: hop .6s ease-out; }
/* ชูมือชูงวงดีใจ (ป้อนครบ / แตะบนแผนที่) */
.mascot.cheer .pose-wave, .mascot.cheer .pose-hungry, .mascot.cheer .pose-jump { display: none !important; }
.mascot.cheer .pose-cheer { display: block; }
.mascot.cheer .m-body { animation: hop .6s ease-out; }
/* หิว: หน้าเศร้า ลูบท้อง ถอนหายใจ (ระหว่างเคี้ยว/ดีใจ ท่ากิน/กระโดดจะแสดงแทน) */
.mascot.hungry .pose-wave { display: none; }
.mascot.hungry:not(.open):not(.happy):not(.cheer) .pose-hungry { display: block; }
.mascot.hungry:not(.open):not(.happy):not(.cheer) .m-body { animation: fa-sigh 3.4s ease-in-out infinite; }
.mascot.rumble:not(.open):not(.happy) .m-body { animation: fa-rumble .8s ease-in-out; }
.mascot.sleepy .m-body { animation: breathe 4s ease-in-out infinite; }
.mascot .zzz { display: none; position: absolute; top: 14%; right: -6%; color: #fff; font-weight: 700; font-size: calc(var(--m, 260px) * .1); }
.mascot.sleepy .zzz { display: block; }
.mascot .zzz span { display: inline-block; animation: zz 2.4s ease-in-out infinite; }
.mascot .zzz span + span { font-size: 1.4em; animation-delay: 1.2s; }

/* ฉากเกาะ (ภาพพื้นหลังหน้าเริ่มและหน้าหลัก) */
.island-bg { background: #8fd3f5 url("../assets/island.webp") center 62% / cover no-repeat; }

/* ===== หน้าเริ่ม ===== */
.start { align-items: center; justify-content: center; gap: clamp(6px, 2vh, 18px); text-align: center; }
.title {
  font-size: clamp(36px, min(10vw, 13vh), 104px); font-weight: 700; color: #fff; line-height: 1.3;
  text-shadow: 0 5px 0 #3d9bd6, 0 10px 24px rgba(0, 0, 0, .18); position: relative; z-index: 1;
}
.subtitle { font-size: clamp(20px, min(3.4vw, 4.5vh), 34px); color: #24557a; position: relative; z-index: 1; }
.m-start { --m: clamp(110px, min(44vw, 40vh), 420px); }
/* หน้าปกใหม่ (ถ้าโหลดภาพปกไม่ได้ จะเห็นภาพเกาะเดิมแทน) */
.cover-bg { background: #8fd3f5 url("../assets/cover.webp") center 60% / cover no-repeat; background-image: url("../assets/cover.webp"), url("../assets/island.webp"); }
@media (orientation: portrait) { .cover-bg { background-image: url("../assets/cover-portrait.webp"), url("../assets/island.webp"); background-position: center; } }
/* มือถือจอยาว: ไม่ตัดตัวละครขอบซ้ายขวา — วางภาพเต็มความกว้างชิดล่าง แล้วเติมสีฟ้าเดียวกับขอบบนของภาพ */
@media (orientation: portrait) and (max-aspect-ratio: 2/3) { .cover-bg { background-color: #0591f9; background-size: 100% auto; background-position: center bottom; } }
.start.cover-bg { justify-content: space-between; padding-top: max(2.5vh, env(safe-area-inset-top)); padding-bottom: max(3vh, env(safe-area-inset-bottom)); }
.start-head { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.start-space { flex: 1; }
.cover-bg .subtitle { padding: 2px 18px; border-radius: 999px; background: rgba(255, 255, 255, .78); }
.play-btn {
  width: clamp(80px, min(16vw, 20vh), 160px); aspect-ratio: 1; border-radius: 50%;
  color: var(--good); font-size: clamp(44px, min(7vw, 9vh), 72px);
  animation: pulse 1.6s ease-in-out infinite; position: relative; z-index: 1;
}
.play-btn img.ico, .go-btn img.ico { width: 100%; height: 100%; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .25)); }
.play-btn:active, .go-btn:active { transform: scale(.92); }

/* ===== หน้าหลัก: แผนที่เกาะเรียนรู้ ===== */
.hub-top { position: relative; z-index: 3; display: flex; align-items: center; flex: none; }
.badge {
  position: absolute; top: -8px; right: -8px; min-width: 30px; height: 30px; padding: 0 7px;
  border-radius: 999px; background: var(--coral); color: #fff; font-size: 16px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 2px 0 rgba(0, 0, 0, .15);
}
.parent-btn {
  margin-left: auto; padding: 8px 14px; border-radius: 999px; font-size: 15px;
  background: rgba(255, 255, 255, .75); color: var(--ink-soft);
}


/* ===== หน้าเกม ===== */
.game { background: linear-gradient(180deg, #fffaf0 0%, #fff 45%, var(--c) 240%); }
.topbar { display: flex; align-items: center; gap: 12px; position: relative; z-index: 5; padding-bottom: 10px; flex: none; }
.tools { display: flex; gap: 12px; }
.stars {
  margin-left: auto; display: flex; gap: 2px; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .92); box-shadow: 0 4px 12px var(--shadow); font-size: calc(var(--tap) * .4); line-height: 1.2;
}
.star { filter: grayscale(1) brightness(.9); opacity: .5; transition: opacity .2s; }
.star.on { filter: none; opacity: 1; animation: pop .5s; }
img.star { width: calc(var(--tap) * .44); height: calc(var(--tap) * .44); object-fit: contain; }
@media (max-width: 480px) { .stars { font-size: 20px; padding: 4px 8px; } img.star { width: 22px; height: 22px; } }
/* จอแคบ: แถบบนมีปุ่มเยอะ (เช่น แท็บ ก/A/中) → ย้ายดาวลงไปใต้แถบ */
@media (max-width: 480px) {
  .game-alphabet .topbar { gap: 8px; }
  .game-alphabet .tools { gap: 8px; }
  .game-alphabet .stars { position: absolute; right: 0; top: calc(100% - 4px); }
}
.stage { flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; }

/* ฉากหลังของแต่ละเกม (assets/bg/*.webp) — ทับด้วยสีขาวโปร่งนิดหน่อยให้การ์ดเด่นขึ้น */
.game-alphabet, .game-counting, .game-shapes, .game-animals { background-color: #fffaf0; background-size: cover; background-position: center; }
.game-alphabet { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/alphabet.webp"); }
.game-counting { background-image: linear-gradient(rgba(255, 255, 255, .2), rgba(255, 255, 255, .2)), url("../assets/bg/counting.webp"); }
.game-shapes { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/shapes.webp"); }
.game-animals { background-image: linear-gradient(rgba(255, 255, 255, .2), rgba(255, 255, 255, .2)), url("../assets/bg/animals.webp"); }

/* การ์ดตัวเลือก */
.choices { display: flex; flex-wrap: wrap; gap: clamp(12px, 2.5vw, 28px); justify-content: center; }
.card {
  width: clamp(96px, min(18vw, 26vh), 190px); aspect-ratio: 1; border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.card .letter { font-size: clamp(52px, min(9vw, 13vh), 104px); font-weight: 700; line-height: 1.15; color: var(--lc, var(--ink)); }
.card .pic { font-size: clamp(28px, min(4vw, 6vh), 44px); line-height: 1.2; }
.card .name { font-size: clamp(14px, 1.8vw, 20px); color: var(--ink-soft); }
.card img.pic { width: 46%; height: auto; aspect-ratio: 1; }
.letter-card img.pic { width: 38%; }
.animal-card img.pic { width: 74%; transform-origin: 50% 90%; }
/* เสียงหาย: หน้าเศร้า ถอนหายใจ (ตัวละจังหวะ) · ได้เสียงคืน: กระโดดดีใจ */
.animal-card.lost img.pic { animation: fa-sigh 3.4s ease-in-out infinite; }
.animal-card.lost:nth-child(2n) img.pic { animation-delay: -1.1s; } .animal-card.lost:nth-child(3n) img.pic { animation-delay: -2.2s; }
.animal-card.right img.pic { animation: fa-hop 1.6s ease-in-out .6s infinite; }
img.prompt-img { width: clamp(76px, min(14vw, 19vh), 150px); height: auto; aspect-ratio: 1; transform-origin: 50% 90%; }
/* ก-ไก่: เพื่อนทำตัวอักษรหาย หน้าเศร้า ถอนหายใจ → หาเจอแล้วกระโดดดีใจ */
.prompt.missing img.prompt-img { animation: fa-sigh 3.4s ease-in-out infinite; }
.prompt.found img.prompt-img { animation: fa-hop 1.6s ease-in-out infinite; }
img.prompt-ear { width: clamp(30px, 3.6vw, 44px); height: auto; aspect-ratio: 1; }
.card.tried { opacity: .35; filter: grayscale(.6); pointer-events: none; }
.card.right { box-shadow: 0 0 0 8px #7be07b, 0 12px 22px var(--shadow); animation: bounce .8s; }

.quiz, .animals { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(14px, 4vh, 40px); width: 100%; }
.prompt { display: flex; align-items: center; gap: 10px; border-radius: 999px; padding: 6px 22px 6px 14px; }
.prompt-pic { font-size: clamp(52px, min(9vw, 13vh), 96px); line-height: 1.15; }
.prompt-ear { font-size: clamp(24px, 3vw, 34px); }

/* แท็บตัวอักษร ก / A / 中 */
.script-tabs { display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: rgba(255, 255, 255, .75); }
.script-tab { width: calc(var(--tap) * .78); height: calc(var(--tap) * .78); border-radius: 50%; font-size: calc(var(--tap) * .38); font-weight: 700; line-height: 1; color: var(--ink); }
.script-tab[data-k="zh"] { font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif; }
.script-tab.on { background: #ffd166; box-shadow: 0 0 0 4px #fff, 0 5px 0 #d9a93e; }
@media (max-width: 480px) { .script-tabs { gap: 3px; padding: 3px; } .script-tab { width: 40px; height: 40px; font-size: 20px; } }
.letter-card.script-zh .letter { font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif; font-weight: 600; line-height: 1.05; }
.letter-card.script-en .letter { letter-spacing: 1px; }
.pinyin { font-size: clamp(14px, 1.9vw, 21px); font-weight: 700; line-height: 1.1; color: var(--ink-soft); }
.count-pic { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px; }
.card .count-pic { width: 76%; }
.count-pic img.cp-img { width: 30%; height: auto; aspect-ratio: 1; }
.prompt-img.count-pic { width: clamp(90px, min(16vw, 20vh), 180px); }

/* โหมดสำรวจ ก-ฮ */
.explore-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(84px, 11vw, 124px), 1fr));
  gap: 16px; width: 100%; max-width: 1000px; max-height: 100%; overflow-y: auto; padding: 8px 8px 28px;
  align-self: stretch; align-content: start; touch-action: pan-y;
}
.explore-grid .card { width: auto; }
.explore-grid .letter { font-size: clamp(40px, min(5.5vw, 8vh), 64px); }
.explore-grid .pic { font-size: clamp(22px, 3vw, 32px); }

/* เกมนับเลข */
.counting { display: flex; align-items: center; justify-content: center; gap: 4vw; width: 100%; height: 100%; }
.count-left { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.m-count { --m: clamp(170px, min(30vw, 52vh), 420px); }
.need { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 999px; padding: 8px 18px 8px 22px; box-shadow: 0 6px 16px var(--shadow); }
.big-num { font-size: clamp(40px, min(7vw, 10vh), 72px); font-weight: 700; color: var(--coral); min-width: 1.1em; text-align: center; line-height: 1.1; }
.plate { display: flex; flex-wrap: wrap; gap: 6px; max-width: min(40vw, 470px); }
/* ระดับ 2 ขึ้นไป: ปุ่ม ✓ ครบแล้ว · ป้อนเกินตุ้บตั้บส่ายหน้า */
.need .count-ok { position: static; flex: none; width: calc(var(--tap) * .8); height: calc(var(--tap) * .8); font-size: calc(var(--tap) * .38); margin: 0; animation: none; }
.need .count-ok[hidden] { display: none; }
.mascot.nope { animation: fa-nope .65s ease-in-out; }
.slot { width: clamp(30px, min(4vw, 6vh), 42px); aspect-ratio: 1; border-radius: 50%; border: 3px dashed #c9cad8; display: grid; place-items: center; font-size: clamp(18px, min(2.6vw, 4vh), 28px); }
.slot.full { border-style: solid; border-color: #ffd84d; background: #fff6d1; animation: pop .4s; }
img.slot-img { width: 86%; height: 86%; }
/* ผ้าปิกนิกลายตาราง */
.basket {
  background-color: #fff;
  background-image:
    linear-gradient(90deg, rgba(255, 107, 107, .42) 50%, transparent 50%),
    linear-gradient(rgba(255, 107, 107, .42) 50%, transparent 50%);
  background-size: 48px 48px;
  border: 6px solid #fff; border-radius: 36px; padding: clamp(14px, 2.5vw, 26px);
  display: flex; flex-wrap: wrap; gap: clamp(8px, 1.5vw, 16px); justify-content: center; align-content: center;
  max-width: 44vw; box-shadow: 0 12px 26px var(--shadow);
}
.food img.food-img { width: 100%; height: 100%; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .2)); }
.food {
  position: relative; font-size: clamp(40px, min(7vw, 9vh), 76px); width: 1.3em; height: 1.3em; line-height: 1;
  display: grid; place-items: center; cursor: grab;
}
.food.disabled { opacity: .35; pointer-events: none; }
@media (orientation: portrait) {
  .counting { flex-direction: column; gap: 3vh; }
  .basket { max-width: 92vw; }
  .plate { max-width: 70vw; }
}

/* เกมรูปทรง */
.shapes { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(14px, 5vh, 48px); width: 100%; }
.board {
  display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(10px, 2vw, 24px);
  background-color: #c98f5c;
  background-image: repeating-linear-gradient(100deg, rgba(255, 255, 255, .07) 0 6px, transparent 6px 22px, rgba(0, 0, 0, .06) 22px 25px, transparent 25px 40px);
  padding: clamp(10px, 2vw, 20px) clamp(14px, 3vw, 28px); border-radius: 32px;
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, .12), 0 10px 24px var(--shadow);
}
.hole, .piece { width: clamp(64px, min(13vw, 20vh), 140px); aspect-ratio: 1; }
.hole svg, .piece svg { width: 100%; height: 100%; display: block; }
.hole.pop svg { animation: pop .35s; }
/* รูปทรงหลงทาง: โยกเศร้า ๆ ในถาด (ตัวละจังหวะ) · กลับช่องแล้ว: กระโดดดีใจ */
.piece svg { transform-origin: 50% 90%; animation: fa-sigh 3.4s ease-in-out infinite; }
.piece.turned svg { rotate: var(--rot); transform-origin: 50% 50%; } /* ระดับ 2+: ชิ้นเอียง ต้องจำรูปทรงให้ได้ */
.piece:nth-child(2n) svg { animation-delay: -1.1s; } .piece:nth-child(3n) svg { animation-delay: -2.2s; }
.hole.home svg { transform-origin: 50% 90%; animation: pop .35s, fa-hop 1.6s ease-in-out .5s infinite; }
.tray { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(12px, 3vw, 36px); }
.piece { position: relative; cursor: grab; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, .15)); }

/* เกมเสียงสัตว์ */
.sound-btn {
  --c: var(--sun); width: clamp(110px, min(18vw, 24vh), 170px); aspect-ratio: 1; border-radius: 50%;
  font-size: clamp(52px, min(8vw, 11vh), 84px); display: grid; place-items: center; line-height: 1;
}
.sound-btn.ring { animation: ring .9s ease-out; }
.sound-btn img.sound-ico { width: 62%; height: 62%; }
.sound-btn img.sound-img { width: 82%; height: 82%; }
.animal-card .pic { font-size: clamp(56px, min(9vw, 13vh), 104px); }

/* ลาก-วาง */
.dragging { z-index: 60; transition: none !important; animation: none !important; cursor: grabbing; filter: drop-shadow(0 16px 12px rgba(0, 0, 0, .25)); }
.returning { transition: transform .3s cubic-bezier(.3, 1.4, .5, 1); }
.locked { pointer-events: none; }
.gone { visibility: hidden; }

/* ===== สติกเกอร์ ===== */
.stickers { background: linear-gradient(#ffe9c7, #fff6e6); }
.page-title { font-size: clamp(22px, 3.2vw, 34px); }
.book {
  flex: 1; min-height: 0; overflow-y: auto; width: 100%; max-width: 980px; margin: 0 auto;
  background: #fff; border-radius: 28px; padding: clamp(14px, 3vw, 28px);
  box-shadow: 0 8px 0 #f1d9b5, 0 14px 30px var(--shadow); touch-action: pan-y;
}
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(70px, 10vw, 110px), 1fr)); gap: clamp(10px, 2vw, 18px); }
.sticker { aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font-size: clamp(38px, 6vw, 64px); line-height: 1; }
.sticker.have { transform: rotate(var(--r, 0deg)); }
.sticker.have img { width: 100%; height: 100%; display: block; pointer-events: none; -webkit-user-drag: none; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .22)); }
.sticker.empty { border: 3px dashed #e8dcc8; color: #e0d2bb; font-size: clamp(22px, 3vw, 34px); }
.sticker.empty img { width: 78%; height: 78%; filter: brightness(0); opacity: .1; pointer-events: none; } /* เงาของสติกเกอร์ที่ยังไม่ได้ */
/* ตู้เย็นผลงาน: ภาพติดแม่เหล็ก เอียงนิด ๆ */
.fridge { margin-top: clamp(18px, 4vw, 34px); padding: clamp(12px, 2.5vw, 22px); border-radius: 22px; background: linear-gradient(180deg, #eef6ff, #dfeefc); box-shadow: inset 0 0 0 3px #fff; }
.fridge-title { margin: 0 0 12px; font-size: clamp(18px, 2.4vw, 26px); }
.fridge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(110px, 18vw, 180px), 1fr)); gap: clamp(12px, 2.4vw, 22px); }
.work { position: relative; padding: 8px; border: 0; border-radius: 6px; background: #fff; box-shadow: 0 6px 14px rgba(0, 0, 0, .15); transform: rotate(var(--r)); cursor: pointer; }
.work::before { content: ""; position: absolute; top: -8px; left: 50%; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ff9ab8, #e2457a); box-shadow: 0 2px 3px rgba(0, 0, 0, .3); }
.work img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; pointer-events: none; }
.work.princess img { aspect-ratio: .75; }
.work-zoom img { max-width: 90vw; max-height: 86vh; border-radius: 14px; background: #fff; padding: 10px; box-shadow: 0 14px 40px rgba(0, 0, 0, .35); }

/* ===== หน้าง่วงนอน ===== */
.night { background: linear-gradient(180deg, #1c2350, #3c3f85 70%, #5b5aa0); color: #fff; align-items: center; justify-content: center; gap: 2vh; text-align: center; }
.moon { position: absolute; top: 8%; left: 10%; width: 80px; height: 80px; border-radius: 50%; box-shadow: -18px 10px 0 0 #ffe9a8; }
.tw { position: absolute; width: 4px; height: 4px; border-radius: 50%; background: #fff; animation: twinkle 2.5s ease-in-out infinite; }
.m-sleepy { --m: clamp(150px, min(40vw, 44vh), 400px); }
.sleepy-title { font-size: clamp(30px, 5vw, 52px); position: relative; }
.sleepy-sub { font-size: clamp(18px, 2.6vw, 26px); opacity: .85; position: relative; }
.night .parent-btn { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); }

/* ===== มุมผู้ปกครอง ===== */
.parent { background: #f3f5fb; }
.parent-title { font-size: clamp(22px, 3vw, 30px); }
.parent-body {
  flex: 1; overflow-y: auto; display: grid; gap: 14px; align-content: start; touch-action: pan-y;
  width: 100%; max-width: 760px; margin: 0 auto; padding-bottom: 24px;
}
.panel { background: #fff; border-radius: 20px; padding: 16px 18px; box-shadow: 0 2px 10px rgba(43, 45, 66, .08); display: grid; gap: 10px; justify-items: start; }
.panel h3 { font-size: 18px; }
.seg-row { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { padding: 10px 16px; border-radius: 999px; background: #eef1f8; font-size: 16px; }
.seg.on { background: var(--ink); color: #fff; }
.stat-table { width: 100%; border-collapse: collapse; font-size: 16px; }
.stat-table th, .stat-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #eef0f5; }
.stat-table th { font-weight: 500; color: var(--ink-soft); font-size: 14px; }
.muted { color: var(--ink-soft); font-size: 15px; line-height: 1.55; }
.small { font-size: 13px; }
.text-btn { padding: 10px 16px; border-radius: 12px; background: #eef1f8; font-size: 15px; }
.text-btn.primary { background: var(--ink); color: #fff; margin-left: auto; }
.text-btn.danger { background: #ffe8e6; color: #c0392b; }

/* ===== ป๊อปอัป ===== */
.overlay { position: fixed; inset: 0; z-index: 100; display: flex; overflow: auto; padding: 16px; background: rgba(28, 32, 64, .45); animation: fade .2s; }
.overlay > * { margin: auto; }
.award-card {
  background: #fff; border-radius: 36px; padding: clamp(18px, 4vh, 32px) clamp(24px, 5vw, 48px);
  text-align: center; display: grid; justify-items: center; gap: 8px; animation: pop .5s; box-shadow: 0 10px 0 #f1d9b5;
}
.award-title { font-size: clamp(24px, 4vw, 40px); font-weight: 700; color: var(--coral); }
.award-sticker {
  width: clamp(130px, min(28vw, 32vh), 256px); aspect-ratio: 1; display: block; -webkit-user-drag: none;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .25)); animation: spinpop .9s ease-out;
}
.award-name { font-size: clamp(20px, 3vw, 30px); font-weight: 700; }
.go-btn { width: calc(var(--tap) * 1.1); height: calc(var(--tap) * 1.1); border-radius: 50%; color: var(--good); font-size: calc(var(--tap) * .42); }

.gate-card { background: #fff; border-radius: 24px; padding: 20px; width: min(92vw, 360px); text-align: center; display: grid; gap: 10px; }
.gate-card h3 { font-size: 20px; }
.gate-q { font-size: 17px; line-height: 1.5; }
.gate-display { height: 52px; border-radius: 12px; background: #f3f5fb; font-size: 30px; display: grid; place-items: center; letter-spacing: 4px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.key { height: 54px; border-radius: 12px; background: #eef1f8; font-size: 24px; }
.key:active { background: #dfe4f1; }
.keypad.off { pointer-events: none; opacity: .5; }
.gate-msg { color: #c0392b; min-height: 1.4em; font-size: 15px; }
.gate-cancel { font-size: 15px; color: var(--ink-soft); padding: 8px; }
@media (max-height: 560px) { .key { height: 40px; font-size: 20px; } .gate-display { height: 42px; } }

/* ===== กรอบข้อความเสียงพูด ===== */
.bubble {
  position: fixed; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(86vw, 560px); padding: 6px 16px; border-radius: 18px; z-index: 90; pointer-events: none;
  background: rgba(255, 255, 255, .92); color: var(--ink-soft); font-size: clamp(14px, 1.8vw, 19px);
  box-shadow: 0 4px 12px var(--shadow); transition: opacity .3s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bubble.hide { opacity: 0; }


/* ===== หน้าหลัก: หมู่เกาะสายรุ้ง (world.js) ===== */
.world { padding: 0; background: linear-gradient(#00a4f9, #04b6f2 45%, #01cfe8); }
.world-strip {
  /* isolation: อาคาร (z-index สูงตามความลึก) ต้องไม่ลอยทับแถบบนตอนจอแนวตั้ง */
  position: absolute; inset: 0; isolation: isolate; display: flex; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory;
  scrollbar-width: none; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.world-strip::-webkit-scrollbar { display: none; }
.island { position: relative; flex: 0 0 100%; height: 100%; scroll-snap-align: start; }
.island-map {
  --mw: min(100vw, 177.78vh); position: absolute; left: 50%; top: 50%; width: var(--mw); aspect-ratio: 16 / 9;
  transform: translate(-50%, -50%); background: var(--map) center / 100% 100% no-repeat;
}
.spot {
  position: absolute; left: var(--x); top: var(--y); width: var(--w); transform: translate(-50%, -74%); z-index: 2;
  display: flex; flex-direction: column; align-items: center; padding: 0; border: 0; background: none; cursor: pointer; transition: transform .1s;
}
.spot:active { transform: translate(-50%, -74%) scale(.94); }
.spot-img { width: 100%; height: auto; display: block; pointer-events: none; filter: drop-shadow(0 8px 8px rgba(0, 0, 0, .22)); animation: floaty 3.4s ease-in-out infinite; }
.spot:nth-child(2n) .spot-img { animation-delay: .9s; } .spot:nth-child(3n) .spot-img { animation-delay: 1.7s; } .spot:nth-child(5n) .spot-img { animation-delay: 2.5s; }
.spot-name {
  position: relative; z-index: 1; margin-top: -9%; padding: 2px 12px; border-radius: 999px; background: rgba(255, 255, 255, .95); white-space: nowrap;
  font-size: clamp(11px, min(1.9vw, 3.3vh), 24px); font-weight: 700; box-shadow: 0 3px 0 rgba(0, 0, 0, .08);
}
.island-town .spot-name { margin-top: -3%; font-size: clamp(10px, min(1.35vw, 2.4vh), 17px); padding: 1px 9px; }
.spot.locked .spot-img { filter: grayscale(.85) opacity(.75); }
.spot.locked .spot-name { color: var(--ink-soft); }
.s-stickers { z-index: 3; }
.s-stickers .badge { top: 4%; right: 2%; }
.world-mascot { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -92%); z-index: 4; cursor: pointer; }
.world-mascot .m-hub { --m: calc(var(--mw) * .19); }
.world-king { position: absolute; left: 50%; top: 1%; width: 10%; padding: 0; border: 0; background: none; z-index: 3; cursor: pointer; animation: floaty 2.6s ease-in-out infinite; }
.world-king img { width: 100%; height: auto; display: block; filter: drop-shadow(0 0 14px rgba(255, 255, 255, .9)); }
.world-king:not(.happy) img { animation: pulse 1.2s ease-in-out infinite; }
/* ความมีชีวิตบนแผนที่: เมฆ นก เรือ */
.w-cloud { position: absolute; top: 3%; width: 13%; aspect-ratio: 2.6; border-radius: 50%; pointer-events: none; z-index: 1; opacity: .85;
  background: radial-gradient(ellipse at 30% 60%, #fff 0 38%, transparent 40%), radial-gradient(ellipse at 62% 45%, #fff 0 44%, transparent 46%), radial-gradient(ellipse at 50% 72%, #fff 0 50%, transparent 52%);
  filter: drop-shadow(0 4px 6px rgba(80, 140, 200, .25)); left: 0; animation: w-drift 46s linear infinite; }
.w-cloud.c2 { top: 9%; width: 9%; animation-duration: 64s; animation-delay: -30s; opacity: .7; }
.w-birds { position: absolute; top: 14%; left: 0; width: 7%; height: 4%; pointer-events: none; z-index: 1; animation: w-birds-x 22s linear infinite, w-birds-y 22s linear infinite; }
.w-birds i { position: absolute; width: 34%; aspect-ratio: 2; border: 2px solid #3b4a5a; border-color: #3b4a5a transparent transparent; border-radius: 50% 50% 0 0; animation: wing 0.6s ease-in-out infinite; }
.w-birds i:nth-child(1) { left: 0; top: 30%; } .w-birds i:nth-child(2) { left: 36%; top: 0; animation-delay: .2s; } .w-birds i:nth-child(3) { left: 66%; top: 45%; animation-delay: .4s; }
.w-boat { position: absolute; bottom: 2%; left: 0; font-size: calc(var(--mw) * .035); pointer-events: none; z-index: 1; animation: w-sail 38s linear infinite, w-boat-bob 2.4s ease-in-out infinite; }
/* ขยับด้วย transform/translate (ไม่ใช้ left) — ลื่นบน iPad รุ่นเก่า · --mw = ความกว้างแผนที่ */
@keyframes w-drift { from { transform: translateX(calc(var(--mw) * -.15)); } to { transform: translateX(calc(var(--mw) * 1.05)); } }
@keyframes w-birds-x { from { translate: calc(var(--mw) * -.1) 0; } to { translate: calc(var(--mw) * 1.05) 0; } }
@keyframes w-birds-y { 0% { transform: translateY(0); } 50% { transform: translateY(-30%); } 100% { transform: translateY(10%); } }
@keyframes w-sail { from { translate: calc(var(--mw) * -.06) 0; } to { translate: calc(var(--mw) * 1.02) 0; } }
@keyframes w-boat-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-18%); } }
/* เกาะที่เลื่อนออกนอกจอ: หยุดแอนิเมชันทั้งหมด ประหยัดแบตและเครื่อง */
.island.idle *, .island.idle *::before, .island.idle *::after { animation-play-state: paused !important; }
@keyframes cloud-drift { from { left: -15%; } to { left: 105%; } }
@keyframes spin-slow { to { transform: rotate(360deg); } }
@keyframes birds-fly { from { left: -10%; transform: translateY(0); } 50% { transform: translateY(-30%); } to { left: 105%; transform: translateY(10%); } }
@keyframes wing { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(.4) translateY(30%); } }
@keyframes boat-sail { from { left: -6%; } to { left: 102%; } }
@keyframes bob { 0%, 100% { margin-bottom: 0; } 50% { margin-bottom: .6%; } }
/* สะพานไม้เชื่อมเกาะ */
.bridge {
  --bw: calc(var(--mw) * .13 + (100vw - var(--mw)));
  position: absolute; left: calc(97.5% - var(--bw) / 2 + (100vw - var(--mw)) / 2); top: 57%; width: var(--bw); aspect-ratio: 1;
  transform: translate(0, -50%); z-index: 5; pointer-events: none;
  background: url("../assets/world/bridge.webp") center / 100% auto no-repeat; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .25));
}
/* แถบบน */
.world-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6; display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
}
.island-tabs { display: flex; gap: 8px; }
.island-tab { display: flex; align-items: center; gap: 6px; padding: 6px 14px 6px 10px; border-radius: 999px; font-weight: 700; font-size: clamp(13px, 1.6vw, 18px); }
.island-tab.on { background: #ffd166; box-shadow: 0 0 0 3px #fff, 0 5px 0 #d9a93e; }
.it-icon { font-size: 1.3em; line-height: 1; }
.story-btn { margin-left: auto; width: calc(var(--tap) * .7); height: calc(var(--tap) * .7); font-size: calc(var(--tap) * .34); }
.world-top .parent-btn { margin-left: 0; }
.world-arrow {
  position: absolute; top: 50%; z-index: 6; width: calc(var(--tap) * .78); height: calc(var(--tap) * .78); border-radius: 50%;
  transform: translateY(-50%); font-size: calc(var(--tap) * .3); color: var(--ink); opacity: .92;
}
.world-arrow.prev { left: max(10px, env(safe-area-inset-left)); }
.world-arrow.next { right: max(10px, env(safe-area-inset-right)); }
.world-arrow.hide { display: none; }
@media (max-width: 1180px) { .it-name { display: none; } .island-tab { padding: 6px 10px; } } /* 4 เกาะ: จอไม่กว้างพอ แสดงแค่ไอคอน */
@media (orientation: portrait) {
  .world-strip {
    flex-direction: column; overflow-x: hidden; overflow-y: auto; scroll-snap-type: none; gap: 14vw;
    padding: calc(var(--tap) * 1.5 + 20px) 0 90px;
  }
  .island { flex: 0 0 auto; height: auto; }
  .island-map { --mw: 100vw; position: relative; left: auto; top: auto; transform: none; width: 100vw; }
  /* เกาะเรียงต่อกันในแนวตั้ง: ขอบบน-ล่างของภาพจางกลืนไปกับทะเล ไม่เห็นรอยต่อเป็นเส้นตรง (จางเฉพาะภาพ ไม่ตัดอาคารที่ยื่นออกนอกกรอบ) */
  .island-map { background: none; }
  .island-map::before {
    content: ''; position: absolute; inset: 0; z-index: 0; pointer-events: none; background: var(--map) center / 100% 100% no-repeat;
    -webkit-mask-image: linear-gradient(transparent, #000 8%, #000 90%, transparent); mask-image: linear-gradient(transparent, #000 8%, #000 90%, transparent);
  }
  .w-boat { bottom: 11%; }
  .bridge { --bw: calc(14vw + var(--mw) * .1); left: calc(26% - var(--bw) / 2); top: calc(98% + 7vw); transform: translate(0, -50%) rotate(90deg); }
  .world-arrow { display: none; }
  .spot-name { font-size: clamp(10px, 3vw, 16px); padding: 1px 8px; }
  .island-town .spot-name { font-size: clamp(8px, 2.3vw, 13px); padding: 0 6px; }
}
/* จอมือถือแคบ: ชื่ออาคารในเมืองยาวเกินจนทับกัน — ซ่อนไว้ (แตะแล้วเข้าเกมได้เลย) */
@media (orientation: portrait) and (max-width: 560px) { .island-town .spot-name { display: none; } }
.rainbow-meter {
  display: flex; gap: 2px; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .92); box-shadow: 0 4px 12px var(--shadow);
}
.rainbow-meter { align-items: center; }
.sleepy-toast {
  position: fixed; left: 50%; top: max(14px, env(safe-area-inset-top)); z-index: 300; transform: translateX(-50%); padding: 10px 18px; border-radius: 999px;
  background: #2f2a52; color: #fff; font-weight: 700; font-size: clamp(15px, 2vw, 20px); box-shadow: 0 8px 22px rgba(0, 0, 0, .3); animation: pop .4s;
}
.stat-table tr.off td { opacity: .45; }
.stat-table .seg.small { padding: 4px 10px; font-size: 14px; }
.rm-piece { width: clamp(13px, 2.3vw, 30px); height: auto; aspect-ratio: 1; object-fit: contain; filter: grayscale(1); opacity: .35; }
.rm-count { margin-left: 6px; font-weight: 700; font-size: clamp(13px, 1.7vw, 20px); color: #7a4fd0; white-space: nowrap; }
/* ตึกต่อไปที่ควรไปช่วยเพื่อน: มือชี้เด้ง ๆ */
.bld-next { position: absolute; top: 2%; left: 4%; z-index: 3; font-size: clamp(28px, 4.2vw, 54px); transform: rotate(-20deg); animation: point-bob 1s ease-in-out infinite; pointer-events: none; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .3)); }
@keyframes point-bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 22%; } }
/* ในเกม: เพื่อนที่ติดในฟองสบู่ + จุดบอกว่าเหลืออีกกี่ข้อ */
.rescue-hint { margin-left: auto; display: flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border: 0; border-radius: 999px; background: rgba(255, 255, 255, .92); box-shadow: 0 4px 12px var(--shadow); cursor: pointer; }
.rescue-hint + .stars { margin-left: 8px; }
.rh-bubble {
  width: calc(var(--tap) * .62); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .95) 0 7%, rgba(255, 255, 255, .3) 8% 55%, rgba(160, 210, 255, .5) 75%, rgba(255, 170, 230, .75) 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85);
}
.rh-bubble img { width: 78%; height: 78%; object-fit: contain; }
.rh-dots { display: flex; gap: 4px; }
.rh-dots i { width: 12px; height: 12px; border-radius: 50%; background: #e3dcef; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .15); }
.rh-dots i.on { background: #ff7eb6; animation: pop .4s; }
.rescue-hint.wobble .rh-bubble { animation: wiggle .6s ease-in-out 2; }
@media (max-width: 480px) { .rh-dots i { width: 9px; height: 9px; } .rescue-hint { padding: 3px 7px 3px 3px; } }
.rm-piece.on { filter: none; opacity: 1; animation: pop .5s; }
.bld-soon {
  position: absolute; top: 34%; padding: 2px 10px; border-radius: 10px; background: rgba(73, 80, 87, .85); color: #fff;
  font-size: clamp(10px, 1.1vw, 14px); transform: rotate(-8deg); white-space: nowrap;
}
.bld-bubble {
  position: absolute; top: -24%; right: -12%; width: 50%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .95) 0 7%, rgba(255, 255, 255, .3) 8% 55%, rgba(160, 210, 255, .5) 75%, rgba(255, 170, 230, .75) 100%);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .85), 0 4px 10px rgba(0, 0, 0, .15); animation: floaty 2.6s ease-in-out infinite;
}
.bld-bubble img { width: 72%; height: 72%; object-fit: contain; }
.bld-saved { position: absolute; top: -30%; right: -8%; width: 48%; height: auto; animation: floaty 3s ease-in-out infinite; }

/* ===== ฉากเปิดเรื่อง ===== */
.intro { background: #1f2a44; padding: 0; cursor: pointer; }
.intro-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: blur(24px) brightness(.8); transform: scale(1.1); }
.intro-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.intro-bottom {
  position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(94vw, 860px); display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 22px;
  background: rgba(255, 255, 255, .95); border-radius: 26px; box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}
.intro-text { flex: 1; text-align: center; }
.intro-caption { font-size: clamp(16px, 2.3vw, 26px); line-height: 1.5; font-weight: 700; }
.intro-dots { display: flex; justify-content: center; gap: 8px; margin-top: 6px; }
.intro-dots span { width: 10px; height: 10px; border-radius: 50%; background: #cfd4e4; }
.intro-dots span.on { background: var(--coral); }
.intro-next { flex: none; }
body:has(.intro) .bubble { display: none; } /* คำบรรยายแสดงในกล่องของฉากอยู่แล้ว */
.intro-skip {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); z-index: 2;
  padding: 8px 16px; border-radius: 999px; background: rgba(255, 255, 255, .88); font-size: 16px;
}

/* ===== ฉากช่วยเพื่อนสำเร็จ ===== */
.rescue-card {
  position: relative; width: min(90vw, 460px); display: grid; justify-items: center; gap: 6px; text-align: center;
  padding: clamp(16px, 3vh, 28px) clamp(20px, 4vw, 40px); border-radius: 36px; background: #fff;
  box-shadow: 0 10px 0 #d9e4ff; animation: pop .5s;
}
.rs-cloud { width: clamp(90px, 16vh, 150px); height: auto; animation: floaty 2.4s ease-in-out infinite; }
.rs-cloud.happy { animation: hop .6s ease-out, floaty 2.4s ease-in-out .6s infinite; }
.rs-bubble { position: relative; width: clamp(130px, 24vh, 210px); aspect-ratio: 1; display: grid; place-items: center; }
.rs-bubble::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .95) 0 7%, rgba(255, 255, 255, .25) 8% 55%, rgba(160, 210, 255, .45) 75%, rgba(255, 170, 230, .7) 100%);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .85), 0 6px 18px rgba(0, 0, 0, .15); animation: wobble 2s ease-in-out infinite;
}
.rs-bubble.pop::before { animation: burst-bubble .45s ease-out forwards; }
.rs-friend { position: relative; width: 72%; height: 72%; object-fit: contain; }
.rs-bubble:not(.pop) .rs-friend { transform-origin: 50% 90%; animation: fa-sigh 3.4s ease-in-out infinite; } /* เศร้าอยู่ในฟอง */
.rs-bubble.pop .rs-friend { transform-origin: 50% 90%; animation: hop .7s ease-out .4s, fa-hop 1.6s ease-in-out 1.1s infinite; } /* ออกมาได้ กระโดดดีใจ */
.rs-title { font-size: clamp(20px, 3vw, 30px); font-weight: 700; }
.rs-piece {
  display: flex; align-items: center; gap: 8px; font-size: clamp(18px, 2.4vw, 26px); font-weight: 700;
  opacity: 0; transform: scale(.5); transition: opacity .4s, transform .4s cubic-bezier(.3, 1.5, .5, 1);
}
.rs-piece.show { opacity: 1; transform: none; }
.rs-piece img { width: clamp(70px, 13vh, 120px); height: auto; } /* ชิ้นสายรุ้งใหญ่ เห็นชัดว่าได้ของสำคัญ */
.rs-go { visibility: hidden; }
.rs-go.show { visibility: visible; animation: pop .4s; }

/* ===== ตัวละครประจำเกม (มุมล่างซ้าย) ===== */
.host {
  position: absolute; left: max(6px, env(safe-area-inset-left)); bottom: 0; height: clamp(110px, 26vh, 240px); width: auto;
  z-index: 3; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .2));
}
@media (orientation: portrait), (max-width: 760px) { .host { display: none; } }

/* ===== เกมในเมือง ===== */
.game-farm, .game-routine, .game-tidy { background-color: #fffaf0; background-size: cover; background-position: center; }
.game-farm { background-image: linear-gradient(rgba(255, 255, 255, .15), rgba(255, 255, 255, .15)), url("../assets/bg/animals.webp"); }
.game-routine { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/alphabet.webp"); }
.game-tidy { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/shapes.webp"); }
.farm, .routine, .tidy {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(14px, 4vh, 40px); width: 100%; height: 100%;
}

/* ฟาร์ม */
.farm-row { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(10px, 2vw, 24px); }
.farm-animal {
  position: relative; width: clamp(110px, min(19vw, 27vh), 200px); padding: 10px 8px 8px; border-radius: 28px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; background: rgba(255, 255, 255, .9);
  box-shadow: 0 6px 0 rgba(0, 0, 0, .08), 0 10px 20px var(--shadow);
}
.fa-body { position: relative; width: 78%; transform-origin: 50% 92%; }
.fa-body img.fa-img { width: 100%; height: auto; aspect-ratio: 1; }
/* หิว: ถอนหายใจ ตัวห่อ โยกช้า ๆ */
.farm-animal.hungry .fa-body { animation: fa-sigh 3.4s ease-in-out var(--d, 0s) infinite; }
.farm-animal.hungry .fa-img { filter: saturate(.85); }
/* ท้องร้อง: ตัวสั่นดุ๊กดิ๊ก มีคลื่นโครก ๆ ที่ท้อง */
.fa-growl { position: absolute; left: 50%; top: 66%; font-size: clamp(16px, 2.4vw, 26px); font-weight: 700; color: #b0763a; opacity: 0; pointer-events: none; transform: translate(-50%, 0); }
.farm-animal.rumble .fa-body { animation: fa-rumble .8s ease-in-out; }
.farm-animal.rumble .fa-growl { animation: fa-growl .9s ease-out; }
/* อาหารลอยมาใกล้: ตาโต ลุกขึ้นรอ เด้งดึ๋ง ๆ */
.farm-animal.eager .fa-body { animation: fa-eager .45s ease-in-out infinite alternate; }
.farm-animal.eager { box-shadow: 0 0 0 5px #ffd166, 0 10px 20px var(--shadow); }
/* อาหารไม่ถูก: ส่ายหน้า */
.fa-body.nope { animation: fa-nope .65s ease-in-out !important; }
/* ได้กิน: เคี้ยวหงับ ๆ แล้วกระโดดดีใจ */
.farm-animal.munch .fa-body { animation: fa-munch .38s ease-in-out 3; }
.farm-animal.happy .fa-body { animation: fa-hop 1.6s ease-in-out infinite; }
.farm-animal.fed .fa-plate { transform: scale(0); opacity: 0; transition: transform .3s, opacity .3s; }
@keyframes fa-sigh { 0%, 100% { transform: translateY(0) rotate(0) scale(1, 1); } 35% { transform: translateY(3%) rotate(-2.5deg) scale(1.02, .96); } 70% { transform: translateY(1%) rotate(2deg) scale(1, .99); } }
@keyframes fa-rumble { 0%, 100% { transform: translateX(0) scale(1); } 15%, 45%, 75% { transform: translateX(-3%) scale(1.02, .98); } 30%, 60%, 90% { transform: translateX(3%) scale(.98, 1.02); } }
@keyframes fa-growl { 0% { opacity: 0; transform: translate(-50%, 0) scale(.6); } 30% { opacity: 1; transform: translate(-10%, -10%) scale(1.1); } 100% { opacity: 0; transform: translate(30%, -60%) scale(1.3); } }
@keyframes fa-eager { from { transform: translateY(-3%) scale(1.04); } to { transform: translateY(-9%) scale(1.08) rotate(2deg); } }
@keyframes fa-nope { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(-9deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(-6deg); } 80% { transform: rotate(4deg); } }
@keyframes fa-munch { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.07, .9); } }
@keyframes mood-droop { 0%, 100% { transform: translateY(0) scale(1, 1); } 40% { transform: translateY(1.5%) scale(1.01, .975); } }
@keyframes ponder { 0%, 100% { transform: rotate(0); } 30%, 55% { transform: rotate(-6deg); } 75% { transform: rotate(3deg); } }
@keyframes sob { 0%, 100% { transform: translateY(0) scale(1, 1); } 15% { transform: translateY(1%) scale(1.02, .97); } 30% { transform: translateY(0) scale(1, 1); } 45% { transform: translateY(1%) scale(1.02, .97); } 60% { transform: translateY(0); } }
@keyframes fa-hop { 0%, 60%, 100% { transform: translateY(0) scale(1, 1); } 10% { transform: translateY(0) scale(1.06, .92); } 25% { transform: translateY(-12%) scale(.97, 1.04); } 40% { transform: translateY(0) scale(1.05, .94); } 50% { transform: translateY(0) scale(1, 1); } }
/* ฉลองตอนช่วยสำเร็จ: กระโดดตัวลอย แล้วเต้นดุ๊กดิ๊กต่อ (แทนท่าดีใจเดิมของแต่ละเกม) */
.joy { transform-origin: 50% 90%; animation: joy-jump .95s cubic-bezier(.3, .7, .4, 1), joy-dance 1.3s ease-in-out .95s infinite !important; }
.pr-big.joy, .pr-final-body.joy, .kid-card.joy, .m-body.joy, .cl-patient.joy, .th-toy.joy { --jump: 13%; --hop: 5%; }
.pl-owner.joy, .dt-patient.joy { --jump: 20%; --hop: 8%; }
.sw-body.joy, .zoo-home.joy { display: block; }
@keyframes joy-jump {
  0% { transform: translateY(0) scale(1, 1) rotate(0); }
  14% { transform: translateY(4%) scale(1.14, .82) rotate(0); }
  42% { transform: translateY(calc(var(--jump, 30%) * -1)) scale(.9, 1.12) rotate(-10deg); }
  58% { transform: translateY(calc(var(--jump, 30%) * -1.12)) scale(.94, 1.07) rotate(10deg); }
  76% { transform: translateY(0) scale(1.12, .86) rotate(0); }
  89% { transform: translateY(-7%) scale(.97, 1.04) rotate(0); }
  100% { transform: translateY(0) scale(1, 1) rotate(0); }
}
@keyframes joy-dance {
  0%, 100% { transform: translateY(0) rotate(0) scale(1, 1); }
  12% { transform: translateY(0) rotate(-7deg) scale(1.06, .94); }
  28% { transform: translateY(calc(var(--hop, 12%) * -1)) rotate(-3deg) scale(.97, 1.04); }
  44% { transform: translateY(0) rotate(7deg) scale(1.06, .94); }
  60% { transform: translateY(calc(var(--hop, 12%) * -1)) rotate(3deg) scale(.97, 1.04); }
  76% { transform: translateY(0) rotate(0) scale(1.03, .97); }
}
.fx-yay {
  position: fixed; transform: translate(-50%, -100%); padding: 4px 14px; border-radius: 999px; background: #fff; color: #ff4f8b;
  font-weight: 800; font-size: clamp(18px, 2.6vw, 30px); line-height: 1.3; white-space: nowrap; pointer-events: none;
  box-shadow: 0 6px 14px rgba(0, 0, 0, .15), 0 0 0 3px #ffd6e6; animation: fx-yay 1.6s ease-out forwards;
}
@keyframes fx-yay {
  0% { opacity: 0; transform: translate(-50%, -60%) scale(.4); }
  14% { opacity: 1; transform: translate(-50%, -115%) scale(1.18); }
  28% { transform: translate(-50%, -108%) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -175%) scale(1); }
}
.fx-heart { position: fixed; margin: -14px 0 0 -14px; font-size: 26px; line-height: 1; pointer-events: none; opacity: 0; animation: fx-heart 1.5s ease-out forwards; }
@keyframes fx-heart { 0% { opacity: 0; transform: translate(0, 0) scale(calc(var(--s) * .4)); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), -150px) scale(var(--s)); } }
.fa-name { font-weight: 700; font-size: clamp(14px, 1.8vw, 20px); }
.fa-plate {
  position: absolute; right: -8%; bottom: 20%; width: 38%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center;
  background: #fff; border: 3px dashed #c9d6b8;
}
.fa-plate img.fp-img { width: 82%; height: 82%; }
.farm-animal.fed { box-shadow: 0 0 0 6px #7be07b, 0 10px 20px var(--shadow); }
.farm-tray { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(12px, 2.5vw, 28px); padding: 12px 20px; border-radius: 28px; background: rgba(255, 255, 255, .6); }
.farm-food { position: relative; width: clamp(70px, min(11vw, 15vh), 120px); aspect-ratio: 1; cursor: grab; }
.farm-food img.ff-img { width: 100%; height: 100%; filter: drop-shadow(0 5px 4px rgba(0, 0, 0, .25)); }

/* กิจวัตรตอนเช้า */
/* ปาลินในบ้านตุ้บตั้บ/ห้องของเล่น: เศร้า/กังวล → ทำเสร็จแล้วยิ้ม (แสดงแทนรูปปาลินมุมจอ จะได้เห็นทั้งแนวตั้งและแนวนอน) */
.game-routine .host, .game-tidy .host { display: none; }
.kid-row { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 2vw, 24px); max-width: 100%; }
.kid-card { flex: none; height: clamp(130px, 31vh, 270px); aspect-ratio: 306 / 640; }
.kid-card img.kid-img { width: 100%; height: 100%; object-fit: contain; transform-origin: 50% 95%; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .2)); }
.kid-card:not(.happy) img.kid-img { animation: fa-sigh 3.4s ease-in-out infinite; }
.kid-card.happy img.kid-img { animation: fa-hop 1.6s ease-in-out infinite; }
@media (orientation: portrait) { .kid-card { height: clamp(90px, 14vh, 140px); } }
.rt-track { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(6px, 1.2vw, 14px); padding: 10px 16px; border-radius: 24px; background: rgba(255, 255, 255, .75); }
.rt-slot {
  width: clamp(56px, min(9vw, 12vh), 104px); aspect-ratio: 1; border-radius: 18px; overflow: hidden; display: grid; place-items: center;
  border: 3px dashed #c8b6a6; background: rgba(255, 255, 255, .6);
}
.rt-num { font-size: clamp(20px, 2.6vw, 30px); font-weight: 700; color: #c8b6a6; }
.rt-slot.done { border: 3px solid #7be07b; animation: pop .4s; }
.rt-slot img.rt-slot-img { width: 100%; height: 100%; object-fit: cover; }
.rt-cards { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(10px, 1.8vw, 20px); max-width: 980px; }
.rt-card { width: clamp(100px, min(16vw, 21vh), 170px); padding: 8px; border-radius: 22px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rt-card img.rt-img { width: 100%; height: auto; aspect-ratio: 1; border-radius: 14px; object-fit: cover; }
.rt-label { font-size: clamp(13px, 1.6vw, 18px); font-weight: 700; line-height: 1.25; text-align: center; }
.rt-card.hint { animation: pulse 1s ease-in-out infinite; box-shadow: 0 0 0 6px #ffd166, 0 12px 22px var(--shadow); }

/* ห้องของเล่น */
/* พรมกลางห้อง: ของเล่นตกกระจัดกระจาย (เลื่อน+เอียงแบบสุ่ม) ให้ดูรกจริง */
.td-floor {
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: clamp(4px, 1.2vw, 14px);
  min-height: 26vh; min-width: min(60vw, 520px); max-width: 900px; padding: 22px 34px; border-radius: 50% / 38%;
  background: radial-gradient(ellipse at center, #ffe3ec 0 38%, #ffd0de 39% 52%, #ffe3ec 53% 66%, #fbc2d3 67% 100%);
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, .55), 0 10px 24px var(--shadow);
}
.td-item { position: relative; width: clamp(70px, min(11vw, 15vh), 120px); aspect-ratio: 1; transform: rotate(var(--r, 0deg)); translate: var(--dx, 0) var(--dy, 0); cursor: grab; }
.td-item img.td-img { width: 100%; height: 100%; filter: drop-shadow(0 5px 4px rgba(0, 0, 0, .25)); }
.td-bins { display: flex; justify-content: center; gap: clamp(16px, 4vw, 48px); }
.td-bin {
  width: clamp(110px, min(18vw, 24vh), 190px); padding: 8px; border-radius: 26px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(255, 255, 255, .8); box-shadow: 0 6px 0 rgba(0, 0, 0, .08), 0 10px 20px var(--shadow); cursor: pointer;
}
.td-bin img.td-bin-img { width: 90%; height: auto; aspect-ratio: 1; }
.td-bin-name { font-weight: 700; font-size: clamp(13px, 1.7vw, 19px); }

/* ===== เฟส 2: สายการแพทย์ ===== */
.game-clinic, .game-dental, .game-toyhospital { background-color: #fffaf0; background-size: cover; background-position: center; }
.game-clinic { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/clinic.webp"); }
.game-dental { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/dental.webp"); }
.game-toyhospital { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/toyhospital.webp"); }
.clinic, .dental, .toyhospital { display: flex; align-items: center; justify-content: center; gap: clamp(16px, 5vw, 64px); width: 100%; height: 100%; }
@media (orientation: portrait) { .clinic, .dental, .toyhospital { flex-direction: column; gap: 3vh; } }
.cl-next { animation: pulse 1.2s ease-in-out infinite; box-shadow: 0 0 0 5px #ffd166; background: rgba(255, 247, 214, .92); border-radius: 22px; }

/* คลินิกคุณหมอ */
.cl-bed { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 18px 10px; border-radius: 32px; background: rgba(255, 255, 255, .9); box-shadow: 0 10px 24px var(--shadow); }
.cl-patient { position: relative; width: clamp(200px, min(36vw, 52vh), 400px); aspect-ratio: 1; }
.cl-patient img.cl-img { width: 100%; height: 100%; }
.cl-patient.well img.cl-img { animation: bounce .8s; }
/* ไม่สบาย: ตัวห่อ หายใจช้า ๆ (ไม่เอียง จุดตรวจบนตัวจะได้ไม่เลื่อน) · หายแล้ว: กระโดดดีใจทั้งตัว */
.cl-patient:not(.well) { transform-origin: 50% 90%; animation: mood-droop 3.4s ease-in-out infinite; }
.cl-patient.well { transform-origin: 50% 90%; animation: fa-hop 1.6s ease-in-out .8s infinite; }
.cl-patient.well::after { content: "💖"; position: absolute; top: 2%; right: 4%; font-size: clamp(32px, 4vw, 52px); animation: floaty 2s ease-in-out infinite; }
.cl-name { font-weight: 700; font-size: clamp(16px, 2vw, 22px); }
.cl-spot { position: absolute; transform: translate(-50%, -50%); pointer-events: none; }
.cl-booboo {
  width: 16%; aspect-ratio: 1; border-radius: 50%; animation: spotpulse 1.4s ease-in-out infinite;
  border: 3px dashed #e5383b; box-shadow: 0 0 0 4px rgba(255, 255, 255, .85);
  background: radial-gradient(circle, #e5383b 0 26%, rgba(229, 56, 59, .3) 28% 100%);
}
.cl-booboo.fixed { width: 28%; background: none; border: 0; box-shadow: none; animation: none; }
.cl-booboo img.cl-plaster { width: 100%; height: auto; transform: rotate(-20deg); }
.cl-thermo { width: 26%; }
.cl-thermo.put-away { opacity: 0; transition: opacity .3s; }
.cl-booboo.fixed { transition: left .35s ease-out, top .35s ease-out; }
.cl-thermo img.cl-mini { width: 100%; height: auto; transform: rotate(-35deg); filter: drop-shadow(0 0 10px rgba(255, 80, 80, .8)); }
.cl-heart { font-size: clamp(30px, 4vw, 48px); animation: spotpulse .5s ease-in-out 6, fade-away .5s 3s forwards; }
.cl-ring { position: absolute; left: 50%; top: 50%; width: 100%; aspect-ratio: 1; margin: -50% 0 0 -50%; border-radius: 50%; border: 3px solid rgba(255, 80, 110, .7); animation: ring-out 1s ease-out 3; }
.cl-ring.r2 { animation-delay: .5s; }
.cl-temp { position: absolute; left: 70%; top: -30%; padding: 2px 8px; border-radius: 10px; background: #e8f6ff; color: #1c7ed6; font-weight: 700; font-size: clamp(12px, 1.6vw, 18px); white-space: nowrap; font-variant-numeric: tabular-nums; box-shadow: 0 2px 6px rgba(0, 0, 0, .15); }
.cl-temp.hot { background: #ffe3e3; color: #e03131; animation: pop .35s; }
@keyframes ring-out { from { transform: scale(.6); opacity: 1; } to { transform: scale(2.4); opacity: 0; } }
.cl-tray { display: flex; flex-direction: column; gap: clamp(10px, 2vh, 18px); padding: 14px; border-radius: 28px; background: rgba(255, 255, 255, .9); box-shadow: 0 10px 24px var(--shadow); }
@media (orientation: portrait) { .cl-tray { flex-direction: row; } }
.cl-tool { position: relative; width: clamp(72px, min(11vw, 14vh), 120px); aspect-ratio: 1; padding: 6px; border-radius: 22px; cursor: grab; }
.cl-tool img.cl-tool-img { width: 100%; height: 100%; filter: drop-shadow(0 5px 4px rgba(0, 0, 0, .2)); }
.cl-spoon { position: fixed; z-index: 150; font-size: 44px; pointer-events: none; }

/* คลินิกหมอฟัน */
.dt-mouth { position: relative; width: clamp(260px, min(54vw, 68vh), 640px); aspect-ratio: 4 / 3; }
.dt-mouth img.dt-mouth-img { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.dt-germ {
  position: absolute; width: 13%; aspect-ratio: 1; pointer-events: none;
  transform: translate(-50%, -50%) scale(calc(1 - var(--scrub, 0) * .4)); opacity: calc(1 - var(--scrub, 0) * .5);
}
.dt-mouth.animal .dt-germ { width: 10.5%; } /* ฟันสัตว์ห่างกันราว 10% */
.dt-germ img.dt-germ-img { width: 100%; height: 100%; animation: wiggle 1.6s ease-in-out infinite; }
.dt-germ.zapped { animation: germ-zap .5s forwards; }
/* คนไข้เจ้าของฟัน: การ์ดเล็กมุมซ้ายบนของภาพปาก (ไม่ทับจุดเชื้อโรค ซึ่งอยู่ตั้งแต่ 22% ไปทางขวา) */
.dt-patient {
  position: absolute; left: -17%; top: -18%; width: 32%; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 6px 4px; border-radius: 22px; background: rgba(255, 255, 255, .94); box-shadow: 0 8px 18px var(--shadow); cursor: pointer;
}
.dt-patient img.dt-patient-img { width: 100%; height: auto; aspect-ratio: 1; transform-origin: 50% 90%; }
.dt-patient-name { font-weight: 700; font-size: clamp(12px, 1.5vw, 18px); white-space: nowrap; }
.dt-patient:not(.well) img.dt-patient-img { animation: sob 1.6s ease-in-out infinite; } /* ปวดฟัน สะอื้นเบา ๆ */
.dt-patient.well img.dt-patient-img { animation: fa-hop 1.6s ease-in-out infinite; }
/* จอแนวตั้ง: ภาพปากกว้างเต็มจอ ไม่มีที่ด้านข้าง — วางการ์ดคนไข้ไว้เหนือปากแทน */
@media (orientation: portrait) { .dt-patient { left: 2%; top: auto; bottom: 100%; margin-bottom: 8px; width: 30%; } }
.dt-mouth.sparkly::after { content: "✨"; position: absolute; top: 10%; right: 12%; font-size: clamp(36px, 5vw, 64px); animation: pop .6s, floaty 2s ease-in-out .6s infinite; }
.dt-tools, .th-tools { padding: 14px; border-radius: 28px; background: rgba(255, 255, 255, .9); box-shadow: 0 10px 24px var(--shadow); }
.dt-tools { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.dt-foam { position: absolute; margin: -6px 0 0 -6px; border-radius: 50%; pointer-events: none; z-index: 2; background: radial-gradient(circle at 35% 30%, #fff 0 45%, #e8f6ff 70%, #cfeaff); box-shadow: 0 1px 2px rgba(0, 60, 120, .15); animation: pop .25s; }
.dt-foam.wash { animation: foam-wash .7s ease-in forwards; }
.dt-rinse { position: absolute; inset: 18% 8%; border-radius: 40%; pointer-events: none; z-index: 3; background: linear-gradient(100deg, transparent, rgba(120, 200, 255, .55) 40%, rgba(220, 245, 255, .8) 50%, rgba(120, 200, 255, .55) 60%, transparent); animation: rinse-sweep .9s ease-in-out forwards; }
.dt-cup.pour img.dt-cup-img { animation: cup-pour .9s ease-in-out; }
@keyframes foam-wash { to { transform: translate(40px, 30px) scale(.2); opacity: 0; } }
@keyframes rinse-sweep { from { transform: translateX(-70%); opacity: 0; } 30% { opacity: 1; } to { transform: translateX(70%); opacity: 0; } }
@keyframes cup-pour { 0%, 100% { transform: rotate(0); } 40%, 70% { transform: rotate(-55deg); } }
@media (orientation: portrait) { .dt-tools { flex-direction: row; } }
.dt-brush { position: relative; z-index: 5; width: clamp(96px, min(14vw, 18vh), 160px); aspect-ratio: 1; cursor: grab; }
.dt-brush img.dt-brush-img { width: 100%; height: 100%; transform: rotate(-25deg); filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .2)); }
.dt-cup { width: clamp(76px, min(10vw, 13vh), 116px); aspect-ratio: 1; padding: 6px; border-radius: 22px; }
.dt-cup img.dt-cup-img { width: 100%; height: 100%; }
.dt-quiz-title { font-size: clamp(40px, 6vw, 64px); }
.dt-food img.pic { width: 64%; }

/* โรงพยาบาลตุ๊กตา */
.th-toy { position: relative; width: clamp(240px, min(44vw, 62vh), 520px); aspect-ratio: 1; }
.th-toy img.th-img { width: 100%; height: 100%; pointer-events: none; }
.th-toy.well img.th-img { animation: bounce .8s; }
.th-toy:not(.well) { transform-origin: 50% 90%; animation: mood-droop 3.8s ease-in-out infinite; }
.th-toy.well { transform-origin: 50% 90%; animation: fa-hop 1.6s ease-in-out .8s infinite; }
.th-toy.well::after { content: "💖"; position: absolute; top: 0; right: 6%; font-size: clamp(32px, 4vw, 52px); animation: floaty 2s ease-in-out infinite; }
/* รอยขาดเห็นชัด: ร่องสีเข้มขอบเส้นประหนา · จุดเย็บใหญ่ขึ้น (~40px) แตะง่ายสำหรับนิ้วเด็ก */
.th-rip {
  position: absolute; height: 7.5%; margin-top: -3.75%; transform-origin: 0 50%; border-radius: 99px; pointer-events: none;
  background: repeating-linear-gradient(90deg, #f6dcc6 0 10px, #ecc6a6 10px 14px); border: 3px dashed #7a4524;
  box-shadow: inset 0 3px 6px rgba(122, 69, 36, .45), 0 0 0 3px rgba(255, 255, 255, .7);
}
.th-dot {
  position: absolute; width: clamp(28px, 6.2%, 42px); aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; cursor: pointer;
  background: #fff; border: 4px solid #ff6f96; box-shadow: 0 2px 5px rgba(0, 0, 0, .25);
}
.th-dot::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; } /* พื้นที่แตะกว้างกว่าที่เห็น */
.th-dot.next { animation: spotpulse 1s ease-in-out infinite; box-shadow: 0 0 0 5px rgba(255, 209, 102, .9); }
.th-dot.sewn { background: none; border: 0; box-shadow: none; display: grid; place-items: center; }
.th-dot.sewn::before { content: "✕"; color: #e8436f; font-weight: 700; font-size: clamp(16px, 2.4vw, 28px); line-height: 1; }
.th-tools { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.th-thread { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; z-index: 3; }
.th-thread polyline, .th-thread line { fill: none; stroke: #ff4f8b; stroke-width: 3.5px; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.th-thread line.loose { opacity: .85; stroke-dasharray: 2 0; }
.th-needle { position: relative; z-index: 5; width: clamp(96px, min(14vw, 18vh), 160px); aspect-ratio: 1; cursor: grab; }
.th-needle img.th-needle-img { width: 100%; height: 100%; filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .2)); }
.th-prep img.pic { width: 64%; }
@media (orientation: portrait) {
  .th-toy { width: min(90vw, 52vh); }
  .dt-mouth { width: min(94vw, 60vh); }
  .cl-patient { width: min(76vw, 44vh); }
  .th-tools, .dt-tools { padding: 10px; }
}

/* ===== เฟส 3: อาชีพในเมือง ===== */
.game-school, .game-police, .game-fire, .game-art { background-color: #fffaf0; background-size: cover; background-position: center; }
.game-school { background-image: linear-gradient(rgba(255, 255, 255, .2), rgba(255, 255, 255, .2)), url("../assets/bg/classroom.webp"); }
.game-police { background-image: linear-gradient(rgba(255, 255, 255, .2), rgba(255, 255, 255, .2)), url("../assets/bg/police.webp"); }
.game-fire { background-image: linear-gradient(rgba(255, 255, 255, .2), rgba(255, 255, 255, .2)), url("../assets/bg/fire.webp"); }
.game-art { background-image: linear-gradient(rgba(255, 255, 255, .25), rgba(255, 255, 255, .25)), url("../assets/bg/art.webp"); }
.school, .police, .firegame, .artgame { display: flex; align-items: center; justify-content: center; gap: clamp(14px, 4vw, 56px); width: 100%; height: 100%; }
@media (orientation: portrait) { .school, .police, .firegame, .artgame { flex-direction: column; gap: 2.5vh; } }
.panel, .sc-student, .fr-tools, .phone, .ar-palette { background: rgba(255, 255, 255, .92); border-radius: 28px; box-shadow: 0 10px 24px var(--shadow); }

/* โรงเรียน */
.sc-student { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 16px 10px; cursor: pointer; }
.sc-student img.sc-student-img { width: clamp(100px, min(17vw, 24vh), 190px); height: auto; aspect-ratio: 1; }
.sc-hand { position: absolute; top: -14px; right: -10px; font-size: clamp(34px, 4.6vw, 56px); transform-origin: 50% 90%; animation: wiggle 1s ease-in-out infinite; }
.sc-student.happy .sc-hand { display: none; }
/* สงสัย: เอียงหัวคิด · เข้าใจแล้ว: กระโดดดีใจ */
.sc-student:not(.happy) img.sc-student-img { transform-origin: 50% 90%; animation: ponder 3s ease-in-out infinite; }
.sc-student.happy img.sc-student-img { transform-origin: 50% 90%; animation: fa-hop 1.6s ease-in-out infinite; }
.sc-student.happy::after { content: "💖"; position: absolute; top: -10px; right: -6px; font-size: clamp(30px, 4vw, 48px); animation: pop .5s; }
.sc-desk { font-weight: 700; font-size: clamp(15px, 1.9vw, 21px); }
.sc-main { display: flex; flex-direction: column; align-items: center; gap: clamp(10px, 2.6vh, 26px); }
.sc-board {
  display: flex; align-items: center; justify-content: center; min-width: clamp(250px, 42vw, 560px); min-height: clamp(130px, 28vh, 270px);
  padding: 14px 20px; border-radius: 16px; background: radial-gradient(circle at 30% 30%, #3d8062, #2b5d47); border: 10px solid #c58b55;
  box-shadow: 0 10px 22px var(--shadow), inset 0 0 30px rgba(0, 0, 0, .25);
}
.sc-items { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: clamp(240px, 40vw, 520px); }
.sc-item { position: relative; width: clamp(54px, min(8vw, 11vh), 92px); aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer; }
.sc-items.many .sc-item { width: clamp(42px, min(6vw, 8.5vh), 70px); }
.sc-item img.sc-item-img { width: 100%; height: 100%; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .3)); }
.sc-num { position: absolute; top: -6px; left: -6px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: #ffd166; color: #5a3a12; font-weight: 700; font-size: 15px; animation: pop .3s; }
.sc-shape { width: clamp(110px, min(19vw, 24vh), 190px); aspect-ratio: 1; }
.sc-shape svg, .sc-opt-shape svg { width: 100%; height: 100%; display: block; }
.sc-shape.chalk { filter: drop-shadow(0 0 6px rgba(255, 255, 255, .45)); }
.sc-choice { width: clamp(80px, min(14vw, 19vh), 150px); }
.sc-digit { font-size: clamp(38px, min(6.5vw, 9vh), 76px); font-weight: 700; line-height: 1; color: #3d5bd9; }
.sc-dots { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; max-width: 78%; }
.sc-dots i { width: 9px; height: 9px; border-radius: 50%; background: #ff8c42; }
.sc-swatch { display: block; width: 62%; aspect-ratio: 1; border-radius: 50%; box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .14); }
.sc-opt-shape { display: block; width: 64%; aspect-ratio: 1; }

/* สถานีตำรวจ */
.pl-owner { position: relative; padding: 14px; } /* ยืนบนพื้น ไม่อยู่ในการ์ดขาวแบบลูกหมา — เด็กจะได้ไม่แตะผิด */
.pl-owner img.pl-owner-img { width: clamp(100px, min(17vw, 24vh), 190px); height: auto; aspect-ratio: 1; display: block; }
/* ร้องไห้: ไหล่สะอื้น · เจอลูกหมาแล้ว: กระโดดดีใจ */
.pl-owner:not(.found) img.pl-owner-img { transform-origin: 50% 90%; animation: sob 1.3s ease-in-out infinite; }
.pl-owner.found img.pl-owner-img { transform-origin: 50% 90%; animation: fa-hop 1.6s ease-in-out .5s infinite; }
.pl-owner img.pl-found-pup { position: absolute; right: -30%; bottom: -8%; width: 72%; height: auto; animation: pop .5s; }
.pl-pups { max-width: min(72vw, 820px); }
.pl-pup { width: clamp(96px, min(16vw, 23vh), 176px); }
.pl-pup img.pl-pup-img { width: 90%; height: auto; aspect-ratio: 1; object-fit: contain; }
.police.cross, .police.call { flex-direction: row; }
@media (orientation: portrait) { .police.cross, .police.call { flex-direction: column; } }
.tlight { display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 24px; background: #3b3f4a; box-shadow: 0 10px 22px var(--shadow); }
@media (orientation: portrait) { .tlight { flex-direction: row; } }
.tlight i { width: clamp(40px, 7vh, 66px); aspect-ratio: 1; border-radius: 50%; background: #666; opacity: .35; transition: opacity .2s; }
.tlight .tl-red.on { background: #ff4d4d; opacity: 1; box-shadow: 0 0 24px #ff4d4d; }
.tlight .tl-yellow.on { background: #ffd23f; opacity: 1; box-shadow: 0 0 24px #ffd23f; }
.tlight .tl-green.on { background: #35d46a; opacity: 1; box-shadow: 0 0 24px #35d46a; }
.pl-road { --rw: min(66vw, 720px); display: flex; align-items: stretch; width: var(--rw); height: clamp(150px, 30vh, 250px); border-radius: 24px; overflow: hidden; box-shadow: 0 10px 22px var(--shadow); }
@media (orientation: portrait) { .pl-road { --rw: 92vw; } }
.pl-side { width: 30%; flex: none; display: flex; align-items: center; justify-content: center; background: #efe2c9; }
.pl-zebra { flex: 1; background: #8d939e; background-image: repeating-linear-gradient(180deg, #fff 0 18px, transparent 18px 36px); background-size: 70% 100%; background-repeat: no-repeat; background-position: center; }
.pl-walker { position: relative; z-index: 2; display: flex; align-items: flex-end; padding: 0; border: 0; background: none; cursor: pointer; transition: transform 1.5s ease-in-out; }
.pl-walker img.pl-walker-kid { width: clamp(66px, 13vh, 120px); height: auto; }
.pl-walker img.pl-walker-pup { width: clamp(50px, 9.5vh, 88px); height: auto; margin-left: -14px; }
.pl-walker.walk { transform: translateX(calc(var(--rw) * .7)); }
.pl-walker.walk img { animation: step .32s ease-in-out infinite; }
.pl-walker.walk img + img { animation-delay: .16s; }
.pl-car.flash::after { content: ""; position: absolute; left: 30%; top: 2%; width: 40%; height: 18%; border-radius: 40%; animation: siren-light .25s steps(2) 8; pointer-events: none; }
.pl-car { position: relative; }
@keyframes step { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10%) rotate(3deg); } }
@keyframes siren-light { 0% { background: rgba(255, 60, 60, .85); box-shadow: 0 0 30px 12px rgba(255, 60, 60, .7); } 100% { background: rgba(60, 120, 255, .85); box-shadow: 0 0 30px 12px rgba(60, 120, 255, .7); } }
.pl-home { font-size: clamp(44px, 9vh, 88px); }
.pl-car { padding: 0; border: 0; background: none; }
.pl-car img.pl-car-img { width: clamp(140px, 22vw, 260px); height: auto; }

/* โทรศัพท์ */
.phone { display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.4vh, 12px); padding: clamp(10px, 2vh, 18px) 18px; }
.phone img.ph-img { width: clamp(56px, 9vh, 100px); height: auto; }
.phone.ringing img.ph-img { animation: wiggle .25s ease-in-out 8; }
.ph-display { display: flex; gap: 8px; }
.ph-slot { width: clamp(40px, 6vh, 56px); height: clamp(46px, 7vh, 62px); display: grid; place-items: center; border-radius: 12px; border: 3px dashed #b9c6ea; background: #eef3ff; font-size: clamp(24px, 4vh, 34px); font-weight: 700; }
.ph-slot.on { border-style: solid; border-color: #ffc93c; background: #fff4c2; animation: pop .3s; }
.ph-keys { display: grid; grid-template-columns: repeat(3, auto); gap: clamp(6px, 1.2vh, 10px); }
.ph-key { width: clamp(50px, min(8vw, 8.5vh), 74px); aspect-ratio: 1; border-radius: 50%; font-size: clamp(22px, 3.6vh, 32px); font-weight: 700; }
.ph-key[data-d="0"] { grid-column: 2; }
.ph-key.cl-next { border-radius: 50%; }

/* สถานีดับเพลิง */
.fr-house, .fr-tree { position: relative; width: clamp(240px, min(46vw, 62vh), 520px); aspect-ratio: 1; }
@media (orientation: portrait) { .fr-house, .fr-tree { width: min(86vw, 50vh); } }
.fr-house img.fr-house-img, .fr-tree img.fr-tree-img { width: 100%; height: 100%; pointer-events: none; }
.fr-flame { position: absolute; width: 24%; aspect-ratio: 1; pointer-events: none; transform: translate(-50%, -62%) scale(calc(1 - var(--douse, 0) * .55)); }
.fr-flame img.fr-flame-img { width: 100%; height: 100%; transform-origin: 50% 100%; animation: flicker .7s ease-in-out infinite alternate; }
.fr-flame.out { animation: germ-zap .5s forwards; }
.fr-house.safe::after { content: "✨"; position: absolute; top: 4%; right: 8%; font-size: clamp(34px, 5vw, 60px); animation: pop .6s, floaty 2s ease-in-out .6s infinite; }
.fr-tools { padding: 14px; }
.fr-hose, .fr-ladder { position: relative; z-index: 5; width: clamp(96px, min(14vw, 18vh), 160px); aspect-ratio: 1; cursor: grab; }
.fr-hose img, .fr-ladder img { width: 100%; height: 100%; filter: drop-shadow(0 6px 5px rgba(0, 0, 0, .2)); }
.fr-hose img.fr-hose-img { transform: scaleX(-1); } /* ให้หัวฉีดหันไปทางบ้าน */
.fr-water { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 140; pointer-events: none; opacity: 0; transition: opacity .12s; }
.fr-water.on { opacity: 1; }
.fr-stream { fill: none; stroke: #3fa9f5; stroke-width: 14; stroke-linecap: round; stroke-dasharray: 22 9; animation: flow .35s linear infinite; opacity: .88; filter: drop-shadow(0 3px 4px rgba(0, 60, 140, .35)); }
.fr-stream-shine { fill: none; stroke: #e3f6ff; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 10 22; animation: flow .35s linear infinite; opacity: .9; }
.fr-hose.spraying img.fr-hose-img { animation: nozzle-kick .18s linear infinite; }
@keyframes nozzle-kick { 0%, 100% { transform: scaleX(-1) translate(0, 0); } 50% { transform: scaleX(-1) translate(2px, -2px); } }
.fr-steam { position: fixed; z-index: 139; width: 26px; height: 26px; margin-left: -13px; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, rgba(255, 255, 255, .95), rgba(255, 255, 255, 0) 70%); animation: steam-up 1.4s ease-out forwards; }
@keyframes flow { to { stroke-dashoffset: -62; } }
@keyframes steam-up { from { transform: translateY(0) scale(.6); opacity: .9; } to { transform: translateY(-70px) scale(2.2); opacity: 0; } }
.fr-drop { position: fixed; z-index: 150; width: 12px; height: 16px; margin-left: -6px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: #4fb6e8; pointer-events: none; animation: drop-fall .6s ease-in forwards; }
.fr-cat { position: absolute; left: 57%; top: 31%; width: 24%; transition: left 1.2s ease-in-out, top 1.2s ease-in-out; }
.fr-cat img.fr-cat-img { width: 100%; height: auto; animation: wiggle 1.4s ease-in-out infinite; }
.fr-cat.down { left: 72%; top: 68%; }
.fr-cat.down img.fr-cat-img { transform-origin: 50% 90%; animation: fa-hop 1.6s ease-in-out 1.2s infinite; } /* ลงมาได้แล้ว กระโดดดีใจ */
.fr-ladder-placed { position: absolute; left: 49%; top: 48%; width: 44%; transform: rotate(-8deg); pointer-events: none; animation: pop .4s; }
.fr-ladder-placed img { width: 100%; height: auto; }
.fr-truck { padding: 0; border: 0; background: none; }
.fr-truck img.fr-truck-img { width: clamp(150px, 24vw, 280px); height: auto; }
.fr-truck.go { animation: bounce .6s 3; }

/* ห้องศิลปะ */
.ar-easel { position: relative; padding: 12px; border-radius: 20px; background: #fff; border: 8px solid #f0c987; box-shadow: 0 10px 24px var(--shadow); }
.ar-canvas { --ar: 1.2; display: block; width: min(60vw, calc(min(64vh, 600px) * var(--ar))); height: auto; aspect-ratio: var(--ar); cursor: pointer; touch-action: manipulation; border-radius: 10px; }
@media (orientation: portrait) { .ar-canvas { width: min(86vw, calc(50vh * var(--ar))); } }
.ar-canvas.framed { box-shadow: 0 0 0 6px #ffd166; }
/* ห้องศิลปะ: ผีเสื้อน้อยเกาะมุมซ้ายบนของขาตั้งภาพ */
.ar-friend { position: absolute; left: -36px; top: -50px; width: clamp(76px, min(12vw, 17vh), 132px); z-index: 3; pointer-events: none; }
.ar-friend img { width: 100%; height: auto; display: block; transform-origin: 50% 90%; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .2)); }
.ar-friend:not(.happy) img { animation: fa-sigh 3.4s ease-in-out infinite; }
.ar-friend.happy img { animation: fa-hop 1.6s ease-in-out infinite; }
@media (orientation: portrait) { .ar-friend { left: 6px; top: -70px; } } /* จอแนวตั้งขาตั้งภาพกว้างเกือบเต็มจอ: เกาะด้านบนแทน ไม่ล้นจอ */
.ar-done { position: absolute; right: -20px; bottom: -20px; display: none; place-items: center; background: #fff; box-shadow: 0 6px 0 #c9b28f, 0 10px 18px var(--shadow); }
.ar-done.show { display: grid; animation: pop .4s; }
.ar-done.pulse { animation: pulse 1.1s ease-in-out infinite; }
.ar-next { position: absolute; right: -20px; bottom: -20px; display: grid; place-items: center; background: #fff; color: var(--coral); animation: pop .4s, pulse 1.4s ease-in-out .6s infinite; box-shadow: 0 6px 0 #c9b28f, 0 10px 18px var(--shadow); }
.ar-palette { display: grid; grid-template-columns: repeat(2, auto); gap: 12px; padding: 14px; }
@media (orientation: portrait) { .ar-palette { grid-template-columns: repeat(8, auto); gap: 6px; padding: 10px; } }
.ar-swatch { width: clamp(40px, min(7vw, 9vh), 70px); aspect-ratio: 1; padding: 0; border-radius: 50%; border: 4px solid #fff; background: var(--sc); box-shadow: 0 4px 0 rgba(0, 0, 0, .15); cursor: pointer; transition: transform .15s; }
@media (orientation: portrait) { .ar-swatch { width: 9.5vw; border-width: 3px; } }
.ar-swatch.on { transform: scale(1.14); outline: 4px solid #5a3a12; outline-offset: 2px; }
.artgame.mixing { flex-direction: column; }
.ar-bowl { position: relative; width: clamp(200px, 30vw, 320px); aspect-ratio: 5 / 3; overflow: hidden; border-radius: 12px 12px 50% 50% / 12px 12px 100% 100%; background: #fff; border: 8px solid #e7d3b5; box-shadow: 0 10px 24px var(--shadow); }
.ar-paint { position: absolute; inset: 34% 0 0 0; background: transparent; transition: background .5s; border-radius: 0 0 50% 50% / 0 0 100% 100%; overflow: hidden; }
.ar-bowl.p1 .ar-paint { background: var(--p1); }
.ar-bowl.p2 .ar-paint { background: linear-gradient(90deg, var(--p1) 50%, var(--p2) 50%); }
.ar-bowl.swirl .ar-paint { background: conic-gradient(from 0deg, var(--p1), var(--p2), var(--p1), var(--p2), var(--p1)); animation: wiggle .3s ease-in-out 3; }
.ar-bowl.mixed .ar-paint { background: var(--out); animation: none; }
.ar-tray { display: flex; gap: clamp(24px, 6vw, 60px); }
.ar-bowl { overflow: visible; }
.ar-stream { position: absolute; top: -70%; width: 9%; height: 100%; border-radius: 40px; background: linear-gradient(var(--pc), var(--pc)); transform-origin: 50% 0; animation: pour-stream .9s ease-in-out forwards; z-index: 2; }
.ar-ripple { position: absolute; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%; border: 4px solid var(--pc); pointer-events: none; animation: ripple-out .7s ease-out forwards; }
@keyframes pour-stream { 0% { transform: scaleY(0); opacity: 1; } 35% { transform: scaleY(1); } 75% { transform: scaleY(1) translateY(30%); opacity: 1; } 100% { transform: scaleY(.2) translateY(160%); opacity: 0; } }
@keyframes ripple-out { from { transform: scale(.3); opacity: 1; } to { transform: scale(4); opacity: 0; } }
.ar-pot { position: relative; z-index: 5; width: clamp(80px, min(12vw, 16vh), 124px); aspect-ratio: 1; overflow: hidden; cursor: grab; border-radius: 16px 16px 28px 28px; background: #fff; border: 6px solid #e9e9ee; box-shadow: 0 8px 14px var(--shadow); }
.ar-pot-paint { position: absolute; inset: 32% 0 0 0; background: var(--pc); }
.ar-pot.gone { visibility: hidden; }
.ar-guess { width: clamp(84px, min(14vw, 19vh), 140px); }

/* ปุ่มปราสาทเมฆบนแผนที่ + ตอนจบ */
.end-king { display: none; position: absolute; left: 50%; top: 44%; width: clamp(180px, 36vh, 340px); padding: 0; border: 0; background: none; transform: translate(-50%, -50%); cursor: pointer; }
.end-king img { width: 100%; height: auto; display: block; animation: floaty 2.4s ease-in-out infinite; }
.with-king .end-king { display: block; }
.with-king.king-wait .end-king img { animation: pulse 1.1s ease-in-out infinite; filter: drop-shadow(0 0 18px rgba(255, 255, 255, .9)); }
.with-king.king-wait .intro-next { opacity: .3; }

/* ===== เกาะมหัศจรรย์: ปราสาทเจ้าหญิง ===== */
.game-princess { background: #ffe3f1 url("../assets/bg/princess.webp") center / cover no-repeat; }
.game-princess.ballroom { background-image: url("../assets/bg/ballroom.webp"); }
.pr-pick { display: flex; align-items: flex-end; justify-content: center; gap: clamp(8px, 2vw, 24px); width: 100%; flex-wrap: wrap; }
.pr-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 10px 10px; border-radius: 26px; width: clamp(110px, min(17vw, 30vh), 190px); }
.pr-card img.pr-card-img { width: 100%; height: auto; aspect-ratio: 314 / 640; object-fit: contain; }
.pr-card-name { font-weight: 700; font-size: clamp(12px, 1.5vw, 17px); white-space: nowrap; }
@media (orientation: portrait) { .pr-card { width: 28vw; } }
.pr-dressing { display: flex; align-items: center; justify-content: center; gap: clamp(16px, 4vw, 56px); width: 100%; height: 100%; }
@media (orientation: portrait) { .pr-dressing { flex-direction: column; gap: 2vh; } }
.pr-spot { position: relative; height: min(70vh, 600px); aspect-ratio: 0.62; display: grid; place-items: end center; }
@media (orientation: portrait) { .pr-spot { height: 44vh; } }
.pr-light { position: absolute; inset: 6% 4% 0; border-radius: 50% 50% 46% 46%; background: radial-gradient(ellipse at 50% 70%, rgba(255, 255, 255, .95), rgba(255, 240, 250, .5) 55%, transparent 72%); }
/* ภาพเจ้าหญิงเต็มกรอบพอดี (เดิม height:100% ในกริดไม่มีผล ภาพสูงล้นกรอบลงไปทับแถวชุดบนมือถือ) */
.pr-big { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; object-position: 50% 100%; filter: drop-shadow(0 10px 12px rgba(0, 0, 0, .18)); }
.pr-big.poof { animation: pr-poof .55s ease-out; }
.pr-big.sad { transform-origin: 50% 95%; animation: mood-droop 3.4s ease-in-out infinite; } /* ยังไม่มีชุด หน้าเศร้า */
.pr-wardrobe { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px; border-radius: 28px; background: rgba(255, 255, 255, .88); box-shadow: 0 10px 24px var(--shadow); }
.pr-dresses { display: grid; grid-template-columns: repeat(3, auto); gap: 10px; }
.pr-dress { width: clamp(70px, min(11vw, 15vh), 124px); aspect-ratio: .7; padding: 6px; border-radius: 18px; }
.pr-dress img.pr-dress-img { width: 100%; height: 100%; object-fit: contain; }
.pr-dress.on { box-shadow: 0 0 0 5px #ff8fc8, 0 6px 0 #d987a9; }
/* มือถือแนวตั้ง: 3 คอลัมน์ 2 แถว ปุ่มชุดใหญ่พอสำหรับนิ้วเด็ก (เดิม 6 คอลัมน์เหลือ ~49px) */
@media (orientation: portrait) { .pr-dresses { grid-template-columns: repeat(3, auto); gap: 8px; } .pr-dress { width: min(24vw, 120px); } .pr-wardrobe { padding: 10px; } }
.pr-ok { display: none; }
.pr-ok.show { display: grid; place-items: center; animation: pop .4s, pulse 1.4s ease-in-out .4s infinite; }
.pr-makeup { display: flex; align-items: center; justify-content: center; gap: clamp(12px, 3vw, 40px); width: 100%; height: 100%; }
@media (orientation: portrait) { .pr-makeup { flex-direction: column; gap: 2vh; } }
.pr-tools { display: grid; grid-template-columns: repeat(1, auto); gap: 10px; }
@media (orientation: portrait) { .pr-tools { grid-template-columns: repeat(5, auto); } }
.pr-tool { width: clamp(60px, min(9vw, 12vh), 96px); aspect-ratio: 1; padding: 6px; border-radius: 20px; }
.pr-tool img.pr-tool-img { width: 100%; height: 100%; object-fit: contain; }
.pr-tool .pic { font-size: clamp(28px, 4vw, 44px); }
.pr-tool.on { box-shadow: 0 0 0 5px #ff8fc8, 0 6px 0 #d987a9; }
.pr-mirror { padding: clamp(10px, 1.6vw, 18px); border-radius: 50%; background: linear-gradient(135deg, #ffe8a3, #f7c873); box-shadow: 0 12px 26px var(--shadow), inset 0 0 0 4px #fff3cf; }
.pr-face { position: relative; height: min(64vh, 540px); aspect-ratio: .98; border-radius: 50%; background: #fff; }
@media (orientation: portrait) { .pr-face { height: auto; width: 74vw; } }
.pr-face-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.pr-layers { position: absolute; inset: 0; pointer-events: none; }
.mk { position: absolute; transform: translate(-50%, -50%); opacity: 0; transition: opacity .5s; }
.mk.on { opacity: 1; animation: pop .45s; }
.mk-lips { aspect-ratio: 2.3; border-radius: 48% 48% 50% 50% / 40% 40% 60% 60%; background: var(--mk); mix-blend-mode: multiply; filter: blur(1.5px); }
.mk-lips.on { opacity: .82; }
.mk-blush { aspect-ratio: 1.4; border-radius: 50%; background: radial-gradient(ellipse, var(--mk) 0 35%, transparent 72%); mix-blend-mode: multiply; }
.mk-blush.on { opacity: .95; }
.mk-shadow { aspect-ratio: 2.1; border-radius: 50% 50% 18% 18% / 100% 100% 20% 20%; background: var(--mk); mix-blend-mode: multiply; filter: blur(2px); }
.mk-shadow.on { opacity: .72; }
.mk-sticker { position: absolute; transform: translate(-50%, -50%); font-size: clamp(24px, 4vw, 44px); animation: pop .4s; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .2)); }
.mk-glitter { position: absolute; transform: translate(-50%, -50%); font-size: clamp(14px, 2.2vw, 26px); animation: twinkle 1.6s ease-in-out infinite; }
.pr-side { display: flex; flex-direction: column; align-items: center; gap: 14px; min-width: 70px; }
@media (orientation: portrait) { .pr-side { flex-direction: row; } }
.pr-palette { display: grid; grid-template-columns: repeat(2, auto); gap: 10px; }
@media (orientation: portrait) { .pr-palette { grid-template-columns: repeat(5, auto); } }
.pr-swatch { width: clamp(46px, min(7vw, 9vh), 68px); aspect-ratio: 1; padding: 0; border-radius: 50%; border: 4px solid #fff; background: var(--sc, #fff); box-shadow: 0 4px 0 rgba(0, 0, 0, .15); cursor: pointer; }
.pr-swatch.emoji { font-size: clamp(24px, 3.4vw, 36px); display: grid; place-items: center; }
.pr-final { position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 2vw; }
.pr-again { position: absolute; right: 0; bottom: 0; display: grid; place-items: center; background: #fff; color: #e0569a; animation: pop .4s, pulse 1.4s ease-in-out .6s infinite; }
.pr-final-face .pr-face { height: min(56vh, 440px); }
.pr-final-face { padding: 12px; border-radius: 50%; background: linear-gradient(135deg, #ffe8a3, #f7c873); animation: pop .6s; }
.pr-final-body { height: min(70vh, 560px); width: auto; animation: pop .6s .15s both; filter: drop-shadow(0 10px 12px rgba(0, 0, 0, .2)); }
@media (orientation: portrait) { .pr-final { flex-direction: column; align-items: center; } .pr-final-body { height: 30vh; } .pr-final-face .pr-face { width: 60vw; } }
@keyframes pr-poof { 0% { transform: scale(.85); filter: brightness(1.6) drop-shadow(0 0 20px #fff); } 60% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes twinkle { 0%, 100% { opacity: .2; transform: translate(-50%, -50%) scale(.6); } 50% { opacity: 1; transform: translate(-50%, -50%) scale(1.2); } }

/* ===== เกาะมหัศจรรย์: สวนสัตว์ ===== */
.game-zoo { background: #cfeec0 url("../assets/bg/zoo.webp") center / cover no-repeat; }
.zoo-find { display: flex; flex-direction: column; align-items: center; gap: 3vh; }
.zoo-card { width: clamp(110px, min(19vw, 28vh), 210px); }
.zoo-card img.zoo-img { width: 84%; height: auto; aspect-ratio: 1; object-fit: contain; }
.zoo-card.cheer img.zoo-img { animation: hop .6s ease-out 2; }
.zoo-ear { width: calc(var(--tap) * 1.1); height: calc(var(--tap) * 1.1); border-radius: 50%; font-size: calc(var(--tap) * .5); animation: pulse 1.4s ease-in-out infinite; }
.zoo-explore .zoo-card { width: auto; }
.zoo-sort { display: flex; flex-direction: column; gap: 2vh; width: 100%; height: 100%; padding-bottom: 5vh; }
.zoo-zones { flex: 1; min-height: 0; display: flex; flex-direction: column; border-radius: 28px; overflow: hidden; box-shadow: 0 10px 24px var(--shadow); border: 4px solid rgba(255, 255, 255, .85); }
.zoo-zone { position: relative; flex: 1; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; padding: 34px 10px 6px; overflow: hidden; }
.zoo-zone.sky { background: linear-gradient(#7fcfff, #cdeeff); }
.zoo-zone.ground { background: radial-gradient(120% 60% at 50% 0%, #c6ef94, transparent 60%), linear-gradient(#a3dc72, #6fbf4c); }
/* ขอบหญ้าหยัก ๆ ระหว่างฟ้ากับพื้น */
.zoo-zone.ground::before { content: ''; position: absolute; left: 0; right: 0; top: -1px; height: 14px; background: radial-gradient(circle at 10px 0, #cdeeff 9px, transparent 10px) 0 0 / 20px 14px repeat-x; }
.zoo-zone-name { position: absolute; z-index: 2; top: 8px; left: 12px; padding: 3px 14px; border-radius: 999px; background: rgba(255, 255, 255, .92); font-weight: 700; font-size: clamp(15px, 2vw, 22px); box-shadow: 0 3px 8px var(--shadow); }
.zoo-deco { position: absolute; pointer-events: none; line-height: 1; }
.zoo-deco.sun { right: 4%; top: 8%; font-size: clamp(44px, 10vh, 90px); animation: spin-slow 24s linear infinite; }
.zoo-deco.cloud { font-size: clamp(60px, 14vh, 130px); opacity: .9; animation: cloud-drift 26s linear infinite; }
.zoo-deco.cloud.c1 { top: 2%; animation-delay: -6s; }
.zoo-deco.cloud.c2 { top: 40%; font-size: clamp(44px, 10vh, 96px); animation-duration: 34s; animation-delay: -22s; }
.zoo-deco.plant { bottom: 4%; font-size: clamp(34px, 7vh, 64px); }
.zoo-deco.plant.p1 { left: 2%; font-size: clamp(60px, 14vh, 130px); bottom: 0; }
.zoo-deco.plant.p2 { left: 22%; }
.zoo-deco.plant.p3 { right: 18%; }
.zoo-deco.plant.p4 { right: 4%; }
.zoo-home { position: relative; z-index: 1; width: clamp(78px, min(12vw, 18vh), 150px); animation: pop .4s; }
.zoo-home img { width: 100%; height: auto; }
.zoo-home.bird img { animation: flap 1.2s ease-in-out infinite; }
.zoo-home.land img { animation: hop 1.8s ease-in-out infinite; }
.zoo-tray { display: flex; justify-content: center; gap: clamp(8px, 2vw, 22px); flex-wrap: wrap; }
.zoo-item { position: relative; z-index: 5; width: clamp(84px, min(13vw, 17vh), 140px); aspect-ratio: 1; padding: 6px; border-radius: 22px; background: rgba(255, 255, 255, .92); box-shadow: 0 6px 12px var(--shadow); cursor: grab; }
.zoo-item img.zoo-img { width: 100%; height: 100%; object-fit: contain; }
/* หลงทาง: ตัวห่อ โยกช้า ๆ ถอนหายใจ (ตัวละจังหวะไม่พร้อมกัน) */
.zoo-item.lost img.zoo-img { transform-origin: 50% 90%; animation: fa-sigh 3.4s ease-in-out infinite; }
.zoo-item.lost:nth-child(2n) img.zoo-img { animation-delay: -1.2s; } .zoo-item.lost:nth-child(3n) img.zoo-img { animation-delay: -2.3s; }
@keyframes flap { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }

/* ===== เกาะมหัศจรรย์: โลกใต้น้ำ ===== */
.game-ocean { background: #0d6fb8 url("../assets/bg/ocean.webp") center / cover no-repeat; }
.game-ocean .stage { padding: 0; }
.sea-tank { position: relative; width: 100%; height: 100%; overflow: hidden; border-radius: 24px; touch-action: manipulation; container-type: inline-size; }
.sea-rays {
  /* แสงแดดส่องลงมาเป็นลำนุ่ม ๆ จางลงตามความลึก */
  position: absolute; inset: -10% -10% 25%; pointer-events: none; opacity: .55; mix-blend-mode: screen;
  background:
    linear-gradient(104deg, transparent 0 16%, rgba(255, 255, 255, .32) 21%, transparent 27%),
    linear-gradient(98deg, transparent 0 41%, rgba(255, 255, 255, .26) 46%, transparent 53%),
    linear-gradient(108deg, transparent 0 66%, rgba(255, 255, 255, .3) 71%, transparent 78%);
  -webkit-mask-image: linear-gradient(#000 10%, transparent 90%); mask-image: linear-gradient(#000 10%, transparent 90%);
  animation: rays 7s ease-in-out infinite alternate; filter: blur(12px);
}
.sea-swimmers { position: absolute; inset: 0; }
.swimmer { position: absolute; top: var(--top); left: var(--x, 0); width: var(--size); padding: 0; border: 0; background: none; cursor: pointer; z-index: 2; }
/* ขอบขาวเรือง ๆ รอบตัวสัตว์ — ไม่กลืนกับปะการังสีเดียวกัน */
.swimmer .sea-img { width: 100%; height: auto; display: block; filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 5px rgba(255, 255, 255, .85)) drop-shadow(0 8px 10px rgba(0, 30, 80, .3)); pointer-events: none; }
.swimmer.swim { animation: sea-swim var(--dur) linear var(--delay) infinite; }
.swimmer.swim .sw-body { display: block; animation: wobble-y 2.2s ease-in-out infinite; }
.swimmer.bob .sw-body { display: block; animation: sea-bob 4.2s ease-in-out var(--delay) infinite; }
.swimmer.walk { animation: sea-walk calc(var(--dur) * .7) ease-in-out var(--delay) infinite; }
.swimmer.rest .sw-body { display: block; animation: breathe 3s ease-in-out infinite; }
.swimmer.happy .sw-body { animation: spin-happy .9s ease-out; }
.swimmer.shy .sw-body { animation: shake .5s; }
.sea-bubbles { position: absolute; inset: 0; pointer-events: none; }
/* รอบเก็บขยะ: น้ำขุ่น (จางลงตามขยะที่เหลือ) · ขยะลอยไปมา · ถังรีไซเคิลมุมขวาล่าง */
.sea-murk {
  position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; transition: opacity .6s;
  background: linear-gradient(rgba(125, 135, 80, .34), rgba(90, 100, 55, .52));
}
.sea-murk.on { opacity: var(--murk, 1); }
.sea-litter { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.sea-trash {
  position: absolute; width: clamp(58px, min(10vw, 14vh), 110px); padding: 0; border: 0; background: none; cursor: pointer; pointer-events: auto;
  transform: translate(-50%, -50%) rotate(var(--r)); animation: trash-float 4.6s ease-in-out var(--d) infinite;
}
.sea-trash img { width: 100%; height: auto; display: block; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(0, 30, 60, .3)); }
.sea-bin { position: absolute; right: 2%; bottom: 3%; width: clamp(72px, min(12vw, 17vh), 130px); }
.sea-bin img { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 8px rgba(0, 30, 60, .3)); }
.sea-bin.gulp { animation: gulp .45s ease-out; }
@keyframes trash-float { 0%, 100% { transform: translate(-50%, -50%) rotate(var(--r)); } 50% { transform: translate(-50%, calc(-50% - 10px)) rotate(calc(var(--r) * -1)); } }
@media (orientation: portrait) { .sea-trash { width: clamp(64px, 19vw, 110px); } .sea-bin { width: clamp(72px, 22vw, 120px); } }
.sea-bubble {
  position: absolute; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, .95) 0 18%, rgba(255, 255, 255, .25) 30% 60%, rgba(255, 255, 255, .5) 100%);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .7); animation: bubble-up 4s ease-in forwards;
}
.sea-bubble.big { width: 22px; height: 22px; margin-left: -11px; }
.sea-explore .sea-card img.sea-img { width: 80%; height: auto; aspect-ratio: 1; object-fit: contain; }
/* ว่ายไปกลับด้วย translate (หน่วย cqw = % ของความกว้างตู้ปลา) แทน left — ไม่ต้องคำนวณเลย์เอาต์ใหม่ทุกเฟรม */
@keyframes sea-swim {
  0% { translate: -4cqw 0; transform: scaleX(1); } 49.9% { translate: calc((100 - var(--sz)) * 1cqw) 0; transform: scaleX(1); }
  50% { translate: calc((100 - var(--sz)) * 1cqw) 0; transform: scaleX(-1); } 99.9% { translate: -4cqw 0; transform: scaleX(-1); } 100% { translate: -4cqw 0; transform: scaleX(1); }
}
@keyframes sea-walk { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(120%); } }
@keyframes sea-bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-28px) rotate(3deg); } }
@keyframes wobble-y { 0%, 100% { transform: translateY(0) rotate(1.5deg); } 50% { transform: translateY(-8px) rotate(-1.5deg); } }
@keyframes spin-happy { 0% { transform: scale(1) rotate(0); } 50% { transform: scale(1.3) rotate(15deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes bubble-up { 0% { transform: translate(0, 0) scale(.6); opacity: 0; } 10% { opacity: 1; } 100% { transform: translate(14px, -110vh) scale(1.1); opacity: .2; } }
@keyframes sway { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes rays { from { transform: translateX(-4%); opacity: .45; } to { transform: translateX(4%); opacity: .8; } }

/* ===== เอฟเฟกต์ ===== */
.fx-bubble {
  position: fixed; margin: -10px 0 0 -10px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 30% 28%, rgba(255, 255, 255, .95) 0 14%, rgba(200, 235, 255, .25) 30% 62%, rgba(255, 190, 240, .55) 100%);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .8); animation: fx-rise 1.8s ease-out forwards;
}
.fx-crumb { position: fixed; width: 8px; height: 8px; margin: -4px 0 0 -4px; border-radius: 40%; pointer-events: none; animation: fx-crumb .75s cubic-bezier(.2, .6, .4, 1) forwards; }
@keyframes fx-rise { 0% { transform: translate(0, 0) scale(.3); opacity: 0; } 15% { opacity: 1; } 85% { opacity: .9; } 100% { transform: translate(var(--drift), var(--rise)) scale(1); opacity: 0; } }
@keyframes fx-crumb { 0% { transform: translate(0, 0) rotate(0); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) rotate(200deg); opacity: 0; } }
.fx-ring { position: fixed; border-radius: 50%; border: 6px solid var(--rc); pointer-events: none; transform: translate(-50%, -50%) scale(.3); animation: fx-ring .6s ease-out forwards; }
@keyframes fx-ring { 0% { opacity: .95; } 100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; border-width: 1px; } }
.fx-puff { position: fixed; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, rgba(255, 255, 255, .95), var(--tint) 55%, transparent 70%); animation: fx-puff .85s ease-out forwards; }
@keyframes fx-puff { 0% { transform: translate(0, 0) scale(.4); opacity: .95; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.9); opacity: 0; } }
/* กล่องของเล่นอ้าปากรับของ */
.td-bin.gulp { animation: gulp .45s ease-out; }
@keyframes gulp { 0% { transform: scale(1); } 30% { transform: scale(1.12, .86); } 60% { transform: scale(.94, 1.08); } 100% { transform: scale(1); } }
/* ชิ้นรูปทรงลงล็อก: ช่องเรืองแสงแว้บหนึ่ง */
.hole.pop { animation: hole-glow .6s ease-out; border-radius: 18px; }
@keyframes hole-glow { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .9); } 100% { box-shadow: 0 0 0 22px rgba(255, 255, 255, 0); } }
/* กระดานดำ: ครูวาดรูปด้วยชอล์กทีละเส้น แล้วค่อยระบายเต็ม */
.sc-shape.chalk g { stroke-dasharray: 600; stroke-dashoffset: 600; fill-opacity: 0; animation: chalk-draw 1.5s ease-out forwards; }
@keyframes chalk-draw { 70% { stroke-dashoffset: 0; fill-opacity: 0; } 100% { stroke-dashoffset: 0; fill-opacity: .92; } }
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 200; overflow: hidden; }
.spark { position: absolute; font-size: 30px; animation: burst .8s ease-out forwards; }
.confetti { position: absolute; top: 0; width: 12px; height: 18px; border-radius: 3px; animation: fall linear forwards; }
.ghost { pointer-events: none; }
.shake { animation: shake .5s; }
.bounce { animation: bounce .7s; }

@keyframes pop { 0% { transform: scale(.4); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes bounce { 0%, 100% { transform: translateY(0) scale(1); } 30% { transform: translateY(-18px) scale(1.06); } 55% { transform: translateY(0) scale(.97); } 75% { transform: translateY(-6px); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-10px) rotate(-3deg); } 40% { transform: translateX(10px) rotate(3deg); } 60% { transform: translateX(-7px); } 80% { transform: translateX(6px); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 35% { transform: translateY(-14%) rotate(-4deg); } 60% { transform: translateY(0); } 80% { transform: translateY(-4%) rotate(2deg); } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.025, .985); } }
@keyframes zz { 0% { opacity: 0; transform: translate(0, 0) scale(.6); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(14px, -30px) scale(1.2); } }
@keyframes burst { from { transform: translate(-50%, -50%) scale(.6); opacity: 1; } to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.2); opacity: 0; } }
@keyframes fall { from { transform: translate(0, -10vh) rotate(0); } to { transform: translate(var(--drift), 110vh) rotate(var(--rot)); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-5deg); } 75% { transform: rotate(5deg); } }
@keyframes ring { from { box-shadow: 0 0 0 0 rgba(255, 209, 102, .8); } to { box-shadow: 0 0 0 40px rgba(255, 209, 102, 0); } }
@keyframes twinkle { 50% { opacity: .25; } }
@keyframes fade { from { opacity: 0; } }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes wobble { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.04, .97); } }
@keyframes burst-bubble { to { transform: scale(1.6); opacity: 0; } }
@keyframes spotpulse { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.22); } }
@keyframes fade-away { to { opacity: 0; } }
@keyframes flicker { from { transform: scale(1, 1) rotate(-3deg); } to { transform: scale(1.06, .94) rotate(3deg); } }
@keyframes drop-fall { to { transform: translateY(46px) scale(.5); opacity: 0; } }
@keyframes germ-zap { to { transform: translate(-50%, -50%) scale(1.6) rotate(40deg); opacity: 0; } }
@keyframes spinpop { from { transform: scale(0) rotate(-200deg); } 70% { transform: scale(1.2) rotate(10deg); } to { transform: scale(1) rotate(0); } }

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

/* ===== ก-ไก่ โหมดเขียน: ลากนิ้วระบายตามรอยตัวอักษร ===== */
.trace { display: flex; align-items: center; justify-content: center; gap: clamp(14px, 3vw, 36px); width: 100%; height: 100%; }
.trace-side { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.trace-pic { width: clamp(110px, min(18vw, 24vh), 190px); aspect-ratio: 1; padding: 10px; border-radius: 26px; display: grid; place-items: center; background: #fff; }
.trace-pic .tp-img { width: 100%; height: 100%; object-fit: contain; font-size: clamp(64px, min(11vw, 15vh), 120px); line-height: 1; display: grid; place-items: center; }
.trace-count { font-weight: 700; color: #8a7aa8; font-size: clamp(14px, 1.8vw, 19px); }
.trace-nav { display: flex; gap: 10px; }
.trace-board {
  position: relative; width: min(62vh, 58vw, 560px); aspect-ratio: 1; border-radius: 32px; overflow: hidden; touch-action: none;
  background: repeating-linear-gradient(0deg, #fffdf7 0 calc(25% - 2px), #e9e2f5 calc(25% - 2px) 25%); box-shadow: 0 10px 26px var(--shadow), inset 0 0 0 4px #fff;
}
.trace-board canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.trace-board .tr-demo { pointer-events: none; }
/* จุดเริ่ม (เขียว ▶) และจุดจบ (🏁) บนเส้นกลางตัวอักษร */
.tr-start, .tr-end { position: absolute; z-index: 2; transform: translate(-50%, -50%); pointer-events: none; display: grid; place-items: center; }
.tr-start {
  width: clamp(26px, 7%, 40px); aspect-ratio: 1; border-radius: 50%; background: #2fb344; color: #fff; font-size: clamp(11px, 2vmin, 17px);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .9), 0 3px 8px rgba(0, 0, 0, .25); animation: tr-pulse 1.1s ease-in-out infinite;
}
.tr-end { font-size: clamp(26px, 4.6vmin, 42px); line-height: 1; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .3)); }
.tr-start[hidden], .tr-end[hidden] { display: none; } /* รูปปิดอย่าง 0 8 O ไม่มีธง */
.trace-board.drawing .tr-start { animation: none; opacity: .85; }
.tr-end:not(.reached) { animation: tr-pulse 1.1s ease-in-out infinite; } /* ธงเด้งรอจนกว่าจะลากไปถึง */
.tr-start.reached { background: #8a8a8a; }
.trace-board.done .tr-start, .trace-board.done .tr-end { opacity: 0; transition: opacity .3s; }
@keyframes tr-pulse { 0%, 100% { scale: 1; } 50% { scale: 1.22; } }
.tr-progress { position: absolute; left: 8%; right: 8%; bottom: 4%; height: 10px; border-radius: 99px; background: rgba(120, 100, 160, .15); overflow: hidden; pointer-events: none; }
.tr-progress i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #ffd166, #2fb344); transition: width .2s; }
.trace-board .tr-ink { cursor: crosshair; touch-action: none; }
.trace-board.done { animation: pop .5s; box-shadow: 0 0 0 6px #ffd166, 0 10px 26px var(--shadow); }
.trace-btn.on { background: #ffd166; box-shadow: 0 0 0 3px #fff, 0 5px 0 #d9a93e; }
/* โหมดเขียนตัวเลข: แท็บเลขอารบิก/เลขไทย และแอปเปิ้ลเท่าจำนวน */
.digit-tabs { display: flex; gap: 8px; }
.digit-tabs .script-tab { width: auto; padding: 0 16px; border-radius: 999px; font-size: calc(var(--tap) * .3); }
.digit-tabs .script-tab.on { background: #ffd166; }
.trace-pic .count-pic { gap: 1px; align-content: center; }
.trace-pic .count-pic img.cp-img { width: 28%; }
@media (orientation: portrait) {
  .trace { flex-direction: column-reverse; }
  .trace-side { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .trace-pic { width: clamp(80px, 22vw, 130px); }
  .trace-board { width: min(88vw, 52vh); }
}

/* ===== เกาะนักคิด ===== */
.game-emotions, .game-phonics, .game-memory, .game-patterns { background: linear-gradient(180deg, #fff7fb 0%, #fff 50%, var(--c) 220%); }
/* บ้านอารมณ์ */
.emotions { display: flex; flex-direction: column; align-items: center; gap: clamp(12px, 3vh, 28px); width: 100%; }
.emo-card { position: relative; padding: 12px 18px 8px; border-radius: 28px; background: #fff; box-shadow: 0 10px 24px var(--shadow); display: flex; flex-direction: column; align-items: center; }
.emo-card .emo-img { width: clamp(150px, min(30vw, 34vh), 300px); height: auto; aspect-ratio: 1; object-fit: contain; }
.emo-card.helped { box-shadow: 0 0 0 6px #ffd166, 0 10px 24px var(--shadow); }
.emo-name { font-weight: 700; font-size: clamp(18px, 2.4vw, 26px); }
.emo-options { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(10px, 2vw, 20px); }
.emo-opt { width: clamp(100px, min(15vw, 20vh), 160px); padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.emo-big { font-size: clamp(42px, min(7vw, 9vh), 72px); line-height: 1.1; display: grid; place-items: center; }
.emo-big img.emo-help-img { width: clamp(52px, 8vw, 84px); height: auto; }
.emo-label { font-weight: 700; font-size: clamp(14px, 1.8vw, 20px); line-height: 1.25; text-align: center; }
/* บ้านการ์ดจับคู่ */
.memory { width: 100%; display: grid; place-items: center; }
.mem-grid { display: grid; gap: clamp(8px, 1.6vw, 16px); grid-template-columns: repeat(4, auto); }
.mem-grid.n2 { grid-template-columns: repeat(4, auto); }
.mem-grid.n3 { grid-template-columns: repeat(3, auto); }
.mem-grid.n6 { grid-template-columns: repeat(4, auto); }
.mem-card { position: relative; width: clamp(78px, min(15vw, 19vh), 150px); aspect-ratio: 3 / 4; border: 0; padding: 0; background: none; cursor: pointer; perspective: 600px; }
.mem-card > span { position: absolute; inset: 0; border-radius: 16px; display: grid; place-items: center; backface-visibility: hidden; transition: transform .35s ease; box-shadow: 0 6px 0 rgba(0, 0, 0, .1), 0 8px 16px var(--shadow); }
.mem-back { background: repeating-linear-gradient(45deg, #b197fc 0 14px, #9775fa 14px 28px); color: #fff; font-size: clamp(28px, 4vw, 44px); }
.mem-front { background: #fff; transform: rotateY(180deg); }
.mem-front .mem-img { width: 80%; height: auto; font-size: clamp(40px, 6vw, 64px); }
.mem-card.up .mem-back { transform: rotateY(180deg); }
.mem-card.up .mem-front { transform: rotateY(360deg); }
.mem-card.done .mem-front { box-shadow: 0 0 0 5px #8ce99a, 0 8px 16px var(--shadow); }
@media (orientation: portrait) { .mem-grid, .mem-grid.n6 { grid-template-columns: repeat(3, auto); } .mem-grid.n2 { grid-template-columns: repeat(2, auto); } }
/* ร้านลูกปัด */
.patterns, .ordering { display: flex; flex-direction: column; align-items: center; gap: clamp(16px, 4vh, 40px); width: 100%; }
.bead-string { position: relative; display: flex; align-items: center; gap: clamp(4px, 1vw, 10px); padding: 14px 20px; border-radius: 999px; background: rgba(255, 255, 255, .85); box-shadow: 0 8px 20px var(--shadow); flex-wrap: wrap; justify-content: center; }
.bead-string::before { content: ""; position: absolute; left: 16px; right: 16px; top: 50%; height: 4px; background: #c9a27a; z-index: 0; border-radius: 4px; }
.bead, .bead-pic, .bead-slot { position: relative; z-index: 1; width: clamp(40px, min(7vw, 9vh), 70px); aspect-ratio: 1; }
@media (max-width: 480px) { .bead-string { gap: 3px; padding: 10px 12px; } .bead, .bead-pic, .bead-slot { width: 32px; } } /* มือถือแนวตั้ง: สายลูกปัดอยู่แถวเดียว */
.bead { display: block; border-radius: 50%; background: radial-gradient(circle at 32% 30%, #fff 0 12%, var(--bc) 30%, color-mix(in srgb, var(--bc) 70%, #000) 100%); box-shadow: 0 3px 5px rgba(0, 0, 0, .25); }
.bead-pic { height: auto; object-fit: contain; font-size: clamp(30px, 5vw, 52px); display: grid; place-items: center; }
.bead-slot { display: grid; place-items: center; border-radius: 50%; border: 3px dashed #c9a27a; background: #fff; font-weight: 700; font-size: clamp(20px, 3vw, 32px); color: #c9a27a; animation: pulse 1.2s ease-in-out infinite; }
.bead-slot.filled { border: 0; background: none; animation: pop .4s; }
.bead-opt { width: clamp(80px, min(12vw, 16vh), 120px); aspect-ratio: 1; display: grid; place-items: center; }
.order-row { display: flex; align-items: flex-end; gap: clamp(8px, 2vw, 20px); padding: 12px 18px; border-radius: 22px; background: rgba(255, 255, 255, .85); box-shadow: 0 8px 20px var(--shadow); }
.order-slot { width: clamp(70px, min(14vw, 18vh), 130px); aspect-ratio: 1; display: grid; place-items: end center; border-bottom: 4px solid #e3d5c3; }
.order-pile { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: clamp(10px, 2vw, 24px); }
.order-item { width: clamp(70px, min(14vw, 18vh), 130px); aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer; display: grid; place-items: end center; }
.order-item .order-img { width: var(--sz); height: auto; font-size: calc(var(--sz) * .9); filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .2)); }
.order-item.gone { visibility: hidden; }
.order-item.placed { cursor: default; }
/* บ้านอ่านคำ */
.phonics { display: flex; flex-direction: column; align-items: center; gap: clamp(16px, 4vh, 40px); width: 100%; }
.ph-top { display: flex; align-items: center; gap: clamp(10px, 2vw, 24px); flex-wrap: wrap; justify-content: center; }
.ph-eq { display: flex; align-items: center; gap: clamp(6px, 1.2vw, 12px); }
.ph-tile, .ph-opt { min-width: clamp(64px, min(10vw, 13vh), 104px); aspect-ratio: 1; border-radius: 20px; display: grid; place-items: center; font-size: clamp(38px, min(6.5vw, 8.5vh), 72px); font-weight: 700; line-height: 1.3; padding: 0 10px 6px; border: 0; cursor: pointer; }
.ph-tile { background: #fff; box-shadow: 0 6px 0 rgba(0, 0, 0, .08), 0 8px 16px var(--shadow); }
.ph-c { color: #1c7ed6; } .ph-v { color: #e8436f; } .ph-f { color: #2f9e44; } .ph-t { color: #f08c00; }
.ph-tile.blank { color: #c9b8a6; border: 4px dashed #c9b8a6; background: #fffdf8; animation: pulse 1.2s ease-in-out infinite; }
.ph-tile.filled { animation: pop .4s; box-shadow: 0 0 0 5px #ffd166, 0 8px 16px var(--shadow); }
.ph-plus, .ph-eqsign { font-size: clamp(26px, 4vw, 44px); font-weight: 700; color: #9a8f86; }
.ph-pic { width: clamp(120px, min(18vw, 24vh), 200px); padding: 8px; display: flex; flex-direction: column; align-items: center; }
.ph-pic .ph-img { width: 82%; height: auto; aspect-ratio: 1; object-fit: contain; font-size: clamp(56px, 8vw, 90px); display: grid; place-items: center; }
.ph-word { min-height: 1.3em; font-size: clamp(26px, 3.6vw, 40px); font-weight: 700; color: var(--coral); }
.ph-pic.read { box-shadow: 0 0 0 6px #ffd166, 0 8px 16px var(--shadow); }

/* ===== บทที่ 2: งานเทศกาลสายรุ้ง ===== */
.bld-fest { position: absolute; top: -26%; right: -6%; font-size: clamp(22px, 3.4vw, 44px); filter: grayscale(1) opacity(.45); animation: floaty 2.6s ease-in-out infinite; pointer-events: none; }
.bld-fest.got { filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .25)); }
.rainbow-meter.fest { gap: 0; }
.rm-balloon { font-size: clamp(14px, 2.3vw, 26px); line-height: 1; filter: grayscale(1) opacity(.35); }
.rm-balloon.on { filter: hue-rotate(var(--h)) saturate(1.2); animation: pop .5s; }
.world-king.call img { animation: pulse 1.1s ease-in-out infinite; }
.king-call { position: absolute; top: -10%; right: -10%; font-size: clamp(20px, 3vw, 36px); animation: bounce 1s ease-in-out infinite; }
.rh-balloon { font-size: calc(var(--tap) * .4); line-height: 1; }
.fest-card { gap: 10px; }
.fest-king { width: clamp(110px, 18vh, 170px); height: auto; animation: floaty 2.4s ease-in-out infinite; }
.fest-balloons { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; max-width: min(80vw, 460px); }
.fest-balloons .fb { font-size: clamp(26px, 5vh, 44px); filter: grayscale(1) opacity(.3); }
.fest-balloons .fb.on { filter: hue-rotate(var(--h)) saturate(1.2); }
.fest-balloons .fb.new { animation: pop .6s .3s both, floaty 2s ease-in-out 1s infinite; }
.fest-count { font-weight: 700; font-size: clamp(20px, 3vw, 30px); color: #7a4fd0; }

/* ---------- รายงานทักษะ (มุมผู้ปกครอง) ---------- */
.panel.skills .skill-head { font-size: 18px; font-weight: 500; color: var(--ink); margin: 4px 0 10px; }
.skill-group h4 { margin: 14px 0 6px; font-size: 16px; font-weight: 600; }
.skill-row { display: grid; grid-template-columns: minmax(150px, 1.1fr) minmax(90px, 1fr) minmax(110px, auto); gap: 4px 12px; align-items: center; padding: 6px 0; border-bottom: 1px solid #eef0f5; font-size: 15px; }
.skill-row.none { opacity: .5; }
.skill-bar { position: relative; height: 12px; border-radius: 99px; background: #eef0f5; overflow: hidden; }
.skill-bar::before, .skill-bar::after { content: ''; position: absolute; inset: 0 auto 0 0; border-radius: inherit; }
.skill-bar::before { width: var(--t); background: #bfe6c8; }
.skill-bar::after { width: var(--k); background: #3fb26b; }
.skill-val { font-variant-numeric: tabular-nums; }
.skill-try { display: block; font-size: 12px; color: var(--ink-soft); }
.skill-miss { grid-column: 1 / -1; font-size: 13px; color: var(--ink-soft); line-height: 1.6; }
@media (max-width: 560px) { .skill-row { grid-template-columns: 1fr auto; } .skill-bar { grid-column: 1 / -1; grid-row: 2; } }
