:root {
  --bg: #FDF4E4;
  --surface: #FFFFFF;
  --surface-2: #F7EBD3;
  --ink: #163442;
  --muted: #5B6B73;
  --line: #E7D9BE;
  --accent: #F06C54;
  --accent-ink: #FFFFFF;
  --teal: #2EA096;
  --en: #182440;
  --hl: #E85D04;
  --vi: #28609F;
  --ok: #2E8B57;
  --bad: #C0392B;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 52, 66, .08), 0 4px 16px rgba(22, 52, 66, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1E26;
    --surface: #16303C;
    --surface-2: #1C3A48;
    --ink: #F3EADB;
    --muted: #A7B6BD;
    --line: #28495A;
    --accent: #F58470;
    --accent-ink: #10202A;
    --teal: #4CC2B6;
    --en: #F6F1E7;
    --hl: #FF9A4D;
    --vi: #8CC2FF;
    --ok: #5BD08F;
    --bad: #FF7B6B;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* ---------- khung ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--ink); color: var(--bg);
}
@media (prefers-color-scheme: dark) { .topbar { background: #0A161C; color: var(--ink); } }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand img { flex: none; }
.brand img { border-radius: 8px; }
.topnav { display: flex; gap: 2px; flex: none; }
.topnav a {
  text-decoration: none; padding: 6px 10px; border-radius: 999px; font-size: .9rem; white-space: nowrap;
}
.topnav a:hover, .topnav a.active { background: rgba(255, 255, 255, .14); }

main {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
  outline: none;
}
h1 { font-size: 1.5rem; line-height: 1.25; margin: 8px 0 4px; }
h2 { font-size: 1.15rem; margin: 24px 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); cursor: pointer; text-decoration: none;
  font-weight: 600; -webkit-tap-highlight-color: transparent;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.teal { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn.ghost { background: transparent; }
.btn.icon { min-width: 44px; padding: 8px; }
.btn.big { min-height: 52px; font-size: 1.05rem; padding: 10px 22px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.spread { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }

/* ---------- thẻ tập ---------- */
.hero {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 16px; border: 1px solid var(--line);
}
.hero p { margin: 4px 0 12px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; text-decoration: none;
  display: flex; flex-direction: column;
}
.card:hover { border-color: var(--accent); }
.card .thumb { aspect-ratio: 16 / 9; width: 100%; height: auto; flex: none; object-fit: cover; background: var(--surface-2); }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title { font-weight: 700; line-height: 1.3; }
.tag {
  display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.tag.live { background: var(--teal); color: #fff; }
.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--teal); transition: width .3s; }

/* ---------- trang tập ---------- */
.back { display: inline-block; margin: 4px 0; text-decoration: none; color: var(--muted); }
.tabs {
  display: flex; gap: 0; overflow-x: auto; margin: 12px -16px 16px; padding: 0 16px;
  position: sticky; top: 52px; z-index: 5; background: var(--bg); scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 1 0 auto; text-align: center; text-decoration: none; padding: 10px 4px; border-bottom: 3px solid transparent;
  font-weight: 600; color: var(--muted);
}
.tabs a.active { color: var(--ink); border-bottom-color: var(--accent); }

.video {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-top: 12px;
}
.video .frame { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: #000; margin-bottom: 10px; }
.video iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
details.chap summary { cursor: pointer; margin-top: 10px; color: var(--muted); font-size: .9rem; }
.chapters { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chapters a { font-size: .85rem; }

.sent {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center;
  padding: 12px; border-bottom: 1px solid var(--line);
}
.sent:last-child { border-bottom: 0; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.sent .en { font-size: 1.1rem; font-weight: 600; color: var(--en); }
.sent .ipa { font-size: .85rem; color: var(--muted); font-family: "Segoe UI", "Lucida Sans Unicode", "DejaVu Sans", sans-serif; }
.sent .vi { color: var(--vi); }
.sent .who { font-size: .75rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.sent .acts { grid-row: 1 / span 4; grid-column: 2; display: flex; gap: 4px; }
.sent.done .en::after { content: " ✓"; color: var(--ok); font-size: .9rem; }
.sent.speaking { background: var(--surface-2); }

/* ---------- luyện nói ---------- */
.stage {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px 16px; text-align: center; min-height: 300px;
  display: flex; flex-direction: column; justify-content: center; gap: 12px;
}
.stage .step { font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stage .vi { font-size: 1.25rem; color: var(--vi); }
.stage .en { font-size: 1.6rem; font-weight: 700; color: var(--en); line-height: 1.3; min-height: 2.1rem; }
.stage .en .w { transition: color .15s; }
.stage .en .w.on { color: var(--hl); }
.stage .ipa { color: var(--muted); }
.chip {
  display: inline-block; align-self: center; padding: 6px 16px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; letter-spacing: .04em;
}
.chip.teal { background: var(--teal); color: #fff; }
.count { font-size: 2.2rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.controls { justify-content: center; margin-top: 14px; }
.opts { margin: 10px 0; gap: 12px; }
.opts label { display: inline-flex; gap: 6px; align-items: center; }
select {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; min-height: 40px; padding: 4px 8px; max-width: 100%;
}

/* ---------- thẻ ôn ---------- */
.flash {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px 16px; text-align: center; min-height: 240px;
  display: flex; flex-direction: column; justify-content: center; gap: 10px;
}
.flash .front { font-size: 1.3rem; color: var(--vi); }
.flash .back-en { font-size: 1.5rem; font-weight: 700; color: var(--en); }

/* ---------- kiểm tra ---------- */
.q { font-size: 1.2rem; font-weight: 600; margin: 8px 0 14px; }
.choices { display: grid; gap: 8px; }
.choice {
  text-align: left; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px;
  background: var(--surface); cursor: pointer; min-height: 48px; font-size: 1.02rem;
}
.choice.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.answer {
  min-height: 56px; border: 2px dashed var(--line); border-radius: 12px; padding: 8px;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px;
}
.answer.right { border-color: var(--ok); border-style: solid; }
.answer.wrong { border-color: var(--bad); border-style: solid; }
.word {
  padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  cursor: pointer; font-weight: 600; min-height: 40px;
}
.pool { display: flex; flex-wrap: wrap; gap: 6px; }
.feedback { margin-top: 10px; font-weight: 600; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.score { font-size: 3rem; font-weight: 800; color: var(--teal); }

.stat { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat div { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; font-size: .85rem; line-height: 1.3; }
.stat b { display: block; font-size: 1.3rem; }

.prose p, .prose li { max-width: 62ch; }
.prose a { color: var(--vi); }

/* ================= lộ trình ================= */
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .875rem; }
.btn.wide { width: 100%; }
.tag.hot { background: var(--accent); color: var(--accent-ink); }
.tip {
  display: flex; gap: 10px; align-items: center; background: var(--surface-2); border-radius: var(--radius);
  padding: 12px 14px; margin: 12px 0; text-decoration: none; font-size: .95rem;
}
.tip.row.spread { justify-content: space-between; }
.hero h1 { margin-top: 2px; }

.pick-grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left;
  padding: 12px 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer;
}
.pick.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.pick-ico { font-size: 1.6rem; }

details.level {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden;
}
details.level > summary {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; list-style: none; font-weight: 700;
}
details.level > summary::-webkit-details-marker { display: none; }
details.level > summary::after { content: '▾'; margin-left: 8px; color: var(--muted); transition: transform .2s; }
details.level:not([open]) > summary::after { transform: rotate(-90deg); }
.lv-badge { background: var(--ink); color: var(--bg); border-radius: 8px; padding: 2px 8px; font-size: .85rem; }
@media (prefers-color-scheme: dark) { .lv-badge { background: var(--teal); color: #fff; } }
.lv-name { flex: 1; }
.units { border-top: 1px solid var(--line); }
.unit {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none;
  border-bottom: 1px solid var(--line);
}
.unit:last-child { border-bottom: 0; }
.unit:hover { background: var(--surface-2); }
.unit.next { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.unit.done .unit-title { color: var(--muted); }
.unit-ico { font-size: 1.4rem; flex: none; }
.unit-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.unit-title { font-weight: 700; }

/* ---------- trang đơn vị ---------- */
.can-do { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin: 8px 0 12px; font-size: .95rem; }
.steps {
  display: flex; gap: 4px; overflow-x: auto; margin: 0 -16px 16px; padding: 4px 16px 8px;
  position: sticky; top: 52px; z-index: 5; background: var(--bg); scrollbar-width: none;
}
.steps::-webkit-scrollbar { display: none; }
.steps a {
  flex: 1 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 48px;
  text-decoration: none; color: var(--muted); font-size: .72rem; font-weight: 600; padding: 4px 1px; white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.steps .dot {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid var(--line); background: var(--surface); font-size: .8rem;
}
.steps a.ok .dot { background: var(--teal); border-color: var(--teal); color: #fff; }
.steps a.active { color: var(--ink); border-bottom-color: var(--accent); }
.steps a.active .dot { border-color: var(--accent); }

.vrow { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.vrow:last-child { border-bottom: 0; }
.vrow.done .en::after { content: " ✓"; color: var(--ok); font-size: .9rem; }
.vmain { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.vrow .acts { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; max-width: 140px; }
.vrow .en, .line .en { font-size: 1.1rem; font-weight: 600; color: var(--en); }
.vrow .vi, .line .vi { color: var(--vi); }
.vrow .ipa, .ipa { font-size: .85rem; color: var(--muted); font-family: "Segoe UI", "Lucida Sans Unicode", "DejaVu Sans", sans-serif; }
.pos { font-size: .7rem; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; margin-left: 6px; vertical-align: middle; }
.ex { font-size: .95rem; margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ex .btn.icon { min-height: 32px; min-width: 32px; padding: 2px; }
.note { font-size: .875rem; color: var(--muted); }
.who { font-size: .75rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }

.pattern {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: var(--surface-2);
  border-radius: 10px; padding: 10px 12px; font-weight: 600; overflow-x: auto;
}
.explain { padding-left: 20px; margin: 4px 0; }
.explain li { margin: 4px 0; }
.warn {
  border-left: 4px solid var(--hl); background: color-mix(in srgb, var(--hl) 10%, var(--surface));
  padding: 10px 12px; border-radius: 8px;
}

.dialog .line {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.dialog .line:last-child { border-bottom: 0; }
.dialog .line .who, .dialog .line .en, .dialog .line .vi { grid-column: 1; }
.dialog .line .acts { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
.line.speaking { background: var(--surface-2); }
.blur { filter: blur(6px); user-select: none; }
.blur:hover { filter: none; }

/* ---------- bài tập ---------- */
.card-ex {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin: 10px 0;
}
.ex-type { font-size: .8rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.q.row { gap: 8px; }
.choice.picked { border-color: var(--vi); }
.text-in, .slot {
  font: inherit; color: inherit; background: var(--bg); border: 2px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; font-size: 1.05rem;
}
.text-in:focus, .slot:focus { outline: none; border-color: var(--accent); }
.slot { width: auto; min-width: 7em; max-width: 100%; padding: 4px 8px; margin: 2px 4px; font-size: 1rem; }
.frame-line { font-size: 1.05rem; font-weight: 600; color: var(--en); line-height: 2.2; }
details.hint summary { cursor: pointer; color: var(--muted); margin: 8px 0; }
.sr { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; align-items: flex-start; }
.sr-words .ok { color: var(--ok); font-weight: 700; }
.sr-words .miss { color: var(--bad); text-decoration: underline wavy; }
.result { text-align: center; }
.stack.center { align-items: center; text-align: center; }
.hero-actions { margin-top: 12px; }

@media (max-width: 440px) {
  .brand span { font-size: .9rem; }
  .topnav a { padding: 6px 6px; font-size: .85rem; }
}
@media (max-width: 400px) { .brand span { display: none; } }
