:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1b1f2a;
  --muted: #6b7080;
  --line: #e4e0d6;
  --navy: #14213d;
  --gold: #c9971c;
  --gold-soft: #f6ecd2;
  --ok: #2f9e5b;
  --ok-soft: #e3f4ea;
  --bad: #d0453a;
  --bad-soft: #fbe6e3;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 4px 16px rgba(20, 33, 61, .06);
  --r: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10131b;
    --card: #1a1f2b;
    --ink: #eceef3;
    --muted: #9aa0ae;
    --line: #2a3140;
    --navy: #0b1020;
    --gold: #e0b544;
    --gold-soft: #3a3120;
    --ok: #4cc27c;
    --ok-soft: #173325;
    --bad: #f06a5e;
    --bad-soft: #3a1d1b;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }

/* ---------- Thanh trên ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px;
  background: var(--navy); color: #fff;
}
.top-title { flex: 1; font-weight: 700; font-size: 18px; padding-left: 4px; }
.top .bar { flex: 1; height: 10px; border-radius: 99px; background: rgba(255,255,255,.18); overflow: hidden; }
.top .bar i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 99px; transition: width .3s; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; display: grid; place-items: center; color: #fff;
}
.icon-btn:active { background: rgba(255,255,255,.12); }
[hidden] { display: none !important; }

main { max-width: 560px; margin: 0 auto; padding: 16px 16px 120px; }

/* ---------- Trang chủ ---------- */
.hello { margin: 4px 0 14px; }
.hello h1 { font-size: 22px; margin: 0; }
.hello p { margin: 2px 0 0; color: var(--muted); }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.today { background: var(--navy); color: #fff; border: 0; }
.today .row { display: flex; gap: 10px; margin: 6px 0 14px; }
.today .stat { flex: 1; background: rgba(255,255,255,.08); border-radius: 12px; padding: 10px; }
.today .stat b { display: block; font-size: 24px; line-height: 1.2; color: var(--gold); }
.today .stat span { font-size: 13px; opacity: .8; }
.today h2 { margin: 0; font-size: 17px; }
.today .sub { font-size: 13px; opacity: .75; margin-top: 2px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 14px;
  padding: 15px 16px; font-weight: 700; font-size: 17px;
  background: var(--gold); color: #1b1606;
  box-shadow: 0 3px 0 rgba(0,0,0,.18);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.btn.ghost { background: transparent; color: inherit; border: 1.5px solid var(--line); box-shadow: none; font-weight: 600; }
.btn.navy { background: var(--navy); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); color: #fff; }
.btn:disabled { opacity: .45; }
.btn + .btn { margin-top: 10px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { margin: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile {
  text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; box-shadow: var(--shadow);
}
.tile .ic { font-size: 22px; }
.tile b { display: block; margin-top: 4px; }
.tile span { font-size: 13px; color: var(--muted); }
.tile:active { transform: scale(.98); }

.goal .meter { height: 10px; border-radius: 99px; background: var(--gold-soft); overflow: hidden; margin: 8px 0 6px; }
.goal .meter i { display: block; height: 100%; background: var(--gold); }
.goal .line { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.goal h3 { margin: 0; font-size: 15px; }

/* ---------- Thẻ học ---------- */
.q-label { font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 4px 0 10px; }
.word-card { text-align: center; padding: 26px 16px 20px; }
.word { font-size: 34px; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; word-break: break-word; }
.ipa { color: var(--muted); margin-top: 4px; font-size: 17px; }
.pos { display: inline-block; font-size: 12px; font-weight: 700; color: var(--gold); background: var(--gold-soft); border-radius: 6px; padding: 1px 7px; margin-left: 6px; vertical-align: middle; }
.meaning { font-size: 19px; font-weight: 600; margin-top: 12px; }
.ex { text-align: left; margin-top: 16px; padding: 12px 14px; border-radius: 12px; background: var(--bg); }
.ex .en { font-weight: 500; }
.ex .vi { color: var(--muted); font-size: 14px; margin-top: 2px; }
mark { background: var(--gold-soft); color: inherit; border-radius: 4px; padding: 0 2px; }
.ex mark { background: var(--gold-soft); color: inherit; border-radius: 4px; padding: 0 2px; }
.speak-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--gold-soft); color: var(--gold); vertical-align: middle;
}
.speak-btn.sm { width: 34px; height: 34px; float: right; margin: -2px -4px 0 8px; }
.big-listen { width: 96px; height: 96px; margin: 18px auto 6px; display: grid; }
.big-listen svg { width: 42px; height: 42px; }
.slow { font-size: 13px; border: 0; background: none; color: var(--muted); text-decoration: underline; }

.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; padding: 14px 16px; border-radius: 14px;
  background: var(--card); border: 2px solid var(--line); font-size: 17px; font-weight: 500;
  box-shadow: 0 2px 0 var(--line);
}
.opt:active { transform: translateY(1px); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opts.done .opt { pointer-events: none; }

.prompt-vi { font-size: 22px; font-weight: 700; text-align: center; margin: 6px 0 4px; }
.blank-ex { text-align: center; color: var(--muted); margin-bottom: 14px; }
.text-in {
  width: 100%; padding: 14px 16px; font-size: 19px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--card); color: var(--ink); outline: none;
}
.text-in:focus { border-color: var(--gold); }

.mic {
  width: 104px; height: 104px; border-radius: 50%; border: 0; margin: 18px auto 10px;
  display: grid; place-items: center; background: var(--navy); color: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.mic svg { width: 44px; height: 44px; }
.mic.on { background: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(208,69,58,.5)} 70%{box-shadow:0 0 0 18px rgba(208,69,58,0)} 100%{box-shadow:0 0 0 0 rgba(208,69,58,0)} }
.heard { text-align: center; min-height: 26px; color: var(--muted); }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; }

/* ---------- Thanh phản hồi dưới ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(0,0,0,.08);
  animation: up .18s ease-out;
}
.sheet-in { max-width: 560px; margin: 0 auto; }
.sheet.ok { background: var(--ok-soft); }
.sheet.bad { background: var(--bad-soft); }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.sheet.ok h3 { color: var(--ok); }
.sheet.bad h3 { color: var(--bad); }
.sheet .ans { margin-bottom: 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0 } to { transform: none; opacity: 1 } }
.fixed-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.fixed-bottom > div { max-width: 560px; margin: 0 auto; }

/* ---------- Chấm câu nói/nghe ---------- */
.diff { font-size: 18px; line-height: 1.7; }
.diff .g { color: var(--ok); font-weight: 600; }
.diff .r { color: var(--bad); text-decoration: underline wavy; text-underline-offset: 4px; }
.score { font-size: 40px; font-weight: 800; text-align: center; }

/* ---------- Tiến độ ---------- */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.kpi b { display: block; font-size: 24px; }
.kpi span { font-size: 12px; color: var(--muted); }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 110px; margin-top: 10px; }
.chart i { flex: 1; background: var(--gold); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .9; }
.chart i.zero { background: var(--line); }
.chart-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ---------- Danh sách từ ---------- */
.search { margin-bottom: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.chip { flex: none; border: 1.5px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 14px; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.wl { list-style: none; margin: 0; padding: 0; }
.wl li { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.wl .t { flex: 1; min-width: 0; }
.wl .t b { display: block; }
.wl .t span { font-size: 14px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.dot.L { background: var(--bad); } .dot.R { background: var(--gold); } .dot.M { background: var(--ok); }

/* ---------- Cài đặt ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button { width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-size: 22px; }
.stepper b { font-size: 22px; min-width: 40px; text-align: center; }
select.text-in { appearance: none; font-size: 16px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 50; font-size: 15px;
  max-width: calc(100% - 32px);
}
.done-hero { text-align: center; padding: 20px 0 10px; }
.done-hero .big { font-size: 56px; }
.done-hero h2 { margin: 4px 0; }
