:root {
  --bg: #f4f6fb; --card: #ffffff; --text: #18202e; --muted: #5d6779; --line: #e1e6ef;
  --brand: #1f5fbf; --brand-2: #e8f0fc; --accent: #0d9b6c; --accent-2: #e3f6ef;
  --bad: #d64545; --bad-2: #fdecec; --warn: #b7791f; --warn-2: #fdf4e3;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 14px rgba(20,30,50,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --card: #18202b; --text: #e8ecf3; --muted: #9aa5b6; --line: #273142;
    --brand: #6ea4ff; --brand-2: #1c2b45; --accent: #3fcf9b; --accent-2: #15302a;
    --bad: #ff7b7b; --bad-2: #3a1d20; --warn: #f0b552; --warn-2: #3a2e17;
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", "Sarabun", sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.5rem; margin: .4rem 0 .6rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 1.6rem 0 .6rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .4rem; }
small { display: block; color: var(--muted); font-size: .82rem; }
.muted { color: var(--muted); } .small { font-size: .9rem; } .center { text-align: center; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .hidden { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
main { max-width: 720px; margin: 0 auto; padding: 12px 16px 24px; }

.nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { flex: 1; text-align: center; padding: 7px 0 8px; font-size: .72rem; color: var(--muted); }
.nav a span { display: block; font-size: 1.3rem; line-height: 1.3; filter: grayscale(1); opacity: .7; }
.nav a.on { color: var(--brand); font-weight: 600; }
.nav a.on span { filter: none; opacity: 1; }
body.focus .nav, body.focus .top { display: none; }
body.focus { padding-bottom: 0; }

/* hero */
.hero { display: flex; gap: 10px; margin: 4px 0 12px; }
.hero-main { flex: 2; display: flex; align-items: center; gap: 12px; background: linear-gradient(135deg, #1f5fbf, #3b82f6); color: #fff; border-radius: var(--radius); padding: 16px; }
.hero-main .big { font-size: 2.8rem; font-weight: 800; line-height: 1; }
.hero-main .sub, .hero-side .sub { color: inherit; opacity: .8; font-size: .8rem; }
.hero-side { flex: 1; background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); font-size: .85rem; display: flex; flex-direction: column; justify-content: center; }
.hero-side b { font-size: 1.6rem; display: block; line-height: 1.1; }
.banner { display: block; background: var(--warn-2); color: var(--text); border-radius: 12px; padding: 10px 14px; margin: 8px 0; font-size: .92rem; border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }
.banner.warn { background: var(--brand-2); border-color: color-mix(in srgb, var(--brand) 30%, transparent); }

/* lists */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list.left { text-align: left; margin: 12px 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); color: var(--text); cursor: pointer; min-height: 56px; }
.row:last-child { border-bottom: 0; }
.row:active { background: var(--brand-2); }
.row .grow { flex: 1; min-width: 0; }
.row .ic { font-size: 1.35rem; width: 30px; text-align: center; flex-shrink: 0; color: var(--muted); font-weight: 700; }
.row .chev { color: var(--muted); font-size: 1.4rem; }
.row .done { color: var(--accent); font-weight: 700; font-size: 1.1rem; }
.row .ptxt { font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row.vocab { align-items: flex-start; cursor: default; }
.bar { width: 60px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar i.mid { background: var(--warn); } .bar i.lo { background: var(--bad); }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 6px 0 4px; }
.progress.sm { height: 5px; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.stats div { background: var(--card); border-radius: 12px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); }
.stats b { font-size: 1.2rem; display: block; }
.stats small { font-size: .7rem; }

.plan .pw { background: var(--card); border-radius: 12px; margin-bottom: 8px; box-shadow: var(--shadow); border-left: 4px solid var(--line); }
.plan .pw.now { border-left-color: var(--brand); }
.plan .pw.past { opacity: .6; }
.plan summary { padding: 12px 14px; display: flex; justify-content: space-between; gap: 8px; cursor: pointer; font-weight: 600; list-style: none; }
.plan summary::-webkit-details-marker { display: none; }
.plan summary small { white-space: nowrap; }
.plan ul { margin: 0; padding: 0 16px 12px 34px; font-size: .92rem; }
.foot { color: var(--muted); font-size: .8rem; margin-top: 24px; text-align: center; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; background: var(--brand); color: #fff; font: inherit; font-weight: 600; padding: 12px 18px; border-radius: 12px; cursor: pointer; min-height: 46px; text-align: center; }
.btn:active { transform: scale(.98); }
.btn.alt { background: var(--accent); }
.btn.ghost { background: var(--card); color: var(--brand); border: 1px solid var(--line); }
.btn.sm { padding: 8px 12px; min-height: 38px; font-size: .9rem; }
.btn.block { display: flex; width: 100%; margin: 8px 0; }
.btn:disabled { opacity: .4; }
.btn.flagged { color: var(--warn); border-color: var(--warn); }
.icon-btn { border: 0; background: transparent; font-size: 1.2rem; padding: 6px 8px; cursor: pointer; color: var(--text); }
.actions { display: flex; flex-direction: column; gap: 8px; margin: 20px 0; }
.back { display: inline-block; margin: 2px 0 8px; font-weight: 600; }

/* lesson */
.lesson { background: var(--card); border-radius: var(--radius); padding: 4px 16px 14px; box-shadow: var(--shadow); }
.lesson table { width: 100%; border-collapse: collapse; font-size: .88rem; margin: 10px 0; display: block; overflow-x: auto; }
.lesson th, .lesson td { border: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
.lesson th { background: var(--brand-2); }
.lesson ul, .lesson ol { padding-left: 22px; }
.lesson li { margin: 4px 0; }
.ex { background: var(--accent-2); border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: .95rem; }
.tip { background: var(--brand-2); border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: .93rem; }
.th { background: var(--warn-2); border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: .93rem; }
s { color: var(--bad); }

/* questions */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin: 10px 0; }
.qlabel { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.qtext { font-size: 1.08rem; margin: 8px 0 12px; line-height: 1.6; }
.blank { display: inline-block; border-bottom: 2px solid var(--brand); min-width: 60px; color: transparent; line-height: 1.1; }
.seg { text-decoration: none; border-bottom: 2px solid var(--brand); padding-bottom: 1px; }
.seg sub { font-size: .65rem; font-weight: 700; color: var(--brand); margin-left: 1px; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opt { display: flex; align-items: center; gap: 12px; text-align: left; background: var(--card); color: var(--text); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; font: inherit; cursor: pointer; min-height: 50px; }
.opt .ol { width: 28px; height: 28px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex-shrink: 0; }
.opt.chosen { border-color: var(--brand); background: var(--brand-2); }
.opt.chosen .ol { background: var(--brand); color: #fff; }
.opt.correct { border-color: var(--accent); background: var(--accent-2); }
.opt.correct .ol { background: var(--accent); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-2); }
.opt.wrong .ol { background: var(--bad); color: #fff; }
.opt:disabled { opacity: 1; cursor: default; }
.explain { margin-top: 12px; border-radius: 10px; padding: 10px 12px; font-size: .95rem; }
.explain.ok { background: var(--accent-2); } .explain.bad { background: var(--bad-2); }
.passage { background: var(--bg); border-radius: 10px; margin: 8px 0 4px; border: 1px solid var(--line); }
.passage summary { padding: 10px 12px; font-weight: 600; cursor: pointer; }
.ptext { padding: 0 12px 6px; max-height: 48vh; overflow-y: auto; font-size: .95rem; }
.cprog { display: flex; align-items: center; gap: 10px; font-size: .85rem; color: var(--muted); }
.cprog .progress { flex: 1; }
.review.ok { border-left: 4px solid var(--accent); } .review.bad { border-left: 4px solid var(--bad); }

/* mock */
.mockbar { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 8px; background: var(--card); margin: -12px -16px 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.msec { flex: 1; font-weight: 600; font-size: .9rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.1rem; background: var(--brand-2); color: var(--brand); padding: 4px 10px; border-radius: 8px; }
.timer.low { background: var(--bad-2); color: var(--bad); }
.mocknav { display: grid; grid-template-columns: 1fr 1fr 1fr 1.3fr; gap: 6px; position: sticky; bottom: 0; z-index: 4; background: var(--bg); border-top: 1px solid var(--line); margin: 0 -16px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
.mocknav .btn { padding: 10px 4px; font-size: .9rem; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; max-height: 85vh; overflow-y: auto; border-radius: 18px 18px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; }
.sheet-h { display: flex; justify-content: space-between; align-items: center; }
.gsec { font-size: .8rem; font-weight: 700; color: var(--muted); margin: 12px 0 6px; }
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.qgrid button { height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; position: relative; }
.qgrid button.ans { background: var(--brand-2); border-color: var(--brand); }
.qgrid button.flag::after { content: '🚩'; position: absolute; top: -6px; right: -4px; font-size: .7rem; }
.qgrid button.cur { outline: 2px solid var(--accent); outline-offset: 1px; }
.score { display: flex; gap: 16px; align-items: center; margin: 10px 0 14px; }
.score p { margin: 6px 0 0; font-size: .93rem; }
.ring { --p: 0; width: 96px; height: 96px; flex-shrink: 0; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); }
.ring span { background: var(--bg); width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.3rem; }
.tabs { display: flex; gap: 6px; margin: 8px 0; }
.tabs a { padding: 7px 14px; border-radius: 20px; background: var(--card); border: 1px solid var(--line); font-size: .9rem; color: var(--text); }
.tabs a.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* flashcards */
.deck-grid { display: grid; gap: 10px; margin: 14px 0; }
@media (min-width: 600px) { .deck-grid { grid-template-columns: 1fr 1fr; } }
.deck { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.deck-h { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.deck-h .ic { font-size: 1.6rem; }
.deck-b { display: flex; gap: 6px; margin-top: 10px; }
.deck-b .btn { flex: 1; }
.toggle { display: flex; gap: 10px; align-items: center; font-size: .92rem; margin: 10px 2px; color: var(--muted); }
.toggle input { width: 20px; height: 20px; }
.flash { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); min-height: 300px; margin: 12px 0; padding: 24px 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; cursor: pointer; border: 1.5px solid var(--line); user-select: none; }
.flash.flipped { border-color: var(--brand); }
.cw { font-size: 1.9rem; font-weight: 700; line-height: 1.3; }
.cw.sm { font-size: 1.3rem; color: var(--brand); }
.cw.th, .th.big { font-size: 1.5rem; font-weight: 600; background: none; padding: 0; margin: 6px 0; }
.cdef { color: var(--muted); margin: 6px 0; }
.cex { font-style: italic; margin-top: 8px; font-size: .95rem; }
.hint { margin-top: 26px; font-size: .8rem; color: var(--muted); }
.row-btns { display: flex; justify-content: center; gap: 8px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.grades button { border: 0; border-radius: 12px; padding: 12px 4px; font: inherit; font-weight: 700; color: #fff; cursor: pointer; }
.grades button small { color: rgba(255,255,255,.85); font-weight: 400; font-size: .72rem; }
.g0 { background: #d64545; } .g1 { background: #c98a1c; } .g2 { background: #1f5fbf; } .g3 { background: #0d9b6c; }
.center-card { text-align: center; background: var(--card); border-radius: var(--radius); padding: 24px 16px; box-shadow: var(--shadow); margin: 12px 0; }
.big-msg { font-size: 1.6rem; font-weight: 800; margin: 6px 0; }
.center-card .btn { margin: 6px 4px; }

/* essay & interview */
.prompt p { margin: 6px 0; font-size: 1.02rem; }
.essaybar { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
textarea#essay { width: 100%; min-height: 50vh; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--text); padding: 12px; font: inherit; font-size: 1rem; line-height: 1.6; resize: vertical; }
textarea#essay:focus { outline: none; border-color: var(--brand); }
.help { background: var(--card); border-radius: 12px; margin: 10px 0; padding: 0 14px; border: 1px solid var(--line); }
.help summary { padding: 12px 0; font-weight: 600; cursor: pointer; }
.help ul { padding-left: 20px; margin-top: 0; }
.checks { list-style: none; padding: 0; }
.checks li { padding: 6px 10px; border-radius: 8px; margin: 4px 0; font-size: .93rem; }
.checks li.y { background: var(--accent-2); } .checks li.n { background: var(--warn-2); }
.rubric label { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .93rem; }
.rubric input { width: 20px; height: 20px; flex-shrink: 0; margin-top: 2px; }
.model p { margin: 0 0 12px; }
.iq { border-bottom: 1px solid var(--line); padding: 0 14px; }
.iq:last-child { border-bottom: 0; }
.iq summary { padding: 14px 0; font-weight: 600; cursor: pointer; }
.iq .tip { margin-top: 0; }
.sample { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: .95rem; }
.sample p { margin: 4px 0 10px; }
.iqtext { font-size: 1.3rem !important; font-weight: 700; }
.recbox { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; }
.recbox audio { width: 100%; }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #18202e; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; font-size: .92rem; max-width: 90vw; text-align: center; }
