:root {
  --bg: #eef5fc;
  --surface: #ffffff;
  --surface-2: #e6f0fb;
  --text: #0f2540;
  --muted: #56708c;
  --line: #d3e3f4;
  --accent: #1f7ae0;        /* ocean blue */
  --accent-2: #4fc3f7;
  --accent-deep: #0e4fa8;
  --accent-soft: #dcecfd;
  --teal: #12b5a5;
  --gold: #e0a400;
  --gold-soft: #fff6dc;
  --good: #1f8a4c;
  --good-soft: #e5f5ec;
  --bad: #c43d3d;
  --bad-soft: #fbeaea;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .05);
  --font: "Be Vietnam Pro", "Noto Sans SC", system-ui, -apple-system, "PingFang SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1a24;
    --surface: #16232f;
    --surface-2: #1d2e3d;
    --text: #e8f2fb;
    --muted: #93a9bd;
    --line: #2a3e50;
    --accent: #5aaef5;
    --accent-2: #7fd8ff;
    --accent-deep: #a9d4ff;
    --accent-soft: #16304b;
    --teal: #3fd6c4;
    --gold: #f2c14e;
    --gold-soft: #352b14;
    --good: #4cc27f;
    --good-soft: #17301f;
    --bad: #ff7b7b;
    --bad-soft: #3a1c1c;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #0f1a24;
    --surface: #16232f;
    --surface-2: #1d2e3d;
    --text: #e8f2fb;
    --muted: #93a9bd;
    --line: #2a3e50;
    --accent: #5aaef5;
    --accent-2: #7fd8ff;
    --accent-deep: #a9d4ff;
    --accent-soft: #16304b;
    --teal: #3fd6c4;
    --gold: #f2c14e;
    --gold-soft: #352b14;
    --good: #4cc27f;
    --good-soft: #17301f;
    --bad: #ff7b7b;
    --bad-soft: #3a1c1c;
    --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.65;
}
a { color: inherit; }
button { font: inherit; color: inherit; }

.container { max-width: 980px; margin: 0 auto; padding: 24px 16px 64px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px;
}
.brand-text { font-weight: 700; line-height: 1.2; }
.brand-text small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.topnav { display: flex; gap: 4px; }
.topnav a {
  text-decoration: none; padding: 6px 12px; border-radius: 999px; font-size: 14px; color: var(--muted);
}
.topnav a:hover, .topnav a.active { background: var(--surface-2); color: var(--text); }
@media (max-width: 560px) { .brand-text small { display: none; } .topnav a { padding: 6px 8px; font-size: 13px; } }

.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 16px 40px; }

/* ---------- home ---------- */
.hero {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px; box-shadow: var(--shadow); margin-bottom: 28px;
  display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center;
}
.hero h1 { margin: 0 0 6px; font-size: 28px; line-height: 1.25; }
.hero p { margin: 0; color: var(--muted); }
.stat { text-align: center; min-width: 110px; }
.stat b { display: block; font-size: 32px; color: var(--accent); line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
.progress-bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 14px; }
.progress-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
@media (max-width: 560px) { .hero { grid-template-columns: 1fr; padding: 20px; } .hero h1 { font-size: 23px; } }

.chapter { margin-bottom: 32px; }
.chapter-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.chapter-head h2 { margin: 0; font-size: 20px; }
.chapter-head span { color: var(--muted); font-size: 14px; }

.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.lesson-card {
  display: flex; gap: 14px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; text-decoration: none; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .12s ease;
}
.lesson-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.lesson-card.missing { opacity: .55; pointer-events: none; box-shadow: none; border-style: dashed; }
.lesson-no {
  flex: none; width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.lesson-card.done .lesson-no { background: var(--good); color: #fff; }
.lesson-card h3 { margin: 0; font-size: 15px; line-height: 1.35; }
.lesson-card p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-top: 6px; }

/* ---------- lesson page ---------- */
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 10px; }
.crumbs a { color: var(--muted); }
.lesson-head {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.lesson-head .kicker { color: var(--accent); font-weight: 600; font-size: 13px; letter-spacing: .04em; }
.lesson-head h1 { margin: 4px 0 2px; font-size: 28px; line-height: 1.25; }
.lesson-head .zh-title { color: var(--muted); font-size: 17px; }
.lesson-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 8px 16px; font-size: 14px; text-decoration: none; font-weight: 500;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.small { padding: 4px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

.toc {
  display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 12px; margin-bottom: 8px;
  position: sticky; top: calc(61px + env(safe-area-inset-top, 0px)); z-index: 10; background: var(--bg);
  scrollbar-width: thin;
}
.toc a {
  flex: none; font-size: 13px; text-decoration: none; padding: 5px 12px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.toc a:hover { color: var(--text); border-color: var(--accent); }

.section {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); scroll-margin-top: 120px;
}
.section > h2 { margin: 0 0 14px; font-size: 20px; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.section > h2 small { font-size: 14px; color: var(--muted); font-weight: 500; }
.block { margin-top: 18px; }
.block:first-of-type { margin-top: 0; }
.block > h3 { font-size: 16px; margin: 0 0 10px; }
@media (max-width: 560px) { .section, .lesson-head { padding: 16px; } .lesson-head h1 { font-size: 23px; } }

.bi { margin: 0; }
.bi .vi { display: block; }
.bi .zh { display: block; color: var(--muted); font-size: 14.5px; }

ul.clean { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
ul.clean li { padding-left: 18px; position: relative; }
ul.clean li::before { content: ""; position: absolute; left: 2px; top: .7em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.tips { background: var(--gold-soft); border-radius: 12px; padding: 14px 16px; }
.tips h3 { color: color-mix(in srgb, var(--gold) 70%, var(--text)); }
.tips ul.clean li::before { background: var(--gold); }

/* speakable Vietnamese text */
.say {
  cursor: pointer; border-radius: 4px; text-decoration: underline dotted color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 4px;
}
.say:hover { background: var(--accent-soft); }
.say.playing { background: var(--accent-soft); color: var(--accent); }
.spk {
  border: none; background: var(--accent-soft); color: var(--accent); border-radius: 50%;
  width: 28px; height: 28px; display: inline-grid; place-items: center; cursor: pointer; font-size: 13px;
  vertical-align: middle; flex: none;
}
.spk:hover { background: var(--accent); color: #fff; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th { background: var(--surface-2); font-weight: 600; font-size: 13px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.vi-cell { font-weight: 600; font-size: 16px; white-space: nowrap; }

/* syllable grid */
.grid { display: grid; grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr)); gap: 8px; }
.grid .cell {
  background: var(--surface-2); border: 1px solid transparent; border-radius: 10px; padding: 10px 6px;
  text-align: center; font-size: 18px; font-weight: 600; cursor: pointer; min-height: 48px;
}
.grid .cell:hover { border-color: var(--accent); }
.grid .cell.head { background: transparent; color: var(--muted); font-size: 13px; cursor: default; font-weight: 500; }
.grid .cell.empty { background: transparent; cursor: default; }
.grid .cell.playing { background: var(--accent); color: #fff; }
@media (max-width: 560px) { .grid { gap: 5px; } .grid .cell { font-size: 15px; padding: 8px 2px; } }

/* phrases / sentences */
.pairs { display: grid; gap: 8px; }
.pair {
  display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--surface-2);
}
.pair .num { color: var(--muted); font-size: 13px; width: 20px; flex: none; }
.pair .vi { font-weight: 600; }
.pair .zh { color: var(--muted); font-size: 14.5px; }

/* reading */
.reading { background: var(--surface-2); border-radius: 12px; padding: 16px 18px; }
.reading .line { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; }
.reading .who { flex: none; font-weight: 700; color: var(--accent); min-width: 56px; }
.reading .vi { font-size: 17px; line-height: 1.7; }
.reading .zh { color: var(--muted); font-size: 14.5px; display: none; }
.reading.show-zh .zh { display: block; }
.reading-tools { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

/* grammar */
.grammar-item { border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; margin-bottom: 16px; }
.grammar-item h4 { margin: 0 0 4px; font-size: 16px; }
.grammar-item .body { white-space: pre-line; color: var(--text); }
.grammar-item .ex { margin-top: 8px; }

/* vocab */
.vocab-list { display: grid; gap: 10px; }
.vocab {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px;
}
.vocab .word { display: flex; align-items: center; gap: 8px; }
.vocab .word b { font-size: 18px; }
.vocab .pos { font-size: 12px; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 1px 6px; }
.vocab .mean { align-self: center; }
.vocab .ex { grid-column: 1 / -1; font-size: 14.5px; color: var(--muted); display: grid; gap: 2px; }
.vocab .ex .say { color: var(--text); }

/* exercises */
.exercise { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-top: 14px; }
.exercise > h3 { margin: 0 0 4px; font-size: 16px; }
.exercise .hint { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.q { padding: 10px 0; border-top: 1px dashed var(--line); }
.q:first-of-type { border-top: none; }
.q .prompt { font-weight: 600; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 14px; cursor: pointer;
}
.opt:hover { border-color: var(--accent); }
.opt.right { background: var(--good-soft); border-color: var(--good); color: var(--good); font-weight: 600; }
.opt.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.opt:disabled { cursor: default; }
input.text, textarea.text, select.text {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px;
}
select.text { width: auto; min-width: 160px; }
input.text:focus, textarea.text:focus, select.text:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.answer { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--good-soft); font-size: 14.5px; display: none; }
.answer.show { display: block; }
.feedback { font-size: 14px; margin-top: 6px; }
.feedback.ok { color: var(--good); } .feedback.no { color: var(--bad); }
.match-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; flex-wrap: wrap; }
.match-row .vi { font-weight: 600; min-width: 90px; }
.ex-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.blank { display: inline-block; min-width: 60px; border-bottom: 2px solid var(--accent); margin: 0 4px; text-align: center; }
.fill-text { line-height: 2.2; }
.fill-text select { margin: 0 4px; }

.recorder { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.recorder audio { height: 36px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* flashcards */
.flash-wrap { max-width: 520px; margin: 0 auto; text-align: center; }
.flashcard {
  perspective: 1000px; height: 280px; margin: 18px 0; cursor: pointer;
}
.flashcard-inner {
  position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 20px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.face.back { transform: rotateY(180deg); background: var(--accent-soft); }
.face .big { font-size: 42px; font-weight: 700; line-height: 1.2; }
.face .mid { font-size: 22px; }
.face .small { font-size: 14px; color: var(--muted); }
.flash-nav { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.counter { color: var(--muted); font-size: 14px; }

/* quiz */
.quiz-card { max-width: 620px; margin: 0 auto; }
.quiz-q { font-size: 15px; color: var(--muted); }
.quiz-word { font-size: 34px; font-weight: 700; margin: 10px 0 18px; display: flex; gap: 12px; align-items: center; }
.quiz-opts { display: grid; gap: 10px; }
.quiz-opts .opt { text-align: left; padding: 12px 16px; font-size: 16px; }
.result { text-align: center; padding: 30px 10px; }
.result b { font-size: 48px; color: var(--accent); display: block; }

.empty-note { color: var(--muted); font-size: 14px; }
.voice-warning {
  background: var(--gold-soft); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px;
}

/* ---------- light-blue look & animation ---------- */
.brand-mark { background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-size: 15px; box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 35%, transparent); }
.brand:hover .brand-mark { animation: wiggle .5s ease; }

.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface) 60%);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent-2) 45%, transparent), transparent 70%);
  animation: float 9s ease-in-out infinite;
}
.hero::before { width: 260px; height: 260px; right: -60px; top: -80px; }
.hero::after { width: 180px; height: 180px; left: 40%; bottom: -90px; animation-delay: -4s; }
.hero > * { position: relative; }
.hero h1 .wave { display: inline-block; animation: wave 2.2s ease-in-out infinite; transform-origin: 70% 70%; }
.stat b { color: var(--accent); }
.progress-bar > i { background: linear-gradient(90deg, var(--accent), var(--accent-2)); animation: grow 1s ease-out both; }

/* page + items enter */
#app > * { animation: rise .45s ease both; }
.lesson-card, .section, .vocab, .pair, .grid .cell {
  animation: rise .45s ease both; animation-delay: calc(var(--i, 0) * 35ms);
}
.lesson-card { transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease; }
.lesson-card:hover { transform: translateY(-4px); box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 22%, transparent); }
.lesson-card:hover .lesson-no { transform: rotate(-8deg) scale(1.08); }
.lesson-no { transition: transform .25s ease; }
.lesson-card .t-vi { margin: 0; font-size: 15.5px; line-height: 1.35; font-weight: 700; }
.lesson-card .t-zh { margin: 2px 0 0; font-size: 13.5px; color: var(--muted); }

.lesson-head { background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.lesson-head h1 { margin: 2px 0 2px; }
.lesson-head .zh-title { font-size: 18px; }

.btn { transition: transform .12s ease, border-color .15s ease, box-shadow .15s ease, background .15s ease; }
.btn:hover { transform: translateY(-1px); }
.btn:active, .opt:active, .grid .cell:active { transform: scale(.95); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; box-shadow: 0 4px 12px color-mix(in srgb, var(--accent) 30%, transparent); }

.grid .cell, .opt, .spk { transition: transform .12s ease, background .15s ease, border-color .15s ease; }
.grid .cell:hover { transform: translateY(-2px); }
.spk:hover { transform: scale(1.12); }
.playing, .grid .cell.playing { animation: pulse .8s ease-in-out infinite; }
.opt.right { animation: pop .35s ease; }
.opt.wrong { animation: shake .4s ease; }
.feedback.ok { animation: pop .35s ease; }
.flashcard:hover .flashcard-inner { transform: translateY(-4px); }
.flashcard.flipped:hover .flashcard-inner { transform: rotateY(180deg) translateY(-4px); }
.flashcard-inner { transition: transform .55s cubic-bezier(.3, 1.4, .5, 1); }
.result b { animation: pop .6s ease; }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes float { 50% { transform: translate(-20px, 18px) scale(1.08); } }
@keyframes wave { 0%, 60%, 100% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-8deg); } 45% { transform: rotate(10deg); } }
@keyframes wiggle { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }
@keyframes grow { from { width: 0; } }
@keyframes pop { 0% { transform: scale(.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 25%, transparent); } }

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

/* ---------- teacher recording page ---------- */
.footer-link { margin-left: 8px; color: var(--muted); }
.rec-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 14px; }
.rec-list { display: grid; gap: 8px; }
.rec-row {
  display: grid; grid-template-columns: 110px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  animation: rise .35s ease both; animation-delay: calc(var(--i, 0) * 25ms);
}
.rec-row.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rec-row.recording { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); animation: pulse 1s ease-in-out infinite; }
.rec-text { font-weight: 600; font-size: 16px; }
.rec-btns { display: flex; gap: 6px; }
.rec-state { font-size: 12.5px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); text-align: center; }
.rec-row[data-st="local"] .rec-state { background: var(--gold-soft); color: color-mix(in srgb, var(--gold) 70%, var(--text)); }
.rec-row[data-st="file"] .rec-state { background: var(--good-soft); color: var(--good); }
@media (max-width: 560px) {
  .rec-row { grid-template-columns: 1fr; gap: 6px; }
  .rec-state { justify-self: start; }
}

[hidden] { display: none !important; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--bg); }

