/* ===== โลกของลิลลี่ — ธีมหลัก ===== */

:root {
  --pink: #ff8fc0;
  --pink-dark: #d9598f;
  --yellow: #ffc94d;
  --yellow-dark: #d99d1c;
  --blue: #6ec6ff;
  --blue-dark: #2f96de;
  --green: #7ed957;
  --green-dark: #4da62c;
  --purple: #b08cff;
  --purple-dark: #7e57e0;
  --orange: #ffa45c;
  --orange-dark: #dd7726;

  --ink: #4a3b52;
  --ink-soft: #8b7a94;
  --card: #fffdfa;
  --card-edge: #f0e2ec;

  --r-lg: 32px;
  --r-md: 22px;
  --r-sm: 14px;

  --font-th: 'Itim', 'Noto Sans Thai', system-ui, sans-serif;
  --font-num: 'Fredoka', 'Itim', system-ui, sans-serif;
}

/* ตัวอักษรขอบหนาแบบเกมเด็ก อ่านง่ายบนพื้นหลังสีอ่อน */
.outlined {
  color: #fff;
  text-shadow:
    -2px -2px 0 var(--pink-dark), 2px -2px 0 var(--pink-dark),
    -2px 2px 0 var(--pink-dark), 2px 2px 0 var(--pink-dark),
    0 6px 0 var(--pink-dark), 0 10px 14px rgba(0, 0, 0, .22);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ล็อกหน้าให้อยู่กับที่บนมือถือ — overflow:hidden อย่างเดียว Safari ยังปล่อยให้ลากหน้าขยับได้
   ตอนเด็กลากนิ้วเขียนตัวอักษร หน้าเลยเลื่อนตาม */
body {
  position: fixed;
  inset: 0;
  width: 100%;
  font-family: var(--font-th);
  color: var(--ink);
  background: linear-gradient(180deg, #bfe9ff 0%, #ffe4f1 55%, #fff4dd 100%);
  background-attachment: fixed;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-size: 18px;
}

/* ===== ท้องฟ้า + เมฆลอย ===== */
.sky { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }

.cloud {
  position: absolute;
  background: rgba(255, 255, 255, 0.78);
  border-radius: 999px;
  filter: blur(0.5px);
  animation: drift linear infinite;
}
.cloud::before, .cloud::after {
  content: '';
  position: absolute;
  background: inherit;
  border-radius: 999px;
}
.cloud::before { width: 55%; height: 150%; left: 12%; top: -60%; }
.cloud::after  { width: 42%; height: 130%; right: 10%; top: -40%; }

.c1 { width: 160px; height: 52px; top: 8%;  animation-duration: 68s; }
.c2 { width: 110px; height: 38px; top: 24%; animation-duration: 92s; animation-delay: -30s; }
.c3 { width: 200px; height: 62px; top: 46%; animation-duration: 110s; animation-delay: -60s; opacity: .6; }
.c4 { width: 130px; height: 44px; top: 66%; animation-duration: 80s; animation-delay: -15s; opacity: .5; }

@keyframes drift {
  from { transform: translateX(-260px); }
  to   { transform: translateX(calc(100vw + 260px)); }
}

/* ===== โครงหน้าจอ ===== */
#app {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
           max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  overflow: hidden;
}

.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  animation: screen-in .35s cubic-bezier(.2, .9, .3, 1.2);
}

@keyframes screen-in {
  from { opacity: 0; transform: scale(.96) translateY(12px); }
  to   { opacity: 1; transform: none; }
}

/* ===== ปุ่มแบบของเล่น ===== */
.btn {
  font-family: var(--font-th);
  font-size: 1.35rem;
  color: #fff;
  background: var(--pink);
  border: none;
  border-radius: var(--r-md);
  padding: 16px 34px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--pink-dark), 0 10px 18px rgba(0, 0, 0, .12);
  transition: transform .08s, box-shadow .08s, filter .15s;
  line-height: 1.2;
}
.btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--pink-dark), 0 4px 10px rgba(0, 0, 0, .12);
}
.btn.big { font-size: 1.9rem; padding: 20px 56px; border-radius: var(--r-lg); }
.btn.blue   { background: var(--blue);   box-shadow: 0 6px 0 var(--blue-dark),   0 10px 18px rgba(0,0,0,.12); }
.btn.blue:active   { box-shadow: 0 1px 0 var(--blue-dark),   0 4px 10px rgba(0,0,0,.12); }
.btn.green  { background: var(--green);  box-shadow: 0 6px 0 var(--green-dark),  0 10px 18px rgba(0,0,0,.12); }
.btn.green:active  { box-shadow: 0 1px 0 var(--green-dark),  0 4px 10px rgba(0,0,0,.12); }
.btn.yellow { background: var(--yellow); box-shadow: 0 6px 0 var(--yellow-dark), 0 10px 18px rgba(0,0,0,.12); }
.btn.yellow:active { box-shadow: 0 1px 0 var(--yellow-dark), 0 4px 10px rgba(0,0,0,.12); }
.btn.purple { background: var(--purple); box-shadow: 0 6px 0 var(--purple-dark), 0 10px 18px rgba(0,0,0,.12); }
.btn.purple:active { box-shadow: 0 1px 0 var(--purple-dark), 0 4px 10px rgba(0,0,0,.12); }

.icon-btn {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  font-size: 1.7rem;
  font-family: var(--font-th);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--card-edge), 0 6px 14px rgba(0, 0, 0, .1);
  display: grid;
  place-items: center;
  transition: transform .08s, box-shadow .08s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--card-edge); }

/* ===== หน้าแรก ===== */
.home {
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}
.home h1 {
  font-size: clamp(2.6rem, 8vw, 4.6rem);
  margin: 0;
  letter-spacing: 1px;
  animation: title-bob 3s ease-in-out infinite;
}
@keyframes title-bob {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50%      { transform: translateY(-10px) rotate(1deg); }
}
.home .tagline { color: var(--ink-soft); font-size: 1.2rem; margin: 4px 0 18px; }

.home-buddies { display: flex; gap: 18px; margin: 4px 0 22px; }
.home-buddies span {
  font-size: clamp(3rem, 10vw, 4.6rem);
  animation: hop 1.6s ease-in-out infinite;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .15));
}
.home-buddies span:nth-child(2) { animation-delay: .2s; }
.home-buddies span:nth-child(3) { animation-delay: .4s; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40%      { transform: translateY(-18px) scale(1.05); }
}

.home-stars {
  margin-top: 20px;
  font-size: 1.25rem;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, .7);
  border-radius: 999px;
  padding: 8px 22px;
}

.home-row { display: flex; align-items: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; justify-content: center; }
.home-row .home-stars { margin-top: 0; }
.btn.small { font-size: 1.05rem; padding: 10px 20px; border-radius: 999px; }
.home-next { margin-top: 12px; color: var(--ink-soft); font-size: 1.05rem; }
.home-next b { font-family: var(--font-num); color: var(--purple-dark); font-size: 1.2rem; }

/* ===== รางวัล: popup, ตู้รางวัล ===== */
.reward-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(74, 59, 82, .45);
  animation: screen-in .3s ease-out;
}
.reward-card {
  position: relative;
  background: #fff;
  border-radius: var(--r-lg);
  padding: clamp(18px, 3vh, 30px) clamp(22px, 5vw, 44px);
  text-align: center;
  box-shadow: 0 10px 0 var(--card-edge), 0 24px 50px rgba(0, 0, 0, .3);
  max-width: min(92vw, 440px);
  animation: pop-in .5s cubic-bezier(.2, .9, .3, 1.5);
}
.reward-burst { font-size: 2rem; animation: hop 1.2s ease-in-out infinite; }
.reward-title { font-size: 1.3rem; color: var(--ink-soft); }
.reward-emoji {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: clamp(110px, 24vw, 150px);
  aspect-ratio: 1;
  margin: 8px 0;
  border-radius: 50%;
  background: radial-gradient(circle, #fff7d6, #ffe08a);
  box-shadow: 0 0 0 6px #fff, 0 0 0 10px var(--yellow), 0 8px 20px rgba(255, 201, 77, .5);
  font-size: clamp(3.6rem, 9vw, 5rem);
  line-height: 1;
  animation: star-pop .7s cubic-bezier(.2, .9, .3, 1.6);
}
/* ถ้วยรางวัล: 🏆 อยู่หลัง แล้วสัตว์ตัวโปรดนั่งข้างบน */
.reward-emoji.cup { font-size: clamp(3.2rem, 8vw, 4.4rem); }
.reward-emoji.cup span {
  position: absolute;
  top: 6%;
  font-size: .6em;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .25));
}
.reward-emoji.small { width: clamp(64px, 12vw, 84px); font-size: clamp(2rem, 5vw, 2.8rem); margin: 0 0 6px; box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--yellow); }
.reward-emoji.small.cup { font-size: clamp(1.9rem, 4.6vw, 2.5rem); }
.reward-name { font-size: 1.5rem; }
.reward-desc { color: var(--ink-soft); margin: 4px 0 14px; }
.reward-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.reward-progress .bar { margin: 10px 0 6px; }
.reward-progress b { font-family: var(--font-num); color: var(--purple-dark); }

.reward-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.reward-tile {
  background: #fff;
  border-radius: var(--r-md);
  padding: 14px 10px 12px;
  text-align: center;
  box-shadow: 0 5px 0 var(--card-edge);
  transition: transform .1s;
}
.reward-tile.open[data-type="mini"] { cursor: pointer; }
.reward-tile.open[data-type="mini"]:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--card-edge); }
.reward-tile.locked { background: #f3eef6; }
.reward-tile.locked .reward-emoji { filter: grayscale(1) opacity(.45); background: #e8e0ec; box-shadow: 0 0 0 3px #fff, 0 0 0 5px #d8cfe0; }
.reward-tile.nope { animation: wiggle .45s; }
.tile-name { font-size: 1.05rem; line-height: 1.2; min-height: 2.4em; display: grid; place-items: center; }
.tile-meta { font-size: .9rem; color: var(--ink-soft); margin-top: 4px; }
.play-tag { color: var(--green-dark); font-weight: 400; }
.tile-stars { font-family: var(--font-num); font-size: .85rem; color: var(--ink-soft); margin-top: 4px; }

/* ===== มินิเกม ===== */
.mini-stage { gap: clamp(6px, 1.4vh, 14px); }
.mini-top, .palette, .mini-actions, .seed-tray { display: flex; gap: clamp(6px, 1.4vw, 12px); flex-wrap: wrap; justify-content: center; flex: 0 0 auto; }
.mini-actions .btn { font-size: 1rem; padding: 10px 20px; }
.mini-hint { font-size: clamp(.95rem, 2.2vw, 1.15rem); color: var(--ink-soft); text-align: center; flex: 0 0 auto; }

.pic-btn, .seed-btn {
  font-size: clamp(1.6rem, 4.5vw, 2.4rem);
  width: clamp(52px, 10vw, 72px);
  height: clamp(52px, 9vh, 72px);
  border: 4px solid transparent;
  border-radius: var(--r-sm);
  background: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--card-edge);
  line-height: 1;
}
.pic-btn.on, .seed-btn.on { border-color: var(--purple); background: #f3ecff; }

.art-wrap { flex: 1 1 auto; min-height: 0; width: 100%; display: grid; place-items: center; }
.art {
  width: auto;
  height: 100%;
  max-width: 100%;
  max-height: min(52vh, 420px);
  aspect-ratio: 200 / 160;
  background: #fff;
  border-radius: var(--r-md);
  box-shadow: 0 6px 0 var(--card-edge), 0 10px 20px rgba(0, 0, 0, .1);
  touch-action: manipulation;
}
.art .r { cursor: pointer; transition: fill .15s; }
.art .r.pop { animation: region-pop .35s ease-out; }
@keyframes region-pop { 50% { stroke-width: 6; } }
.art .d { pointer-events: none; }
.art text { pointer-events: none; }
.art.tiny { height: clamp(48px, 9vh, 70px); box-shadow: 0 3px 0 var(--card-edge); border-radius: 10px; }

.swatch {
  width: clamp(38px, 7.5vw, 52px);
  height: clamp(38px, 7.5vw, 52px);
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .15);
  cursor: pointer;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform .1s;
}
.swatch.on { transform: scale(1.22); box-shadow: 0 0 0 3px var(--purple), 0 3px 0 rgba(0, 0, 0, .15); }
.swatch.eraser, .swatch.topping { background: #fff; }
.palette-gap { width: 14px; }

/* สวนผัก */
.basket {
  background: #fff;
  border-radius: 999px;
  padding: 8px 20px;
  font-size: clamp(1.1rem, 2.8vw, 1.5rem);
  box-shadow: 0 4px 0 var(--card-edge);
  display: flex;
  gap: 14px;
  align-items: center;
  flex: 0 0 auto;
}
.basket span b { font-family: var(--font-num); font-size: .85em; color: var(--purple-dark); margin-left: 2px; }
.basket .dim, .showcase .dim { color: var(--ink-soft); font-size: .9em; }
.garden {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 2vw, 18px);
  flex: 0 0 auto;
  width: min(100%, 520px);
}
.plot {
  position: relative;
  aspect-ratio: 1.15;
  border: none;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, #a5d86e 0 38%, #8d6e63 38%);
  box-shadow: 0 6px 0 #6d4c41, 0 8px 16px rgba(0, 0, 0, .15);
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
  transition: transform .08s;
}
.plot:active { transform: translateY(4px); box-shadow: 0 2px 0 #6d4c41; }
.plot.s0::after { content: '+'; color: rgba(255, 255, 255, .7); font-family: var(--font-num); font-size: 2rem; }
.plot .growing { font-size: .6em; display: inline-block; animation: hop 2s ease-in-out infinite; }
.plot .ready { display: inline-block; animation: ready-pulse 1s ease-in-out infinite; }
.plot .spark { position: absolute; top: 8px; right: 10px; font-size: .5em; font-style: normal; animation: hop 1.2s ease-in-out infinite; }
.plot .splash {
  position: absolute;
  left: 50%; top: 20%;
  transform: translateX(-50%);
  font-size: .55em;
  animation: splash-up .8s ease-out forwards;
  pointer-events: none;
}
@keyframes splash-up { 0% { opacity: 1; transform: translate(-50%, 0) scale(.6); } 100% { opacity: 0; transform: translate(-50%, -40px) scale(1.3); } }

/* ระนาด */
/* ใช้ grid เพราะความสูงเป็น % ของแท่งจะคำนวณได้แน่นอนกว่าใน flex */
.xylo {
  display: grid;
  grid-template-columns: repeat(8, clamp(34px, 9vw, 72px));
  align-items: end;
  justify-content: center;
  gap: clamp(6px, 1.6vw, 14px);
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  width: 100%;
  padding: 10px 0;
}
.xbar {
  width: 100%;
  height: var(--h);
  border: none;
  border-radius: 14px;
  background: var(--c);
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, .15), 0 6px 0 rgba(0, 0, 0, .2);
  color: #fff;
  font-family: var(--font-th);
  font-size: clamp(.9rem, 2.4vw, 1.2rem);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12px;
  cursor: pointer;
  touch-action: none;
  transition: transform .06s;
}
.xbar.hit { animation: bar-hit .25s ease-out; }
@keyframes bar-hit { 0% { transform: scale(1.06); filter: brightness(1.3); } 100% { transform: scale(1); } }

/* ลูกโป่ง */
.balloon-score b { font-family: var(--font-num); color: var(--purple-dark); font-size: 1.3em; }
.sky-box {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, .25), rgba(255, 255, 255, .55));
}
.balloon {
  position: absolute;
  bottom: -120px;
  width: clamp(56px, 12vw, 84px);
  height: clamp(68px, 14.5vw, 100px);
  border: none;
  padding: 0;
  background: var(--c);
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  box-shadow: inset -8px -10px 0 rgba(0, 0, 0, .12), inset 6px 8px 0 rgba(255, 255, 255, .35);
  cursor: pointer;
  touch-action: none;
  animation: float-up linear forwards;
  display: grid;
  place-items: center;
  font-size: 1.8rem;
}
.balloon .string {
  position: absolute;
  top: 100%;
  left: 50%;
  width: 2px;
  height: 40px;
  background: rgba(90, 74, 99, .5);
}
.balloon.pop { animation: pop-out .35s ease-out forwards; background: none; box-shadow: none; }
@keyframes float-up { to { transform: translateY(calc(-100vh - 200px)) rotate(4deg); } }
@keyframes pop-out { to { transform: scale(1.8); opacity: 0; } }

/* ตู้ปลา */
.tank {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  border-radius: var(--r-md);
  background: linear-gradient(180deg, #bfe9ff 0%, #6ec6ff 70%, #e8d5a3 88%, #d9c48f 100%);
  box-shadow: inset 0 0 0 6px rgba(255, 255, 255, .6), 0 6px 0 var(--card-edge);
}
.tank-item { position: absolute; cursor: pointer; line-height: 1; user-select: none; }
.tank-item.swim { animation: swim var(--dur) ease-in-out infinite alternate; animation-delay: var(--delay); }
.tank-item.decor { animation: sway 3s ease-in-out infinite alternate; transform-origin: bottom; }
.tank-item.boing { animation: cheer .5s cubic-bezier(.2, .9, .3, 1.6); }
@keyframes swim {
  0% { transform: translateX(0) scaleX(-1); }
  49% { transform: translateX(min(60vw, 420px)) scaleX(-1); }
  51% { transform: translateX(min(60vw, 420px)) scaleX(1); }
  100% { transform: translateX(0) scaleX(1); }
}
@keyframes sway { from { transform: rotate(-6deg); } to { transform: rotate(6deg); } }
.tray .pic-btn { width: clamp(44px, 8vw, 60px); height: clamp(44px, 7vh, 60px); font-size: clamp(1.3rem, 3.5vw, 1.9rem); }

/* แต่งตัวเพื่อนซี้ */
.dress-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: min(100%, 420px);
  aspect-ratio: 1;
  max-height: 46vh;
  background: #fff;
  border-radius: var(--r-md);
  box-shadow: 0 6px 0 var(--card-edge), 0 10px 20px rgba(0, 0, 0, .1);
  cursor: crosshair;
  overflow: hidden;
}
.dress-buddy {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(7rem, 30vh, 13rem);
  line-height: 1;
  pointer-events: none;
}
.worn {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: clamp(2.2rem, 8vh, 3.6rem);
  line-height: 1;
  cursor: pointer;
  animation: pop-in .3s cubic-bezier(.2, .9, .3, 1.5);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .2));
}

/* ร้านขนม */
.showcase {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 1.2rem;
}
.shelf-item { display: inline-block; }

.parent-link {
  margin-top: 18px;
  background: none;
  border: none;
  font-family: var(--font-th);
  font-size: 1rem;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 999px;
}
.parent-link:active { background: rgba(255, 255, 255, .5); }

/* ===== หน้าสรุปสำหรับผู้ปกครอง ===== */
.summary-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 4px 4px 30px;
  -webkit-overflow-scrolling: touch;
}

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat {
  background: #fff;
  border-radius: var(--r-md);
  padding: 14px 10px;
  text-align: center;
  box-shadow: 0 4px 0 var(--card-edge);
}
.stat b { display: block; font-family: var(--font-num); font-size: 2rem; color: var(--purple-dark); line-height: 1.1; }
.stat b small { font-size: 1rem; color: var(--ink-soft); }
.stat span { font-size: .9rem; color: var(--ink-soft); }

.summary .card {
  background: #fff;
  border-radius: var(--r-md);
  padding: 16px 18px;
  box-shadow: 0 4px 0 var(--card-edge);
}
.summary .card h3 { margin: 0 0 10px; font-size: 1.2rem; font-weight: 400; }
.summary .card.empty { text-align: center; color: var(--ink-soft); font-size: 1.1rem; padding: 26px; }
.summary .hint { margin: -4px 0 10px; font-size: .92rem; color: var(--ink-soft); }
.summary .foot { text-align: center; color: var(--ink-soft); font-size: .88rem; }

.subj-row { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 12px; padding: 6px 0; }
.subj-name { font-size: 1.05rem; }
.subj-meta { font-size: .9rem; color: var(--ink-soft); white-space: nowrap; }
.bar { height: 14px; border-radius: 999px; background: #f0e9f4; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--green), var(--blue)); transition: width .4s; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.lv-chip {
  font-family: var(--font-th);
  font-size: .98rem;
  color: var(--ink);
  background: #f7f1fb;
  border: none;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--card-edge);
}
.lv-chip b { font-family: var(--font-num); color: var(--purple-dark); margin-left: 4px; }
.lv-chip:active { transform: translateY(2px); box-shadow: none; }

.table-wrap { overflow-x: auto; }
.lv-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.lv-table th { text-align: left; color: var(--ink-soft); font-weight: 400; padding: 6px 8px; border-bottom: 2px solid var(--card-edge); white-space: nowrap; }
.lv-table td { padding: 7px 8px; border-bottom: 1px solid #f3edf6; white-space: nowrap; }
.lv-table td.lv { white-space: normal; min-width: 150px; }
.lv-table td.stars { font-size: .85rem; letter-spacing: -2px; }
.lv-table .dim { opacity: .2; filter: grayscale(1); }
.lv-table tr.untried td { color: var(--ink-soft); }

.summary .card.danger { border: 2px dashed #f4c7c7; }
.hold-btn {
  position: relative;
  overflow: hidden;
  background: #f7f1fb;
  color: var(--ink);
  box-shadow: 0 5px 0 var(--card-edge);
  font-size: 1.05rem;
  padding: 14px 28px;
  touch-action: none;
  user-select: none;
}
.hold-btn .fill {
  position: absolute;
  inset: 0;
  width: 0;
  background: #ff6b6b;
  transition: width 0s;
}
.hold-btn.holding .fill { width: 100%; transition: width 2s linear; }
.hold-btn .label { position: relative; }
.hold-btn.holding .label { color: #fff; }

/* ===== แผนที่ด่าน ===== */
.map-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 6px 10px;
  flex: 0 0 auto;
}
.map-head h2 { margin: 0; font-size: 1.7rem; }
.spacer { flex: 1; }

.star-counter {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, .85);
  border-radius: 999px;
  padding: 8px 20px;
  font-size: 1.4rem;
  font-family: var(--font-num);
  font-weight: 600;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .06);
}

/* แถบกรองหมวดบนแผนที่ */
.subject-bar {
  display: flex;
  gap: 8px;
  padding: 0 6px 8px;
  flex: 0 0 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.subject-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  font-family: var(--font-th);
  font-size: clamp(.95rem, 2.2vw, 1.15rem);
  color: var(--ink);
  background: rgba(255, 255, 255, .8);
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--card-edge);
  transition: transform .08s, background .15s, color .15s;
}
.chip.on { background: var(--purple); color: #fff; box-shadow: 0 3px 0 var(--purple-dark); }
.chip:active { transform: translateY(2px); box-shadow: none; }

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: safe center;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: none;
}
.map-wrap::-webkit-scrollbar { display: none; }

.map-stage {
  position: relative;
  flex: 0 0 auto;
  height: 100%;
  max-height: 100%;
}
.map-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-path {
  fill: none;
  stroke: #fff;
  stroke-width: 17;
  stroke-linecap: round;
  stroke-dasharray: 1 36;
  filter: drop-shadow(0 3px 2px rgba(120, 90, 130, .35));
}

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: clamp(84px, 12vw, 128px);
  aspect-ratio: 1;
  border: none;
  border-radius: 30%;
  background: var(--card);
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 0;
  padding: 0;
  font-family: var(--font-th);
  box-shadow: 0 7px 0 var(--card-edge), 0 12px 22px rgba(0, 0, 0, .16);
  transition: transform .12s, box-shadow .12s;
}
.node:active { transform: translate(-50%, -50%) translateY(4px); box-shadow: 0 3px 0 var(--card-edge); }
.node .node-icon { font-size: clamp(2.2rem, 5vw, 3.2rem); line-height: 1; }
.node .node-num {
  position: absolute;
  top: -10px; left: -10px;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  font-family: var(--font-num);
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 0 var(--purple-dark);
}
.node .node-stars {
  position: absolute;
  bottom: -14px;
  display: flex;
  gap: 2px;
  font-size: 1.15rem;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .18));
}
.node .node-stars .off { opacity: .25; filter: grayscale(1); }
.node .node-label {
  position: absolute;
  top: calc(100% + 26px);
  white-space: nowrap;
  font-size: clamp(.8rem, 1.6vw, 1.05rem);
  color: var(--ink);
  background: rgba(255, 255, 255, .85);
  padding: 2px 12px;
  border-radius: 999px;
}
/* เด้งเฉพาะด่านที่ควรเล่นต่อ ด่านอื่นเปิดให้กดได้หมดแต่ไม่ต้องแย่งความสนใจ */
.node.current { animation: node-pulse 2.4s ease-in-out infinite; }
.node.current .node-num { background: var(--green); box-shadow: 0 3px 0 var(--green-dark); }
@keyframes node-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%      { transform: translate(-50%, -50%) scale(1.055); }
}

/* ===== หน้าจอเกม ===== */
.game-screen { gap: 8px; }

.game-bar { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }

.dots { display: flex; gap: 8px; }
.dots i {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .75);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, .08);
  transition: background .3s, transform .3s;
}
.dots i.done { background: var(--green); transform: scale(1.15); }
.dots i.now  { background: var(--yellow); transform: scale(1.3); }

.game-stage {
  flex: 1;
  min-height: 0;
  background: rgba(255, 255, 255, .55);
  border-radius: var(--r-lg);
  padding: clamp(10px, 2vh, 22px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vh, 20px);
  position: relative;
  overflow: hidden;
}

.prompt {
  font-size: clamp(1.1rem, 2.6vw, 1.6rem);
  color: var(--ink);
  background: #fff;
  border-radius: 999px;
  padding: 8px 26px;
  box-shadow: 0 4px 0 var(--card-edge);
  text-align: center;
  flex: 0 0 auto;
}

/* ===== เกมบวกเลข: บล็อกฐานสิบ ===== */
.equation {
  display: flex;
  align-items: center;
  gap: clamp(8px, 2vw, 18px);
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(2.2rem, 7vw, 4rem);
  color: var(--ink);
  flex: 0 0 auto;
}
.equation .num { color: var(--purple-dark); }
.equation .op { color: var(--ink-soft); }
.equation .qmark {
  color: var(--pink-dark);
  animation: hop 1.4s ease-in-out infinite;
  display: inline-block;
}

.workspace {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 3vw, 34px);
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}
.workspace .plus {
  font-family: var(--font-num);
  font-size: clamp(2rem, 5vw, 3rem);
  color: var(--ink-soft);
}

.group {
  background: rgba(255, 255, 255, .8);
  border-radius: var(--r-md);
  padding: clamp(8px, 1.6vh, 16px) clamp(10px, 2vw, 20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .05);
  transition: transform .4s cubic-bezier(.4, 0, .2, 1), opacity .4s;
}
.group.merge-left  { transform: translateX(30%) scale(.9); opacity: 0; }
.group.merge-right { transform: translateX(-30%) scale(.9); opacity: 0; }
.group.pop-in { animation: pop-in .45s cubic-bezier(.2, .9, .3, 1.5); }
@keyframes pop-in {
  from { transform: scale(.7); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.rods { display: flex; gap: 6px; min-height: 10px; align-items: flex-end; }

.rod {
  width: clamp(14px, 2.2vw, 22px);
  height: clamp(70px, 13vh, 110px);
  border-radius: 7px;
  background: repeating-linear-gradient(
    to bottom,
    var(--blue) 0, var(--blue) calc(10% - 1.5px),
    rgba(255, 255, 255, .75) calc(10% - 1.5px), rgba(255, 255, 255, .75) 10%
  );
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .12), 0 3px 0 var(--blue-dark);
}
.rod.new-rod { animation: rod-drop .55s cubic-bezier(.2, .9, .3, 1.6); }
@keyframes rod-drop {
  0%   { transform: translateY(60px) scale(.4) rotate(-20deg); opacity: 0; }
  60%  { transform: translateY(-8px) scale(1.12); opacity: 1; }
  100% { transform: none; }
}

.units {
  display: grid;
  grid-template-columns: repeat(10, auto);
  justify-content: center;
  gap: clamp(3px, .7vw, 7px);
  padding: 6px;
  border-radius: var(--r-sm);
  background: rgba(0, 0, 0, .04);
  min-height: 10px;
}
.units.empty { display: none; }

.unit {
  width: clamp(16px, 2.6vw, 26px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 30%, #ffd89a, var(--orange));
  box-shadow: 0 2px 0 var(--orange-dark);
}
.units.bundle-ready {
  cursor: pointer;
  padding: 12px;
  background: rgba(255, 201, 77, .25);
  box-shadow: 0 0 0 4px rgba(255, 201, 77, .65);
}

.unit.ready {
  background: radial-gradient(circle at 32% 30%, #fff3b0, var(--yellow));
  box-shadow: 0 0 0 3px rgba(255, 201, 77, .55), 0 2px 0 var(--yellow-dark);
  animation: ready-pulse .9s ease-in-out infinite;
}
@keyframes ready-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.18); }
}
.unit.bundling { animation: bundle-away .45s ease-in forwards; }
@keyframes bundle-away {
  to { transform: scale(.2) translateY(-40px); opacity: 0; }
}

.carry-badge {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--yellow);
  color: #fff;
  font-size: clamp(1.2rem, 3.4vw, 2rem);
  padding: 10px 28px;
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--yellow-dark);
  animation: badge-in 1.6s ease-out forwards;
  pointer-events: none;
  z-index: 5;
}
@keyframes badge-in {
  0%   { transform: translateX(-50%) scale(.3); opacity: 0; }
  20%  { transform: translateX(-50%) scale(1.15); opacity: 1; }
  35%  { transform: translateX(-50%) scale(1); }
  80%  { opacity: 1; }
  100% { transform: translateX(-50%) translateY(-30px) scale(.9); opacity: 0; }
}

/* ตัวเลือกคำตอบ */
.choices { display: flex; gap: clamp(10px, 3vw, 28px); flex-wrap: wrap; justify-content: center; flex: 0 0 auto; }

.choice {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(2rem, 5.5vw, 3.2rem);
  color: #fff;
  background: var(--purple);
  border: none;
  border-radius: var(--r-md);
  min-width: clamp(100px, 18vw, 160px);
  padding: clamp(10px, 2vh, 20px) 10px;
  cursor: pointer;
  box-shadow: 0 7px 0 var(--purple-dark), 0 10px 18px rgba(0, 0, 0, .14);
  transition: transform .08s, box-shadow .08s;
}
.choice:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--purple-dark); }
.choice.correct {
  background: var(--green);
  box-shadow: 0 7px 0 var(--green-dark);
  animation: cheer .55s cubic-bezier(.2, .9, .3, 1.6);
}
@keyframes cheer {
  0% { transform: scale(1); } 45% { transform: scale(1.2) rotate(3deg); } 100% { transform: scale(1.08); }
}
.choice.nope { animation: wiggle .45s; }
@keyframes wiggle {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-12px) rotate(-4deg); }
  40% { transform: translateX(12px) rotate(4deg); }
  60% { transform: translateX(-8px) rotate(-2deg); }
  80% { transform: translateX(8px) rotate(2deg); }
}

/* ===== เกมจับคู่คำศัพท์ ===== */
.match-area {
  display: flex;
  flex-direction: column;
  gap: clamp(30px, 6vh, 56px);
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.pic-row, .word-row {
  display: flex;
  gap: clamp(10px, 3vw, 30px);
  justify-content: center;
  flex-wrap: wrap;
}

.pic-card {
  width: clamp(96px, 17vw, 160px);
  aspect-ratio: 1;
  border-radius: var(--r-md);
  background: var(--card);
  display: grid;
  place-items: center;
  font-size: clamp(3rem, 8vw, 5rem);
  box-shadow: 0 6px 0 var(--card-edge), 0 10px 18px rgba(0, 0, 0, .1);
  position: relative;
  transition: transform .15s, box-shadow .15s;
}
.pic-card.hover-target {
  transform: scale(1.08);
  box-shadow: 0 6px 0 var(--green-dark), 0 0 0 5px var(--green);
}
.pic-card.solved {
  background: #eaffe2;
  box-shadow: 0 6px 0 var(--green-dark);
}
.pic-card .answer-tag {
  position: absolute;
  bottom: -16px;
  background: var(--green);
  color: #fff;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: clamp(.9rem, 2vw, 1.2rem);
  letter-spacing: 1px;
  padding: 4px 16px;
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--green-dark);
  animation: pop-in .4s cubic-bezier(.2, .9, .3, 1.5);
}
.letter-mode .pic-card {
  font-family: var(--font-num);
  font-weight: 700;
  color: var(--purple-dark);
}
/* ตัวอักษรเดียวทำให้การ์ดหดเล็กจนนิ้วเด็กแตะยาก */
.letter-mode .word-card {
  min-width: clamp(74px, 13vw, 112px);
  font-size: clamp(1.7rem, 4.5vw, 2.6rem);
}

.pic-card.solved::after {
  content: '✅';
  position: absolute;
  top: -10px; right: -10px;
  font-size: 1.6rem;
  animation: pop-in .4s cubic-bezier(.2, .9, .3, 1.5);
}

.word-card {
  font-family: var(--font-num);
  font-weight: 700;
  letter-spacing: 2px;
  font-size: clamp(1.3rem, 3.6vw, 2.1rem);
  color: #fff;
  background: var(--pink);
  border: none;
  border-radius: var(--r-md);
  padding: clamp(10px, 2vh, 18px) clamp(18px, 3vw, 34px);
  cursor: grab;
  box-shadow: 0 6px 0 var(--pink-dark), 0 8px 16px rgba(0, 0, 0, .12);
  touch-action: none;
  transition: transform .12s, box-shadow .12s, opacity .2s;
}
.word-card:nth-child(2) { background: var(--blue);   box-shadow: 0 6px 0 var(--blue-dark),   0 8px 16px rgba(0,0,0,.12); }
.word-card:nth-child(3) { background: var(--purple); box-shadow: 0 6px 0 var(--purple-dark), 0 8px 16px rgba(0,0,0,.12); }
.word-card:nth-child(4) { background: var(--orange); box-shadow: 0 6px 0 var(--orange-dark), 0 8px 16px rgba(0,0,0,.12); }

.word-card.selected { transform: translateY(-8px) scale(1.08); animation: ready-pulse 1s ease-in-out infinite; }
.word-card.dragging {
  z-index: 100;
  position: relative;
  pointer-events: none;
  transition: none;
  cursor: grabbing;
}
.word-card.used { opacity: 0; pointer-events: none; transform: scale(.5); }
.word-card.nope { animation: wiggle .45s; }

/* ===== ตั้งบวก/ตั้งลบแนวตั้ง ===== */
.col-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.5vw, 28px);
  flex: 0 1 auto;
  min-height: 0;
  max-width: 100%;
}

/* ภาพช่วยตอนทด: ลูกบอล 10 ลูกมัดเป็นแท่งสิบ โผล่ข้างตารางเฉพาะตอนที่ต้องทด */
.carry-aid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: #fffbe8;
  border: 3px dashed var(--yellow);
  border-radius: var(--r-md);
  padding: clamp(8px, 1.6vh, 16px) clamp(10px, 2vw, 18px);
  animation: pop-in .4s cubic-bezier(.2, .9, .3, 1.5);
  max-width: min(46vw, 360px);
}
.carry-aid[hidden] { display: none; }
.carry-aid .blocks { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.carry-aid .rod { height: clamp(64px, 11vh, 96px); width: clamp(16px, 2.4vw, 24px); }
.carry-aid .unit { width: clamp(17px, 2.6vw, 26px); }
.carry-aid .units { gap: 5px; }
.carry-aid-title {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(1.1rem, 2.8vw, 1.6rem);
  color: var(--purple-dark);
}
.carry-aid-note { font-size: clamp(.85rem, 2vw, 1.05rem); color: var(--ink-soft); text-align: center; }

.col-sum {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: clamp(2px, .6vh, 8px) clamp(6px, 1.4vw, 14px);
  align-items: center;
  justify-items: center;
  background: #fff;
  border-radius: var(--r-md);
  padding: clamp(8px, 1.6vh, 20px) clamp(16px, 3.5vw, 34px);
  box-shadow: 0 6px 0 var(--card-edge), 0 10px 20px rgba(0, 0, 0, .1);
  font-family: var(--font-num);
  font-weight: 700;
  flex: 0 1 auto;
  min-height: 0;
}

.col-sum .cell {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(40px, 8vw, 72px);
  height: clamp(40px, 7.5vh, 76px);
  font-size: clamp(1.6rem, 4.6vw, 3rem);
  border-radius: var(--r-sm);
  color: var(--ink);
  transition: background .2s, color .2s;
}
.col-sum .cell.spacer { width: clamp(30px, 5vw, 48px); }
.col-sum .cell.op { color: var(--ink-soft); }
.col-sum .cell.blank { background: none; }

.col-sum .cell.carry {
  height: clamp(22px, 3.4vh, 38px);
  font-size: clamp(1rem, 2.4vw, 1.5rem);
  color: var(--pink-dark);
}
.col-sum .cell.carry.pulse,
.col-sum .cell.slot.pulse,
.col-sum .cell.digit.pulse {
  cursor: pointer;
  background: rgba(255, 201, 77, .35);
  box-shadow: 0 0 0 4px var(--yellow);
  animation: ready-pulse 1s ease-in-out infinite;
}

.col-sum .cell.digit.active { background: rgba(110, 198, 255, .22); }
/* ขีดฆ่าแบบเอียงเหมือนเวลาเด็กขีดในสมุด — ใช้ pseudo-element เพราะ
   Chrome ไม่วาด text-decoration ให้ข้อความในกล่อง grid */
.col-sum .cell.digit.struck { color: var(--ink-soft); }
.col-sum .cell.digit.struck::after {
  content: '';
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 5px;
  border-radius: 3px;
  background: var(--pink-dark);
  transform: rotate(-12deg);
}

.col-sum .cell.slot {
  border: 4px dashed var(--card-edge);
  color: var(--purple-dark);
}
.col-sum .cell.slot.filled { border-style: solid; border-color: var(--green); background: #f0ffe8; }
.col-sum .cell.slot.active { border-color: var(--blue); }

.col-sum .cell.pop { animation: pop-in .45s cubic-bezier(.2, .9, .3, 1.6); }
.col-sum .cell.nope { animation: wiggle .45s; }

.col-rule {
  grid-column: 1 / -1;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--ink);
  margin: 4px 0;
}

/* ===== แป้นกดตัวเลข (เกมตั้งเลข) ===== */
.pad-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.4vh, 14px);
  flex: 0 0 auto;
}

.entry { display: flex; justify-content: center; }

.entry-box {
  display: grid;
  place-items: center;
  min-width: clamp(64px, 12vw, 104px);
  height: clamp(38px, 6.2vh, 62px);
  padding: 0 14px;
  border-radius: var(--r-sm);
  border: 4px dashed var(--blue);
  background: #fff;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(1.4rem, 4vw, 2.3rem);
  color: var(--purple-dark);
}
.entry-box.correct {
  border-style: solid;
  border-color: var(--green);
  background: #f0ffe8;
  animation: cheer .5s cubic-bezier(.2, .9, .3, 1.6);
}
.entry-box.nope { border-color: var(--pink-dark); animation: wiggle .45s; }

.keypad {
  display: grid;
  grid-template-columns: repeat(6, auto);
  gap: clamp(5px, 1.2vw, 11px);
  justify-content: center;
}

.key {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(1.3rem, 3.4vw, 2rem);
  color: #fff;
  background: var(--purple);
  border: none;
  border-radius: var(--r-sm);
  width: clamp(44px, 8vw, 70px);
  height: clamp(38px, 6.2vh, 62px);
  cursor: pointer;
  box-shadow: 0 5px 0 var(--purple-dark);
  transition: transform .07s, box-shadow .07s;
}
.key:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--purple-dark); }
.key.del { background: var(--orange); box-shadow: 0 5px 0 var(--orange-dark); font-size: clamp(1.1rem, 2.6vw, 1.5rem); }
.key.del:active { box-shadow: 0 1px 0 var(--orange-dark); }

@media (max-width: 560px) {
  .keypad { grid-template-columns: repeat(5, auto); }
  .col-area { flex-direction: column; gap: 8px; }
  .carry-aid { max-width: 90vw; flex-direction: row; flex-wrap: wrap; justify-content: center; }
}

/* ===== ชุดคำถามแบบเลือกตอบ ===== */
.quiz-visual {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vh, 18px);
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.count-tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: clamp(4px, 1.2vw, 12px);
  max-width: min(100%, 620px);
  background: rgba(255, 255, 255, .8);
  border-radius: var(--r-md);
  padding: clamp(10px, 2vh, 20px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .05);
}
.count-tray span { font-size: clamp(1.9rem, 5.5vw, 3.2rem); line-height: 1; }

.seq-row { display: flex; gap: clamp(6px, 1.6vw, 16px); flex-wrap: wrap; justify-content: center; }

.seq-box {
  display: grid;
  place-items: center;
  min-width: clamp(50px, 10vw, 88px);
  height: clamp(56px, 11vh, 96px);
  padding: 0 8px;
  border-radius: var(--r-sm);
  background: #fff;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(1.7rem, 5vw, 3rem);
  color: var(--ink);
  box-shadow: 0 5px 0 var(--card-edge);
}
.seq-box.blank {
  color: var(--pink-dark);
  background: #fff6fb;
  box-shadow: 0 5px 0 var(--pink-dark);
  animation: ready-pulse 1.3s ease-in-out infinite;
}

.letter-hint { font-size: clamp(2.6rem, 8vw, 4.6rem); line-height: 1; }
.letter-hint.big { font-size: clamp(4rem, 14vw, 7.5rem); }

/* ตัวเลือกที่เป็นรูป emoji / คำอังกฤษ / ขนาดต่างกัน */
.choice.emoji { font-size: clamp(2.4rem, 7vw, 4rem); min-width: clamp(84px, 16vw, 140px); line-height: 1.1; }
.choice.emoji.size-s { font-size: clamp(1.3rem, 3.5vw, 2rem); }
.choice.emoji.size-m { font-size: clamp(2.2rem, 6vw, 3.4rem); }
.choice.emoji.size-l { font-size: clamp(3.4rem, 10vw, 5.4rem); }
.choice.word { font-size: clamp(1.4rem, 4vw, 2.2rem); letter-spacing: 1px; }

.seq-box.emoji { font-size: clamp(1.6rem, 4.5vw, 2.8rem); }
.shape-hint { font-size: clamp(1rem, 2.4vw, 1.3rem); color: var(--ink-soft); text-align: center; }

/* จับคู่เงา: ทำ emoji ให้เป็นสีดำล้วน */
.shadow {
  font-size: clamp(4rem, 14vw, 7.5rem);
  line-height: 1;
  filter: brightness(0) opacity(.8);
}

.blocks-card {
  background: #fff;
  border-radius: var(--r-md);
  padding: clamp(10px, 2vh, 20px) clamp(14px, 3vw, 28px);
  box-shadow: 0 5px 0 var(--card-edge);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* เส้นจำนวน 0-10 กบยืนบนเลขเริ่มต้น */
.numline { display: flex; gap: clamp(2px, .6vw, 6px); flex-wrap: wrap; justify-content: center; }
.nl-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: clamp(30px, 6.5vw, 56px);
  height: clamp(58px, 10vh, 84px);
  border-radius: var(--r-sm);
  background: #fff;
  box-shadow: 0 4px 0 var(--card-edge);
  font-size: clamp(1.2rem, 3.4vw, 2rem);
  line-height: 1;
}
.nl-cell b { font-family: var(--font-num); font-size: clamp(.95rem, 2.4vw, 1.4rem); color: var(--ink); padding: 4px 0 6px; }
.nl-cell.start { background: #eaffe2; box-shadow: 0 4px 0 var(--green-dark); }

/* ตำแหน่งซ้าย/ขวา/บน/ล่าง: ห้ามพับแถว ไม่งั้นคำตอบเพี้ยน */
.choices.row-fixed { flex-wrap: nowrap; }
.choices.col { flex-direction: column; align-items: center; gap: clamp(8px, 1.6vh, 16px); }
.choices.col .choice.emoji, .choices.row-fixed .choice.emoji {
  font-size: clamp(2rem, 5.5vw, 3.2rem);
  min-width: clamp(74px, 13vw, 120px);
  padding: clamp(6px, 1.2vh, 12px) 10px;
}

/* นาฬิกา */
.clock { width: clamp(150px, 30vh, 260px); height: auto; }
.clock .face { fill: #fff; stroke: var(--purple); stroke-width: 4; }
.clock text {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 9px;
  fill: var(--ink);
  text-anchor: middle;
  dominant-baseline: central;
}
.clock .minute { stroke: var(--blue-dark); stroke-width: 3; stroke-linecap: round; }
.clock .hour { stroke: var(--pink-dark); stroke-width: 5; stroke-linecap: round; }
.clock .pin { fill: var(--ink); }

/* คู่-คี่: เรียงเป็นคู่แนวตั้ง ตัวเหลือจะโดดออกมาให้เห็นเอง */
.big-num { font-family: var(--font-num); font-weight: 700; font-size: clamp(2.4rem, 7vw, 4rem); color: var(--purple-dark); line-height: 1; }
.pair-tray {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, auto);
  gap: clamp(4px, 1vw, 10px) clamp(10px, 2.4vw, 22px);
  background: rgba(255, 255, 255, .8);
  border-radius: var(--r-md);
  padding: clamp(10px, 2vh, 18px) clamp(14px, 3vw, 26px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .05);
}
.pair-tray span { font-size: clamp(1.8rem, 5vw, 3rem); line-height: 1; }

/* ตัวเลือกภาษาไทยใช้ฟอนต์ไทย ไม่ต้องเว้นตัวอักษรห่างแบบคำอังกฤษ */
.choice.thai { font-family: var(--font-th); font-weight: 400; letter-spacing: 0; font-size: clamp(1.8rem, 5vw, 3rem); }
.seq-row.thai .seq-box { font-family: var(--font-th); font-weight: 400; }

/* ===== สะกดคำ / ผสมคำ ===== */
.spell-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.5vh, 24px);
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}
.spell-slots, .spell-tiles { display: flex; gap: clamp(6px, 1.6vw, 14px); flex-wrap: wrap; justify-content: center; }
.spell-slots { align-items: center; }

/* หนึ่งช่องหลัก + แถวช่องเล็กบนและล่าง (สูงคงที่ให้พยัญชนะทุกตัวอยู่ระดับเดียวกัน) */
.spell-cell {
  display: grid;
  grid-template-rows: var(--mark-h) auto var(--mark-h);
  justify-items: center;
  align-items: center;
  --mark-h: clamp(34px, 5.5vh, 46px);
}
.mark-row { display: flex; gap: 4px; align-items: center; justify-content: center; height: 100%; }
.mark-slot {
  display: grid;
  place-items: center;
  width: clamp(38px, 7vw, 56px);
  height: clamp(30px, 5vh, 40px);
  border-radius: 10px;
  border: 3px dashed var(--card-edge);
  background: #fff;
  font-family: var(--font-th);
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  line-height: 1;
  color: var(--pink-dark);
}
.mark-slot.now { border-color: var(--blue); animation: ready-pulse 1.2s ease-in-out infinite; }
.mark-slot.filled { border-style: solid; border-color: var(--green); background: #f0ffe8; animation: pop-in .35s cubic-bezier(.2, .9, .3, 1.5); }

.spell-slot {
  display: grid;
  place-items: center;
  width: clamp(52px, 10vw, 84px);
  height: clamp(58px, 10vh, 92px);
  border-radius: var(--r-sm);
  border: 4px dashed var(--card-edge);
  background: #fff;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(1.7rem, 4.6vw, 2.8rem);
  color: var(--purple-dark);
}
.spell-slot.now { border-color: var(--blue); animation: ready-pulse 1.2s ease-in-out infinite; }
.spell-slot.filled { border-style: solid; border-color: var(--green); background: #f0ffe8; animation: pop-in .35s cubic-bezier(.2, .9, .3, 1.5); }

.spell-tile {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: clamp(1.6rem, 4.4vw, 2.6rem);
  color: #fff;
  background: var(--pink);
  border: none;
  border-radius: var(--r-sm);
  width: clamp(54px, 10.5vw, 88px);
  height: clamp(54px, 9.5vh, 84px);
  cursor: pointer;
  box-shadow: 0 6px 0 var(--pink-dark), 0 8px 14px rgba(0, 0, 0, .12);
  transition: transform .08s, box-shadow .08s, opacity .25s;
}
.spell-tile:nth-child(2n) { background: var(--blue); box-shadow: 0 6px 0 var(--blue-dark), 0 8px 14px rgba(0,0,0,.12); }
.spell-tile:nth-child(3n) { background: var(--purple); box-shadow: 0 6px 0 var(--purple-dark), 0 8px 14px rgba(0,0,0,.12); }
.spell-tile:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, .2); }
.spell-tile.used { opacity: .18; pointer-events: none; transform: scale(.85); }
.spell-tile.nope { animation: wiggle .45s; }

/* ===== เขียนตัวอักษรตามรอย ===== */
.trace-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: none;
}
.trace-wrap canvas {
  border-radius: var(--r-md);
  box-shadow: 0 6px 0 var(--card-edge), 0 10px 20px rgba(0, 0, 0, .1);
  touch-action: none;
  cursor: crosshair;
}
.trace-ok[hidden] { display: none; }
.trace-ok {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(5rem, 20vw, 10rem);
  color: var(--green);
  text-shadow: 0 6px 0 var(--green-dark), 0 10px 20px rgba(0, 0, 0, .2);
  pointer-events: none;
  animation: star-pop .6s cubic-bezier(.2, .9, .3, 1.7);
}
.trace-actions { flex: 0 0 auto; }
.trace-actions .btn { font-size: 1.1rem; padding: 12px 26px; }
.croc { font-size: clamp(3rem, 9vw, 5rem); animation: hop 2s ease-in-out infinite; }
.croc-hint { color: var(--ink-soft); font-size: clamp(.95rem, 2.2vw, 1.2rem); text-align: center; }

/* ===== เกมความจำ ===== */
.mem-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(8px, 2vw, 18px);
  flex: 0 0 auto;
  max-width: min(100%, 620px);
}

.mem-card {
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  perspective: 700px;
  aspect-ratio: 1;
  width: clamp(64px, 14vw, 130px);
}
.mem-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transition: transform .45s cubic-bezier(.3, .8, .4, 1.3);
  transform-style: preserve-3d;
}
.mem-card.open .mem-inner, .mem-card.done .mem-inner { transform: rotateY(180deg); }

.mem-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: var(--r-md);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}
.mem-front {
  background: linear-gradient(150deg, var(--purple), var(--pink));
  color: #fff;
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  box-shadow: 0 5px 0 var(--purple-dark);
}
.mem-back {
  transform: rotateY(180deg);
  background: var(--card);
  box-shadow: 0 5px 0 var(--card-edge);
  font-size: clamp(1.8rem, 5vw, 3.4rem);
}
.mem-back.word {
  font-family: var(--font-num);
  font-weight: 700;
  letter-spacing: 1px;
  font-size: clamp(.85rem, 2.4vw, 1.5rem);
  color: var(--purple-dark);
}
.mem-card.done { cursor: default; }
.mem-card.done .mem-back { background: #eaffe2; box-shadow: 0 5px 0 var(--green-dark); }

/* ===== เพื่อนซี้ ===== */
.buddy {
  position: absolute;
  right: clamp(6px, 2vw, 22px);
  bottom: clamp(6px, 2vh, 18px);
  font-size: clamp(2.4rem, 6vw, 4rem);
  animation: hop 2.2s ease-in-out infinite;
  pointer-events: none;
  z-index: 4;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .18));
}
.buddy.happy { animation: cheer .5s ease-in-out 2; }

.bubble {
  position: absolute;
  right: clamp(6px, 2vw, 22px);
  bottom: clamp(72px, 12vh, 120px);
  background: #fff;
  border-radius: var(--r-md);
  padding: 10px 20px;
  font-size: clamp(.95rem, 2vw, 1.25rem);
  box-shadow: 0 4px 0 var(--card-edge), 0 8px 16px rgba(0, 0, 0, .12);
  z-index: 4;
  pointer-events: none;
  animation: pop-in .3s cubic-bezier(.2, .9, .3, 1.5);
  max-width: 44vw;
  text-align: center;
}

/* ===== หน้าสรุปผล ===== */
.result {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
}
.result h2 {
  font-size: clamp(2rem, 6vw, 3.4rem);
  margin: 0;
}
.result .buddy-big { font-size: clamp(4rem, 14vw, 8rem); animation: hop 1.4s ease-in-out infinite; }

.result-stars { display: flex; gap: 14px; margin: 6px 0 4px; }
.result-stars span {
  font-size: clamp(3rem, 10vw, 5rem);
  opacity: .2;
  filter: grayscale(1);
  transform: scale(.6);
  transition: none;
}
.result-stars span.on {
  opacity: 1;
  filter: none;
  animation: star-pop .6s cubic-bezier(.2, .9, .3, 1.7) forwards;
}
@keyframes star-pop {
  0%   { transform: scale(.2) rotate(-90deg); opacity: 0; }
  60%  { transform: scale(1.35) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
.result .score { font-size: 1.3rem; color: var(--ink-soft); }
.result-actions { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }

/* ===== คอนเฟตตี ===== */
.confetti {
  position: absolute;
  width: 12px;
  height: 16px;
  border-radius: 3px;
  z-index: 50;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  from { transform: translateY(0) rotate(0deg); opacity: 1; }
  to   { transform: translateY(105vh) rotate(760deg); opacity: 0; }
}

/* ===== จอเล็ก / แนวตั้ง ===== */
@media (max-width: 560px) {
  body { font-size: 16px; }
  .node .node-label { display: none; }
  .workspace { flex-wrap: wrap; }

  /* แถบบนแคบ ต้องย่อทุกอย่างไม่ให้จุดบอกความคืบหน้าถูกเบียดหาย */
  .icon-btn { width: 46px; height: 46px; font-size: 1.4rem; }
  .dots { gap: 5px; }
  .dots i { width: 10px; height: 10px; }
  .game-bar .star-counter { font-size: .95rem; padding: 6px 14px; }
}
