/* ---------- tokens ---------- */
:root {
  --bg: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #F1EEE7;
  --ink: #1F2328;
  --muted: #6B6F76;
  --border: #E6E1D7;
  --brand: #5B4FE0;
  --brand-soft: #ECEAFD;
  --brand-ink: #FFFFFF;
  --good: #16A34A;
  --good-soft: #DCFCE7;
  --bad: #DC2626;
  --bad-soft: #FEE2E2;
  --shadow: 0 1px 2px rgba(31, 35, 40, .04), 0 4px 16px rgba(31, 35, 40, .06);

  --warn: #B45309; --warn-soft: #FDF1E1;
  --on-c: #FFFFFF; /* ตัวหนังสือบนพื้นสีภาษา */
  /* สีของแต่ละภาษา (--en, --ja, …) สร้างจาก colors ใน data.js ตอนเปิดแอป */

  --radius: 18px;
  --font: 'Noto Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Prompt', 'Noto Sans Thai', system-ui, sans-serif;
  --font-cjk: 'Hiragino Sans', 'PingFang SC', 'Apple SD Gothic Neo', 'Noto Sans CJK JP', 'Noto Sans JP', 'Microsoft YaHei', 'Malgun Gothic', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318; --surface: #1A1D24; --surface-2: #232731; --ink: #ECEDEE; --muted: #9BA1A6;
    --border: #2B303A; --brand: #8B80FF; --brand-soft: #2A2750; --brand-ink: #0E0D1A;
    --good: #4ADE80; --good-soft: #163322; --bad: #F87171; --bad-soft: #3A1A1A;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --warn: #F5A93A; --warn-soft: #3A2A14; --on-c: #111318;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111318; --surface: #1A1D24; --surface-2: #232731; --ink: #ECEDEE; --muted: #9BA1A6;
  --border: #2B303A; --brand: #8B80FF; --brand-soft: #2A2750; --brand-ink: #0E0D1A;
  --good: #4ADE80; --good-soft: #163322; --bad: #F87171; --bad-soft: #3A1A1A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --warn: #F5A93A; --warn-soft: #3A2A14; --on-c: #111318;
  color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; margin: 0; line-height: 1.3; }
[lang="ja"], [lang="zh"], [lang="ko"] { font-family: var(--font-cjk); }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.view { flex: 1; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
body.in-session .tabbar, body.in-session .topbar { display: none; }
body.in-session .view { padding-bottom: 24px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 6px;
}
.brand { display: flex; align-items: center; gap: 8px; font: 700 20px var(--font-head); }
.brand img { border-radius: 9px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.streak {
  font: 600 14px var(--font-head); padding: 6px 12px; border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow);
}
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 12px;
  color: var(--muted); transition: background .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }

/* ---------- search ---------- */
.search-wrap { position: sticky; top: 0; z-index: 5; padding: 8px 0 12px; background: linear-gradient(var(--bg) 75%, transparent); }
.searchbar {
  display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 14px;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.searchbar:focus-within { border-color: var(--brand); }
.searchbar > .ic { color: var(--muted); }
.searchbar input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: 500 18px var(--font); padding: 8px 2px;
}
.searchbar input::placeholder { color: var(--muted); font-weight: 400; }
.searchbar input::-webkit-search-cancel-button { display: none; }
.mic.listening { color: var(--bad); background: var(--bad-soft); animation: pulse 1.2s infinite; }
.mic-lang { width: 34px; height: 34px; border-radius: 10px; font-size: 18px; background: var(--surface-2); flex: none; }
.mic-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; animation: rise .18s ease both; }
.mic-picker[hidden] { display: none; }
.mic-picker .chip { padding: 5px 11px; font-size: 13px; }

@keyframes pulse { 50% { transform: scale(1.08); } }

.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 2px 10px; font: 600 16px var(--font-head); }
.section-title small { font: 400 13px var(--font); color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; }

/* ---------- phrase card ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 14px 8px; margin-bottom: 12px; animation: rise .22s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-head .th { font: 600 20px var(--font-head); padding-top: 4px; }
.card-head .cat { display: block; font: 400 12px var(--font); color: var(--muted); margin-top: 2px; }
.star.on { color: #F5B301; }
.star.on .ic { fill: currentColor; }

.row {
  --c: var(--brand); --c-soft: var(--brand-soft);
  display: flex; align-items: center; gap: 10px; padding: 8px 4px 8px 0;
  border-top: 1px solid var(--border); cursor: pointer;
}
.row:first-child { border-top: 0; }
.badge {
  flex: none; width: 34px; text-align: center; padding: 3px 0; border-radius: 8px;
  font: 700 11px var(--font-head); letter-spacing: .04em; color: var(--c); background: var(--c-soft);
}
.row .txt { flex: 1; min-width: 0; }
.row .native { font-size: 18px; font-weight: 500; line-height: 1.4; word-break: break-word; }
.row .read { font-size: 14px; color: var(--c); line-height: 1.45; }
.row .roman { color: var(--muted); }
.row .speak { color: var(--c); width: 38px; height: 38px; }
.row .speak:hover { background: var(--c-soft); color: var(--c); }

/* ---------- home ---------- */
.today {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--brand), #8A63F0); color: #fff; box-shadow: var(--shadow);
}
.today .ring { --p: 0; flex: none; width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(#fff calc(var(--p) * 1%), rgba(255, 255, 255, .25) 0); }
.today .ring span { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(40, 24, 120, .55); font: 600 14px var(--font-head); }
.today .t { flex: 1; }
.today h2 { font-size: 17px; }
.today p { margin: 2px 0 0; font-size: 13px; opacity: .9; }
.today .go { background: #fff; color: #3B2FC0; font: 600 14px var(--font-head); padding: 8px 14px; border-radius: 12px; white-space: nowrap; }

.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cat-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 6px;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); text-align: center;
  transition: transform .12s;
}
.cat-tile:active { transform: scale(.96); }
.cat-tile .e { font-size: 28px; line-height: 1; }
.cat-tile b { font: 500 14px var(--font-head); }
.cat-tile small { font-size: 12px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 13px; border-radius: 999px; background: var(--surface); border: 1.5px solid var(--border);
  font-size: 14px; transition: background .15s, border-color .15s;
}
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }

.banner {
  display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 12px 14px;
  background: var(--surface); border: 1.5px dashed var(--border); border-radius: 16px; font-size: 14px;
}
.banner .t { flex: 1; }

.empty { text-align: center; padding: 36px 12px; color: var(--muted); }
.empty .e { font-size: 44px; }
.empty h3 { color: var(--ink); margin: 6px 0 4px; }
.online-links { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 14px; font: 600 16px var(--font-head);
  background: var(--brand); color: var(--brand-ink); transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.block { width: 100%; }
.btn.sm { padding: 9px 12px; font-size: 14px; border-radius: 12px; }

.back { display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 4px -6px; padding: 6px; color: var(--muted); font-size: 15px; }
.page-title { display: flex; align-items: center; gap: 10px; margin: 4px 2px 14px; font-size: 24px; }

/* ---------- show mode ---------- */
.show {
  --c: var(--brand);
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column;
  background: var(--surface); padding: calc(12px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  animation: fade .18s ease both;
}
@keyframes fade { from { opacity: 0; } }
.show-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.show .tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.show .tabs button { padding: 6px 12px; border-radius: 999px; font: 600 13px var(--font-head); color: var(--muted); background: var(--surface-2); }
.show .tabs button.on { color: var(--on-c); background: var(--c); }
.show-body { flex: 1; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 18px; padding: 10px 4px; overflow: auto; }
.show-native { font-weight: 600; line-height: 1.25; word-break: break-word; color: var(--ink); }
.show-read { font-size: 22px; color: var(--c); }
.show-read .roman { display: block; font-size: 16px; color: var(--muted); margin-top: 4px; }
.show-th { font-size: 17px; color: var(--muted); padding-top: 14px; border-top: 1px solid var(--border); }
.show .btn { background: var(--c); color: var(--on-c); }

/* ---------- practice ---------- */
.lang-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(62px, 1fr)); gap: 8px; }
.lang-pick button {
  padding: 10px 4px; border-radius: 14px; background: var(--surface); box-shadow: var(--shadow);
  font: 500 14px var(--font-head); border: 2px solid transparent; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.lang-pick button .f { font-size: 22px; line-height: 1.1; }
.lang-pick button.on { border-color: var(--c); background: var(--c-soft); color: var(--c); }

.modes { display: grid; gap: 10px; }
.mode {
  --c: var(--brand); --c-soft: var(--brand-soft);
  display: flex; align-items: center; gap: 14px; padding: 14px; text-align: left; width: 100%;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); transition: transform .12s;
}
.mode:active { transform: scale(.98); }
.mode .e { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 26px; background: var(--c-soft); flex: none; }
.mode b { display: block; font: 600 17px var(--font-head); }
.mode small { color: var(--muted); font-size: 13px; }
.mode .ic { margin-left: auto; color: var(--muted); }

.select {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--ink); font: 500 15px var(--font); appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%; background-size: 6px 6px; background-repeat: no-repeat;
}

.session { display: flex; flex-direction: column; min-height: calc(100dvh - 24px); padding-top: calc(12px + env(safe-area-inset-top)); }
.session-top { display: flex; align-items: center; gap: 10px; }
.progress { flex: 1; height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.progress div { height: 100%; background: var(--c, var(--brand)); border-radius: 99px; transition: width .3s ease; }
.session-top .count { font: 600 14px var(--font-head); color: var(--muted); min-width: 42px; text-align: right; }

.q-card {
  margin-top: 22px; padding: 28px 18px; text-align: center; border-radius: 24px;
  background: var(--surface); box-shadow: var(--shadow); animation: rise .22s ease both;
}
.q-card .label { font-size: 13px; color: var(--muted); }
.q-card .big { font: 600 28px var(--font-head); margin: 6px 0; word-break: break-word; }
.q-card .native { font-size: 30px; font-weight: 600; margin: 4px 0; word-break: break-word; color: var(--ink); }
.q-card .read { color: var(--c); font-size: 18px; }
.q-card .roman { color: var(--muted); font-size: 14px; }
.q-card .answer { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--border); animation: rise .2s ease both; }
.play-big {
  width: 96px; height: 96px; border-radius: 50%; margin: 10px auto; display: grid; place-items: center;
  background: var(--c-soft); color: var(--c);
}
.play-big .ic { width: 44px; height: 44px; }

.answers { display: grid; gap: 10px; margin-top: 18px; }
.opt {
  padding: 14px 16px; border-radius: 16px; text-align: left; background: var(--surface);
  border: 2px solid var(--border); transition: transform .1s, border-color .15s, background .15s;
}
.opt:active { transform: scale(.98); }
.opt .native { font-size: 19px; font-weight: 500; }
.opt .read { font-size: 13px; color: var(--muted); }
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
.opt[disabled] { cursor: default; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.grade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 18px; }
.grade button { padding: 12px 4px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); font: 600 14px var(--font-head); }
.grade button span { display: block; font-size: 24px; }
.grade small { display: block; font: 400 11px var(--font); color: var(--muted); }
.session-foot { margin-top: auto; padding-top: 18px; }

.result { text-align: center; padding: 40px 8px 10px; }
.result .e { font-size: 64px; animation: pop .5s ease both; }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.15); } }
.result h2 { font-size: 26px; margin-top: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 22px 0; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px 6px; box-shadow: var(--shadow); }
.stat b { display: block; font: 700 22px var(--font-head); }
.stat small { color: var(--muted); font-size: 12px; }

/* ---------- saved ---------- */
.level { display: inline-flex; gap: 3px; vertical-align: middle; margin-left: 6px; }
.level i { width: 6px; height: 6px; border-radius: 50%; background: var(--border); }
.level i.on { background: var(--good); }

/* ---------- settings ---------- */
.setting { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 14px; margin-bottom: 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.setting-row:first-child { border-top: 0; }
.setting-row .t small { display: block; color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { padding: 6px 11px; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.switch { width: 50px; height: 30px; border-radius: 99px; background: var(--border); position: relative; transition: background .2s; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.switch.on { background: var(--brand); }
.switch.on::after { transform: translateX(20px); }
.voice-ok { color: var(--good); font-weight: 600; }
.voice-no { color: var(--muted); }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 20;
  width: min(560px, 100%); display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0; font-size: 12px; color: var(--muted); border-radius: 12px; }
.tab .pill { padding: 3px 14px; border-radius: 99px; transition: background .2s; }
.tab.on { color: var(--brand); font-weight: 600; }
.tab.on .pill { background: var(--brand-soft); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 14px; transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- match game ---------- */
.match-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.match-grid .col { display: grid; gap: 10px; align-content: start; }
.tile {
  min-height: 64px; padding: 10px 8px; border-radius: 16px; background: var(--surface);
  border: 2px solid var(--border); box-shadow: var(--shadow); font-size: 16px; line-height: 1.35;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; word-break: break-word;
  transition: transform .12s, border-color .15s, background .15s, opacity .3s;
}
.tile:active { transform: scale(.96); }
.tile small { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.sel { border-color: var(--c); background: var(--c-soft); }
.tile.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake .35s; }
.tile.done { border-color: var(--good); background: var(--good-soft); opacity: .45; box-shadow: none; cursor: default; }

/* ---------- speak practice ---------- */
.speak-zone { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 22px; }
.mic-big {
  width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center;
  background: var(--c); color: var(--on-c); box-shadow: 0 6px 20px color-mix(in srgb, var(--c) 35%, transparent);
  transition: transform .12s;
}
.mic-big .ic { width: 38px; height: 38px; }
.mic-big:active { transform: scale(.94); }
.mic-big.listening { animation: ring 1.2s infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--c) 45%, transparent); } 100% { box-shadow: 0 0 0 22px transparent; } }
.feedback { width: 100%; margin-top: 8px; padding: 12px 14px; border-radius: 16px; text-align: center; animation: rise .2s ease both; }
.feedback b { display: block; font: 600 16px var(--font-head); }
.feedback small { color: var(--muted); }
.feedback.good { background: var(--good-soft); color: var(--good); }
.feedback.near { background: var(--warn-soft); color: var(--warn); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.meter { height: 8px; border-radius: 99px; background: rgba(127, 127, 127, .18); margin: 8px 0 6px; overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 99px; background: currentColor; }

/* ---------- money ---------- */
.cur-pick { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px; margin: 0 -2px; scrollbar-width: none; }
.cur-pick::-webkit-scrollbar { display: none; }
.cur-pick .chip { white-space: nowrap; flex: none; }
.conv { position: relative; margin-top: 10px; background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); }
.conv-row { display: flex; align-items: center; gap: 12px; padding: 18px; }
.conv-row + .swap + .conv-row { border-top: 1px solid var(--border); }
.conv-cur { flex: none; font: 600 16px var(--font-head); padding: 6px 10px; border-radius: 12px; background: var(--surface-2); }
.conv-row input, .conv-row output {
  flex: 1; min-width: 0; text-align: right; border: 0; outline: 0; background: transparent; color: var(--ink);
  font: 600 32px var(--font-head);
}
.conv-row.out output { color: var(--brand); }
.swap {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 1;
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); box-shadow: var(--shadow);
}
.swap:active { transform: translate(-50%, -50%) scale(.92); }
.rate-table b { font-family: var(--font-head); }
.rate-info { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 16px 0 6px; }
.rate-info small { display: block; color: var(--muted); font-size: 13px; }
.rate-info .ic { width: 18px; height: 18px; }

/* ---------- roleplay ---------- */
.dlg-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dlg {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px; text-align: left;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); transition: transform .12s;
}
.dlg:active { transform: scale(.97); }
.dlg .e { font-size: 26px; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--c-soft); margin-bottom: 6px; }
.dlg b { font: 600 15px var(--font-head); }
.dlg small { color: var(--muted); font-size: 12px; }
.talk-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 2px 4px; font: 600 15px var(--font-head); }
.talk-head .chip { font: 500 12px var(--font); padding: 5px 10px; }
.chat { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.bubble { display: flex; align-items: flex-end; gap: 8px; max-width: 88%; animation: rise .22s ease both; }
.bubble.me { align-self: flex-end; }
.bubble .avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); font-size: 18px; }
.bubble-body {
  display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 14px; border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 6px;
}
.bubble.me .bubble-body { background: var(--c); color: var(--on-c); border-bottom-left-radius: 18px; border-bottom-right-radius: 6px; }
.bubble-body .native { font-size: 17px; font-weight: 500; }
.bubble-body .read { font-size: 13px; color: var(--c); }
.bubble.me .bubble-body .read, .bubble.me .bubble-body .th { color: inherit; opacity: .85; }
.bubble-body .th { font-size: 12px; color: var(--muted); }
.turn {
  margin-top: 16px; padding: 18px 16px; text-align: center; border-radius: 22px; background: var(--surface);
  box-shadow: var(--shadow); border: 2px dashed var(--c); animation: rise .22s ease both;
}
.turn .label { font-size: 13px; color: var(--muted); }
.turn .big { font: 600 22px var(--font-head); margin: 4px 0 8px; }
.turn .native { font-size: 22px; font-weight: 600; }
.turn .read { color: var(--c); }
.turn .roman { color: var(--muted); font-size: 13px; }
.talk-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

/* ระดับความยาก */
.level-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.level-pick button {
  padding: 10px 6px; border-radius: 14px; border: 1.5px solid var(--border); background: var(--surface);
  font: 600 15px var(--font-head); color: var(--muted);
}
.level-pick button.on { border-color: var(--c); background: var(--c-soft); color: var(--c); }
.level-desc { margin: 8px 2px 0; font-size: 13px; }
.lv-badge { font: 600 12px var(--font-head); padding: 3px 9px; border-radius: 99px; background: var(--c-soft); color: var(--c); }
.answers.many { grid-template-columns: 1fr 1fr; }
.answers.many .opt .native { font-size: 17px; }
.opt.sel { border-color: var(--c); background: var(--c-soft); }
.opt-audio { display: flex; align-items: center; gap: 12px; }
.opt-audio > .ic { color: var(--c); flex: none; }
.opt-audio .num { font: 700 15px var(--font-head); width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.play-big[disabled] { opacity: .4; }
.btn[disabled] { opacity: .5; }

/* ฝึกอ่าน */
.rd-entry { text-decoration: none; color: inherit; }
.rd-lessons { display: grid; gap: 8px; }
.rd-lesson {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--shadow); text-align: left; width: 100%;
}
.rd-lesson .n { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--c-soft); color: var(--c); font: 700 14px var(--font-head); }
.rd-lesson .t { flex: 1; min-width: 0; }
.rd-lesson b { display: block; font: 600 15px var(--font-head); }
.rd-lesson small { color: var(--muted); font-size: 14px; }
.rd-lesson .pct { font: 600 13px var(--font-head); color: var(--c); }
.rd-lesson .ic { color: var(--muted); }
.rd-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.rd-card {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px 8px; border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow);
}
.rd-card b { font-size: 40px; line-height: 1.2; font-weight: 600; }
.rd-card .th { color: var(--c); font: 600 18px var(--font-head); }
.rd-card small { color: var(--muted); font-size: 13px; text-align: center; }
.rd-card .ex { color: var(--ink); }
.rd-card .note { font-size: 12px; }
.rd-card:active, .rd-tile:active { transform: scale(.97); }
.rd-chart { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 6px; }
.rd-chart.five { grid-template-columns: repeat(5, 1fr); }
.rd-tile { display: flex; flex-direction: column; align-items: center; padding: 8px 2px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.rd-tile b { font-size: 22px; font-weight: 600; }
.rd-tile b.sm { font-size: 15px; line-height: 29px; }
.rd-tile b.xs { font-size: 12px; line-height: 29px; }
.rd-tile .th { color: var(--c); font-size: 13px; }
.rd-tile small { color: var(--muted); font-size: 11px; }
.rd-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.rd-chips button { min-width: 42px; padding: 8px 10px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); font-size: 18px; }
.rd-chips button.on { border-color: var(--c); background: var(--c-soft); color: var(--c); }
.rd-built .native { font-size: 64px; }
.q-card .rd-big { font-size: 56px; }
.rd-opt-c { font-size: 30px !important; text-align: center; }
.mode[disabled] { opacity: .5; }
.rd-card b.l { font-size: 26px; }
.rd-card b.xl { font-size: 20px; }
.q-card .rd-big.long { font-size: 34px; }

/* การ์ดระดับของฉัน */
.lv-card { margin-top: 14px; padding: 14px 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); display: grid; gap: 8px; }
.lv-head { display: flex; align-items: center; gap: 12px; }
.lv-head b { display: block; font: 600 15px var(--font-head); }
.lv-head small { color: var(--muted); font-size: 13px; }
.lv-badge { flex: none; min-width: 54px; padding: 8px 10px; border-radius: 14px; text-align: center; background: var(--c-soft); color: var(--c); font: 700 16px var(--font-head); }
.lv-card .progress { flex: none; }
.lv-row { display: flex; justify-content: space-between; font-size: 14px; }
.lv-row b { color: var(--c); }
.lv-card .hint { margin: 2px 0 0; font-size: 12px; }

/* ไวยากรณ์ */
.gm-level { display: inline-block; padding: 2px 8px; border-radius: 8px; background: var(--c-soft); color: var(--c); font: 700 12px var(--font-head); margin-right: 4px; }
.gm-explain { margin: 12px 0 0; padding: 14px 16px 14px 34px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); display: grid; gap: 8px; font-size: 15px; line-height: 1.5; }
.gm-exs { display: grid; gap: 8px; }
.gm-ex { display: grid; gap: 2px; text-align: left; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.gm-ex .native { font-size: 20px; font-weight: 600; }
.gm-ex .native i { display: inline-block; width: 4px; }
.gm-ex .read { color: var(--c); font-size: 14px; }
.gm-ex small { color: var(--muted); font-size: 13px; }
.gm-ex:active { transform: scale(.98); }
.gm-sentence { font-size: 26px; }
.gm-blank { display: inline-block; min-width: 48px; border-bottom: 3px solid var(--c); color: var(--c); margin: 0 4px; }
.gm-filled { color: var(--c); margin: 0 2px; }
.gm-line { min-height: 58px; margin-top: 18px; padding: 8px; border-radius: 16px; border: 2px dashed var(--border); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.gm-line.ok { border-style: solid; border-color: var(--good); background: var(--good-soft); }
.gm-line.bad { border-style: solid; border-color: var(--bad); background: var(--bad-soft); }
.gm-line button, .gm-pool button { min-width: 42px; padding: 8px 12px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface); font-size: 18px; }
.gm-line button { border-color: var(--c); color: var(--c); }
.gm-pool { margin-top: 14px; justify-content: center; }
