/* ---------- 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; }
.section-title.cat-group { margin-top: 20px; justify-content: flex-start; gap: 8px; }
.section-title.cat-group:first-of-type { margin-top: 6px; }
.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, .answer .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; }

/* ---------- sky: พลังดาวและดาวสะสม ---------- */
/* ท้องฟ้ากลางคืนใช้สีเดิมทั้งธีมสว่างและมืด */
.night {
  position: relative; isolation: isolate; color: #EEF0FF;
  background:
    radial-gradient(90% 60% at 85% 0%, rgba(124, 92, 255, .38), transparent 70%),
    radial-gradient(70% 50% at 5% 100%, rgba(40, 160, 200, .22), transparent 70%),
    linear-gradient(#11133B, #090A1F);
}
.night::before {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; opacity: .85;
  background-image:
    radial-gradient(1.3px 1.3px at 12% 18%, #fff 60%, transparent 62%),
    radial-gradient(1px 1px at 34% 62%, #fff 60%, transparent 62%),
    radial-gradient(1.6px 1.6px at 58% 12%, #CFE0FF 60%, transparent 62%),
    radial-gradient(1px 1px at 76% 44%, #fff 60%, transparent 62%),
    radial-gradient(1.2px 1.2px at 90% 82%, #FFE9C9 60%, transparent 62%),
    radial-gradient(1px 1px at 22% 88%, #fff 60%, transparent 62%),
    radial-gradient(.9px .9px at 48% 36%, #fff 60%, transparent 62%),
    radial-gradient(.9px .9px at 66% 74%, #D9CCFF 60%, transparent 62%),
    radial-gradient(.8px .8px at 5% 50%, #fff 60%, transparent 62%),
    radial-gradient(.8px .8px at 84% 20%, #fff 60%, transparent 62%);
  /* กระเบื้องดาวสองขนาดซ้อนกัน ลายจึงไม่ซ้ำเป็นตารางบนจอกว้าง */
  background-size: 230px 230px, 230px 230px, 230px 230px, 230px 230px, 230px 230px, 317px 317px, 317px 317px, 317px 317px, 317px 317px, 317px 317px;
}

.sky-chip { position: relative; }
.sky-chip.ready { box-shadow: 0 0 0 1.5px #A996FF, 0 0 12px rgba(150, 130, 255, .6); }
.sky-chip.ready::after { content: ''; position: absolute; top: -2px; right: -2px; width: 9px; height: 9px; border-radius: 50%; background: #FF6B9A; }

.egg {
  --s: 170px; position: relative; display: block; flex: none; width: var(--s); height: var(--s); border-radius: 50%;
  background: radial-gradient(circle, #fff 0 5%, #D6DBFF 13%, rgba(150, 125, 255, .6) 36%, rgba(70, 45, 170, .18) 60%, transparent 70%);
  filter: drop-shadow(0 0 26px rgba(150, 130, 255, .85));
  animation: egg-pulse 2.4s ease-in-out infinite;
}
.egg i { position: absolute; inset: 8%; border-radius: 50%; border: 2px solid transparent; border-top-color: rgba(255, 255, 255, .75); border-right-color: rgba(160, 200, 255, .35); animation: sky-spin 3s linear infinite; }
.egg i:nth-child(2) { inset: 21%; animation-duration: 2s; animation-direction: reverse; border-top-color: rgba(255, 170, 230, .8); }
.egg i:nth-child(3) { inset: 33%; animation-duration: 1.3s; border-top-color: rgba(120, 240, 220, .85); }
.egg.sm { --s: 46px; filter: drop-shadow(0 0 8px rgba(150, 130, 255, .85)); }
.egg.sm i { border-width: 1.5px; }
.egg.dim { animation: none; opacity: .75; }
@keyframes egg-pulse { 50% { transform: scale(1.07); filter: drop-shadow(0 0 40px rgba(175, 155, 255, 1)); } }
@keyframes sky-spin { to { transform: rotate(360deg); } }

.sky-strip {
  display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 10px; padding: 12px 14px;
  border-radius: var(--radius); overflow: hidden; text-align: left; box-shadow: var(--shadow);
}
.sky-strip .t { flex: 1; min-width: 0; display: block; }
.sky-strip b { display: block; font: 600 15px var(--font-head); }
.sky-strip small, .sky-energy small { display: block; font-size: 12px; color: #B9BEE8; }
.sky-strip .n { font: 600 13px var(--font-head); padding: 5px 10px; border-radius: 999px; background: rgba(255, 255, 255, .1); white-space: nowrap; }
.sky-strip .go { background: #fff; color: #3B2FC0; font: 600 14px var(--font-head); padding: 8px 14px; border-radius: 12px; }
.sky-strip.ready { border: 1px solid rgba(190, 170, 255, .7); animation: sky-ready 1.6s ease-in-out infinite alternate; }
.sky .sky-strip.ready { background: rgba(255, 255, 255, .07); margin: 0 0 12px; }
@keyframes sky-ready { from { box-shadow: 0 0 6px rgba(150, 130, 255, .3); } to { box-shadow: 0 0 22px rgba(170, 150, 255, .8); } }
.night .bar { display: block; height: 6px; margin: 6px 0 4px; border-radius: 9px; background: rgba(255, 255, 255, .14); }
.night .bar i { display: block; height: 100%; min-width: 6px; border-radius: inherit; background: linear-gradient(90deg, #7FD8FF, #B78BFF, #FF8AD0); box-shadow: 0 0 8px #B78BFF; }

.btn.sky-btn { background: linear-gradient(135deg, #8B7BFF, #C77DFF); color: #fff; box-shadow: 0 0 20px rgba(160, 130, 255, .55); }
.btn.sky-btn2 { background: rgba(255, 255, 255, .1); color: #fff; }

/* หน้าท้องฟ้าของฉัน */
.sky { margin: 6px -6px 0; padding: 20px 14px 22px; border-radius: 24px; overflow: hidden; }
.sky-head { text-align: center; margin-bottom: 14px; }
.sky-head h1 { font: 700 24px var(--font-head); margin: 0; }
.sky-head p { margin: 2px 0 0; font-size: 14px; color: #B9BEE8; }
.sky-head p b { color: #fff; }
.sky-energy { padding: 12px 14px; border-radius: 16px; background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .09); }
.sky-energy .row { display: flex; justify-content: space-between; font: 600 14px var(--font-head); }
.sky-energy .btn { margin-top: 10px; }
.sky-rar { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 2px 8px; color: var(--rc); font: 600 14px var(--font-head); }
.sky-rar small { color: #B9BEE8; font-weight: 500; }
.sky-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sky-tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px;
  border-radius: 14px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .08); color: inherit;
}
button.sky-tile:active { transform: scale(.95); }
.sky-tile .nm { font-size: 11.5px; line-height: 1.25; text-align: center; }
.sky-tile .x { position: absolute; top: 4px; right: 6px; font: 600 11px var(--font-head); color: var(--rc); }
.sky-tile.locked .star-art { filter: grayscale(1) brightness(.28); opacity: .7; }
.sky-tile.locked .nm { color: #6F75A8; }
.sky-odds { margin: 18px 0 0; font-size: 12px; line-height: 1.6; text-align: center; color: #8A90C2; }

.star-art { display: block; width: 54px; height: 54px; }
.star-art svg { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 0 5px color-mix(in srgb, var(--rc) 55%, transparent)); }
.star-art.big { width: 100%; height: 100%; }
.star-art.big svg { filter: drop-shadow(0 0 22px color-mix(in srgb, var(--rc) 65%, transparent)); }

/* หน้าดาวกำเนิด (เต็มจอ) */
body.sky-open { overflow: hidden; }
.skyfx {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto; animation: fade .25s;
}
.skyfx > * { width: 100%; max-width: 400px; }
.skyfx-x { position: absolute; z-index: 2; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 40px; color: #C9CEF5; }
.skyfx.ph-egg, .skyfx.ph-hatch { justify-content: center; gap: 30px; }
.egg-wrap { display: grid; place-items: center; width: auto; padding: 20px; border-radius: 50%; }
.skyfx-msg { margin: 0; text-align: center; font-size: 15px; color: #B9BEE8; }
.skyfx-msg b { display: block; margin-top: 2px; font: 600 20px var(--font-head); color: #fff; }
.skyfx .flash { position: absolute; inset: 0; max-width: none; opacity: 0; pointer-events: none; background: radial-gradient(circle, #fff 10%, var(--rc) 45%, transparent 75%); }
.skyfx.ph-hatch .egg { animation: egg-hatch 1.9s cubic-bezier(.5, 0, .8, .4) forwards; }
.skyfx.ph-hatch .egg i { animation-duration: .45s; }
.skyfx.ph-hatch .flash { animation: sky-flash 1.9s ease-in forwards; }
@keyframes egg-hatch {
  0% { transform: scale(1); }
  10%, 30%, 50% { transform: scale(1.08) translateX(-6px) rotate(-5deg); }
  20%, 40%, 60% { transform: scale(1.12) translateX(6px) rotate(5deg); }
  72% { transform: scale(.75); filter: drop-shadow(0 0 30px var(--rc)); }
  86% { transform: scale(.5); filter: drop-shadow(0 0 60px var(--rc)) brightness(1.5); }
  100% { transform: scale(3.4); filter: drop-shadow(0 0 80px var(--rc)) brightness(2.2); }
}
@keyframes sky-flash { 0%, 80% { opacity: 0; } 100% { opacity: 1; } }

.star-stage { position: relative; flex: none; width: min(58vw, 230px); aspect-ratio: 1; margin: 34px 0 4px; animation: sky-float 4s ease-in-out infinite; }
@keyframes sky-float { 50% { transform: translateY(-7px); } }
.burst { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.burst i { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--rc); box-shadow: 0 0 8px var(--rc); opacity: 0; }
.star-info { text-align: center; }
.star-info .rar { color: var(--rc); font: 600 14px var(--font-head); letter-spacing: .02em; }
.star-info .rar b { margin-left: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.star-info .new { background: #FF6B9A; color: #fff; }
.star-info .dup { background: rgba(255, 255, 255, .12); color: #D5D9FF; }
.star-info h2 { margin: 4px 0 2px; font: 700 28px var(--font-head); text-shadow: 0 0 18px color-mix(in srgb, var(--rc) 60%, transparent); }
.star-info .fact { margin: 0 0 14px; font-size: 14px; color: #B9BEE8; }
.star-names { display: grid; gap: 7px; text-align: left; }
.star-name { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 14px; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1); color: #fff; }
.star-name:active { background: rgba(255, 255, 255, .14); }
.star-name .tx { font-size: 18px; }
.star-name small { font-size: 13px; color: #AEB4E6; }
.star-name .ic { margin-left: auto; width: 18px; height: 18px; opacity: .7; }
.skyfx-foot { display: grid; gap: 9px; margin-top: auto; padding-top: 6px; }

@media (prefers-reduced-motion: no-preference) {
  .skyfx.ph-reveal::after { content: ''; position: absolute; inset: 0; max-width: none; background: #fff; pointer-events: none; animation: sky-fade .8s ease-out forwards; }
  .skyfx.ph-reveal .star-art.big { animation: star-pop .9s cubic-bezier(.2, 1.4, .4, 1) both; }
  .skyfx.ph-reveal .star-info { animation: sky-up .6s .35s ease-out both; }
  .skyfx.ph-reveal .skyfx-foot { animation: sky-up .6s .7s ease-out both; }
  .skyfx.ph-reveal .burst i { animation: sky-burst 1.2s var(--t) ease-out forwards; }
}
@keyframes sky-fade { from { opacity: 1; } to { opacity: 0; } }
@keyframes star-pop { from { transform: scale(.15) rotate(-30deg); opacity: 0; } }
@keyframes sky-up { from { transform: translateY(18px); opacity: 0; } }
@keyframes sky-burst { 0% { transform: rotate(var(--a)) translateY(-20px) scale(1); opacity: 1; } 100% { transform: rotate(var(--a)) translateY(calc(var(--d) * -1.7)) scale(.2); opacity: 0; } }

/* ---------- ธีมท้องฟ้ายามค่ำคืน (ทั้งแอป) ---------- */
:root[data-theme="night"] {
  --bg: #0B0D26; --surface: #171A42; --surface-2: #222659; --ink: #EEF0FF; --muted: #A6ACDD;
  --border: #2C3172; --brand: #A99BFF; --brand-soft: #2D2B70; --brand-ink: #0B0D26;
  --good: #5EEAA0; --good-soft: #12383A; --bad: #FF8A8A; --bad-soft: #43204A;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 6px 20px rgba(3, 4, 20, .45);
  --warn: #FFC56B; --warn-soft: #3D2F3A; --on-c: #0B0D26;
  color-scheme: dark;
}
/* พื้นหลังดาวตรึงกับจอ (ใช้ชั้น fixed แทน background-attachment ที่ iOS ไม่รองรับ) */
:root[data-theme="night"] body::before, :root[data-theme="night"] body::after {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
}
:root[data-theme="night"] body::before {
  background:
    radial-gradient(90% 55% at 88% 0%, rgba(124, 92, 255, .30), transparent 70%),
    radial-gradient(70% 45% at 0% 100%, rgba(40, 160, 200, .18), transparent 70%),
    linear-gradient(#11133B, #080919);
}
:root[data-theme="night"] body::after {
  opacity: .8;
  background-image:
    radial-gradient(1.3px 1.3px at 12% 18%, #fff 60%, transparent 62%),
    radial-gradient(1px 1px at 34% 62%, #fff 60%, transparent 62%),
    radial-gradient(1.6px 1.6px at 58% 12%, #CFE0FF 60%, transparent 62%),
    radial-gradient(1px 1px at 76% 44%, #fff 60%, transparent 62%),
    radial-gradient(1.2px 1.2px at 90% 82%, #FFE9C9 60%, transparent 62%),
    radial-gradient(1px 1px at 22% 88%, #fff 60%, transparent 62%),
    radial-gradient(.9px .9px at 48% 36%, #fff 60%, transparent 62%),
    radial-gradient(.9px .9px at 66% 74%, #D9CCFF 60%, transparent 62%),
    radial-gradient(.8px .8px at 5% 50%, #fff 60%, transparent 62%),
    radial-gradient(.8px .8px at 84% 20%, #fff 60%, transparent 62%);
  background-size: 230px 230px, 230px 230px, 230px 230px, 230px 230px, 230px 230px, 317px 317px, 317px 317px, 317px 317px, 317px 317px, 317px 317px;
}
@media (prefers-reduced-motion: no-preference) {
  :root[data-theme="night"] body::after { animation: night-twinkle 5s ease-in-out infinite alternate; }
}
@keyframes night-twinkle { from { opacity: .45; } to { opacity: .95; } }
:root[data-theme="night"] .today { background: linear-gradient(135deg, #5B4FE0, #9A5BE8); }
.setting-row { flex-wrap: wrap; }

/* ---------- ดาวพิเศษ · แชร์รูป ---------- */
.sky-tile.locked .nm.how { font-size: 10.5px; color: #9AA0D2; }
body.share-open { overflow: hidden; }
.sharefx {
  position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: calc(56px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom)); animation: fade .2s;
}
.sharefx img { flex: 0 1 auto; min-height: 0; max-width: min(100%, 400px); max-height: 100%; object-fit: contain; border-radius: 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }
.sharefx .skyfx-foot { flex: none; width: 100%; max-width: 400px; margin-top: 0; }

/* ---------- สอบวัดระดับ ---------- */
a.lv-exam { margin-top: 2px; padding-top: 8px; border-top: 1px dashed var(--border); }
.ex-lv { margin-top: 12px; padding: 14px 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); display: grid; gap: 10px; }
.ex-lv.passed { border-color: var(--c); }
.ex-lv-head { display: flex; align-items: center; gap: 12px; }
.ex-lv-head b { display: block; font: 700 19px var(--font-head); }
.ex-lv-head small { color: var(--muted); font-size: 13px; }
.ex-lv .lv-badge { min-width: 46px; border-radius: 14px; padding: 8px; font-size: 20px; text-align: center; }
.ex-lv .hint { margin: 0; font-size: 13px; }
.ex-cert { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--c-soft); font-size: 13px; }
.ex-time { font: 600 14px var(--font-head); padding: 3px 9px; border-radius: 99px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.ex-time.low { background: var(--bad-soft); color: var(--bad); }
.ex-quit { display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 10px 12px; border-radius: 14px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.ex-quit span { flex: 1; }
.ex-foot { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.ex-foot .btn[disabled] { opacity: .45; }
.ex-score { margin: 4px 0 14px; padding: 16px; border-radius: 20px; text-align: center; background: var(--good-soft); color: var(--good); }
.ex-score.bad { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.ex-score b { display: block; font: 700 46px/1.1 var(--font-head); }
.ex-score b small { font-size: 22px; opacity: .7; }
.ex-score span { font-size: 14px; }
.ex-parts { display: grid; gap: 10px; }
.ex-part { padding: 12px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); }
.ex-part.bad { border-color: var(--bad); }
.ex-part .ex-row { display: flex; justify-content: space-between; gap: 10px; font: 600 14px var(--font-head); }
.ex-part .ex-row b { color: var(--c); white-space: nowrap; }
.ex-part.bad .ex-row b { color: var(--bad); }
.ex-part .progress { position: relative; margin: 8px 0 6px; overflow: visible; }
.ex-part .progress i { position: absolute; top: -3px; bottom: -3px; width: 2px; border-radius: 2px; background: var(--ink); }
.ex-part small { color: var(--muted); font-size: 12.5px; }
.ex-note { display: grid; gap: 3px; margin-top: 12px; padding: 12px 14px; border-radius: 16px; font-size: 14px; }
.ex-note b { font-family: var(--font-head); }
.ex-note.ok { background: var(--good-soft); }
.ex-note.bad { background: var(--bad-soft); }
.ex-review { display: grid; gap: 8px; margin-top: 14px; }
.ex-rv { padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); font-size: 14px; }
.ex-rv small { color: var(--muted); font-size: 12px; }
.ex-rv .ask { margin: 2px 0 4px; font-size: 16px; font-weight: 600; word-break: break-word; font-family: var(--font), var(--font-cjk); }
.ex-rv .no { color: var(--bad); }
.ex-rv .yes { color: var(--good); }
