:root {
  --bg: #f6f7fb; --card: #ffffff; --text: #1f2333; --muted: #6b7085; --line: #e4e6ef;
  --accent: #4f46e5; --accent-2: #eef0ff; --ok: #16a34a; --ok-bg: #e8f8ee; --bad: #dc2626; --bad-bg: #fdecec;
  --warn-bg: #fff7e0; --radius: 16px; --shadow: 0 1px 2px rgba(20,24,60,.06), 0 4px 16px rgba(20,24,60,.06);
  --nav-h: 64px; --top-h: 56px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans CJK SC", "Hiragino Sans", "PingFang SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #11131a; --card: #1b1e29; --text: #eceef6; --muted: #9ea3b8; --line: #2b2f3e;
    --accent: #8b83ff; --accent-2: #262a47; --ok-bg: #12301f; --bad-bg: #3a1717; --warn-bg: #3a3015; --shadow: none; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #11131a; --card: #1b1e29; --text: #eceef6; --muted: #9ea3b8; --line: #2b2f3e;
    --accent: #8b83ff; --accent-2: #262a47; --ok-bg: #12301f; --bad-bg: #3a1717; --warn-bg: #3a3015; --shadow: none; color-scheme: dark; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; font-size: 16px; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: .2em 0 .4em; }
h2 { font-size: 1.2rem; margin: 1.2em 0 .6em; }
h3 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
small { color: var(--muted); }
.muted, .hint, .fine { color: var(--muted); }
.fine { font-size: .82rem; }
.ok { color: var(--ok); } .bad { color: var(--bad); }

/* ---------- Khung ---------- */
.top { position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: 10px;
  padding: 0 max(12px, env(safe-area-inset-left)); padding-top: env(safe-area-inset-top); background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); white-space: nowrap; }
.logo img { width: 30px; height: 30px; }
.langbar { display: flex; gap: 4px; overflow-x: auto; flex: 1; justify-content: center; scrollbar-width: none; }
.langbar::-webkit-scrollbar { display: none; }
.stats { display: flex; gap: 10px; align-items: center; white-space: nowrap; font-size: .92rem; }
.stats .sync { font-size: 1.1rem; }

.nav { position: fixed; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; color: var(--muted); }
.nav a span { font-size: 1.3rem; }
.nav a.on { color: var(--accent); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); outline: none; }

@media (max-width: 799px) {
  .nav { left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); }
  .logo span { display: none; }
  .chip span { display: none; }
  .top { gap: 6px; }
  .langbar .chip { padding: 2px 7px; min-height: 30px; }
  .stats { gap: 6px; font-size: .85rem; }
}
@media (min-width: 800px) {
  .nav { top: var(--top-h); left: 0; bottom: 0; width: 92px; flex-direction: column; justify-content: flex-start; padding-top: 12px; border-top: 0; border-right: 1px solid var(--line); }
  .nav a { flex: 0 0 76px; }
  main { margin-left: 92px; padding: 24px 28px 48px; }
  body { font-size: 17px; }
}
@media (min-width: 1200px) { main { margin-left: max(92px, calc((100vw - 1100px) / 2)); } }

/* ---------- Thành phần ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 16px; color: var(--text); }
.grid { display: grid; gap: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-align: center; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.badge { background: #fff; color: var(--accent); border-radius: 99px; padding: 0 8px; font-size: .85rem; }
.icon { border: 0; background: transparent; font-size: 1.25rem; min-width: 40px; min-height: 40px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.icon:hover { background: var(--accent-2); }
.icon.playing, .say.playing { animation: pulse 1s infinite; background: var(--accent-2); }
@keyframes pulse { 50% { transform: scale(1.15); } }
.pulse { display: inline-block; animation: pulse 1s infinite; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 99px;
  padding: 4px 10px; min-height: 34px; font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap; opacity: .55; filter: grayscale(.7); }
.chip.on { opacity: 1; filter: none; color: var(--text); border-color: var(--accent); background: var(--accent-2); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0 12px; }
.tabs .chip { opacity: 1; filter: none; }
.toggle { display: inline-flex; gap: 6px; align-items: center; margin-left: auto; color: var(--muted); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; flex: 1; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #22c1c3); border-radius: 99px; transition: width .4s; }
.warn { background: var(--warn-bg); padding: 12px 14px; border-radius: 12px; margin: 12px 0; }
.crumbs { margin-bottom: 8px; }
.pager { display: flex; justify-content: space-between; gap: 8px; margin: 20px 0; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Trang chủ */
.hero { display: grid; gap: 16px; background: linear-gradient(135deg, var(--accent-2), var(--card)); }
.hero p { margin: .2em 0 .8em; color: var(--muted); }
.hero-actions { display: flex; flex-direction: column; gap: 8px; }
.goal { display: flex; align-items: center; gap: 10px; font-size: .9rem; color: var(--muted); }
@media (min-width: 700px) { .hero { grid-template-columns: 1fr auto; align-items: center; } }
.scripts-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.big-emoji { font-size: 2.2rem; line-height: 1.2; }
.topics { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.topic { display: flex; flex-direction: column; gap: 10px; transition: transform .15s; }
.topic:hover { transform: translateY(-2px); border-color: var(--accent); }
.t-head { display: flex; gap: 12px; align-items: center; }
.t-head b { display: block; }
.t-emoji { font-size: 2rem; }
.t-emoji.xl { font-size: 3.2rem; }
.t-bars { display: grid; gap: 4px; }
.t-bar { display: flex; align-items: center; gap: 6px; font-size: .8rem; }

/* Chủ đề */
.topic-head { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; align-items: center; }
.topic-head h1 { margin: 0; }
.topic-head p { margin: 0; color: var(--muted); }
.topic-head .actions { grid-column: 1 / -1; margin-top: 8px; }
.items { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.items.phrases { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
@media (max-width: 420px) { .items, .items.phrases { grid-template-columns: 1fr; } }
.item { padding: 0; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.item:hover { border-color: var(--accent); }
.item .body { padding: 10px 12px 12px; }
.vi { font-weight: 700; font-size: 1.05rem; margin: 2px 0 6px; }
h2.vi { font-size: 1.35rem; text-align: center; }
.lvl { color: var(--ok); font-size: .7rem; letter-spacing: 1px; vertical-align: middle; }

.media { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 16 / 9; background: var(--accent-2); overflow: hidden; }
.media .emoji { font-size: 3rem; position: relative; z-index: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,.15)); }
.media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .4s; }
.media.has-img img { opacity: 1; }
.media.has-img .emoji { position: absolute; left: 8px; bottom: 6px; font-size: 1.8rem; background: var(--card); border-radius: 12px; padding: 0 6px; }
.media.big { border-radius: 14px; aspect-ratio: 4 / 3; max-height: 42vh; width: 100%; }
.media.big .emoji { font-size: 5rem; }
.media .credit { position: absolute; right: 6px; bottom: 6px; z-index: 2; font-size: .68rem; background: rgba(0,0,0,.55); color: #fff; padding: 2px 6px; border-radius: 6px; max-width: 70%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.lrow { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px dashed var(--line); }
.lrow:first-of-type { border-top: 0; }
.lrow .flag { font-size: 1.2rem; width: 26px; text-align: center; }
.lrow .txt { flex: 1; min-width: 0; }
.lrow .txt b { font-weight: 600; display: block; overflow-wrap: anywhere; }
.lrow .txt small { display: block; font-size: .82rem; }
.rows { margin: 8px 0; }

/* Hộp thoại chi tiết */
dialog { border: 0; padding: 0; background: transparent; max-width: 640px; width: calc(100% - 24px); max-height: calc(100% - 24px); color: var(--text); }
dialog::backdrop { background: rgba(10, 12, 25, .55); }
.sheet { background: var(--card); border-radius: 20px; padding: 16px; position: relative; max-height: calc(100dvh - 40px); overflow-y: auto; }
.sheet .close { position: absolute; right: 22px; top: 22px; z-index: 3; background: var(--card); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.mic-result:not(:empty) { background: var(--accent-2); padding: 10px 12px; border-radius: 12px; margin: 8px 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; }
.gallery img, .gallery video { width: 100%; border-radius: 10px; background: #000; max-height: 260px; object-fit: contain; }
.gallery figcaption { font-size: .72rem; color: var(--muted); overflow-wrap: anywhere; }

/* Học thẻ & luyện tập */
.progress-top { display: flex; align-items: center; gap: 10px; margin: 6px 0 12px; color: var(--muted); font-size: .9rem; }
.flash, .quiz { max-width: 640px; margin: 0 auto; }
.done { text-align: center; max-width: 520px; margin: 24px auto; }
.done .actions { justify-content: center; }
.qlabel { color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.qtext { font-size: 1.7rem; font-weight: 700; text-align: center; padding: 18px 8px; }
.qtext small { display: block; font-size: 1rem; font-weight: 400; margin-top: 4px; }
.qtext.big { font-size: 4rem; padding: 4px; }
.big-say { font-size: 1.3rem; min-height: 72px; width: 100%; margin: 10px 0; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.opts.single { grid-template-columns: 1fr; }
@media (max-width: 420px) { .opts { grid-template-columns: 1fr; } }
.opt { min-height: 56px; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: 1.05rem; cursor: pointer; text-align: left; display: flex; flex-direction: column; justify-content: center; }
.opt small { font-size: .8rem; }
.opt .oe { margin-right: 4px; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.right { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.fb { margin-top: 14px; padding: 12px; border-radius: 12px; display: grid; gap: 8px; }
.fb-ok { background: var(--ok-bg); } .fb-bad { background: var(--bad-bg); }
.fb .btn { justify-self: end; }

/* Hội thoại */
.dialogue { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.bubble { max-width: 560px; width: 92%; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 10px 14px; box-shadow: var(--shadow); transition: box-shadow .2s; }
.bubble.right { align-self: flex-end; background: var(--accent-2); }
.bubble.now { box-shadow: 0 0 0 3px var(--accent); }
.bubble .who { font-weight: 700; font-size: .85rem; color: var(--accent); }
.vi-line { color: var(--muted); font-size: .9rem; margin-top: 4px; }

/* Chữ viết */
.notes { padding-left: 1.2em; margin: 0 0 8px; }
.notes li { margin: 4px 0; }
.kana { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; max-width: 520px; }
.alpha { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 6px; }
.kc { aspect-ratio: 1; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; font: inherit; }
.kc b { font-size: 1.6rem; font-weight: 500; }
.kc:hover, .pc:hover, .tone:hover { border-color: var(--accent); }
.tones { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.tone { text-align: left; display: flex; flex-direction: column; gap: 2px; cursor: pointer; font: inherit; }
.tone b { font-size: 2rem; }
.tone em { font-size: .82rem; color: var(--muted); font-style: normal; }
.ptable { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ptable.small { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
.ptable.wide { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.pc { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 12px; padding: 10px; text-align: left; display: flex; flex-direction: column; gap: 2px; font: inherit; cursor: pointer; }
div.pc { cursor: default; }
.pc b { font-size: 1.3rem; }
.pc .han { font-size: 2rem; font-weight: 500; }
.link { border: 0; background: var(--accent-2); color: var(--text); border-radius: 8px; padding: 4px 8px; margin: 2px; font: inherit; cursor: pointer; }
.drill { margin-top: 16px; text-align: center; }

/* Tiến độ */

.grid.statgrid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.stat p { margin: 8px 0 0; font-size: .9rem; color: var(--muted); }
.st-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.st-head .flag { font-size: 1.5rem; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.chart .col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.chart .col i { display: block; width: 100%; background: var(--line); border-radius: 6px 6px 0 0; min-height: 2px; }
.chart .col i.met { background: var(--accent); }
.chart small { font-size: .7rem; }

/* Cài đặt */
.checks { display: grid; gap: 8px; }
.checks label { display: flex; gap: 8px; align-items: center; min-height: 36px; }
.checks input, .toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.range { display: flex; align-items: center; gap: 10px; margin: 12px 0; flex-wrap: wrap; }
.range input { flex: 1; min-width: 140px; accent-color: var(--accent); }
.voices { padding-left: 1.2em; }
.login { display: grid; gap: 8px; margin-top: 12px; max-width: 360px; }
.login input { min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
section { margin-bottom: 16px; }
