/* HANUMAN CODING ADVENTURE — หน้าจอเกม (เป้าหมายหลัก PC/Notebook 16:9 · แท็บเล็ต/มือถือยังเล่นได้) */
:root {
  --wood: #8a5423; --wood-dark: #5a3210; --wood-light: #c98a45;
  --cream: #fff6dc; --cream-2: #ffe9b8; --gold: #ffc83d; --ink: #4a2a0c; --ink-2: #7a5530;
  --green: #2fa84f; --green-dark: #1f7a37; --bad: #d8432f; --heart: #ef4a5d;
  --sc-motion: #4c97ff; --sc-control: #ffab19; --sc-events: #ffbf00; --sc-looks: #9966ff; --sc-var: #ff8c1a; --sc-glow: #ffd400;
  box-sizing: border-box; color-scheme: light;
}
*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%; font-family: "Mali", "Leelawadee UI", Tahoma, sans-serif; color: var(--ink);
  background: #2f5a3a; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
body::before {
  content: ""; position: fixed; inset: -40px; z-index: -1;
  background: url(../img/home/bg.webp?v=2) center/cover no-repeat; filter: blur(16px) saturate(1.1) brightness(.75);
}
[hidden] { display: none !important; }
button, select { font-family: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- ปุ่ม ---------- */
.wbtn {
  display: inline-grid; place-items: center; width: 50px; height: 50px; flex: none; border: 0; border-radius: 16px; cursor: pointer;
  color: var(--wood-dark); background: linear-gradient(#fff7df, #ffe1a1); box-shadow: 0 4px 0 var(--wood-dark), 0 6px 12px rgba(0, 0, 0, .25);
  font-size: 1.4rem; font-weight: 700;
}
.wbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }
.bigbtn {
  border: 0; border-radius: 16px; padding: 10px 20px; font-size: 1.05rem; font-weight: 700; cursor: pointer;
  color: var(--wood-dark); background: linear-gradient(#fff7df, #ffe1a1); box-shadow: 0 4px 0 var(--wood-dark);
}
.bigbtn.green { color: #fff; background: linear-gradient(#45c96a, var(--green)); box-shadow: 0 4px 0 var(--green-dark); }
.bigbtn.danger { color: #fff; background: linear-gradient(#f2705f, var(--bad)); box-shadow: 0 4px 0 #9a2a1c; }
.bigbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }
.bigbtn:disabled { opacity: .5; cursor: default; transform: none; }
.lvbadge { display: inline-block; background: var(--wood); color: var(--cream); border-radius: 999px; padding: 3px 14px; font-weight: 700; font-size: .9rem; white-space: nowrap; box-shadow: 0 0 0 2px var(--gold); }
.chip { background: rgba(255, 246, 220, .95); color: var(--ink); border-radius: 999px; padding: 6px 14px; font-weight: 700; white-space: nowrap; box-shadow: 0 0 0 2px var(--wood-light); }
.chip.acct { text-decoration: none; color: var(--wood-dark); background: linear-gradient(#fff7df, #ffe1a1); box-shadow: 0 3px 0 var(--wood-dark); }
.chip.acct.on { color: #fff; background: var(--green); box-shadow: 0 3px 0 var(--green-dark); }

/* ================= หน้าแรก ================= */
#scrHome { min-height: 100dvh; display: grid; place-items: center; }
.hstage {
  position: relative; width: min(100vw, calc(100dvh * 1672 / 941)); aspect-ratio: 1672 / 941; overflow: hidden;
  border-radius: clamp(0px, 1vw, 14px); box-shadow: 0 10px 40px rgba(0, 0, 0, .45); container-type: inline-size; user-select: none;
}
.hbg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
/* กะพริบตา (js/blink.js): ภาพหลับตาชิ้นเล็กวางทับตรงตา */
.blinkp { position: absolute; height: auto !important; max-width: none !important; max-height: none !important; opacity: 0; pointer-events: none; }   /* !important: กันกฎภาพของกล่องอื่น (เช่น .cast img) ยืดภาพหลับตา */
.blinkp.on { opacity: 1; }
.bfig { position: relative; display: inline-flex; align-items: flex-start; line-height: 0; }
.bfig > img:not(.blinkp) { display: block; width: 100%; height: 100%; }
/* ข้อความที่แก้จากภาพ (ภาพเดิมสะกดผิด) — วาดทับบนป้ายที่ลบตัวหนังสือออกแล้ว */
.htag {
  position: absolute; left: 37.9%; top: 38.5%; width: 25%; height: 4.4%; margin: 0; display: flex; align-items: center; justify-content: center;
  font: 700 1.22cqw/1 "Mali", sans-serif; color: #2a1606; white-space: nowrap; transform: rotate(-1.2deg); pointer-events: none;
}
.htag b { color: #8a1c1c; font-weight: 700; }
.hplay {
  position: absolute; left: 42.2%; top: 65.6%; width: 15%; height: 6.6%; display: flex; align-items: center; justify-content: center;
  font: 600 2.6cqw/1 "Mitr", "Mali", sans-serif; color: #4a1e05; white-space: nowrap; pointer-events: none; z-index: 3;
  text-shadow: 0 .12cqw 0 rgba(255, 255, 255, .6);
}
/* ปุ่มบนฉาก: โปร่งใส วางทับรูปปุ่มในภาพ · ชี้แล้วสว่างขึ้น + วงแสง */
.hb {
  position: absolute; z-index: 4; border: 0; padding: 0; margin: 0; cursor: pointer; background: transparent; border-radius: 1.4cqw;
  transition: box-shadow .2s ease, backdrop-filter .2s ease;
}
.hb.round { border-radius: 50%; }
.hb:hover, .hb:focus-visible { backdrop-filter: brightness(1.16) saturate(1.2); box-shadow: 0 0 0 .3cqw rgba(255, 244, 170, .95), 0 0 2.2cqw .4cqw rgba(255, 214, 60, .75); outline: none; }
.hb:active { backdrop-filter: brightness(.92); }
.hb.off::after { content: ""; position: absolute; left: 14%; right: 14%; top: 36%; height: 8%; background: #e53935; border-radius: 99px; transform: rotate(-40deg); box-shadow: 0 0 0 .18cqw #fff; }
.p-sound { left: 4.67%; top: 2.66%; width: 5.02%; height: 9.4%; }
.p-music { left: 10.95%; top: 2.66%; width: 5.14%; height: 9.4%; }
.p-play  { left: 38.9%; top: 51.6%; width: 21.5%; height: 22.6%; border-radius: 3cqw; animation: hbreathe 2.4s ease-in-out infinite; }
.p-story { left: 28.1%; top: 75.7%; width: 9.9%; height: 14.9%; }
.p-map   { left: 39.5%; top: 75.7%; width: 9.9%; height: 14.9%; }
.p-bag   { left: 50.7%; top: 75.7%; width: 9.8%; height: 14.9%; }
.p-cast  { left: 61.9%; top: 75.7%; width: 9.6%; height: 14.9%; }
.p-set   { left: 90.8%; top: 59.3%; width: 7.4%; height: 10.5%; }
.p-info  { left: 90.8%; top: 70.5%; width: 7.4%; height: 10.5%; }
@keyframes hbreathe { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 230, 120, 0); } 50% { box-shadow: 0 0 2.4cqw .5cqw rgba(255, 230, 120, .55); } }
.hspark {
  position: absolute; z-index: 6; pointer-events: none; width: 2.1cqw; height: 2.1cqw; margin: -1.05cqw 0 0 -1.05cqw;
  background: radial-gradient(circle, #fff 0 18%, #ffe27a 30%, transparent 62%);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%); animation: hburst .75s ease-out forwards;
}
@keyframes hburst { 0% { transform: translate(0, 0) scale(.2); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(160deg); opacity: 0; } }
.htw {
  position: absolute; z-index: 2; pointer-events: none; width: 1.4cqw; height: 1.4cqw; opacity: 0;
  background: radial-gradient(circle, #fff 0 20%, #fff3b0 35%, transparent 65%);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%); animation: htw 3s ease-in-out infinite;
}
@keyframes htw { 0%, 100% { opacity: 0; transform: scale(.4); } 50% { opacity: 1; transform: scale(1); } }

/* ================= แถบบน ================= */
.bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; position: sticky; top: 0; z-index: 10;
  background: linear-gradient(#a8692d, var(--wood)); box-shadow: 0 3px 0 var(--wood-dark), 0 6px 14px rgba(0, 0, 0, .3);
}
.bar-title { margin: 0; flex: 1; min-width: 0; color: var(--cream); font: 600 1.35rem/1.2 "Mitr", "Mali", sans-serif; text-shadow: 0 2px 0 var(--wood-dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hearts { display: flex; gap: 4px; font-size: 1.7rem; line-height: 1; }
.hearts span { color: var(--heart); text-shadow: 0 2px 0 #7a1020, 0 0 0 #fff; filter: drop-shadow(0 0 2px #fff); }
.hearts .off { color: #6d4a33; text-shadow: none; filter: none; opacity: .6; }
.hearts .lost { animation: heartLost .7s ease-out; }
@keyframes heartLost { 0% { transform: scale(1.6); color: var(--heart); } 100% { transform: scale(1); } }

/* ================= เลือกด่าน ================= */
.mapbody { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; }
/* แถบหัว: ภาพทศกัณฐ์ + ชื่อเกม (ชื่ออยู่ในภาพ จึงมี h2 ซ่อนไว้ให้โปรแกรมอ่านจอ) */
.maphero { position: relative; margin: -20px -16px 14px; overflow: hidden; }
.mh-stage { position: relative; }
.maphero .mh-stage > img:first-of-type { display: block; width: 100%; height: auto; position: relative; -webkit-mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent); mask-image: linear-gradient(90deg, transparent, #000 5%, #000 95%, transparent); }
/* ประกายวิบวับ */
.mh-fx { position: absolute; inset: 0; pointer-events: none; }
.spark { position: absolute; width: calc(36px * var(--s, 1)); aspect-ratio: 1; translate: -50% -50%; opacity: 0; animation: twinkle 3.4s ease-in-out infinite; }
.spark::before, .spark::after { content: ""; position: absolute; inset: 0; background: radial-gradient(closest-side, #fff 0 18%, rgba(255, 236, 150, .9) 30%, transparent 100%); clip-path: polygon(50% 0, 58% 42%, 100% 50%, 58% 58%, 50% 100%, 42% 58%, 0 50%, 42% 42%); }
.spark::after { rotate: 45deg; scale: .55; }
@keyframes twinkle { 0%, 100% { opacity: 0; transform: scale(.3) rotate(0); } 18% { opacity: 1; transform: scale(1) rotate(25deg); } 36% { opacity: 0; transform: scale(.4) rotate(50deg); } }
/* ดาวตก: วาดทับภาพแต่ใช้หน้ากากเฉพาะส่วนท้องฟ้า (banner_sky.png) จึงดูเหมือนพุ่งอยู่หลังทศกัณฐ์/มือ/ปราสาท */
.mh-sky { position: absolute; inset: 0; z-index: 1; pointer-events: none; mix-blend-mode: screen;
  -webkit-mask: url(../img/level/banner_sky.png) 0 0 / 100% 100%; mask: url(../img/level/banner_sky.png) 0 0 / 100% 100%; }
.mh-stage > img:first-of-type { z-index: 0; }
.mh-fx, .mh-stage .blinkp { z-index: 2; }
.meteor {
  position: absolute; width: 160px; height: 3px; border-radius: 3px; opacity: 0; transform-origin: right center;
  background: linear-gradient(90deg, transparent, rgba(255, 220, 140, .5) 60%, #fff); filter: drop-shadow(0 0 6px #ffd66b);
  rotate: 140deg; animation: meteor 4.8s linear infinite;
}
.meteor.r { rotate: 40deg; }
@keyframes meteor { 0% { opacity: 0; translate: 0 0; } 4% { opacity: 1; } 22% { opacity: 0; translate: var(--dx, -150px) 120px; } 100% { opacity: 0; translate: var(--dx, -150px) 120px; } }
.meteor.r { --dx: 150px; }
.mh-prog { position: absolute; z-index: 3; right: 16px; bottom: 26px; margin: 0; padding: 4px 14px; border-radius: 999px; font-weight: 700; color: var(--cream); background: rgba(40, 10, 60, .75); box-shadow: 0 0 0 2px var(--gold); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* การ์ดด่าน: ภาพ + Level + ความยาก + คำอธิบาย + ความคืบหน้า (3 ใบบน 2 ใบล่างกึ่งกลาง) */
.lvgrid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 22px; }
.lvgrid li { grid-column: span 2; min-width: 0; display: flex; }
.lvgrid li:nth-child(4) { grid-column: 2 / span 2; }
.lvcard {
  display: flex; flex-direction: column; width: 100%; padding: 0; border: 0; border-radius: 22px; overflow: hidden; cursor: pointer; text-align: left; color: var(--ink);
  background: var(--cream); box-shadow: 0 0 0 4px var(--gold), 0 8px 0 var(--wood-dark), 0 14px 28px rgba(0, 0, 0, .4); transition: transform .15s ease, box-shadow .15s ease;
}
.lvcard:hover { transform: translateY(-4px); box-shadow: 0 0 0 4px #fff3b0, 0 12px 0 var(--wood-dark), 0 18px 32px rgba(0, 0, 0, .45); }
.lvimg { position: relative; display: block; aspect-ratio: 16 / 10; overflow: hidden; container-type: size; }
.lvimg > img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; object-position: left top; }
/* ชั้นขนาดเท่าภาพเต็ม (ก่อนครอบตัด) ให้ภาพหลับตาวางตรงตา: cover + ชิดซ้ายบน */
.lvimg .bwrap { position: absolute; left: 0; top: 0; aspect-ratio: var(--ar); width: max(100cqw, calc(100cqh * var(--ar))); }
.lvcard.soon .lvimg img { filter: saturate(.6) brightness(.85); }
.lvlv { position: absolute; right: 10px; bottom: 10px; padding: 4px 12px; border-radius: 10px; font: 600 1rem "Mitr", sans-serif; letter-spacing: .04em; color: #fff; background: #5a1f86; box-shadow: 0 0 0 2px var(--gold); }
.lvmeta { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px 14px; flex: 1; }
.lvrow { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; justify-content: space-between; }
.lvpat { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--wood); color: var(--cream); font-weight: 700; font-size: .85rem; }
.diff { font-weight: 700; font-size: .9rem; color: var(--ink-2); white-space: nowrap; }
.diff i { font-style: normal; color: #d9c9a6; }
.diff i.on { color: #f0a400; }
.diff.d1 { color: var(--green-dark); }
.diff.d3 { color: var(--bad); }
.lvname { font: 600 1.25rem/1.25 "Mitr", "Mali", sans-serif; }
.lvdesc { line-height: 1.5; }
.lvskill { margin-bottom: auto; font-size: .88rem; color: var(--ink-2); font-weight: 700; }
.lvgo { margin-top: 8px; align-self: flex-start; padding: 8px 18px; border-radius: 14px; font-weight: 700; color: #fff; background: linear-gradient(#45c96a, var(--green)); box-shadow: 0 4px 0 var(--green-dark); }
.lvgo.ok { color: var(--green-dark); background: #eaffdf; box-shadow: 0 0 0 2px #6bbf59; }
.lvgo.soon { color: var(--cream); background: #6d5640; box-shadow: none; }

/* ================= หน้าด่าน: ทบทวนโค้ด (บน) · ภาพ + ภาพรวม + ปุ่มเริ่ม (ล่าง) ================= */
.lvbody { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; display: grid; gap: 22px; }
.lvreview { background: var(--cream); border-radius: 24px; padding: 16px 20px 20px; box-shadow: 0 0 0 5px var(--wood), 0 0 0 9px var(--gold), 0 18px 40px rgba(0, 0, 0, .4); }
.rv-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between; }
.rv-head h2 { margin: 0; font: 600 1.3rem/1.3 "Mitr", "Mali", sans-serif; }
.rv-sub { margin: 4px 0 0; color: var(--ink-2); }
.lvreview .missions { margin-top: 12px; }
.chip.dark { background: var(--wood); color: var(--cream); box-shadow: none; }
.lvmain { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 22px; align-items: start; }
.lvart { position: sticky; top: 90px; margin: 0; border-radius: 22px; overflow: hidden; box-shadow: 0 0 0 5px var(--gold), 0 18px 40px rgba(0, 0, 0, .4); }
.lvart img { display: block; width: 100%; height: auto; }
.lvinfo { background: var(--cream); border-radius: 24px; padding: 20px 22px; box-shadow: 0 0 0 5px var(--wood), 0 0 0 9px var(--gold), 0 18px 40px rgba(0, 0, 0, .4); min-width: 0; }
.lvinfo .lvrow { justify-content: flex-start; }
.lvinfo h2 { margin: 10px 0 2px; font: 600 1.8rem/1.2 "Mitr", "Mali", sans-serif; }
.lvinfo h3 { margin: 14px 0 4px; font: 600 1.1rem "Mitr", "Mali", sans-serif; color: var(--wood); }
.lvinfo p { margin: 0; line-height: 1.6; }
.lvbtns { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; align-items: center; }
.pm-skill { margin-top: 6px !important; color: var(--ink-2); font-weight: 700; }
.missions { list-style: none; margin: 18px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mis {
  width: 100%; box-sizing: border-box; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; text-align: left; cursor: pointer;
  border: 0; border-radius: 16px; padding: 12px 14px; background: linear-gradient(#fffaf0, var(--cream-2)); color: var(--ink);
  box-shadow: 0 0 0 2px var(--wood-light), 0 4px 0 var(--wood-light); font-size: 1rem; font-weight: 700; transition: transform .15s ease;
}
.missions li { min-width: 0; }
.mtitle { overflow-wrap: anywhere; }
.mis:hover { transform: translateY(-2px); }
.mis.done { background: linear-gradient(#f2ffe9, #d7f5c6); box-shadow: 0 0 0 2px #6bbf59, 0 4px 0 #4e9a40; }
.mis.lock { opacity: .55; cursor: not-allowed; }
.mis.shake { animation: shake .4s; }
.mnum { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--wood); color: var(--cream); font-size: 1.1rem; }
.mstars span, .bigstars span { color: #d9c9a6; }
.mstars span.on, .bigstars span.on { color: #f0b400; text-shadow: 0 2px 0 var(--wood-dark); }

/* ================= เล่นภารกิจ ================= */
.play { display: grid; grid-template-columns: minmax(0, 46fr) minmax(0, 54fr); gap: 14px; padding: 14px; max-width: 1800px; margin: 0 auto; }
.panel { background: var(--cream); border-radius: 22px; padding: 14px; box-shadow: 0 0 0 4px var(--wood), 0 12px 28px rgba(0, 0, 0, .35); min-width: 0; }
.panel.left { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; gap: 10px; }
.goal { display: grid; grid-template-columns: 58px minmax(0, 1fr); gap: 10px; align-items: center; background: #fff; border-radius: 16px; padding: 8px 12px; box-shadow: 0 0 0 2px var(--wood-light); }
.goal-face { width: 58px; height: 58px; object-fit: cover; object-position: top; border-radius: 50%; background: #e8f2ff; box-shadow: 0 0 0 2px var(--gold); }
.goal-text { margin: 0; font-weight: 700; font-size: 1.08rem; line-height: 1.45; }
.goal-tip { margin: 2px 0 0; color: var(--ink-2); font-size: .9rem; line-height: 1.45; }
.learn { margin: 0; font-size: .9rem; color: var(--ink-2); background: #fff7e2; border-radius: 12px; padding: 6px 12px; }
.boardwrap { display: grid; place-items: center; min-height: 300px; height: min(62vh, 560px); }
.board {
  --cols: 7; --cell: 64px; position: relative; display: grid; grid-template-columns: repeat(var(--cols), var(--cell)); grid-auto-rows: var(--cell); gap: 4px;
  padding: 10px; background: #6b4a22; border-radius: 18px; box-shadow: inset 0 0 0 3px #4a2e10, 0 0 0 4px var(--gold);
}
.cell { position: relative; border-radius: 14%; overflow: hidden; background: url(../img/tile/grass.webp) center/cover no-repeat; }
.cell::before { content: ""; position: absolute; inset: 0; background: center/cover no-repeat; }
.cell.t-path::before { background-image: url(../img/tile/path.webp); }
.cell.t-water::before { background-image: url(../img/tile/water.webp); }
.cell.t-tree::before { background-image: url(../img/tile/tree.webp); }
.cell.t-bush::before { background-image: url(../img/tile/bush.webp); }
.cell.t-stump::before { background-image: url(../img/tile/stump.webp); }
.cell.t-rock::before { background-image: url(../img/tile/rock.webp); }
.cell.start::after { content: ""; position: absolute; inset: 18%; border: 3px dashed rgba(255, 255, 255, .85); border-radius: 50%; }
.cell.goal { box-shadow: inset 0 0 0 3px #ffe9a0; overflow: visible; }
.cell .sita { position: absolute; left: 4%; bottom: 2%; width: 92%; height: 108%; object-fit: contain; object-position: bottom; z-index: 2; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .35)); animation: bob 1.8s ease-in-out infinite; }
.cell .fruit { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--cell) * .55); line-height: 1; z-index: 1; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .35)); animation: bob 1.4s ease-in-out infinite; }
.cell .fruit.pick { animation: pick .5s ease-out forwards; }
.cell.splash::after { content: "💦"; position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--cell) * .6); animation: pick .9s ease-out forwards; border: 0; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5%); } }
@keyframes pick { 0% { transform: scale(1); opacity: 1; } 100% { transform: translateY(-70%) scale(1.5); opacity: 0; } }
.hero {
  position: absolute; left: 10px; top: 10px; width: var(--cell); height: var(--cell); z-index: 3; pointer-events: none;
  transition: transform var(--dur, .38s) ease-in-out;
}
.hero img { position: absolute; left: -6%; bottom: 0; width: 112%; height: 118%; object-fit: contain; object-position: bottom; filter: drop-shadow(0 4px 3px rgba(0, 0, 0, .4)); }
.hero img.flip { transform: scaleX(-1); }
.hero .arrow {
  position: absolute; left: 50%; top: 50%; width: 110%; height: 110%; margin: -55% 0 0 -55%; transition: transform .3s ease; z-index: -1;
}
.hero .arrow::before {
  content: ""; position: absolute; left: 50%; top: -4%; margin-left: -12%; width: 24%; height: 22%;
  background: #ffe14d; clip-path: polygon(50% 0, 100% 100%, 0 100%); filter: drop-shadow(0 0 2px #000);
}
.hero.bump { animation: bump .5s ease; }
@keyframes bump { 0%, 100% { translate: 0 0; } 35% { translate: var(--bx) var(--by); } 60% { translate: calc(var(--bx) * -.3) calc(var(--by) * -.3); } }
.hero.cheer img { animation: cheer .45s ease-in-out 2; }
@keyframes cheer { 50% { transform: translateY(-18%) scale(1.08); } }
.say {
  position: absolute; z-index: 5; transform: translate(-50%, -110%); background: #fff; color: var(--ink); border-radius: 14px; padding: 8px 12px;
  font-weight: 700; font-size: .92rem; line-height: 1.4; max-width: 260px; width: max-content; box-shadow: 0 0 0 3px var(--wood-light), 0 6px 14px rgba(0, 0, 0, .3);
  animation: sayIn .25s ease-out;
}
.say.bad { box-shadow: 0 0 0 3px var(--heart), 0 6px 14px rgba(0, 0, 0, .3); }
.say.warn { box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0, 0, 0, .3); }
@keyframes sayIn { from { opacity: 0; transform: translate(-50%, -80%); } }

.panel.right { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; gap: 10px; }
.tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tools .bag { font-weight: 700; color: var(--ink-2); font-size: .92rem; }
.speed { margin-left: auto; font-weight: 700; color: var(--ink-2); }
.speed select { border: 2px solid var(--wood-light); border-radius: 10px; padding: 4px 6px; background: #fff; color: var(--ink); font-weight: 700; }
.code { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 10px; min-height: 0; }
.colh { margin: 0 0 6px; font-weight: 700; color: var(--ink-2); }
.ws { height: min(64vh, 600px); min-height: 360px; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 3px var(--wood-light); }
.scratch { display: grid; justify-items: start; align-content: start; gap: 0; background: #f9f9f9; border-radius: 14px; padding: 14px 12px; box-shadow: 0 0 0 3px var(--wood-light); height: min(56vh, 520px); min-height: 300px; overflow: auto; }
.snote { margin: 8px 0 0; font-size: .8rem; color: var(--ink-2); line-height: 1.45; }
body.running .ws { pointer-events: none; }

/* บล็อก Scratch 3 (วาดด้วย HTML) */
.sb {
  --c: var(--sc-motion); position: relative; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: var(--c); color: #fff; font: 600 .9rem/1.3 "Mali", Tahoma, sans-serif; padding: 8px 12px; border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--c) 72%, #000); margin-bottom: 1px;
}
.sb::after { content: ""; position: absolute; left: 14px; bottom: -7px; width: 20px; height: 7px; background: var(--c); border: 1px solid color-mix(in srgb, var(--c) 72%, #000); border-top: 0; border-radius: 0 0 5px 5px; z-index: 1; }
.sb.ev { --c: var(--sc-events); border-radius: 22px 22px 5px 5px; padding-top: 14px; }
.sb.vr { --c: var(--sc-var); }
.sb.ct { --c: var(--sc-control); }
.sb i { font-style: normal; background: #fff; color: #575e75; border-radius: 999px; padding: 0 9px; }
.sb i.dd { background: color-mix(in srgb, #000 15%, transparent); color: #fff; border-radius: 6px; padding: 0 6px; }
.sb.run { box-shadow: 0 0 0 2px #fff, 0 0 0 5px var(--sc-glow); z-index: 2; }
.c-wrap { display: grid; padding: 0; background: none; border: 0; }
.c-wrap::after { display: none; }
.c-top, .c-foot { background: var(--sc-control); padding: 8px 12px; border-radius: 5px 5px 0 0; color: #fff; }
.c-arm { border-left: 16px solid var(--sc-control); padding: 4px 0 4px 2px; display: grid; justify-items: start; min-height: 24px; }
.c-foot { padding: 6px; border-radius: 0 0 5px 5px; width: 80px; }
.mb { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 8px; color: #fff; font-weight: 700; background: var(--sc-motion); white-space: nowrap; }
.mb.ev { background: var(--sc-events); border-radius: 14px 14px 8px 8px; }
.mb.lk { background: var(--sc-looks); }

/* ================= กล่องข้อความ ================= */
.dlg { border: 0; padding: 0; background: transparent; max-width: min(540px, calc(100vw - 32px)); width: 100%; max-height: calc(100dvh - 16px); overflow: auto; }
.dlg.wide { max-width: min(900px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(30, 15, 0, .6); }
.dlgbody {
  background: var(--cream); color: var(--ink); border-radius: 24px; padding: 22px; display: grid; gap: 12px; justify-items: center; text-align: center;
  box-shadow: 0 0 0 5px var(--wood), 0 0 0 9px var(--gold), 0 20px 40px rgba(0, 0, 0, .45); margin: 12px;
}
.dlgbody h2 { margin: 0; font: 600 1.55rem/1.25 "Mitr", "Mali", sans-serif; }
.dlgbody p { margin: 0; line-height: 1.65; }
.dlgbtns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.dimg { width: 100%; max-width: 240px; max-height: 300px; object-fit: contain; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .25)); }
/* ภาพในกล่องข้อความที่ห่อด้วย .bfig (กะพริบตา): กล่องพอดีภาพ */
.dlgbody > .bfig { justify-self: center; }
.bfig > .dimg { width: auto; height: auto; max-width: min(240px, 100%); }
.mis-learn { color: var(--green-dark); font-weight: 700; }
.bigstars { font-size: 3rem; letter-spacing: 6px; line-height: 1; }
/* กล่องที่มีภาพ: จอกว้างวางแนวนอน ภาพซ้าย เนื้อหาขวา */
@media (min-width: 760px) {
  .dlg.side { max-width: min(860px, calc(100vw - 32px)); }
  .dlg.side .dlgbody { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); column-gap: 26px; align-content: center; justify-items: start; text-align: left; padding: 24px 28px; }
  .dlg.side .dlgbody > * { grid-column: 2; }
  .dlg.side .dimg, .dlg.side .dlgbody > .bfig { grid-column: 1; grid-row: 1 / span 6; align-self: center; justify-self: center; max-width: none; max-height: 380px; }
  .dlg.side .bfig > .dimg { max-width: 100%; max-height: 380px; }
  .dlg.side .dlgbtns { justify-content: flex-start; }
}
.cast { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; width: 100%; }
.cast li { display: grid; gap: 4px; justify-items: center; background: #fff; border-radius: 16px; padding: 10px 8px; box-shadow: 0 0 0 2px var(--wood-light); }
.cast img { height: 190px; width: 100%; object-fit: contain; }
/* กล่องตามขนาดภาพจริง (ไม่มีขอบว่างจาก contain) ภาพหลับตาจึงตรงตา */
.cast .bfig { max-width: 100%; align-self: start; }
.cast .bfig > img:not(.blinkp) { width: auto; height: auto; max-width: 100%; max-height: 190px; }
.cast b { font: 600 1.1rem "Mitr", sans-serif; }
.cast span { font-size: .82rem; line-height: 1.45; color: var(--ink-2); }
.bagsum { font-weight: 700; }
.items { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; width: 100%; }
.items li { display: grid; gap: 4px; justify-items: center; background: #fff; border-radius: 16px; padding: 14px 10px; box-shadow: 0 0 0 2px var(--wood-light); opacity: .6; }
.items li.has { opacity: 1; box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(255, 200, 60, .6); }
.items .iic { font-size: 2.6rem; line-height: 1; }
.items small { color: var(--ink-2); line-height: 1.4; }
.steps { text-align: left; margin: 0; padding-left: 1.4em; display: grid; gap: 6px; line-height: 1.6; }
.blockkey { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; justify-content: center; line-height: 2; }
.note { font-size: .9rem; color: var(--ink-2); }
.hset { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; cursor: pointer; }
.hset input { width: 22px; height: 22px; accent-color: var(--green); }
.credit { font-size: .85rem; color: var(--ink-2); }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ================= สร้างเกม (แบบ Scratch) ================= */
.bigbtn.small { padding: 6px 12px; font-size: .9rem; border-radius: 12px; }
.bigbtn.big { padding: 14px 30px; font-size: 1.25rem; }
.bsteps { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.bsteps li { display: flex; align-items: center; gap: 8px; background: #fff; border-radius: 14px; padding: 10px; font-weight: 700; box-shadow: 0 0 0 2px var(--wood-light); }
.bsteps li.done { background: #eaffdf; box-shadow: 0 0 0 2px #6bbf59; }
.bsteps li.done .mnum { background: var(--green); }
.bsteps li.cur { box-shadow: 0 0 0 3px var(--gold); }
.bsteps .mnum { width: 32px; height: 32px; font-size: .95rem; flex: none; }
.pm-go { display: flex; justify-content: center; margin-top: 16px; }
.sdots { display: flex; gap: 6px; }
.sdot { width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer; font-weight: 700; background: var(--cream-2); color: var(--wood-dark); box-shadow: 0 3px 0 var(--wood-dark); }
.sdot.done { background: var(--green); color: #fff; }
.sdot.cur { box-shadow: 0 0 0 3px #fff, 0 3px 0 var(--wood-dark); }
.sdot:disabled { opacity: .45; cursor: default; }
.maker { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 520px); gap: 14px; padding: 14px; max-width: 1800px; margin: 0 auto; }
.mleft { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr auto; gap: 10px; }
.mleft .goal { grid-template-columns: 58px minmax(0, 1fr) auto; }
.mright { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 8px; }
.stabs { display: flex; gap: 8px; flex-wrap: wrap; }
.stab { display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer; border-radius: 14px; padding: 5px 14px 5px 6px; font-weight: 700; font-size: 1rem;
  background: #fff; color: var(--ink); box-shadow: 0 0 0 2px var(--wood-light); }
.stab img { width: 36px; height: 36px; object-fit: contain; }
.stab .emo { font-size: 1.7rem; line-height: 36px; width: 36px; text-align: center; }
.stab[aria-selected="true"] { background: #e3f0ff; box-shadow: 0 0 0 3px var(--sc-motion); }
.mws-wrap { position: relative; min-height: 0; }
.mws { height: min(calc(100dvh - 330px), 640px); min-height: 380px; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 3px var(--wood-light); }
.copybtn { position: absolute; right: 12px; top: 10px; z-index: 5; }
.stagebar { display: flex; align-items: center; gap: 10px; }
.flagbtn, .stopbtn { width: 46px; height: 40px; border-radius: 10px; border: 0; cursor: pointer; background: #fff; box-shadow: 0 0 0 2px #c9d6ea; font-size: 1.4rem; display: grid; place-items: center; }
.flagbtn.on { background: #dff3ff; box-shadow: 0 0 0 3px var(--sc-motion); }
.stopbtn::before { content: ""; width: 20px; height: 20px; background: #ec5959; clip-path: polygon(30% 0, 70% 0, 100% 30%, 100% 70%, 70% 100%, 30% 100%, 0 70%, 0 30%); }
.stepprog { flex: 1; font-weight: 700; font-size: .92rem; color: var(--ink); background: #fff; border-radius: 12px; padding: 6px 10px; box-shadow: 0 0 0 2px var(--wood-light); min-height: 36px; }
.stage { width: 100%; aspect-ratio: 4 / 3; border-radius: 10px; background: #8fd6ff; box-shadow: 0 0 0 3px #c9d6ea; display: block; outline: none; touch-action: none; }
.stage:focus-visible { box-shadow: 0 0 0 3px var(--gold); }
.pad { display: flex; justify-content: center; gap: 24px; }
.padbtn { width: 84px; height: 48px; border: 0; border-radius: 14px; font-size: 1.6rem; cursor: pointer; background: linear-gradient(#fff7df, #ffe1a1); box-shadow: 0 4px 0 var(--wood-dark); touch-action: none; user-select: none; }
.padbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }
.mscratch { height: auto; min-height: 120px; max-height: 360px; gap: 18px; }
.sstack { display: grid; justify-items: start; }
.sb.mo { --c: var(--sc-motion); }
.sb .op { background: #59c059; border-radius: 999px; padding: 1px 6px; display: inline-flex; gap: 4px; align-items: center; }
.sb .sense, .c-top .sense { background: #5cb1d6; border-radius: 999px; padding: 1px 8px; }
.c-top .hex { background: #5cb1d6; padding: 2px 14px; clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 10px 100%, 0 50%); display: inline-flex; gap: 4px; align-items: center; }
.c-top .hex.opx { background: #59c059; }
.c-top .hex .mo-r { background: #4c97ff; border-radius: 999px; padding: 1px 8px; }
.c-top i { font-style: normal; background: #fff; color: #575e75; border-radius: 999px; padding: 0 8px; }
.c-top i.dd { background: color-mix(in srgb, #000 15%, transparent); color: #fff; border-radius: 6px; padding: 0 6px; }
.c-top { font: 600 .9rem/1.3 "Mali", Tahoma, sans-serif; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.c-wrap.cap .c-foot { border-radius: 0 0 5px 5px; }
.sempty { margin: 0; color: var(--ink-2); font-size: .9rem; }
.hintbody { display: flex; flex-wrap: wrap; gap: 24px; justify-content: center; text-align: left; width: 100%; }
.hintcol { background: #f9f9f9; border-radius: 14px; padding: 12px 14px; box-shadow: 0 0 0 2px #dde3ee; display: grid; gap: 8px; align-content: start; }
.mb.ct { background: var(--sc-control); }
.mb.vr { background: var(--sc-var); }
body.bigstage .maker { grid-template-columns: minmax(0, 1fr); }
body.bigstage .mleft { display: none; }
body.bigstage .stage { width: min(100%, calc((100dvh - 240px) * 4 / 3)); justify-self: center; }
@media (max-width: 1100px) {
  .maker { grid-template-columns: minmax(0, 1fr); }
  .mright { order: -1; }
  .stage { width: min(100%, 80vh); justify-self: center; }
  .bsteps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .mleft .goal { grid-template-columns: 48px minmax(0, 1fr); }
  .mleft .goal .bigbtn { grid-column: 1 / -1; }
  .sdots { order: 5; width: 100%; justify-content: center; }
  .bsteps { grid-template-columns: minmax(0, 1fr); }
}

/* ================= จอเล็ก ================= */
@media (max-width: 1279px) {
  .code { grid-template-columns: minmax(0, 1fr); }
  .scratch { height: auto; min-height: 120px; max-height: 280px; }
  .ws { height: min(52vh, 480px); }
}
@media (max-width: 960px) {
  .play { grid-template-columns: minmax(0, 1fr); }
  .missions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lvmain { grid-template-columns: minmax(0, 1fr); }
  .lvart { position: relative; top: 0; }
  .lvgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lvgrid li, .lvgrid li:nth-child(4) { grid-column: span 1; }
  .lvgrid li:last-child { grid-column: 1 / -1; justify-self: center; width: calc(50% - 11px); }
  .cast { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .boardwrap { height: auto; }
}
@media (max-width: 600px) {
  .play { padding: 10px 8px; }
  .panel { padding: 10px; }
  .bar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .bar-title { font-size: 1.1rem; }
  .chip.acct { order: 9; width: 100%; text-align: center; white-space: normal; }
    .missions, .items { grid-template-columns: minmax(0, 1fr); }
  .lvgrid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .lvgrid li:last-child { grid-column: auto; width: auto; }
  .lvbtns .bigbtn { flex: 1 1 100%; }
  /* มือถือ: ขยายเวทีให้สูงขึ้นแล้วตัดเหลือช่วงกลาง (ตำแหน่งตา/ประกายเป็น % จึงยังตรง) */
  .mh-stage { width: 252.5%; margin-left: -76.25%; }
  .maphero .mh-stage > img:first-of-type { -webkit-mask-image: none; mask-image: none; }
  .mh-prog { position: static; display: table; margin: 0 auto; }
    .speed { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .p-play, .htw, .cell .fruit, .cell .sita, .hero.cheer img { animation: none !important; }
  .hspark, .meteor { display: none; }
  .spark { animation: none; opacity: .8; }
  .hero { transition: none; }
}
