:root {
  --bg: #f7f6ff;
  --surface: #ffffff;
  --surface-2: #efedff;
  --text: #1d1a3a;
  --muted: #5d5a7a;
  --brand: #5b4bff;
  --brand-2: #8f7bff;
  --brand-ink: #ffffff;
  --accent: #ffcf3f;
  --ok: #12a150;
  --ok-bg: #e3f7ec;
  --warn: #b26b00;
  --warn-bg: #fff3d6;
  --bad: #d12c4a;
  --bad-bg: #fde7eb;
  --border: #dedbf5;
  --shadow: 0 6px 24px rgba(40, 30, 120, .08);
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Lao", "Noto Sans Lao UI", "Phetsarath OT", "Lao Sangam MN", "Leelawadee UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12111f; --surface: #1c1a30; --surface-2: #26233f; --text: #f1efff; --muted: #b3afd6;
    --brand: #8f7bff; --brand-2: #b3a6ff; --brand-ink: #12111f; --border: #34305a;
    --ok-bg: #123526; --warn-bg: #3a2c0c; --bad-bg: #3d1520; --shadow: 0 6px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --bg: #12111f; --surface: #1c1a30; --surface-2: #26233f; --text: #f1efff; --muted: #b3afd6;
  --brand: #8f7bff; --brand-2: #b3a6ff; --brand-ink: #12111f; --border: #34305a;
  --ok-bg: #123526; --warn-bg: #3a2c0c; --bad-bg: #3d1520; --shadow: 0 6px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.55 var(--font); min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); overflow-x: hidden; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.08rem; }
p { margin: 0 0 .8rem; }
img, video, canvas, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px; z-index: 99; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; text-decoration: none; color: var(--text); }
.brand img { width: 30px; height: 30px; }
.topbar .spacer { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); font-size: .85rem; font-weight: 700; white-space: nowrap; }

main { max-width: 860px; margin: 0 auto; padding: 16px; outline: none; }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: .72rem; text-decoration: none; color: var(--muted); padding: 4px 0; border-radius: 10px; min-height: 48px; justify-content: center; }
.tabbar a .ico { font-size: 1.25rem; line-height: 1; }
.tabbar a[aria-current="page"] { color: var(--brand); font-weight: 700; background: var(--surface-2); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.muted { color: var(--muted); } .small { font-size: .88rem; } .center { text-align: center; }
.stack > * + * { margin-top: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 2px solid transparent; background: var(--brand); color: var(--brand-ink); font-weight: 700; cursor: pointer; text-decoration: none; transition: transform .08s ease; }
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.ghost { background: transparent; color: var(--brand); border-color: var(--border); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.big { min-height: 56px; font-size: 1.1rem; }

label { display: block; font-weight: 600; margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); min-height: 46px; }
textarea { min-height: 110px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.error { color: var(--bad); font-size: .9rem; margin-top: 6px; }

.hero { text-align: center; padding: 28px 8px 8px; }
.hero h1 { font-size: 2.1rem; }
.mascot { display: inline-block; animation: bob 3s ease-in-out infinite; }
.mascot.dance { animation: dance .6s ease-in-out 4; }
@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes dance { 25% { transform: rotate(-12deg) scale(1.1); } 75% { transform: rotate(12deg) scale(1.1); } }
@media (prefers-reduced-motion: reduce) { .mascot, .mascot.dance { animation: none; } * { transition: none !important; } }
.bubble { position: relative; background: var(--surface-2); border-radius: 16px; padding: 12px 14px; margin: 6px 0 12px; }
.pixel-row { display: flex; gap: 12px; align-items: flex-start; }
.pixel-row .mascot { flex: none; font-size: 2.4rem; }

.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 999px; }
.level-head { display: flex; gap: 12px; align-items: center; }
.belt { font-size: .8rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); }
.lock { opacity: .65; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list a { text-decoration: none; color: var(--text); flex: 1; }
.tick { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; background: var(--surface-2); flex: none; }
.tick.done { background: var(--ok); color: #fff; }

.lesson-card { min-height: 220px; }
.lesson-card .kind { font-size: .75rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); margin-bottom: 6px; }
.lesson-card pre, .codebox { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 12px; border-radius: 12px; font: .85rem/1.5 ui-monospace, Menlo, Consolas, monospace; overflow-x: auto; }
.example { white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 12px; border-left: 4px solid var(--brand); }
.tipbox { background: var(--warn-bg); border-radius: 12px; padding: 12px; }
.funbox { background: var(--surface-2); border-radius: 12px; padding: 12px; font-style: italic; }
.missionbox { background: var(--ok-bg); border-radius: 12px; padding: 12px; }
.dots { display: flex; gap: 6px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--border); }
.dots span.on { background: var(--brand); }

.options { display: grid; gap: 10px; }
.opt { text-align: left; width: 100%; padding: 14px; border-radius: 12px; border: 2px solid var(--border); background: var(--surface); cursor: pointer; min-height: 52px; }
.opt:hover { border-color: var(--brand-2); }
.opt.picked { border-color: var(--brand); background: var(--surface-2); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.feedback { border-radius: 12px; padding: 12px; margin-top: 12px; }
.feedback.good { background: var(--ok-bg); } .feedback.bad { background: var(--bad-bg); }
.hp { display: flex; gap: 4px; font-size: 1.2rem; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.badge { text-align: center; padding: 12px 8px; border-radius: 14px; background: var(--surface-2); }
.badge .b-ico { font-size: 1.9rem; }
.badge.off { filter: grayscale(1); opacity: .45; }
.status { font-size: .8rem; font-weight: 800; padding: 3px 10px; border-radius: 999px; display: inline-block; }
.status.ok { background: var(--ok-bg); color: var(--ok); }
.status.warn { background: var(--warn-bg); color: var(--warn); }
.status.bad { background: var(--bad-bg); color: var(--bad); }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.qr svg, .qr img { display: block; width: 220px; height: 220px; }
.slip-preview { max-height: 260px; border-radius: 12px; border: 1px solid var(--border); }
.snap-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; }
.snap-strip img { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; flex: none; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow-x: auto; }

/* Exam room */
.exam-room { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; padding: 16px; }
.exam-top { display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.cam-thumb { position: fixed; right: 12px; bottom: 12px; width: 132px; border-radius: 12px; border: 3px solid var(--ok); background: #000; z-index: 55; overflow: hidden; }
.cam-thumb.alert { border-color: var(--bad); }
.cam-thumb video { display: block; width: 100%; transform: scaleX(-1); }
.cam-thumb .cam-label { position: absolute; left: 6px; top: 4px; font-size: .7rem; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000; }
.cam-large { width: 100%; max-width: 360px; border-radius: 14px; background: #000; transform: scaleX(-1); }
.pause-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(10, 8, 30, .88); color: #fff; display: grid; place-items: center; padding: 24px; text-align: center; }
.pause-overlay .btn { margin-top: 12px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; }
.qnav { display: flex; gap: 6px; flex-wrap: wrap; }
.qnav button { width: 36px; height: 36px; border-radius: 8px; border: 1.5px solid var(--border); background: var(--surface); cursor: pointer; font-size: .85rem; }
.qnav button.answered { background: var(--surface-2); border-color: var(--brand-2); }
.qnav button.current { border-color: var(--brand); border-width: 3px; }
.qnav button.flagged { box-shadow: inset 0 -4px 0 var(--accent); }
.syscheck li { padding: 6px 0; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 80; transition: all .25s ease; max-width: calc(100% - 32px); text-align: center; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.modal-back { position: fixed; inset: 0; background: rgba(10, 8, 30, .55); z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 18px; padding: 20px; max-width: 480px; width: 100%; max-height: 90vh; overflow-y: auto; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 10px; height: 14px; border-radius: 2px; animation: fall 1.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .8; } }
.notice { border-radius: 12px; padding: 12px; background: var(--warn-bg); margin-bottom: 14px; }
.cert-canvas { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--border); }

/* Lao script: stacked vowels and tone marks need more vertical room; words have no spaces. */
:lang(lo) body { line-height: 1.75; }
:lang(lo) h1, :lang(lo) h2, :lang(lo) h3 { line-height: 1.45; }
:lang(lo) .btn, :lang(lo) .opt { line-height: 1.5; }
:lang(lo) .bubble, :lang(lo) .card { overflow-wrap: anywhere; }
.lang-btn { min-width: 44px; padding-inline: 10px; font-weight: 700; }
