:root {
  --bg: #f3f8fc; --card: #ffffff; --ink: #1d2b3a; --muted: #5d6f82; --line: #dbe5ee;
  --primary: #0b8f8c; --primary-d: #086b69; --primary-l: #d8f3f1;
  --accent: #f4a300; --accent-l: #fff1cc; --danger: #d6455d; --danger-l: #fde3e8;
  --ok: #2e9d57; --ok-l: #dff5e6; --water: #4aa8e8;
  --s-lobby: #94a3b8; --s-understand: #5b8def; --s-plan: #8b5cf6; --s-decide: #f4a300; --s-act: #ef6c3d; --s-evaluate: #0b8f8c; --s-done: #2e9d57;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1a24; --card: #172633; --ink: #e8f0f7; --muted: #9db0c2; --line: #28404f; --primary: #36c2bd; --primary-d: #5fd6d1; --primary-l: #12383a;
    --accent-l: #3b2f10; --danger-l: #3d1b24; --ok-l: #143324; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Noto Sans Thai Looped', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, system-ui, sans-serif; font-size: 17px; line-height: 1.6; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); } h2 { font-size: 1.4rem; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
a { color: var(--primary-d); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 2px rgba(20,40,60,.05); }
.card + .card { margin-top: 14px; }
.muted { color: var(--muted); } .small { font-size: .88rem; } .center { text-align: center; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; } .row.between { justify-content: space-between; }
.grid { display: grid; gap: 14px; }
.hidden { display: none !important; }

button, .btn { font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 20px; cursor: pointer; background: var(--primary); color: #fff; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; min-height: 48px; justify-content: center; transition: transform .08s, filter .15s; }
button:hover, .btn:hover { filter: brightness(1.07); } button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost, .btn.ghost { background: transparent; color: var(--primary-d); border: 2px solid var(--primary); }
button.soft { background: var(--primary-l); color: var(--primary-d); }
button.warn { background: var(--accent); color: #2b1d00; } button.danger { background: var(--danger); }
button.small, .btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input, select, textarea { font: inherit; width: 100%; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); min-height: 48px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; }
textarea { min-height: 96px; resize: vertical; }
label.f { display: block; font-weight: 600; margin: 12px 0 4px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--primary-l); color: var(--primary-d); font-size: .88rem; font-weight: 600; }
.chip.s-lobby { background: #e6ebf1; color: #475569; } .chip.s-understand { background: #e0e9fd; color: #2f55b4; } .chip.s-plan { background: #ece5fd; color: #6a3fcb; }
.chip.s-decide { background: var(--accent-l); color: #8a5a00; } .chip.s-act { background: #fde6dc; color: #b5461c; } .chip.s-evaluate { background: var(--primary-l); color: var(--primary-d); }
.chip.s-done { background: var(--ok-l); color: #1d6e3c; }
.chip.warn { background: var(--danger-l); color: var(--danger); }

.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; cursor: pointer; background: var(--card); }
.choice input { width: 22px; height: 22px; min-height: 0; margin-top: 4px; accent-color: var(--primary); flex: none; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-l); }
.choices { display: grid; gap: 8px; }
.chips-sel { display: flex; flex-wrap: wrap; gap: 8px; }
.chips-sel label { display: inline-flex; gap: 8px; align-items: center; padding: 10px 16px; border: 2px solid var(--line); border-radius: 999px; cursor: pointer; background: var(--card); }
.chips-sel input { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
.chips-sel label:has(input:checked) { border-color: var(--primary); background: var(--primary-l); font-weight: 600; }

/* top bars */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; padding-bottom: 10px; gap: 10px; }
.brand { font-weight: 800; font-size: 1.15rem; color: var(--primary-d); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand span.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 1.1rem; }

/* stepper */
.stepper { display: flex; gap: 4px; padding: 10px 0; }
.step { flex: 1; min-width: 0; text-align: center; font-size: .72rem; padding: 6px 0; overflow: hidden; border-radius: 10px; background: #e6edf3; color: var(--muted); border: 0; min-height: 0; font-weight: 700; }
.step b { display: block; font-size: 1.15rem; }
.step.done { background: var(--primary-l); color: var(--primary-d); } .step.cur { background: var(--primary); color: #fff; }
.step:disabled { opacity: 1; cursor: default; }
@media (prefers-color-scheme: dark) { .step { background: #213442; } }

/* landing */
.hero { padding: 56px 0 34px; background: linear-gradient(180deg, #d8f3f1 0%, var(--bg) 100%); }
@media (prefers-color-scheme: dark) { .hero { background: linear-gradient(180deg, #12383a 0%, var(--bg) 100%); } }
.hero p.lead { font-size: 1.15rem; max-width: 640px; }
.cycle { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.cycle .card { text-align: center; } .cycle .card + .card { margin-top: 0; } .cycle .big { font-size: 2rem; }
.join-box { display: flex; gap: 8px; max-width: 420px; }
.join-box input { font-size: 1.4rem; letter-spacing: .2em; text-align: center; font-weight: 700; }

/* map */
.map { width: 100%; height: auto; border-radius: var(--radius); background: #e8f5ff; border: 1px solid var(--line); display: block; }
.map text { font-family: inherit; }

/* plan grid */
.plan-grid { display: grid; grid-template-columns: 74px repeat(4, 1fr); gap: 6px; align-items: stretch; }
.plan-grid .h { font-weight: 700; text-align: center; font-size: .85rem; color: var(--muted); align-self: end; }
.plan-grid .boat { font-weight: 700; display: flex; align-items: center; gap: 4px; font-size: .95rem; }
.cell { min-height: 64px; border-radius: 12px; border: 2px dashed var(--line); background: var(--card); padding: 4px; font-size: .78rem; line-height: 1.25; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); }
.cell.full { border-style: solid; border-color: var(--primary); background: var(--primary-l); color: var(--ink); font-weight: 600; }
.cell.cont { border-style: solid; border-color: var(--primary); background: var(--primary-l); opacity: .6; cursor: default; }
.cell .e { font-size: 1.4rem; }
.sheet { position: fixed; inset: 0; background: rgba(10,20,30,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet > div { background: var(--card); width: min(560px, 100%); border-radius: 20px 20px 0 0; padding: 18px; max-height: 85vh; overflow: auto; }
.loc-opt { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; margin-top: 8px; background: var(--card); color: var(--ink); border: 2px solid var(--line); font-weight: 500; }
.loc-opt:hover { border-color: var(--primary); }
.stepper-n { display: inline-flex; align-items: center; gap: 8px; }
.stepper-n button { width: 40px; min-height: 40px; padding: 0; border-radius: 10px; }
.stepper-n output { min-width: 28px; text-align: center; font-weight: 800; }
table { border-collapse: collapse; width: 100%; } th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; } th { font-size: .85rem; color: var(--muted); }

/* result */
.meter { height: 14px; background: #e3ebf2; border-radius: 99px; overflow: hidden; display: flex; }
.meter i { display: block; height: 100%; } .m-ok { background: var(--ok); } .m-late { background: var(--accent); } .m-wait { background: var(--danger); }
.score-bar { height: 10px; border-radius: 99px; background: #e3ebf2; overflow: hidden; } .score-bar i { display: block; height: 100%; background: var(--primary); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .85rem; } .legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; background: var(--c); }
.callout { border-left: 5px solid var(--accent); background: var(--accent-l); padding: 12px 14px; border-radius: 8px; }
.callout.ok { border-color: var(--ok); background: var(--ok-l); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; background: #1d2b3a; color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 99; max-width: 90vw; }
.overlay { position: fixed; inset: 0; background: rgba(15,26,36,.82); color: #fff; display: grid; place-items: center; text-align: center; z-index: 60; padding: 20px; }

/* teacher */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { text-align: center; padding: 12px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); } .stat b { font-size: 1.7rem; display: block; line-height: 1.1; }
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; cursor: pointer; text-align: left; display: block; width: 100%; color: var(--ink); font-weight: 400; min-height: 0; }
.pcard.help { border-color: var(--danger); box-shadow: 0 0 0 2px var(--danger-l); }
.pcard .dots { display: flex; gap: 3px; margin-top: 8px; } .pcard .dots i { flex: 1; height: 6px; border-radius: 4px; background: #e3ebf2; } .pcard .dots i.on { background: var(--primary); }
.qr { width: 190px; height: 190px; border-radius: 12px; background: #fff; padding: 6px; border: 1px solid var(--line); }
.bigcode { font-size: 2.6rem; font-weight: 800; letter-spacing: .12em; color: var(--primary-d); line-height: 1; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--bg); z-index: 70; overflow: auto; padding: 16px; box-shadow: -8px 0 30px rgba(0,0,0,.25); }
.stars button { background: #e3ebf2; color: #888; min-height: 36px; width: 36px; padding: 0; } .stars button.on { background: var(--accent); color: #2b1d00; }
@media print { .topbar, .noprint, button { display: none !important; } body { background: #fff; color: #000; } .card { box-shadow: none; break-inside: avoid; } }
@media (max-width: 520px) { body { font-size: 16px; } .plan-grid { grid-template-columns: 56px repeat(4, 1fr); gap: 4px; } .cell { min-height: 58px; font-size: .7rem; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- scenario engines ---------- */
.grow { flex: 1; min-width: 0; }
.big-e { font-size: 1.7rem; line-height: 1; flex: none; }
.say { background: var(--accent-l); color: #8a5a00; min-height: 36px; width: 40px; padding: 0; border-radius: 50%; vertical-align: middle; }
.mascot { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0 12px; }
.mascot .face { font-size: 2.6rem; line-height: 1; }
.mascot .bubble { background: var(--accent-l); border-radius: 16px 16px 16px 4px; padding: 10px 14px; font-weight: 600; }
.pool { display: flex; flex-wrap: wrap; gap: 8px; }
.opt { background: var(--card); color: var(--ink); border: 2px solid var(--line); font-weight: 500; text-align: left; justify-content: flex-start; position: relative; }
.opt.sel { border-color: var(--primary); background: var(--primary-l); font-weight: 700; }
.choices .opt { width: 100%; }
.pool-btn { font-weight: 500; }
.badge { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .8rem; }
.seq-item, .alloc-row, .rrow, .tl-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; margin-top: 6px; background: var(--card); }
.seq-item > b { width: 24px; text-align: center; color: var(--primary-d); }
.drops { letter-spacing: 1px; font-size: 1.1rem; } .drops.sm { font-size: .9rem; min-height: 1.2em; }
.rrow .ri { font-size: 1.5rem; } .rrow .meter.small { height: 8px; margin-top: 4px; }
.meter.small { height: 8px; }
.timeline .tl-item.pop { animation: pop .35s ease-out; }
@keyframes pop { from { transform: translateY(8px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.lib-card { display: flex; flex-direction: column; gap: 6px; } .lib-card + .lib-card { margin-top: 0; }
.chip.playable { background: var(--ok-l); color: #1d6e3c; } .chip.planned { background: #e6ebf1; color: #475569; }
.chip.g1 { background: #ffe5e5; color: #a03030; } .chip.g2 { background: #ffeed9; color: #8a5200; } .chip.g3 { background: #fff6c9; color: #6e5d00; }
.chip.g4 { background: #dff5dc; color: #276c28; } .chip.g5 { background: #dcecff; color: #1f5496; } .chip.g6 { background: #eadcff; color: #5a2d99; }

/* ---------- grade tiers (set from the scenario's grade) ---------- */
body.tier-1 { font-size: 21px; }
body.tier-1 button, body.tier-1 .btn { min-height: 62px; border-radius: 20px; font-size: 1.05rem; }
body.tier-1 button.small { min-height: 52px; font-size: 1rem; padding: 8px 16px; }
body.tier-1 .step { font-size: 0; padding: 10px 0; } body.tier-1 .step b { font-size: 1.9rem; }
body.tier-1 .num, body.tier-1 .small.muted.num { display: none !important; }
body.tier-1 .choice, body.tier-1 .opt, body.tier-1 .seq-item, body.tier-1 .alloc-row { padding: 16px; border-radius: 18px; }
body.tier-1 .cell { min-height: 84px; font-size: 1rem; } body.tier-1 .big-e { font-size: 2.4rem; }
body.tier-1 .card { padding: 20px; border-radius: 24px; } body.tier-1 .mascot .face { font-size: 3.2rem; }
body.tier-1 .stepper-n button { width: 56px; min-height: 56px; } body.tier-1 .stepper-n output { font-size: 1.5rem; min-width: 36px; }
body.tier-2 { font-size: 18px; } body.tier-2 button, body.tier-2 .btn { min-height: 54px; border-radius: 16px; }
body.tier-2 .big-e { font-size: 2rem; } body.tier-2 .step b { font-size: 1.3rem; }
body.tier-2 .num table th:nth-child(n+3) { display: none; }
@media (max-width: 520px) { body.tier-1 { font-size: 20px; } }
.seq-item { flex-wrap: wrap; } .seq-item .grow { flex: 1 1 130px; }
.seq-item button, body.tier-1 .seq-item button.small { min-height: 44px; width: 44px; padding: 0; border-radius: 12px; }
.say, body.tier-1 .say { min-height: 40px; width: 40px; padding: 0; border-radius: 50%; font-size: 1rem; }.seq-item .ctl { margin-left: auto; display: flex; gap: 6px; }

/* ---------- Code Lab ---------- */
.cl-grid { display: grid; gap: 3px; background: #cfe3f3; padding: 6px; border-radius: 14px; max-width: 520px; margin: 8px auto; }
.cl-cell { aspect-ratio: 1; background: #eef7ff; border-radius: 8px; display: grid; place-items: center; position: relative; font-size: clamp(1.1rem, 4.6vw, 1.7rem); }
.cl-cell.wall { background: #7b8794; } .cl-cell.start { background: #fff3c4; } .cl-cell.node { background: #dff5e6; outline: 2px solid var(--primary); }
.cl-cell.node.done { background: #b8ecc6; } .cl-cell.node.decoy { background: #f3e8ff; outline: 2px dashed #a78bfa; }
.cl-cell .ne { line-height: 1; } .cl-cell .no { position: absolute; top: 0; left: 2px; font-size: .62em; color: var(--primary-d); }
.cl-cell .ck { position: absolute; bottom: 0; right: 1px; font-size: .55em; font-style: normal; }
.cl-cell .cl-hero { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.1em; filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.cl-cell.bump { animation: shake .3s; background: #ffd9de; } .cl-cell.wrongv { background: #fff0b8; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.cl-pal { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; justify-content: center; }
.cl-pal .arrow { width: 64px; min-height: 56px; font-size: 1.6rem; padding: 0; background: #1e90ff; }
.cl-pal .blkbtn { background: #7c4dff; }
.cl-prog { min-height: 70px; border: 2px dashed var(--line); border-radius: 14px; padding: 8px; background: var(--card); }
.cl-prog.sel, .cont.sel { outline: 3px solid var(--accent); }
.blk { display: flex; align-items: center; justify-content: space-between; gap: 6px; background: #e0efff; border-radius: 10px; padding: 4px 8px; margin: 4px 0; font-size: 1.4rem; }
.blk.rep { background: #ede4ff; display: block; } .blk.iff { background: #fff0d6; display: block; }
.blk .bh { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 1rem; font-weight: 700; } .blk .lbl { font-size: .85rem; font-weight: 700; margin-top: 4px; }
.blk .rm { min-height: 32px; width: 32px; padding: 0; margin-left: auto; }
.cont { border: 2px dashed #c9bde8; border-radius: 10px; padding: 4px 6px; margin: 4px 0 4px 10px; min-height: 40px; background: rgba(255,255,255,.6); }
.hint { color: var(--muted); font-size: .85rem; }
button.go { background: #1db954; } button.go:disabled { opacity: .7; }
body.tier-1 .cl-pal .arrow { width: 70px; min-height: 70px; font-size: 2rem; } body.tier-1 .blk { font-size: 1.9rem; }