/* คีบพยัญชนะกับหนุมาน AR — ใช้ภาพชุด UI ไม้ + ตัวอักษรเงา (img/ui, img/abc) */
: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;
  box-sizing: border-box; color-scheme: light;
}
*, *::before, *::after { box-sizing: inherit; }
html, body { height: 100%; }
body { margin: 0; font-family: "Mali", "Leelawadee UI", Tahoma, sans-serif; color: var(--ink); background: #6fb35a; -webkit-tap-highlight-color: transparent; overflow: hidden; }
[hidden] { display: none !important; }
button, input { font-family: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; border-radius: 16px; }

/* ---------- ปุ่ม ---------- */
/* ปุ่มรูปภาพ (ป้ายไม้มีข้อความในภาพ) */
.imgbtn { display: inline-block; padding: 0; border: 0; background: none; cursor: pointer; line-height: 0; transition: transform .15s ease, filter .15s ease; filter: drop-shadow(0 3px 0 rgba(60, 30, 5, .55)) drop-shadow(0 10px 12px rgba(0, 0, 0, .45)); }
.imgbtn img { display: block; width: 100%; height: auto; pointer-events: none; }
.imgbtn:hover { transform: translateY(-3px) scale(1.04); filter: drop-shadow(0 4px 0 rgba(60, 30, 5, .55)) drop-shadow(0 16px 16px rgba(0, 0, 0, .45)) brightness(1.07); }
.imgbtn:active { transform: translateY(2px) scale(.98); }
.imgbtn[aria-pressed="false"] { filter: grayscale(.9) drop-shadow(0 4px 4px rgba(0, 0, 0, .3)); opacity: .8; }
/* ปุ่มไม้ที่ไม่มีในชุดภาพ: ทำด้วย CSS ให้หน้าตาเข้ากัน */
.woodbtn {
  border: 3px solid var(--wood-dark); border-radius: 22px; padding: 10px 22px; cursor: pointer; font-size: 1.05rem; font-weight: 700; color: #fff;
  background: linear-gradient(#d18a45, #a3622b 55%, #8a5423); text-shadow: 0 2px 0 var(--wood-dark), 0 0 3px var(--wood-dark);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), inset 0 -3px 0 rgba(0, 0, 0, .18), 0 5px 0 #4a280c, 0 8px 14px rgba(0, 0, 0, .3); transition: transform .15s;
}
.woodbtn:hover { transform: translateY(-2px); }
.woodbtn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), 0 2px 0 #4a280c; }
.woodbtn:disabled { opacity: .6; transform: none; cursor: default; }
.woodchip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border: 3px solid var(--wood-dark); border-radius: 18px; font-weight: 700; font-size: 1.2rem; color: #fff; white-space: nowrap;
  background: linear-gradient(#d18a45, #8a5423); text-shadow: 0 2px 0 var(--wood-dark); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .3), 0 4px 0 #4a280c, 0 10px 16px rgba(0, 0, 0, .4);
}
button.woodchip { cursor: pointer; }

/* ---------- หน้าเริ่ม ---------- */
.start { position: fixed; inset: 0; display: grid; place-items: center; padding: 12px; overflow: auto; }
.sbg { position: fixed; inset: 0; background: url(../img/ui/scene.webp) center/cover; filter: saturate(1.1); }
.sbg::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(255, 255, 255, .05) 30%, rgba(20, 40, 10, .45)); }
.sbox { position: relative; z-index: 1; display: grid; justify-items: center; gap: 10px; width: min(620px, 100%); }
.board { position: relative; width: min(560px, 96vw); }
.board img { display: block; width: 100%; height: auto; filter: drop-shadow(0 10px 12px rgba(0, 0, 0, .35)); }
.board h1, .board p { position: absolute; left: 0; right: 0; margin: 0; text-align: center; }
.board h1 { top: 25%; font: 600 clamp(1.9rem, 7vw, 3.4rem)/1.1 "Mitr", "Mali", sans-serif; color: #fff; text-shadow: 0 3px 0 var(--wood-dark), 0 0 6px var(--wood-dark), 0 6px 10px rgba(0, 0, 0, .3); }
.board h1 span { color: var(--gold); }
.board p { top: 60%; padding: 0 16%; line-height: 1.1; font-weight: 700; font-size: clamp(.95rem, 3.4vw, 1.3rem); color: var(--wood-dark); }
.floatabc { display: flex; gap: 10px; margin-top: -6px; }
.floatabc img { width: clamp(46px, 11vw, 72px); height: auto; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .25)); animation: bob 2.6s ease-in-out infinite; }
.floatabc img:nth-child(2) { animation-delay: -.6s; } .floatabc img:nth-child(3) { animation-delay: -1.2s; } .floatabc img:nth-child(4) { animation-delay: -1.8s; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }
.bigstart { width: min(330px, 78vw); animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.srow { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.srow .imgbtn { width: clamp(118px, 26vw, 170px); }
.setnow { margin: 0; padding: 4px 16px; border-radius: 999px; background: rgba(255, 246, 220, .92); font-weight: 700; box-shadow: 0 0 0 2px var(--wood-light); }
.status { min-height: 1.4em; margin: 0; padding: 0 12px; border-radius: 12px; text-align: center; font-weight: 700; color: #fff; text-shadow: 0 2px 3px rgba(0, 0, 0, .6); }
.status:empty { display: none; }
.status.err { background: rgba(160, 30, 20, .85); text-shadow: none; padding: 6px 12px; }
.sb-home, .sb-sound { position: fixed; top: 10px; z-index: 2; width: clamp(110px, 18vw, 160px); }
.sb-home { left: 10px; } .sb-sound { right: 10px; }
.mascot { position: fixed; left: 0; bottom: 0; z-index: 1; width: clamp(150px, 24vw, 330px); height: auto; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .3)); }
.privacy { position: fixed; right: 12px; bottom: 34px; z-index: 1; margin: 0; padding: 4px 10px; border-radius: 10px; font-size: .8rem; background: rgba(255, 246, 220, .9); }
@media (max-width: 700px), (max-height: 620px) { .mascot { width: 120px; opacity: .9; } .privacy { left: 12px; right: 12px; text-align: center; bottom: 30px; } }

/* ---------- หน้าเล่น ---------- */
.play { position: fixed; inset: 0; }
.stage { position: absolute; inset: 0; overflow: hidden; background: #6fb35a; touch-action: none; user-select: none; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }   /* เหมือนส่องกระจก */
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 8px 10px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hl, .hr { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hr { align-items: flex-end; }
.hexit { width: clamp(110px, 15vw, 160px); }
.hfull { padding: 6px 12px; font-size: 1.1rem; }
/* การ์ดเป้าหมาย: แผ่นกระดาษกรอบไม้ */
.target {
  display: grid; justify-items: center; --tw: clamp(180px, 30vw, 360px); width: var(--tw); aspect-ratio: 900 / 596; padding: calc(var(--tw) * .09) calc(var(--tw) * .1) calc(var(--tw) * .085);   /* % ของ padding อิงความกว้าง HUD จึงคิดจากความกว้างการ์ดเอง */ margin-top: 2px;
  background: url(../img/ui/board2.webp?v=1) center/100% 100% no-repeat; filter: drop-shadow(0 4px 0 rgba(60, 30, 5, .5)) drop-shadow(0 14px 16px rgba(0, 0, 0, .45));
}
.target { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.target b { white-space: nowrap; }
.target small { font-weight: 700; font-size: clamp(.68rem, 1.3vw, .9rem); color: var(--ink-2); line-height: 1.1; white-space: normal; text-align: center; }
.target .tg { display: flex; align-items: center; justify-content: center; gap: 4%; flex: 1; min-height: 0; width: 100%; overflow: hidden; }
.target .slots2 { display: flex; align-items: center; gap: 4px; }
.target .slots2:empty { display: none; }
.target .slots2 i { font-style: normal; font-weight: 700; color: var(--wood); }
.target .ps { display: grid; place-items: center; width: calc(var(--tw) * .18); aspect-ratio: 1; border-radius: 10px; background: #fff8e6; box-shadow: inset 0 2px 4px rgba(90, 50, 16, .35); font: 700 1.3rem Mitr, sans-serif; color: #c9a77a; }
.target .ps img { width: 92%; height: 92%; object-fit: contain; }
.target .ps.on { background: #eaffdf; box-shadow: inset 0 0 0 2px var(--green); }
.target .ps.new img { animation: pop .5s; }
.target .tpic { height: 100%; flex: 1; min-width: 0; min-height: 0; display: grid; place-items: center; font-size: clamp(1.8rem, 4vw, 3rem); line-height: 1; overflow: hidden; }
.target .tpic img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; }   /* ไม่ยืดเกินขนาดจริงมาก (ภาพแตก) */
.target .tpic:has(img.big) { position: relative; align-self: stretch; }
.target .tpic img.big { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; }   /* ภาพชุดใหม่ ~200px: เต็มช่องการ์ดได้โดยไม่แตก */
.target .tpic .emo { font-size: calc(var(--tw) * .26); }
.target b { font: 600 clamp(1rem, 2vw, 1.35rem)/1 "Mitr", "Mali", sans-serif; color: var(--wood-dark); }
.target.pop { animation: pop .5s; }
@keyframes pop { 0% { transform: scale(.6) rotate(-6deg); } 60% { transform: scale(1.12) rotate(2deg); } 100% { transform: none; } }
/* หัวใจ: แถบไม้ + หัวใจ 3 ดวง (ตำแหน่งตามภาพ hearts.webp 307×111) */
.hearts { position: relative; width: clamp(130px, 18vw, 200px); aspect-ratio: 307 / 111; background: url(../img/ui/hearts.webp) center/100% 100%; filter: drop-shadow(0 4px 4px rgba(0, 0, 0, .3)); }
.hearts img { position: absolute; height: auto; transition: filter .3s, opacity .3s; }
.hearts img.lost { filter: grayscale(1) brightness(.8) contrast(.9); animation: hlost .5s; }
@keyframes hlost { 30% { transform: scale(1.35); } }
.hint {
  position: absolute; left: 50%; top: clamp(150px, 24vw, 230px); transform: translateX(-50%); margin: 0; max-width: calc(100% - 24px);
  padding: 8px 18px; border: 3px solid var(--wood-dark); border-radius: 16px; background: rgba(255, 246, 220, .95); color: var(--ink); font-weight: 700; text-align: center; pointer-events: none;
  box-shadow: 0 4px 0 #4a280c;
}
.hint:empty { display: none; }
.hr2 { display: flex; gap: 8px; align-items: center; }
.handchip { font-size: 1.15rem; }
.handchip:empty { display: none; }
.handchip.warn { background: linear-gradient(#ff8a7a, #c8382a); animation: pulse 1.2s ease-in-out infinite; }
.hands-old { pointer-events: none; }

/* ช่องเก็บพยัญชนะด้านล่าง */
/* ช่องเก็บวางบนชั้นวางของกรอบ (ตำแหน่งคำนวณใน game.js placeTray) */
.tray { position: absolute; inset: 0; pointer-events: none; }
.tray .slot { position: absolute; background: url(../img/ui/slot.webp?v=2) center/100% 100% no-repeat; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .3)); }
.tray .slot img { position: absolute; left: 13%; top: 12%; width: 74%; height: 74%; object-fit: contain; }
.tray .slot.new img { animation: pop .5s; }
@media (max-width: 640px) {
  .hexit { width: 92px; } .woodchip { font-size: .95rem; padding: 5px 10px; } .hearts { width: 104px; }
  .target small { font-size: .7rem; }
}

/* ---------- กล่องข้อความ (แผ่นกระดาษกรอบไม้) ---------- */
.dlg { border: 0; padding: 0; background: none; max-width: min(620px, calc(100vw - 20px)); max-height: calc(100dvh - 16px); overflow: visible; }
.dlg::backdrop { background: rgba(30, 15, 3, .55); }
.pbox { position: relative; padding: 10% 11% 9%; background: url(../img/ui/board2.webp?v=1) center/100% 100% no-repeat; filter: drop-shadow(0 4px 0 rgba(60, 30, 5, .5)) drop-shadow(0 14px 20px rgba(0, 0, 0, .4)); min-width: min(560px, calc(100vw - 20px)); }
.pbox h2 { margin: 0 0 8px; text-align: center; font: 600 1.7rem "Mitr", "Mali", sans-serif; color: var(--wood-dark); }
.howto { margin: 0; padding-left: 26px; line-height: 1.75; font-size: 1.05rem; }
.tip { margin: 8px 0 0; font-weight: 700; color: var(--green-dark); }
.dlgbtns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; margin-top: 12px; }
.dlgbtns .imgbtn { width: clamp(130px, 30vw, 180px); }
.sets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.set {
  display: grid; justify-items: center; gap: 2px; padding: 8px 4px; border: 0; border-radius: 16px; cursor: pointer; color: var(--ink);
  background: #fffaf0; box-shadow: 0 0 0 3px var(--wood-light), 0 4px 0 var(--wood-light);
}
.set b { font-size: 1rem; }
.set small { color: var(--ink-2); font-size: .78rem; }
.set .lt { display: flex; gap: 1px; } .set .lt img { width: 20px; height: auto; }
.set[aria-checked="true"] { background: #eaffdf; box-shadow: 0 0 0 4px var(--green), 0 4px 0 var(--green-dark); }
.best { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.best li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 12px; border-radius: 12px; background: #fffaf0; font-weight: 700; box-shadow: 0 0 0 2px var(--wood-light); }
.best .st { color: #f0a400; letter-spacing: 2px; }
.best .none { color: var(--ink-2); font-weight: 600; justify-content: center; }
@media (max-width: 560px) { .sets { grid-template-columns: repeat(2, minmax(0, 1fr)); } .pbox h2 { font-size: 1.35rem; } .howto { font-size: .95rem; } }

/* ใบประกาศ: แผ่นดาว 3 ดวง (stars.webp 379×351) ดาวที่ไม่ได้เป็นสีเทา */
.certwrap { position: relative; display: flex; align-items: flex-end; justify-content: center; }
.cert { position: relative; width: min(400px, 82vw); aspect-ratio: 379 / 351; }
.cbg { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .4)); }
.cstars span { position: absolute; display: block; background: rgba(120, 110, 100, .0); }
.cstars span.off { backdrop-filter: grayscale(1) brightness(.85); -webkit-backdrop-filter: grayscale(1) brightness(.85); border-radius: 50%; }
.cbody { position: absolute; left: 12%; right: 12%; top: 33%; bottom: 10%; display: grid; align-content: start; justify-items: center; gap: 2px; text-align: center; }
.cbody h2 { margin: 0; font: 600 clamp(1.4rem, 5.5vw, 2rem)/1.1 "Mitr", "Mali", sans-serif; color: var(--wood-dark); }
.ctag { margin: 2px 0 4px; padding: 2px 14px; border-radius: 999px; background: var(--bad); color: #fff; font-weight: 700; font-size: .95rem; }
.cbody input { width: 92%; font-size: 1.25rem; font-weight: 700; text-align: center; padding: 4px; border: 0; border-bottom: 3px dashed var(--wood-light); background: transparent; color: var(--ink); }
.cstat { margin: 6px 0 0; font-weight: 700; font-size: .9rem; color: var(--ink-2); }
.cmascot { width: clamp(110px, 22vw, 200px); height: auto; margin-left: -30px; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .3)); }
@media (max-width: 560px) { .cmascot { position: absolute; right: -6px; bottom: -10px; width: 100px; margin: 0; } }
@media (prefers-reduced-motion: reduce) { .target.pop, .floatabc img, .bigstart, .tray .slot.new img, .hearts img.lost { animation: none; } }

/* เลือกด่าน (หน้าเริ่ม) */
.levels { display: flex; gap: 10px; justify-content: center; }
.lvbtn {
  display: grid; gap: 0; padding: 8px 16px; border: 3px solid var(--wood-dark); border-radius: 18px; cursor: pointer; color: var(--ink); text-align: center;
  background: linear-gradient(#fffaf0, #ffe9b8); box-shadow: inset 0 2px 0 #fff, 0 4px 0 #4a280c, 0 10px 14px rgba(0, 0, 0, .35); transition: transform .15s;
}
.lvbtn b { font: 600 1.15rem Mitr, Mali, sans-serif; color: var(--wood-dark); }
.lvbtn small { font-weight: 700; color: var(--ink-2); }
.lvbtn[aria-checked="true"] { background: linear-gradient(#7be38f, #2fa84f); border-color: var(--green-dark); }
.lvbtn[aria-checked="true"] b, .lvbtn[aria-checked="true"] small { color: #fff; text-shadow: 0 2px 0 var(--green-dark); }
.lvbtn:hover { transform: translateY(-2px); }
.tray .slot b { position: absolute; inset: 0; display: grid; place-items: center; font: 600 calc(var(--sw, 40px) * .4) Mitr, sans-serif; color: var(--wood-dark); }

/* หน้าเริ่มบนจอเตี้ย (≤ 820px): ย่อทุกชิ้นให้พอดีจอ */
@media (max-height: 820px) {
  .sbox { gap: 6px; }
  .board { width: min(480px, 80vw); }
  .board p { font-size: .95rem; }
  .floatabc img { width: clamp(38px, 5vh, 58px); }
  .bigstart { width: min(250px, 60vw); }
  .srow .imgbtn { width: clamp(100px, 14vw, 140px); }
  .lvbtn { padding: 5px 14px; } .lvbtn b { font-size: 1rem; }
  .woodbtn { padding: 7px 16px; font-size: .95rem; }
}

/* GAME OVER */
.pbox.over { text-align: center; }
.pbox.over h2 { font-size: 2.6rem; color: #c8382a; letter-spacing: .04em; text-shadow: 0 3px 0 #fff, 0 5px 0 rgba(90, 30, 10, .35); }
.omascot { width: 120px; height: auto; margin: -10px auto 4px; display: block; filter: grayscale(.35) drop-shadow(0 6px 6px rgba(0, 0, 0, .3)); }
.osub { margin: 0; font-weight: 700; font-size: 1.1rem; }
.ostat { margin: 6px 0 0; font-weight: 700; color: var(--ink-2); }
