/* English Quest: Word Detective. Mobile-first (360), up to iPad (820+). */
#app { height: 100dvh; }
.scr { height: 100dvh; max-width: 880px; margin: 0 auto; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0) max(14px, env(safe-area-inset-right, 0)) 0 max(14px, env(safe-area-inset-left, 0)); }
.sub { color: var(--muted); margin: 2px 0 0; font-size: 15px; }
.chip { display: inline-block; background: var(--teal-soft); color: var(--teal); font-size: 13px; font-weight: 700;
  border-radius: 999px; padding: 0 10px; margin-right: 8px; line-height: 24px; vertical-align: 1px; }
.en { font-family: "Nunito", sans-serif; font-weight: 800; }
mark { background: var(--accent-soft); color: inherit; border-radius: 6px; padding: 0 4px; }
html[data-mock] body::after { content: "โหมดทดสอบ"; position: fixed; right: 4px; top: calc(2px + env(safe-area-inset-top, 0)); font-size: 11px;
  background: var(--violet); color: #fff; padding: 0 8px; border-radius: 8px; opacity: .75; pointer-events: none; }

/* ---------- top bar + footer ---------- */
.bar { flex: none; display: flex; align-items: center; gap: 8px; min-height: 62px; padding: 8px 0; }
.bar .ttl { flex: 1; min-width: 0; }
.bar h1 { font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 380px) { /* four header items must fit: smaller title (2 lines allowed) and 44px icons */
  .bar { gap: 6px; }
  .bar .icon { width: 44px; height: 44px; font-size: 20px; }
  .bar h1 { font-size: 18px; white-space: normal; line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}
.kicker { margin: 0; font-size: 13px; font-weight: 800; color: var(--accent); letter-spacing: .04em; }
.icon { flex: none; width: 48px; height: 48px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); font-size: 22px; display: grid; place-items: center; }
.step { font-weight: 800; color: var(--muted); }
.foot { flex: none; display: flex; gap: 10px; padding: 10px 0 calc(16px + env(safe-area-inset-bottom, 0)); }
.foot .next { flex: 1; min-width: 0; height: 60px; border-radius: 18px; background: var(--accent); color: var(--accent-ink);
  font: 700 19px "Mali", var(--font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.foot .next:disabled { background: var(--line); color: var(--muted); box-shadow: none; }
.foot .next:not(:disabled):active { transform: translateY(2px); box-shadow: 0 2px 0 color-mix(in srgb, var(--accent) 60%, #000); }
.foot .prev { flex: none; width: 64px; height: 60px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); font-size: 30px; font-weight: 800; }

/* ---------- code screen ---------- */
.code { justify-content: center; align-items: center; gap: 18px; }
.code-top { text-align: center; display: flex; flex-direction: column; align-items: center; }
.glass { width: 64px; height: 64px; color: var(--accent); margin-bottom: 8px; animation: peek 3s ease-in-out infinite; }
@keyframes peek { 50% { transform: rotate(-12deg) translateX(-4px); } }
.code h1 { font-size: 26px; }
.dots { display: flex; gap: 16px; margin: 18px 0 6px; }
.dots i { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--accent); transition: background .12s; }
.dots i.on { background: var(--accent); }
.msg { height: 3.2em; margin: 4px 0 0; font-size: 15px; color: var(--muted); max-width: 300px; }
.msg.bad { color: var(--bad); font-weight: 700; }
.shake .dots { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: min(100%, 340px); }
.pad button { height: 72px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); font: 800 30px "Nunito", sans-serif; }
.pad button:active { transform: scale(.96); }
.pad .soft { font: 700 18px "Mali", var(--font); color: var(--muted); }
.who { display: grid; gap: 12px; width: min(100%, 340px); }
.big { height: 64px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); font: 700 22px "Mali"; }

/* ---------- teacher picker ---------- */
.pick .back { font-size: 30px; }
.grid { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px; padding: 6px 2px 12px; align-content: start; -webkit-overflow-scrolling: touch; }
.card { position: relative; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); padding: 8px 6px 10px;
  display: flex; flex-direction: column; align-items: center; border: 3px solid transparent; transition: transform .12s; }
.card .char { width: 76px; height: 76px; border-radius: 16px; background: var(--tile); }
.card .nm { font: 700 14px/1.3 "Mali"; margin-top: 6px; text-align: center; height: 2.6em; overflow: hidden; }
.card .tag { position: absolute; top: 4px; left: 4px; font-size: 11px; font-weight: 800; color: #3a2a00; background: var(--tag); border-radius: 8px; padding: 0 6px; }
.card .tag:empty { display: none; }
.card.sel { border-color: var(--accent); transform: translateY(-2px); }
.card.other { opacity: .45; }

/* ---------- map ---------- */
.map .scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding-bottom: 40px; }
.banner { border-radius: 16px; padding: 10px 14px; margin: 4px 0 8px; font-size: 15px; line-height: 1.55; }
.banner .lbl { display: block; font-size: 12px; font-weight: 800; letter-spacing: .03em; }
.banner.focus b { display: block; }
.banner.focus { background: var(--accent-soft); } .banner.focus .lbl { color: var(--accent); }
.banner.plan { background: var(--teal-soft); } .banner.plan .lbl { color: var(--teal); }
.crew { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.crew span { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 999px; padding: 3px 12px 3px 3px; }
.crew .char { width: 30px; height: 30px; }
.path { position: relative; margin-top: 6px; }
.trail { position: absolute; inset: 0; width: 100%; height: 100%; }
.trail path { fill: none; stroke: var(--line); stroke-width: 14; stroke-linecap: round; }
.node { position: absolute; width: 132px; transform: translate(-50%, -34px); display: flex; flex-direction: column; align-items: center; }
.node .disc { width: 68px; height: 68px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  font: 900 26px "Nunito"; box-shadow: 0 5px 0 color-mix(in srgb, var(--accent) 55%, #000); border: 4px solid var(--surface); }
.node.boss .disc { width: 78px; height: 78px; background: var(--violet); color: #fff; font-size: 30px; box-shadow: 0 5px 0 color-mix(in srgb, var(--violet) 55%, #000); }
.node.locked .disc { background: var(--line); color: var(--muted); box-shadow: none; font-size: 24px; }
.node.cur .disc { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.node .stars { margin-top: 4px; font-size: 15px; letter-spacing: 1px; color: color-mix(in srgb, var(--muted) 45%, transparent); line-height: 1; background: var(--bg); border-radius: 999px; padding: 2px 6px; }
.node .stars .on { color: var(--star); }
.node .stars i { font-style: normal; }
.node .lbl { font: 700 13px/1.35 "Mali"; text-align: center; margin-top: 2px; max-height: 2.7em; overflow: hidden; background: var(--bg); border-radius: 8px; padding: 0 4px; }
.avatar { position: absolute; width: 60px; height: 60px; transform: translate(calc(-30px + var(--side, -1) * 88px), -62px); transition: left 1.1s ease-in-out, top 1.1s ease-in-out, transform 1.1s; pointer-events: none;
  animation: hop 2.4s ease-in-out infinite; filter: drop-shadow(0 3px 2px rgba(0,0,0,.15)); }
@keyframes hop { 50% { translate: 0 -6px; } }

/* ---------- play ---------- */
.meter { flex: 1; height: 14px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--teal); border-radius: inherit; transition: width .35s; }
.repair .meter i { background: var(--violet); }
.combo { flex: none; width: 56px; text-align: center; font: 900 18px "Nunito"; color: var(--accent); }
.combo.pop { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.35); } }
.stage { flex: 1; min-height: 0; position: relative; }

/* RPG dialogue: navy box, portrait, yellow name tag, typewriter ~28 chars/s; tap box or ▼ to continue */
.talk { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 6px; }
.portrait { width: 132px; height: 132px; border-radius: 28px; background: var(--tile); margin: 0 0 -14px 8px; position: relative; z-index: 0; box-shadow: var(--shadow); }
.portrait.talking .char { animation: talk .5s ease-in-out 2; transform-origin: 50% 90%; }
@keyframes talk { 50% { transform: scale(1.04, .97); } }
.dlg { position: relative; z-index: 1; background: var(--navy); color: #fff; border: 3px solid var(--navy-line); border-radius: 18px;
  height: 236px; padding: 30px 16px 46px; box-shadow: 0 6px 0 rgba(10, 15, 40, .35); cursor: pointer; }
.dlg .name { position: absolute; top: -18px; left: 16px; background: var(--tag); color: #3a2a00; font: 800 16px/34px "Mali"; padding: 0 14px; border-radius: 10px; }
.dlg .name small { font-size: 12px; margin-left: 6px; opacity: .75; }
.dlg .txt { height: 100%; overflow-y: auto; font: 600 19px/1.65 "Mali", var(--font);
  -webkit-mask-image: linear-gradient(#000 85%, transparent); mask-image: linear-gradient(#000 85%, transparent); padding-bottom: 12px; }
.dlg .txt p { margin: 0; }
.dlg .txt .en { color: #ffe27a; border-bottom: 2px dotted rgba(255, 226, 122, .6); cursor: pointer; }
.dlg mark { background: rgba(255, 213, 74, .22); color: #fff; }
.dlg .dnext { opacity: 0; transition: opacity .2s; }
.dlg.ready .dnext { opacity: 1; }
@keyframes sweep { from { clip-path: inset(0 100% 0 0); opacity: .3; } to { clip-path: inset(0 0 0 0); opacity: 1; } }
.dlg .dnext, .dlg .dprev { position: absolute; bottom: 4px; width: 44px; height: 44px; color: #ffe27a; font-size: 22px; font-weight: 900; }
.dlg .dnext { right: 6px; animation: nudge 1s ease-in-out infinite; }
.dlg .dprev { left: 6px; font-size: 30px; }
.dlg .pg { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font: 700 13px "Nunito"; color: var(--navy-line); pointer-events: none; }
@keyframes nudge { 50% { transform: translateY(4px); } }

/* items */
.item { height: 100%; display: flex; flex-direction: column; gap: 8px; padding: 4px 0 6px; }
.kick { margin: 0; font-size: 13px; font-weight: 800; color: var(--teal); }
.repair .kick { color: var(--violet); }
.q { margin: 0; font: 700 20px/1.4 "Mali"; min-height: 1.4em; }
.body { flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.say { width: 44px; height: 44px; border-radius: 12px; background: var(--teal-soft); font-size: 20px; flex: none; vertical-align: middle; margin-left: 8px; }
.word { height: 112px; display: flex; align-items: center; justify-content: center; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow);
  font: 900 44px "Nunito", sans-serif; letter-spacing: .01em; }
.word.sm { font-size: 34px; }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; }
.opt { min-height: 68px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); border: 3px solid transparent;
  font: 800 21px "Nunito", sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px; line-height: 1.2; }
.opt small { font: 600 12px "Mali"; color: var(--muted); margin-top: 2px; }
.opt.ok, .tok.ok { border-color: var(--ok); background: var(--ok-soft); }
.opt.bad, .tok.bad { border-color: var(--bad); background: var(--bad-soft); }
.opt.dim { opacity: .5; }
.sent { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; justify-content: center; padding: 16px 10px; min-height: 112px;
  border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); font: 800 25px/1.3 "Nunito", sans-serif; }
.sent .w.focus, .tok.focus { text-decoration: underline 4px var(--accent); text-underline-offset: 6px; }
.blank { display: inline-block; min-width: 96px; border-bottom: 4px solid var(--accent); text-align: center; color: var(--ok); }
.tok { min-height: 50px; padding: 0 14px; border-radius: 14px; background: var(--bg); border: 3px solid var(--line); font: 800 23px "Nunito", sans-serif; }
.help { flex: none; height: 132px; overflow-y: auto; }
.hint { height: 48px; padding: 0 16px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font: 700 16px "Mali"; }
.hint small { font-size: 12px; opacity: .8; }
.fb p { margin: 0 0 6px; line-height: 1.55; }
.res { font: 800 18px "Mali"; }
.res.ok { color: var(--ok); } .res.bad { color: var(--bad); }
.is-ok .word, .is-ok .sent { animation: pop .35s; }

/* sort: tap a word, then tap a bin */
.sorter { display: flex; flex-direction: column; gap: 12px; }
.pool { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; min-height: 116px; align-content: center; }
.pool .tok.sel { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-3px); }
.pool .tok.used { visibility: hidden; }
.bins { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.bin { height: 150px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); border: 3px dashed var(--line);
  display: flex; flex-direction: column; align-items: stretch; padding: 6px; overflow: hidden; }
.bin .bn { font: 800 16px/1.2 "Nunito"; text-align: center; }
.bin .bn small { display: block; font: 600 11px "Mali"; color: var(--muted); }
.bin .in { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; overflow-y: auto; }
.chipw { font: 800 14px/26px "Nunito"; border-radius: 8px; padding: 0 6px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chipw.ok { background: var(--ok-soft); color: var(--ok); } .chipw.bad { background: var(--bad-soft); color: var(--bad); font-size: 12px; }
.sorthelp { margin: 0; text-align: center; font-size: 13px; color: var(--muted); }

/* result */
.result { height: 100%; overflow-y: auto; text-align: center; padding: 8px 0 12px; }
.big-stars { display: flex; justify-content: center; gap: 10px; font-size: 64px; line-height: 1.1; color: var(--line); }
.big-stars i { font-style: normal; }
.big-stars .on { color: var(--star); animation: starin .5s var(--d) both cubic-bezier(.3, 1.6, .5, 1); }
@keyframes starin { from { transform: scale(0) rotate(-40deg); } }
.score { font: 700 20px "Mali"; margin: 6px 0 0; }
.note { margin: 0; color: var(--muted); font-size: 14px; }
.talk.mini { flex-direction: row; align-items: center; height: auto; gap: 10px; justify-content: center; margin: 12px 0; }
.talk.mini .portrait { width: 64px; height: 64px; border-radius: 16px; margin: 0; }
.bubble { margin: 0; background: var(--surface); border-radius: 16px; padding: 10px 14px; box-shadow: var(--shadow); text-align: left; max-width: 520px; }
.review { text-align: left; }
.review h3 { font-size: 17px; margin: 8px 0; }
.rv { background: var(--surface); border-radius: 16px; padding: 10px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.rv p { margin: 0 0 4px; }

/* toast + settings sheet */
#toast { position: fixed; top: calc(72px + env(safe-area-inset-top, 0)); left: 50%; transform: translate(-50%, -12px); background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 14px; font: 700 15px "Mali"; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw; z-index: 30; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.sheet-wrap { position: fixed; inset: 0; background: rgba(20, 15, 30, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { width: min(100%, 520px); background: var(--surface); border-radius: 24px 24px 0 0; padding: 20px 20px calc(24px + env(safe-area-inset-bottom, 0));
  display: flex; flex-direction: column; gap: 14px; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.sheet .row small { display: block; font-size: 13px; color: var(--muted); }
.sw { appearance: none; width: 58px; height: 34px; border-radius: 999px; background: var(--line); position: relative; transition: .2s; flex: none; cursor: pointer; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.sw:checked { background: var(--teal); } .sw:checked::after { left: 27px; }
.seg { display: flex; background: var(--bg); border-radius: 14px; padding: 4px; }
.seg button { height: 44px; padding: 0 14px; border-radius: 11px; font: 700 15px "Mali"; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.say-test, .close { height: 52px; border-radius: 16px; font: 700 17px "Mali"; }
.say-test { background: var(--teal-soft); color: var(--teal); }
.close { background: var(--accent); color: var(--accent-ink); }
.link.out { color: var(--muted); font-size: 14px; text-decoration: underline; height: 44px; }
.link.out.armed { background: var(--bad-soft); color: var(--bad); font-weight: 800; border-radius: 14px; }

@media (min-width: 700px) {
  .dlg { height: 250px; } .dlg .txt { font-size: 21px; }
  .portrait { width: 168px; height: 168px; }
  .word { height: 150px; font-size: 56px; } .sent { font-size: 30px; min-height: 150px; }
  .opt { min-height: 80px; font-size: 24px; } .help { height: 150px; }
  .bin { height: 180px; } .node { width: 170px; }
  .avatar { width: 76px; height: 76px; transform: translate(calc(-38px + var(--side, -1) * 106px), -70px); }
}

/* reading passage */
.story { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 16px; height: 100%; overflow-y: auto; }
.sheet .story { height: auto; max-height: 60vh; box-shadow: none; padding: 0; }
.story h3 { font: 900 22px "Nunito"; display: flex; align-items: center; justify-content: space-between; }
.en-text { font: 700 21px/1.7 "Nunito", sans-serif; margin: 10px 0; }
.sline { cursor: pointer; border-radius: 6px; }
.sline:active { background: var(--teal-soft); }
.th-toggle { height: 44px; padding: 0 14px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font: 700 15px "Mali"; }
.th-text { margin: 10px 0 0; color: var(--muted); }

.stephead { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; font: 700 14px "Mali"; color: var(--teal);
  background: var(--teal-soft); border-radius: 999px; padding: 2px 14px; z-index: 1; max-width: 92%; overflow: hidden; text-overflow: ellipsis; }
