/* บล็อกโค้ดสังข์ทอง — โทนไม้/ครีม/ทองเดียวกับ Coding Game สังข์ทอง */
: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;
  --sc-motion: #4c97ff; --sc-control: #ffab19; --sc-events: #ffbf00; --sc-in-ink: #575e75; --sc-glow: #ffd400;
  --dur: 400ms;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  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: #3d6b33; -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
body::before {
  content: ""; position: fixed; inset: -40px; z-index: -1;
  background: url(../img/bgsmall.jpg) center/cover no-repeat; filter: blur(14px) saturate(1.1) brightness(.8);
}
[hidden] { display: none !important; }
button, select { font-family: inherit; }
button:focus-visible, select:focus-visible, a:focus-visible, summary:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- ปุ่ม ---------- */
.wbtn {
  display: inline-grid; place-items: center; width: 52px; height: 52px; 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.3rem; text-decoration: none;
}
.wbtn svg { width: 26px; height: 26px; }
.wbtn.small { width: 40px; height: 40px; border-radius: 12px; font-size: 1.05rem; }
.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.stop { color: #fff; background: linear-gradient(#ef6b55, var(--bad)); box-shadow: 0 4px 0 #8f2618; }
.bigbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--wood-dark); }
.bigbtn:disabled { opacity: .5; cursor: default; transform: none; }
.tbtn {
  border: 2px solid var(--wood-light); background: var(--cream); color: var(--wood-dark); border-radius: 999px;
  padding: 4px 14px; font-weight: 700; font-size: .9rem; cursor: pointer;
}
.tbtn[aria-pressed="true"] { background: var(--wood); border-color: var(--wood); color: var(--cream); }
.minibtn { border: 0; border-radius: 10px; padding: 4px 12px; font-weight: 700; background: var(--gold); color: var(--wood-dark); cursor: pointer; }

/* ---------- หน้าเลือกบท ---------- */
#scrMap { max-width: 1200px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 20px; }
.maphead { display: flex; gap: 16px; align-items: center; color: #fff; }
.maphead h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.6rem); text-shadow: 0 3px 0 var(--wood-dark), 0 6px 16px rgba(0, 0, 0, .4); }
.maphead p { margin: 2px 0 0; text-shadow: 0 2px 6px rgba(0, 0, 0, .6); }
.chapters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.chap {
  background: var(--cream); border-radius: 22px; overflow: hidden; display: grid; grid-template-rows: auto 1fr;
  box-shadow: 0 0 0 4px var(--wood), 0 0 0 7px var(--gold), 0 12px 26px rgba(0, 0, 0, .35);
}
.chap img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; background: var(--cream-2); }
.chap-body { padding: 14px 16px 16px; display: grid; gap: 8px; align-content: start; }
.chap .lv { font-size: .85rem; font-weight: 700; color: var(--wood); }
.chap h2 { margin: 0; font-size: 1.3rem; line-height: 1.3; }
.chap .concept { margin: 0; color: var(--ink-2); font-size: .95rem; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  border: 2px solid var(--wood-light); background: #fff; color: var(--ink); border-radius: 12px; padding: 2px 8px; cursor: pointer;
  font-weight: 700; font-size: .85rem; display: grid; justify-items: center; line-height: 1.2; min-width: 46px;
}
.pill i { font-style: normal; color: #e09a00; font-size: .78rem; letter-spacing: -1px; }
.pill.on { background: #fff4c9; border-color: var(--gold); }
.pill.lock { opacity: .45; cursor: default; }
.pill.obs { border-style: dashed; }
.chap .bigbtn { justify-self: start; margin-top: 4px; }
.chap.lock img, .chap.soon img { filter: grayscale(.8) brightness(.9); }
.chap.soon .chap-body { color: var(--ink-2); }
.chap.soon { grid-template-rows: auto; background: repeating-linear-gradient(45deg, #f7e7c2, #f7e7c2 10px, #fbefd4 10px, #fbefd4 20px); box-shadow: 0 0 0 3px var(--wood-light); }
.chap.soon h2 { font-size: 1.1rem; }
.locknote { font-size: .9rem; color: var(--ink-2); }
.teachbox { background: var(--cream); border-radius: 16px; padding: 12px 18px; box-shadow: 0 0 0 3px var(--wood); }
.teachbox summary { font-weight: 700; cursor: pointer; }
.teachbox li { margin: 4px 0; }

/* ---------- หน้าเล่น ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
}
.lvtitle { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; color: #fff; min-width: 0; }
.lvbadge { background: var(--wood); color: var(--cream); border-radius: 999px; padding: 3px 14px; font-weight: 700; white-space: nowrap; box-shadow: 0 0 0 2px var(--gold); }
.lvname { font-size: 1.25rem; font-weight: 700; text-shadow: 0 2px 0 var(--wood-dark), 0 3px 10px rgba(0, 0, 0, .5); }
.dots { display: flex; gap: 6px; margin-left: auto; }
.dots button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--gold); background: rgba(255, 246, 220, .85); color: var(--ink); font-weight: 700; font-size: .8rem; cursor: pointer; padding: 0; }
.dots button.on { background: var(--gold); }
.dots button.cur { box-shadow: 0 0 0 3px #fff; }
.dots button.lock { opacity: .4; cursor: default; }

.play {
  display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 8fr); gap: 16px; align-items: start;
  padding: 0 max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px));
}
.left, .right { background: var(--cream); border-radius: 22px; padding: 14px; display: grid; gap: 12px; min-width: 0; box-shadow: 0 0 0 4px var(--wood), 0 10px 24px rgba(0, 0, 0, .3); }

.mission { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.mission p { margin: 0; background: #fff; border-radius: 14px; padding: 8px 12px; font-weight: 600; font-size: 1.02rem; line-height: 1.5; position: relative; box-shadow: 0 0 0 2px var(--cream-2); }
.coachimg { width: 52px; height: 52px; border-radius: 50%; background: var(--cream-2); box-shadow: 0 0 0 3px var(--gold); }

/* แผนที่ */
.boardwrap { display: flex; justify-content: center; }
.board {
  position: relative; display: grid; grid-template-columns: repeat(var(--cols), var(--cell)); grid-auto-rows: var(--cell); gap: 3px;
  padding: 8px; border-radius: 18px; background: linear-gradient(#b87838, #8a5423); box-shadow: 0 0 0 4px var(--wood-dark), 0 0 0 7px var(--gold);
}
.cell { position: relative; border-radius: 14%; overflow: hidden; background: center/cover no-repeat; }
.cell.t-path { background-image: url(../img/path.webp); }
.cell.t-water { background-image: url(../img/water.webp); }
.cell.t-tree { background-image: url(../img/tree.webp); }
.cell.t-bush { background-image: url(../img/bush.webp); }
.cell.t-stump { background-image: url(../img/stump.webp); }
.cell.t-mushroom { background-image: url(../img/mushroom.webp); }
.cell.t-rock { background-image: url(../img/rock.webp); }
.cell.t-forest { background-image: url(../img/forest.webp); }
.cell.start::before { content: ""; position: absolute; inset: 18%; border: 3px dashed rgba(255, 255, 255, .85); border-radius: 50%; }
.cell.tint0::after, .cell.tint1::after { content: ""; position: absolute; inset: 0; mix-blend-mode: multiply; }
.cell.tint0::after { background: rgba(255, 171, 25, .45); }
.cell.tint1::after { background: rgba(76, 151, 255, .4); }
.cell.goal { box-shadow: inset 0 0 0 3px #fff3a0; animation: goalGlow 1.4s ease-in-out infinite; }
@keyframes goalGlow { 50% { box-shadow: inset 0 0 0 5px #ffd84a, 0 0 14px 4px rgba(255, 216, 74, .9); } }
.cell .thing { position: absolute; inset: 10%; width: 80%; height: 80%; object-fit: contain; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .35)); }
.cell.goal .thing { animation: bob 1.6s ease-in-out infinite; }
.cell .thing.emoji { display: grid; place-items: center; font-size: calc(var(--cell) * .6); line-height: 1; }
.cell .thing.got { animation: got .6s ease-out forwards; }
@keyframes bob { 50% { transform: translateY(-7%); } }
@keyframes got { 40% { transform: scale(1.4) rotate(-12deg); } 100% { transform: scale(0) rotate(20deg); opacity: 0; } }
.cell .foot { position: absolute; left: 41%; top: 41%; width: 18%; height: 18%; border-radius: 50%; background: rgba(255, 255, 255, .85); animation: foot .3s ease-out; }
@keyframes foot { from { transform: scale(0); } }

.hero {
  position: absolute; left: 8px; top: 8px; width: var(--cell); height: var(--cell); z-index: 3; pointer-events: none;
  will-change: transform; transition: transform var(--dur) cubic-bezier(.45, .05, .35, 1);
}
.hero .face { position: absolute; inset: -8%; transition: transform calc(var(--dur) * .8) cubic-bezier(.45, .05, .35, 1); }
.hero .nose { position: absolute; top: -4%; left: 50%; margin-left: -11px; border: 11px solid transparent; border-bottom: 15px solid var(--gold); border-top: 0; filter: drop-shadow(0 0 2px var(--wood-dark)); }
.hero .lab {
  position: absolute; top: 50%; margin-top: -12px; padding: 0 6px; border-radius: 8px; font-size: 13px; font-weight: 700; line-height: 24px;
  color: #fff; transform: rotate(calc(-1 * var(--rot, 0deg))); transition: transform calc(var(--dur) * .8);
}
.hero .lab.l { right: 100%; background: #2f8cff; }
.hero .lab.r { left: 100%; background: #ec4f9b; }
.hero .bod { position: absolute; inset: -22% 2% 4%; }
.hero .bod img { width: 100%; height: 100%; object-fit: contain; object-position: center bottom; filter: drop-shadow(0 4px 3px rgba(0, 0, 0, .45)); }
.hero .bod img.flip { transform: scaleX(-1); }
.hero.hop .bod { animation: hop var(--dur) ease-in-out; }
@keyframes hop { 45% { transform: translateY(-16%) scale(.95, 1.05); } 85% { transform: translateY(0) scale(1.06, .94); } }
.hero.shake .bod { animation: shake .45s; }
@keyframes shake { 20% { transform: translateX(-12%) rotate(-8deg); } 60% { transform: translateX(12%) rotate(8deg); } }
.hero.cheer .bod { animation: cheer .8s ease-in-out 2; }
@keyframes cheer { 30% { transform: translateY(-22%) rotate(-8deg); } 60% { transform: translateY(0) rotate(8deg); } }
.say {
  position: absolute; z-index: 4; transform: translate(-50%, -100%); background: #fff; color: var(--ink); border-radius: 12px; padding: 4px 10px;
  font-weight: 700; font-size: .9rem; white-space: nowrap; box-shadow: 0 0 0 2px var(--wood-light), 0 4px 10px rgba(0, 0, 0, .3); pointer-events: none;
  animation: say 1.6s ease forwards;
}
@keyframes say { 0% { opacity: 0; translate: 0 6px; } 12% { opacity: 1; translate: 0 0; } 80% { opacity: 1; } 100% { opacity: 0; } }

.bagline { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 14px; font-weight: 600; }
.bag { font-variant-numeric: tabular-nums; }
.bag.full { color: var(--bad); }
.starrule { color: var(--ink-2); font-size: .92rem; }
.coach { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; background: #fff4c9; border-radius: 14px; padding: 8px 12px; box-shadow: 0 0 0 2px var(--gold); }
.coach p { margin: 0; font-weight: 600; }
.coach.hint { background: #e6f4ff; box-shadow: 0 0 0 2px #7cbcff; }
.coach.bad { background: #ffe7e2; box-shadow: 0 0 0 2px #f2a090; }
.teach { font-size: .9rem; color: var(--ink-2); }
.teach summary { cursor: pointer; font-weight: 700; }
.teach ul { margin: 6px 0 0; padding-left: 1.2em; }

/* ฝั่งโค้ด */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.speed { margin-left: auto; display: flex; gap: 6px; align-items: center; font-weight: 600; font-size: .9rem; }
.speed select, .colctl select { border: 2px solid var(--wood-light); border-radius: 10px; background: #fff; color: var(--ink); padding: 2px 6px; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.pair.solo { grid-template-columns: minmax(0, 1fr); }
.pair.stacked { grid-template-columns: minmax(0, 1fr); }
.pair.stacked .code { height: auto; min-height: 160px; }
.colhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 32px; font-weight: 700; font-size: .92rem; color: var(--ink-2); margin-bottom: 4px; }
.colctl { display: flex; gap: 6px; align-items: center; }
.wsbox { position: relative; height: min(560px, calc(100dvh - 190px)); min-height: 380px; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 3px var(--wood-light); }
#ws { position: absolute; inset: 0; }
.blocklyMainBackground { stroke: none !important; }
.hand {
  position: absolute; left: 0; top: 0; z-index: 50; font-size: 40px; pointer-events: none; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .4));
  animation: drag 2.4s ease-in-out infinite;
}
@keyframes drag {
  0%, 10% { transform: translate(var(--x1), var(--y1)) scale(1); opacity: 0; }
  18% { transform: translate(var(--x1), var(--y1)) scale(.85); opacity: 1; }
  70% { transform: translate(var(--x2), var(--y2)) scale(.85); opacity: 1; }
  85%, 100% { transform: translate(var(--x2), var(--y2)) scale(1); opacity: 0; }
}

/* บล็อก Scratch (วาดด้วย HTML) */
.code { height: min(560px, calc(100dvh - 190px)); min-height: 380px; overflow: auto; background: #f9f9f9; border-radius: 14px; padding: 16px 14px; box-shadow: 0 0 0 3px var(--wood-light); display: grid; align-content: start; gap: 14px; }
.stack, .cblock, .cbody { display: grid; justify-items: start; }
.sb {
  --c: var(--sc-motion); position: relative; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer;
  background: var(--c); color: #fff; font: 600 .92rem/1.3 "Mali", Tahoma, sans-serif; padding: 8px 12px; border-radius: 5px;
  border: 1px solid color-mix(in srgb, var(--c) 72%, #000); text-align: left;
}
.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.ct { --c: var(--sc-control); }
.sb.blank { --c: #c9c2b4; color: var(--ink); border-style: dashed; }
.stack > * + *, .cbody > * + * { margin-top: -1px; }
.sb .in { background: #fff; color: var(--sc-in-ink); border-radius: 999px; padding: 0 9px; min-width: 1.8em; text-align: center; }
.sb .flag, .sb .rot { width: 18px; height: 18px; flex: none; }
.sb.now { box-shadow: 0 0 0 2px #fff, 0 0 0 5px var(--sc-glow); z-index: 2; }
.sb.sel { outline: 3px dashed var(--wood); outline-offset: 3px; }
.sb .rd { font-size: .74rem; background: #fff; color: #d27d00; border-radius: 999px; padding: 0 8px; margin-left: 4px; }
.cblock > .sb { border-bottom-left-radius: 0; }
.cbody { border-left: 16px solid var(--sc-control); padding: 7px 0; min-height: 24px; }
.cmid { width: 120px; padding: 4px 12px; background: var(--sc-control); color: #fff; font-weight: 700; font-size: .85rem; border-radius: 0 6px 6px 0; }
.cfoot { width: 80px; height: 16px; background: var(--sc-control); border-radius: 0 0 6px 6px; position: relative; }
.cfoot::after { content: ""; position: absolute; left: 14px; bottom: -7px; width: 20px; height: 7px; background: var(--sc-control); border-radius: 0 0 5px 5px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 12px; }
.opts .sb { font-size: .84rem; padding: 6px 10px; }
.opts .sb::after { display: none; }
.opts .sb.no { animation: shake .35s; opacity: .5; }
.codefoot { color: var(--ink-2); font-size: .82rem; }
.quizscore { color: #c06a00; font-weight: 700; }

/* บล็อกเล็กของเกม (ใช้ในกล่องข้อความ) */
.mbs { display: grid; justify-items: start; gap: 4px; }
.mb img { display: block; }
.mb { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 8px; color: #fff; font-weight: 700; background: var(--sc-motion); position: relative; transition: transform .5s ease, opacity .5s ease; }
.mb.ev { background: var(--sc-events); border-radius: 16px 16px 8px 8px; }
.mb.ct { background: var(--sc-control); }
.mb.hit { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--sc-glow); }
.mb .cnt { position: absolute; right: -40px; top: 50%; margin-top: -15px; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--bad); color: #fff; font-size: .95rem; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(0); } }
.mb.fold { opacity: 0; }
.mloop { display: grid; justify-items: start; animation: grow .6s cubic-bezier(.34, 1.56, .64, 1); }
.mloop .mhead { border-radius: 8px 8px 8px 0; }
.mloop .marm { border-left: 16px solid var(--sc-control); padding: 6px 0 6px 0; }
.mloop.hitbox, .hitbox { outline: 4px solid var(--sc-glow); outline-offset: 3px; border-radius: 8px; }
.mloop .mfoot { width: 90px; height: 16px; background: var(--sc-control); border-radius: 0 0 8px 8px; }
.mloop .in { background: #fff; color: var(--sc-in-ink); border-radius: 999px; padding: 0 9px; }
@keyframes grow { from { transform: scale(.4); opacity: 0; } }

/* ---------- ฉากวาดภาพ (แบบ Scratch) ---------- */
.drawwrap { display: grid; gap: 8px; }
.stage { width: 100%; height: auto; display: block; border-radius: 14px; background: #fff; box-shadow: 0 0 0 4px var(--wood-light); touch-action: none; }
.stage .d-paper { fill: #fff; }
.stage .g20 { stroke: #eef1f6; stroke-width: 1; }
.stage .g100 { stroke: #d5dbe6; stroke-width: 1.2; }
.stage .axis { stroke: #8792a6; stroke-width: 1.6; }
.stage .tick, .stage .axl { font: 600 11px "Mali", Tahoma, sans-serif; fill: #6b7486; text-anchor: middle; }
.stage .axl { font-size: 15px; fill: #3b4252; }
.stage .tick.l, .stage .axl.l { text-anchor: start; }
.stage .tick.r { text-anchor: end; }
.stage .d-target line { stroke: #9db7e8; stroke-width: 7; stroke-linecap: round; stroke-dasharray: 2 10; }
.stage .d-target.done line { stroke: #ffd84a; stroke-dasharray: none; stroke-width: 12; opacity: .55; }
.stage .d-dots circle { fill: #2f6fdc; stroke: #fff; stroke-width: 2; }
.stage .d-dots text, .stage .d-hover text { font: 700 12px "Mali", Tahoma, sans-serif; fill: #1f3f86; paint-order: stroke; stroke: #fff; stroke-width: 4px; }
.stage .d-dots text.r, .stage .d-hover text.r { text-anchor: end; }
.stage .d-ink line { stroke: #0fbd8c; stroke-width: 4; stroke-linecap: round; }
.stage .d-diff .miss { stroke: #e53935; stroke-width: 4; stroke-dasharray: 8 7; stroke-linecap: round; animation: blink 1s ease-in-out infinite; }
.stage .d-diff .extra { stroke: #ff8a1f; stroke-width: 6; stroke-linecap: round; opacity: .9; }
@keyframes blink { 50% { opacity: .35; } }
.stage .d-arc polyline { fill: none; stroke: #ff8a1f; stroke-width: 3; }
.stage .d-arc .ray { stroke: #ff8a1f; stroke-width: 2; stroke-dasharray: 4 4; }
.stage .d-arc text { font: 700 14px "Mali", Tahoma, sans-serif; fill: #c45a00; text-anchor: middle; paint-order: stroke; stroke: #fff; stroke-width: 4px; }
.stage .d-hover line { stroke: #2f6fdc; stroke-width: 1; stroke-dasharray: 3 4; opacity: .7; }
.stage .d-turtle .nose { fill: var(--gold); stroke: var(--wood-dark); stroke-width: 1.5; }
.stage .d-turtle .pendot { fill: #c9c9c9; stroke: #fff; stroke-width: 2; }
.stage .d-turtle .pendot.on { fill: #0fbd8c; }
.stage .d-turtle.shake image { animation: shake .45s; transform-box: fill-box; transform-origin: center; }
.readout { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .92rem; font-variant-numeric: tabular-nums; background: #fff; border-radius: 12px; padding: 6px 12px; box-shadow: 0 0 0 2px var(--cream-2); }
.readout b { color: #1f3f86; }
.readout .pen-on b { color: #0b8f69; }
.readout .pen-off b { color: #8a8a8a; }
.sb.pn { --c: #0fbd8c; }
.mb.pn { background: #0fbd8c; }
.angtab { border-collapse: collapse; width: 100%; font-size: 1rem; }
.angtab th, .angtab td { padding: 6px 8px; border-bottom: 2px solid var(--cream-2); text-align: center; }
.angtab td:first-child { text-align: left; display: flex; align-items: center; gap: 6px; }
.angtab .prod.hit { color: #0b8f69; font-weight: 700; }
.poly { width: 30px; height: 30px; vertical-align: middle; }
.poly polygon { fill: #dff7ee; stroke: #0fbd8c; stroke-width: 2.5; }
.rulebox { background: #fff4c9; border-radius: 14px; padding: 10px 16px; box-shadow: 0 0 0 2px var(--gold); font-size: 1.3rem; }

/* ---------- ตัวละครเต็มตัว (หัวจากภาพเดิม + ตัว SVG) ---------- */
.fig { position: absolute; inset: 0; }
.fig .f-body { position: absolute; left: 22%; width: 56%; bottom: 2%; overflow: visible; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .3)); }
.fig .f-head { position: absolute; left: 17%; top: -10%; width: 66%; height: auto; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .35)); }
.hero .bod .fig .f-head { width: 66%; height: auto; object-fit: contain; }
.f-body g, .sfig g { transform-box: view-box; }
.f-legL { transform-origin: 23px 30px; } .f-legR { transform-origin: 37px 30px; }
.f-armL { transform-origin: 8px 8px; } .f-armR { transform-origin: 52px 8px; }
.hero.hop .f-legL, .hero.hop .f-armR { animation: legA var(--dur) ease-in-out; }
.hero.hop .f-legR, .hero.hop .f-armL { animation: legB var(--dur) ease-in-out; }
.hero.cheer .f-armL { animation: cheerL .4s ease-in-out infinite alternate; }
.hero.cheer .f-armR { animation: cheerR .4s ease-in-out infinite alternate; }
@keyframes legA { 30% { transform: rotate(28deg); } 70% { transform: rotate(-28deg); } }
@keyframes legB { 30% { transform: rotate(-28deg); } 70% { transform: rotate(28deg); } }
@keyframes cheerL { from { transform: rotate(120deg); } to { transform: rotate(160deg); } }
@keyframes cheerR { from { transform: rotate(-120deg); } to { transform: rotate(-160deg); } }

/* ---------- แผนที่หลายแผน (บท 5) ---------- */
.maptabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; }
.maptabs .mt-lab { font-weight: 700; font-size: .88rem; color: var(--ink-2); }
.maptabs .mt { border: 2px solid var(--wood-light); background: #fff; color: var(--ink); border-radius: 999px; padding: 2px 12px; font-weight: 700; font-size: .85rem; cursor: pointer; }
.maptabs .mt.cur { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.maptabs .mt.ok { background: #d9f6df; color: #1f7a37; } .maptabs .mt.ok::after { content: " ✓"; }
.maptabs .mt.no { background: #ffe1db; color: #b23a25; } .maptabs .mt.no::after { content: " ✗"; }
.cell.goal .thing[src*="bridge"] { inset: 0; width: 100%; height: 100%; object-fit: cover; animation: none; }

/* ---------- ฉากประลองจับปลา (แบบ Scratch) ---------- */
.castwrap { display: grid; gap: 8px; }
.fs-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.fs-days { display: flex; gap: 6px; flex-wrap: wrap; }
.fs-day { border-radius: 999px; padding: 2px 12px; font-weight: 700; font-size: .88rem; background: #fff; box-shadow: 0 0 0 2px var(--cream-2); }
.fs-day.cur { box-shadow: 0 0 0 3px var(--gold); }
.fs-day.ok { background: #d9f6df; color: #1f7a37; } .fs-day.ok::after { content: " ✓"; }
.fs-day.no { background: #ffe1db; color: #b23a25; } .fs-day.no::after { content: " ✗"; }
.fs-casts { font-weight: 700; font-variant-numeric: tabular-nums; }
.fs-casts b { color: #d0458a; font-size: 1.15rem; }
.ct-stagewrap { position: relative; }
.ct-stage { width: 100%; height: auto; display: block; border-radius: 14px; box-shadow: 0 0 0 4px var(--wood-light); background: #6fc3ef; touch-action: none; }
.ct-shore { fill: none; stroke: #e9d39a; stroke-width: 6; }
.ct-lily { opacity: .9; }
.ct-grid line { stroke: #fff; stroke-width: .6; opacity: .22; }
.ct-grid line.ax { opacity: .45; stroke-width: 1; }
.ct-shadow { fill: rgba(0, 0, 0, .25); }
.ct-bbody { fill: #7b4a1e; stroke: #5a3210; stroke-width: 2.5; }
.ct-bfill { fill: #5fb0e8; transition: y .3s, height .3s; }
.ct-bucket.full .ct-bfill { fill: #ffcf3f; }
.ct-bucket.over .ct-bbody { fill: #c23b22; }
.ct-bucket.pop { animation: bpop .3s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes bpop { 50% { scale: 1.12; } }
.ct-brim { fill: #a8692f; stroke: #5a3210; stroke-width: 1.5; }
.ct-bcount { font: 700 18px "Mali", Tahoma, sans-serif; fill: #fff; text-anchor: middle; paint-order: stroke; stroke: #5a3210; stroke-width: 3px; }
.ct-blabel, .ct-name { font: 700 10px "Mali", Tahoma, sans-serif; fill: #fff; text-anchor: middle; paint-order: stroke; stroke: rgba(0, 0, 0, .55); stroke-width: 3px; }
.ct-dais { fill: #c0392b; stroke: #f1c232; stroke-width: 2; }
.ct-rc { font: 700 12px "Mali", Tahoma, sans-serif; fill: #1f3f86; text-anchor: middle; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.ct-net { fill: rgba(255, 255, 255, .25); stroke: #fff; stroke-width: 1.2; stroke-dasharray: 2 2; opacity: 0; }
.ct-rival.throw .ct-net { animation: net .6s ease-out; }
.ct-rival.throw .f-armR { animation: throwA .6s ease-out; }
@keyframes net { 30% { opacity: 1; transform: translate(10px, -6px) scale(1.3); } 100% { opacity: 0; transform: translate(26px, 4px) scale(.6); } }
@keyframes throwA { 40% { transform: rotate(-140deg); } }
/* พระสังข์ร่างทอง: ภาพพระสังข์ย้อมเป็นสีทอง เรืองแสง */
.ct-hero .spr image { filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .35)); }
.ct-hero.gold .spr image { filter: sepia(1) saturate(5) hue-rotate(-8deg) brightness(1.3) drop-shadow(0 0 7px #ffd84a); }
.ct-hero.gold .f-head { filter: sepia(1) saturate(3.2) hue-rotate(-8deg) brightness(1.08) drop-shadow(0 0 6px #ffd84a); }
.ct-hero.gold .f-body { filter: drop-shadow(0 0 6px #ffd84a); }
.sfig.cast .f-armL { animation: castL .5s ease-out; } .sfig.cast .f-armR { animation: castR .5s ease-out; }
@keyframes castL { 50% { transform: rotate(150deg); } } @keyframes castR { 50% { transform: rotate(-150deg); } }
.sfig.cheer .f-armL { animation: cheerL .4s ease-in-out infinite alternate; } .sfig.cheer .f-armR { animation: cheerR .4s ease-in-out infinite alternate; }
.sfig.transform { animation: transformA .5s ease-in-out; transform-box: fill-box; transform-origin: center bottom; }
@keyframes transformA { 50% { scale: 1.25; filter: brightness(2.2); } }
.sfig.fizzle, .sfig.sad { filter: grayscale(.5); }
.ct-fish { font-size: 22px; text-anchor: middle; dominant-baseline: middle; }
.ct-fish.pop { animation: pop .3s ease-out; transform-box: fill-box; transform-origin: center; }
.ct-fish.miss { opacity: .5; }
.ct-ripple { fill: none; stroke: #fff; stroke-width: 2; animation: ripple .8s ease-out forwards; transform-box: fill-box; transform-origin: center; }
@keyframes ripple { to { scale: 5; opacity: 0; } }
.ct-spark { font-size: 16px; fill: #ffd84a; text-anchor: middle; animation: say .9s ease forwards; }
.ct-monitor .m-bg { fill: #e9eef2; stroke: #c4ccd5; }
.ct-monitor .m-name { font: 700 11px "Mali", Tahoma, sans-serif; fill: #575e75; }
.ct-monitor .m-val { fill: #ff8c1a; }
.ct-monitor .m-num { font: 700 12px "Mali", Tahoma, sans-serif; fill: #fff; text-anchor: middle; }
.ct-monitor.flash .m-val { animation: mflash .4s ease-out; }
@keyframes mflash { 50% { fill: #ffd84a; } }
.ct-hover line { stroke: #fff; stroke-width: 1; stroke-dasharray: 3 4; opacity: .9; }
.ct-hover text { font: 700 12px "Mali", Tahoma, sans-serif; fill: #1f3f86; paint-order: stroke; stroke: #fff; stroke-width: 4px; }
.ct-hover text.r { text-anchor: end; }
.fs-say { position: absolute; left: 50%; top: 4%; transform: translateX(-50%); z-index: 5; max-width: 92%; text-align: center; background: #fff; border-radius: 12px;
  padding: 4px 12px; font-weight: 700; box-shadow: 0 0 0 2px var(--wood-light), 0 4px 10px rgba(0, 0, 0, .25); pointer-events: none; }
.fs-say.ok { background: #d9f6df; color: #1f7a37; } .fs-say.warn { background: #fff4c9; } .fs-say.bad { background: #ffe1db; color: #b23a25; }
.fs-rivals { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; background: #fff; border-radius: 12px; padding: 8px 10px; box-shadow: 0 0 0 2px var(--cream-2); }
.fs-rival { display: grid; grid-template-columns: 14px auto 1fr 22px; align-items: center; gap: 6px; font-size: .82rem; font-weight: 600; }
.ct-dot { width: 14px; height: 14px; border-radius: 50%; }
.ct-dot.c1 { background: #e85d75; } .ct-dot.c2 { background: #f0a030; } .ct-dot.c3 { background: #3fae5a; }
.ct-dot.c4 { background: #3a8ee6; } .ct-dot.c5 { background: #8a5ce6; } .ct-dot.c6 { background: #20a8a8; } .ct-dot.gold { background: #ffcf3f; box-shadow: 0 0 6px #ffb300; }
.fs-rbar { height: 10px; border-radius: 999px; background: #eef2e7; overflow: hidden; }
.fs-rbar i { display: block; height: 100%; width: 0; background: #7cc4f0; transition: width .3s; }
.fs-rival.me { grid-column: 1 / -1; font-weight: 700; }
.fs-rival.me .fs-rbar i { background: linear-gradient(90deg, #ffcf3f, #ffb300); }
.fs-rival b { text-align: right; font-variant-numeric: tabular-nums; }
.angtab .hidden-row td:not(:first-child) { color: transparent; }
.angtab .show { animation: pop .3s ease-out; }
.angtab b.ok { color: #1f7a37; } .angtab b.no { color: #b23a25; }

/* บล็อก Scratch เพิ่มเติม: บล็อกของฉัน ตัวแปร การรับรู้ สุ่ม */
.sb.my { --c: #ff6680; }
.sb.lk { --c: #9966ff; }
.sb.vr { --c: #ff8c1a; }
.sb .hex { display: inline-flex; align-items: center; gap: 4px; background: #59c059; padding: 2px 14px; clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 10px 100%, 0 50%); }
.sb .hex.sense { background: #5cb1d6; }
.sb .hex.empty { width: 46px; height: 22px; background: color-mix(in srgb, var(--sc-control) 65%, #000); }
.sb .hex .var, .sb .dd.vr { background: #ff8c1a; border-radius: 999px; padding: 0 8px; }
.sb .dd { background: color-mix(in srgb, #000 15%, transparent); border-radius: 6px; padding: 0 6px; }
.sb .swatch { display: inline-block; width: 18px; height: 14px; border-radius: 3px; background: #3a8a2e; box-shadow: 0 0 0 2px #fff; vertical-align: middle; }
.sb .rnd { background: #59c059; border-radius: 999px; padding: 0 8px; display: inline-flex; gap: 4px; align-items: center; }
.mb.my { background: #ff6680; } .mb.lk { background: #9966ff; } .mb.cd { background: #5cb1d6; } .mb.vr { background: #ff8c1a; }
.mb.hexa { clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 10px 100%, 0 50%); padding: 2px 16px; border-radius: 0; }

/* ---------- กากบาทแดงตรงโค้ดที่ผิด ---------- */
.bs-wrong > .blocklyPath { stroke: #e53935 !important; stroke-width: 4px !important; }
.xmark { position: absolute; z-index: 40; display: flex; align-items: center; gap: 6px; transform: translateY(-50%); pointer-events: none; animation: xpop .4s cubic-bezier(.34, 1.56, .64, 1); }
.xmark .xm { width: 34px; height: 34px; flex: none; border-radius: 50%; background: #e53935 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E") center/18px no-repeat; box-shadow: 0 0 0 3px #fff, 0 3px 8px rgba(0, 0, 0, .35); }
.xmark.compact .xt { display: none; }
.xmark .xt { background: #e53935; color: #fff; font-weight: 700; font-size: .85rem; border-radius: 10px; padding: 2px 10px; white-space: nowrap; box-shadow: 0 0 0 2px #fff; }
@keyframes xpop { from { transform: translateY(-50%) scale(0); } }
.sb.wrong { box-shadow: 0 0 0 2px #fff, 0 0 0 5px #e53935; z-index: 2; }
.sb.wrong::before { content: ""; position: absolute; right: -14px; top: -12px; width: 26px; height: 26px; border-radius: 50%; z-index: 3;
  background: #e53935 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E") center/13px no-repeat; box-shadow: 0 0 0 2px #fff; animation: pop .3s ease-out; }
.cell.xcell::before { content: ""; position: absolute; inset: 14%; z-index: 2; border-radius: 50%;
  background: rgba(229, 57, 53, .88) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E") center/55% no-repeat; box-shadow: 0 0 0 3px #fff; animation: pop .3s ease-out; }

/* ---------- หน้าอัดเสียงพากย์ ---------- */
.rec-wrap { max-width: 1000px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)); display: grid; gap: 16px; }
.rec-card { background: var(--cream); border-radius: 18px; padding: 14px 18px; box-shadow: 0 0 0 4px var(--wood); display: grid; gap: 10px; }
.rec-steps { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }
.rec-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.rec-bar .speed { margin-left: 0; }
.rec-info { font-weight: 600; color: var(--ink-2); }
.rec-meter { height: 8px; border-radius: 999px; background: #fff; overflow: hidden; }
.rec-meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #45c96a, #ffc83d, #e5533d); transition: width .08s; }
.rec-count { margin: 0; font-weight: 700; }
.rec-list { display: grid; gap: 8px; }
.rec-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; background: #fff; border-radius: 12px; padding: 8px 12px; box-shadow: 0 0 0 2px var(--cream-2); }
.rec-row.done { box-shadow: 0 0 0 2px #8fd19e; }
.rec-row.recording { box-shadow: 0 0 0 3px #e5533d; background: #fff4f2; }
.rec-text { min-width: 0; line-height: 1.5; }
.rec-key { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; color: var(--ink-2); }
.rec-lab { font-size: .82rem; font-weight: 700; color: var(--wood); }
.rec-st { font-size: .82rem; font-weight: 700; color: var(--ink-2); justify-self: end; }
.rec-row.done .rec-st { color: #1f7a37; }
.rec-btns { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.rec-btns .tbtn:disabled { opacity: .45; cursor: default; }
.rec-btns .tbtn.rec { border-color: #e5533d; color: #b23a25; }
.rec-btns .tbtn.rec.on { background: #e5533d; color: #fff; }

/* ---------- กล่องข้อความ ---------- */
.dlg { border: 0; padding: 0; background: transparent; max-width: min(520px, calc(100vw - 32px)); width: 100%; }
.dlg.wide { max-width: min(760px, calc(100vw - 32px)); }
.dlg { max-height: calc(100dvh - 16px); overflow: auto; }
.dlg::backdrop { background: rgba(30, 15, 0, .55); }
.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-size: 1.5rem; }
.dlgbody p { margin: 0; line-height: 1.6; }
.dlgbtns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.introthumb { width: 100%; max-width: 360px; border-radius: 16px; box-shadow: 0 0 0 3px var(--wood-light); }
/* กล่องที่มีภาพ (แนะนำบท): จอกว้างวางแนวนอน ภาพซ้าย เนื้อหาขวา ไม่ต้องเลื่อนอ่าน */
@media (min-width: 760px) {
  .dlg.side { max-width: min(920px, calc(100vw - 32px)); }
  .dlg.side .dlgbody { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); column-gap: 26px; align-content: center; justify-items: start; text-align: left; padding: 24px 28px; }
  .dlg.side .dlgbody > * { grid-column: 2; }
  .dlg.side .introthumb { grid-column: 1; grid-row: 1 / span 5; align-self: center; max-width: none; }
  .dlg.side .dlgbtns { justify-content: flex-start; }
}
.bigstars { font-size: 3rem; letter-spacing: 6px; color: #f0b400; text-shadow: 0 3px 0 var(--wood-dark); }
.bigstars .off { color: #d9c9a6; }
.bigstars span { display: inline-block; animation: starIn .5s cubic-bezier(.34, 1.56, .64, 1) both; }
.bigstars span:nth-child(2) { animation-delay: .15s; }
.bigstars span:nth-child(3) { animation-delay: .3s; }
@keyframes starIn { from { transform: scale(0) rotate(-40deg); } }
.obs-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; width: 100%; text-align: left; align-items: start; }
.obs-col { display: grid; gap: 8px; justify-items: start; min-width: 0; }
.obs-q { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.obs-q button { min-width: 64px; font-size: 1.4rem; }
.obs-q button.no { animation: shake .4s; background: #ffd8d0; }
.obs-big { font-size: 1.15rem; font-weight: 700; }
.obs-step { font-size: .85rem; font-weight: 700; color: var(--wood); letter-spacing: .03em; }
.rules { text-align: left; margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }

/* แท็บเล็ตแนวนอน: แผนที่กับบล็อกยังอยู่ข้างกัน ช่อง Scratch ย้ายไปใต้บล็อก */
@media (max-width: 1279px) {
  .pair { grid-template-columns: minmax(0, 1fr); }
  .code { height: auto; min-height: 160px; }
}
@media (max-width: 1100px) {
  .chapters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .play { grid-template-columns: minmax(0, 1fr); }
  .wsbox { height: 440px; }
}
@media (max-width: 700px) {
  .pair { grid-template-columns: minmax(0, 1fr); }
  .code { height: auto; min-height: 160px; }
  .chapters { grid-template-columns: minmax(0, 1fr); }
  .obs-grid { grid-template-columns: minmax(0, 1fr); }
  .speed { margin-left: 0; }
  .lvname { font-size: 1.05rem; }
}
@media (prefers-reduced-motion: reduce) {
  .hero, .hero .face, .hero .lab, .mb { transition: none; }
  .hero .bod, .cell .thing, .cell.goal, .hand, .say, .bigstars span, .mloop, .sfig, .ct-fish, .ct-ripple, .xmark, .sb.wrong::before, .cell.xcell::before { animation: none !important; }
}

/* ---------- เลือกตัวละคร ---------- */
.charpick { background: var(--cream); border-radius: 22px; padding: 12px 16px 14px; margin-bottom: 18px; box-shadow: 0 6px 0 var(--wood-dark), 0 10px 24px rgba(0, 0, 0, .3); }
.charpick h2 { margin: 0 0 8px; font-size: 1.15rem; }
.cp-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.cp { display: grid; justify-items: center; gap: 2px; padding: 8px 6px 10px; border: 3px solid transparent; border-radius: 16px; background: #fff; font: inherit; color: var(--ink); cursor: pointer; transition: transform .15s; }
.cp:hover { transform: translateY(-3px); }
.cp:focus-visible { outline: 3px solid #2f8cff; outline-offset: 2px; }
.cp.on { border-color: var(--gold); background: #fff4c9; box-shadow: 0 0 0 3px rgba(241, 194, 50, .35); }
.cp-img { display: flex; justify-content: center; align-items: flex-end; height: 110px; }
.cp-img img { height: 100%; width: auto; max-width: 100%; object-fit: contain; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .3)); }
.cp-img img + img { margin-left: -18%; }
.cp b { font-size: 1rem; }
.cp small { font-size: .75rem; color: var(--ink-2); text-align: center; line-height: 1.2; }
@media (max-width: 640px) {
  .cp-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cp-img { height: 84px; }
}

/* ---------- บัญชี e-learning ---------- */
.acct { margin-left: auto; display: grid; justify-items: end; gap: 2px; text-align: right; }
.acct-who { background: var(--cream); color: var(--ink); border-radius: 999px; padding: 4px 14px; font-weight: 700; box-shadow: 0 3px 0 var(--wood-dark); }
.acct-note { font-size: .8rem; text-shadow: 0 2px 6px rgba(0, 0, 0, .6); }
.acct-link { color: #fff; font-size: .85rem; }
.acct-login { background: #2fae5a; color: #fff; text-decoration: none; font-weight: 700; border-radius: 999px; padding: 6px 16px; box-shadow: 0 4px 0 #1d7a3c; }
.acct-login:hover { filter: brightness(1.08); }
.acct-login:focus-visible, .acct-link:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }
@media (max-width: 640px) { .maphead { flex-wrap: wrap; } .acct { margin-left: 0; justify-items: start; text-align: left; width: 100%; } }

/* ---------- หน้าแรก: ฉากเดียวกับ Coding Game สังข์ทอง (ภาพ 1672×941 ปุ่มวางตามตำแหน่ง %) ---------- */
#scrHome { min-height: 100dvh; display: grid; place-items: center; padding: 0 env(safe-area-inset-right, 0px) 0 env(safe-area-inset-left, 0px); }
.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; }
.htitle {
  position: absolute; left: 36.6%; top: 5.85%; width: 27.5%; height: 9.25%; margin: 0; display: flex; align-items: center; justify-content: center; gap: .1em;
  font: 600 4.6cqw/1 "Mitr", "Mali", sans-serif; letter-spacing: .01em;
  -webkit-text-stroke: .5cqw #fff; paint-order: stroke fill; filter: drop-shadow(0 .3cqw 0 rgba(90, 40, 5, .55));
}
.htitle span { display: inline-block; }
.htitle .b1 { color: #4c97ff; } .htitle .b2 { color: #9966ff; } .htitle .b3 { color: #ffab19; }
.htitle .b4 { color: #59c059; } .htitle .b5 { color: #ff6680; } .htitle .b0 { color: #7a3c10; margin-left: .25em; }
.hbadge {
  position: absolute; left: 88.4%; top: 24.2%; width: 8.85%; height: 7.25%; margin: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; white-space: nowrap;
  color: #fff; font: 700 1.15cqw/1.2 "Mali", sans-serif; text-shadow: 0 .12cqw 0 #a0195e;
}
.htag {
  position: absolute; left: 38%; top: 38.6%; width: 24.6%; margin: 0; text-align: center; white-space: nowrap; transform: rotate(-1.9deg);
  color: #3a1a05; font: 700 1.5cqw/1.2 "Mali", sans-serif; pointer-events: none;
}
.hbadge b { color: #ffe14d; font-size: 1.7cqw; }
.hb {
  position: absolute; padding: 0; margin: 0; border: 0; background: none; cursor: pointer; transform-origin: 50% 60%; color: #4a2008;
  transition: transform .25s cubic-bezier(.34, 1.56, .64, 1), filter .25s; filter: drop-shadow(0 .25cqw .3cqw rgba(0, 0, 0, .25)); outline: none;
}
.hb > img { display: block; width: 100%; height: 100%; pointer-events: none; }
.hb:active { transform: scale(.92) !important; transition-duration: .08s; }
.hb:hover, .hb:focus-visible { filter: drop-shadow(0 0 .5cqw #fff8c4) drop-shadow(0 0 1.2cqw rgba(255, 200, 61, .95)) brightness(1.08); z-index: 5; }
.hlab { position: absolute; left: 6%; right: 6%; top: 61%; height: 33%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; white-space: nowrap; font: 700 1.2cqw/1.2 "Mali", sans-serif; pointer-events: none; }
.hlab.play { left: 16%; right: 16%; top: 66%; height: 24%; font-size: 2.3cqw; }
.hicon { position: absolute; left: 28%; top: 13%; width: 44%; height: 42%; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; pointer-events: none; }
.hicon i { display: block; height: 1.25cqw; box-shadow: 0 .15cqw 0 rgba(0, 0, 0, .18); border-radius: .35cqw; border: .12cqw solid rgba(60, 30, 0, .45); position: relative; }
.hicon i + i { margin-top: -.05cqw; }
.hicon .k1 { width: 80%; height: 1.5cqw; background: #ffbf00; border-radius: 1.2cqw 1.2cqw .35cqw .35cqw; }
.hicon .k2 { width: 100%; background: #4c97ff; margin-left: 12%; }
.hicon .k3 { width: 70%; background: #ffab19; }
.hb-play { animation: hbreathe 2.2s ease-in-out infinite; }
.hb-play:hover, .hb-play:focus-visible { animation: hjelly .7s ease both, hbreatheBig 1.4s .7s ease-in-out infinite; }
@keyframes hbreathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
@keyframes hbreatheBig { 0%, 100% { transform: scale(1.1); } 50% { transform: scale(1.15); } }
@keyframes hjelly { 0% { transform: scale(1); } 30% { transform: scale(1.18, .92); } 50% { transform: scale(.96, 1.14); } 70% { transform: scale(1.12, 1.02); } 100% { transform: scale(1.1); } }
.hb-menu:hover, .hb-menu:focus-visible { animation: hhop .9s ease both, hfloat 1.6s .9s ease-in-out infinite; }
@keyframes hhop { 0% { transform: translateY(0) scale(1); } 30% { transform: translateY(-12%) scale(1.12) rotate(-4deg); } 50% { transform: translateY(-6%) scale(1.1) rotate(3deg); } 70% { transform: translateY(-8%) scale(1.1) rotate(-2deg); } 100% { transform: translateY(-6%) scale(1.1); } }
@keyframes hfloat { 0%, 100% { transform: translateY(-6%) scale(1.1); } 50% { transform: translateY(-9%) scale(1.1); } }
.hb-round { transform-origin: 50% 50%; }
.hb-round:hover, .hb-round:focus-visible { animation: hswing .8s ease both; }
@keyframes hswing { 0% { transform: rotate(0) scale(1); } 25% { transform: rotate(-18deg) scale(1.2); } 50% { transform: rotate(14deg) scale(1.18); } 75% { transform: rotate(-8deg) scale(1.16); } 100% { transform: rotate(0) scale(1.15); } }
.hb-round.off img { filter: grayscale(.75) brightness(.9); }
.hb-round.off::after { content: ""; position: absolute; left: 12%; right: 12%; top: 46%; height: 9%; background: #e53935; border-radius: 99px; transform: rotate(-40deg); box-shadow: 0 0 0 .18cqw #fff; }
.hb-side:hover, .hb-side:focus-visible { animation: hnudge .6s ease both; }
@keyframes hnudge { 0% { transform: translateX(0) scale(1); } 40% { transform: translateX(-10%) scale(1.14) rotate(-5deg); } 100% { transform: translateX(-6%) scale(1.12); } }
.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); } }
@media (prefers-reduced-motion: reduce) {
  .hb-play, .htw { animation: none !important; }
  .hb:hover, .hb:focus-visible { animation: none !important; transform: scale(1.08); }
  .hspark { display: none; }
}

/* กล่องข้อมูลของหน้าแรก */
.homedlg { max-height: calc(100dvh - 32px); overflow: auto; }
.homedlg[open] { display: grid; gap: 12px; }
.homedlg .hclose { position: sticky; top: 0; justify-self: end; margin-bottom: -52px; z-index: 2; }
.hset { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.1rem; cursor: pointer; }
.hset input { width: 22px; height: 22px; accent-color: var(--green); }
.hacct { color: var(--ink-2); font-size: .95rem; }
.hacct a { color: var(--green-dark); font-weight: 700; }
.homecard { background: var(--cream); border-radius: 24px; padding: 8px 22px 22px; scroll-margin-top: 16px; box-shadow: 0 0 0 4px var(--wood), 0 0 0 7px var(--gold), 0 12px 26px rgba(0, 0, 0, .35); }
.htabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 3px solid var(--cream-2); margin: 0 -8px 16px; }
.htabs button {
  border: 0; background: none; font: inherit; font-weight: 700; color: var(--ink-2); cursor: pointer;
  padding: 12px 14px 10px; border-bottom: 4px solid transparent; margin-bottom: -3px;
}
.htabs button[aria-selected="true"] { color: var(--wood-dark); border-bottom-color: var(--wood); }
.hpane .lead { margin: 0 0 14px; color: var(--ink-2); }
.hpane h3, .hpane h4 { margin: 0; }
.path { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.path li { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; background: #fff; border-radius: 16px; padding: 8px; box-shadow: 0 3px 0 var(--cream-2); }
.path img { width: 96px; height: 64px; object-fit: cover; border-radius: 12px; }
.path .lv { display: inline-block; background: var(--wood); color: var(--cream); border-radius: 999px; padding: 1px 12px; font-size: .8rem; font-weight: 700; }
.path h3 { font-size: 1.15rem; margin: 2px 0; }
.path p { margin: 0; font-size: .9rem; color: var(--ink-2); }

.steps { margin: 0; padding: 0; list-style: none; counter-reset: st; display: grid; gap: 10px; }
.steps li { counter-increment: st; position: relative; padding: 10px 12px 10px 56px; background: #fff; border-radius: 14px; line-height: 1.7; }
.steps li::before {
  content: counter(st); position: absolute; left: 12px; top: 10px; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; background: var(--gold); color: var(--wood-dark); font-weight: 700;
}
.steps .mb { padding: 2px 10px; font-size: .9rem; }
.tips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.tips p { margin: 0; padding: 12px 14px; border-radius: 14px; background: var(--cream-2); line-height: 1.6; }

.know { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.know article, .concepts article { background: #fff; border-radius: 16px; padding: 14px 16px; }
.know p, .concepts p { margin: 6px 0 0; line-height: 1.65; }
.hpane h3.sub { margin: 20px 0 10px; font-size: 1.15rem; }
.concepts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.concepts article { position: relative; display: grid; align-content: start; gap: 2px; }
.concepts .cn { position: absolute; right: 12px; top: 10px; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--wood); color: var(--cream); font-weight: 700; font-size: .85rem; }
.concepts h4 { font-size: 1.05rem; padding-right: 34px; }
.concepts .mbs { margin-top: 10px; }
.mb.go { background: var(--green); }
.mb.ind { margin-left: 18px; }
.ct4 { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.ct4 li { background: #fff; border-radius: 14px; padding: 12px; line-height: 1.55; border-top: 5px solid var(--gold); }
.ct4 b { display: block; }

.credit { text-align: center; color: #fff; text-shadow: 0 2px 6px rgba(0, 0, 0, .7); }
.credit p { margin: 2px 0; }
.credit a { color: var(--gold); }
@media (max-width: 760px) {
  .tips, .know { grid-template-columns: 1fr; }
  .ct4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .homecard { padding: 6px 14px 16px; }
  .htabs button { padding: 10px 8px 8px; font-size: .9rem; }
  .path li { grid-template-columns: 72px 1fr; }
  .path img { width: 72px; height: 52px; }
}
