:root {
  --bg: #f1f2f6;
  --card: #ffffff;
  --text: #111114;
  --muted: #6c6c72;
  --line: rgba(60, 60, 67, 0.14);
  --navy: #263366;
  --navy-2: #3d5199;
  --stamp: #b3303b;
  --ok: #248a3d;
  --press: rgba(0, 0, 0, 0.05);
  --bar-bg: rgba(248, 249, 252, 0.88);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #17171a;
    --text: #f2f2f5;
    --muted: #9a9aa2;
    --line: rgba(120, 120, 128, 0.32);
    --navy: #8fa3e6;
    --navy-2: #6d84d4;
    --stamp: #e0646b;
    --ok: #32d74b;
    --press: rgba(255, 255, 255, 0.07);
    --bar-bg: rgba(20, 20, 22, 0.88);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; flex: none; }
h2, h3 { font-weight: 600; }

/* ---------- Thanh tiêu đề ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bar-bg);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 0.5px solid var(--line);
}
.topbar h1 { margin: 0 auto; max-width: 680px; font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--navy); margin: 0 0 2px -6px; font-size: 16px; }
.back[hidden] { display: none; }
.back + h1 { font-size: 21px; }
main { max-width: 680px; margin: 0 auto; padding: 4px 16px 28px; }

/* ---------- Khối danh sách ---------- */
.sec { margin: 18px 0 0; }
.sec-h {
  margin: 0 0 7px 4px; font-size: 12.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
}
.sec-f { margin: 7px 4px 0; font-size: 13px; color: var(--muted); }
.card { background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 11px 16px; min-height: 44px; position: relative;
}
.row + .row::before, .row + .mock-form::before, .mock-form + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--line);
}
.row.col { flex-direction: column; align-items: flex-start; gap: 2px; }
.link-row { cursor: pointer; }
.link-row:active, .check-row:active, .task:active { background: var(--press); }
@media (hover: hover) { .link-row:hover, .check-row:hover { background: var(--press); } }
.grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.title { display: block; }
.sub, .ex { font-size: 13px; color: var(--muted); }
.sub-inline { font-size: 13px; color: var(--muted); font-weight: 400; }
.ex { font-style: italic; }
.one-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--muted); opacity: 0.5; display: flex; }
.chev svg { width: 15px; height: 15px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 11.5px; }
.mono { font-variant-numeric: tabular-nums; }
.ok { color: var(--ok); }
.stamp { color: var(--stamp); }
.accent { color: var(--navy); }
.accent .grow { color: var(--navy); }
.dot { color: var(--muted); opacity: 0.6; }
.note { color: var(--muted); font-size: 13px; margin: 14px 4px 0; }
.note.lead { margin-top: 4px; }
.flag { font-size: 20px; line-height: 1; }

.hero { flex-direction: column; align-items: flex-start; gap: 5px; padding: 14px 16px; }
.big-2 { font-size: 20px; font-weight: 700; }
.h3 { font-size: 17px; font-weight: 650; }
.bar { width: 100%; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin: 8px 0 4px; }
.bar span { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width 0.25s; }

/* ---------- Hôm nay ---------- */
.topline { display: flex; align-items: center; gap: 8px; margin: 12px 0 14px; }
.plan-chip {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; justify-content: space-between;
  background: var(--card); border-radius: 999px; padding: 9px 12px 9px 16px;
  font-weight: 600; color: var(--text); box-shadow: var(--shadow);
}
.plan-chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-chip svg { width: 18px; height: 18px; color: var(--muted); }
.icon-chip {
  display: inline-flex; align-items: center; gap: 5px; background: var(--card); border-radius: 999px;
  padding: 9px 13px; font-size: 13px; font-weight: 600; color: var(--navy); box-shadow: var(--shadow);
}
.icon-chip svg { width: 18px; height: 18px; }

.hero-card {
  border-radius: 18px; padding: 18px; color: #fff;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-2) 100%);
  display: flex; flex-direction: column; gap: 6px;
}
@media (prefers-color-scheme: dark) { .hero-card { color: #0d1020; } }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.hero-badge {
  background: rgba(255, 255, 255, 0.18); border-radius: 999px; padding: 5px 12px;
  font-size: 13px; font-weight: 600;
}
.hero-ring {
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700;
  background: conic-gradient(currentColor calc(var(--pct) * 1%), rgba(255, 255, 255, 0.22) 0);
}
.hero-ring b {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--navy); color: #fff;
}
@media (prefers-color-scheme: dark) { .hero-ring b { background: var(--navy); color: #0d1020; } }
.hero-date { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; }
.hero-meta { font-size: 14px; opacity: 0.85; }
.hero-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill-soft {
  background: rgba(255, 255, 255, 0.16); border-radius: 999px; padding: 5px 11px; font-size: 12.5px;
}

/* ---------- Nhiệm vụ ---------- */
.icon-btn { display: flex; color: var(--muted); padding: 4px; margin: -4px; border-radius: 50%; }
.icon-btn.check svg { width: 26px; height: 26px; }
.icon-btn.check.on { color: var(--ok); }
.icon-btn.speak, .icon-btn.accent { color: var(--navy); }
.icon-btn.del { font-size: 22px; line-height: 1; width: 30px; height: 30px; justify-content: center; align-items: center; }
.task-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; align-self: stretch; }
.task { padding-top: 0; padding-bottom: 0; }
.task .task-link { padding: 11px 0; }
.task.is-done .title { text-decoration: line-through; color: var(--muted); }
.text-btn { display: inline-flex; align-items: center; gap: 6px; color: var(--navy); font-size: 15px; }
.text-btn.stamp { color: var(--stamp); }
.text-btn.ok { color: var(--ok); }
.text-btn svg { width: 20px; height: 20px; }
.text-btn.recording { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.btns { display: flex; gap: 22px; margin-top: 8px; }
.rec-row { align-items: flex-start; }
.step { align-items: flex-start; }
.num { color: var(--navy); min-width: 1.4em; }
.check-row { align-items: flex-start; cursor: pointer; }
.check-row .icon { display: flex; }

.btn {
  border-radius: 13px; padding: 13px 18px; font-weight: 650; font-size: 16px; flex: 1;
  display: inline-flex; justify-content: center; align-items: center; gap: 8px;
}
.btn.primary { background: var(--navy); color: #fff; box-shadow: var(--shadow); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d1020; } }
.btn.outline { background: var(--card); color: var(--navy); box-shadow: var(--shadow); }
.btn.outline.stamp { color: var(--stamp); }
.btn.google { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.btn.google svg { width: 20px; height: 20px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.wide { width: 100%; }
.btn-row { gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 999px; background: var(--press); color: var(--navy); font-weight: 500; }
.badge {
  display: inline-flex; align-items: center; gap: 3px; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--press); color: var(--muted);
  text-transform: none; vertical-align: 1px;
}

/* ---------- Cây lộ trình và từ vựng ---------- */
.tree { margin-top: 14px; }
.tree details + details { border-top: 0.5px solid var(--line); }
.tree summary {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px;
  cursor: pointer; list-style: none;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary::after {
  content: ""; width: 7px; height: 7px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 0.15s; opacity: 0.55;
}
.tree details[open] > summary::after { transform: rotate(45deg); }
.tree summary:active { background: var(--press); }
@media (hover: hover) { .tree summary:hover { background: var(--press); } }
.phase-num {
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--press); color: var(--muted); font-size: 13px; font-weight: 700;
}
.phase-num.on { background: var(--navy); color: var(--card); }
.weeks { padding-left: 14px; border-left: 2px solid var(--line); margin-left: 28px; }
.week + .week { border-top: 0.5px solid var(--line); }
.week > summary { padding-left: 4px; min-height: 46px; }
.days { padding-bottom: 4px; }
.day-row { padding-left: 8px; gap: 10px; }
.day-row::before { left: 8px !important; }
.daynum {
  width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center;
  background: var(--press); font-size: 13px; font-weight: 600; color: var(--muted);
}
.day-row.is-today .daynum { background: var(--stamp); color: #fff; }
.day-row.is-today .title { color: var(--stamp); font-weight: 650; }
.mini { display: flex; align-items: center; gap: 7px; flex: none; }
.mini-bar { width: 40px; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.mini-bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.icon-clock { display: flex; }
.icon-clock svg { width: 18px; height: 18px; }
.words .word:first-child::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--line); }

.plan-head { background: var(--card); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.plan-head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }

/* ---------- Từ vựng ---------- */
.stats-card { margin-top: 12px; }
.stats { justify-content: space-around; padding: 15px 8px; }
.stat { text-align: center; }
.stat-v { font-size: 25px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12px; color: var(--muted); }
.search { margin: 14px 0 0; }
.search input {
  width: 100%; background: var(--card); border: 0; border-radius: 12px; padding: 12px 14px;
  font-size: 16px; box-shadow: var(--shadow);
}
.search input:focus { outline: 2px solid var(--navy); outline-offset: -1px; }

/* ---------- Ôn thẻ ---------- */
.flash {
  background: var(--card); border-radius: 18px; margin-top: 18px; padding: 28px 20px; box-shadow: var(--shadow);
  min-height: 58vh; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 16px;
}
.flash-word { font-size: 34px; font-weight: 700; margin-top: auto; letter-spacing: -0.01em; }
.flash-vi { font-size: 20px; }
.flash-ex { color: var(--muted); font-style: italic; max-width: 32em; }
.flash-actions { margin-top: auto; display: flex; gap: 12px; width: 100%; }
.flash.done { justify-content: center; }
.seal { color: var(--navy); }
.seal svg { width: 60px; height: 60px; }

/* ---------- Biểu mẫu ---------- */
.field select, .field input {
  background: var(--press); border: 0; border-radius: 9px; padding: 8px 10px; max-width: 62%;
}
.field input[type="number"] { width: 84px; text-align: right; }
.wide-field { padding-right: 16px; }
.wide-field input { flex: 1; max-width: none; width: 100%; padding: 12px 14px; }
.seg { display: flex; width: 100%; background: var(--press); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 9px; font-size: 14px; font-weight: 550; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 0 28%; }
.mock-form { position: relative; }
.chip { font-size: 13px; font-variant-numeric: tabular-nums; }
.mock { gap: 10px; }
.plan-row { gap: 8px; }
.plan-pick { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; overflow: hidden; flex: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Trang viết ---------- */
.writer { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.writer .q { margin: 0; font-size: 15px; }
.wbar { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.writer textarea {
  width: 100%; min-height: 48vh; resize: vertical; padding: 14px; border-radius: 14px;
  border: 0; background: var(--card); line-height: 1.55; font-size: 16px; box-shadow: var(--shadow);
}
.writer textarea:focus { outline: 2px solid var(--navy); outline-offset: -1px; }
.writer .note { margin: 0 4px; }

/* ---------- Màn chào và đăng nhập ---------- */
body.gated .tabbar { display: none; }
body.gated { padding-bottom: 28px; }
.auth { max-width: 430px; margin: 6px auto 0; display: flex; flex-direction: column; gap: 12px; }
.auth .brand { font-size: 30px; font-weight: 700; color: var(--navy); margin: 10px 0 0; letter-spacing: -0.02em; }
.auth > .muted { margin: 0; }
.auth .sec-h { margin: 6px 0 0 4px; }
.auth-seg { margin-top: 4px; }
.auth-form { display: block; padding-bottom: 8px; }
.auth-form .row + .row::before { display: none; }
.auth-form input { background: var(--press); border-radius: 11px; }
.auth .note { margin: 0 4px; }
.or { height: 2px; }
.lang-link { align-self: flex-start; margin-top: 4px; }
.lang-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.lang-tile {
  display: flex; align-items: center; gap: 9px; background: var(--card); border-radius: 13px;
  padding: 13px 14px; font-weight: 550; box-shadow: var(--shadow); border: 2px solid transparent;
  text-align: left;
}
.lang-tile.on { border-color: var(--navy); color: var(--navy); }

/* ---------- Bảng chọn ---------- */
.sheet-wrap {
  position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-end; justify-content: center; padding: 0 8px 8px;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 520px; border-radius: 18px; padding: 6px 0 8px;
  max-height: 72vh; overflow: auto; animation: rise 0.18s ease;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
@keyframes rise { from { transform: translateY(14px); } }
.sheet h3 { margin: 12px 16px 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.sheet .row { min-height: 50px; }

/* ---------- Thanh tab ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--bar-bg);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 0.5px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; max-width: 136px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; color: var(--muted); padding: 2px 0;
}
.tabbar a.on { color: var(--navy); font-weight: 650; }
.tabbar svg { width: 25px; height: 25px; }

code { font-size: 13px; background: var(--press); padding: 1px 5px; border-radius: 5px; }
@media (min-width: 720px) { .topbar h1 { font-size: 31px; } }

/* ---------- Thư viện học trong app ---------- */
.lib-bar { gap: 10px; flex-wrap: wrap; }
.lib-bar .text-btn { flex: 0 0 auto; }
.seg.small-seg { width: auto; flex: 1 1 180px; }
.seg.small-seg button { padding: 6px 8px; font-size: 13px; }

.lib-line { transition: background 0.18s ease; border-radius: 8px; }
.lib-line.on { background: color-mix(in srgb, var(--navy) 12%, transparent); }
@supports not (color: color-mix(in srgb, red, blue)) {
  .lib-line.on { background: var(--press); }
}
.lib-line.on > .grow > div:last-child { font-weight: 600; }

.qblock + .qblock { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.q-text { align-items: flex-start; gap: 8px; }
.q-text .num { color: var(--navy); flex: 0 0 auto; }
.opts { display: flex; flex-direction: column; gap: 6px; padding: 4px 0 2px; }
.opt {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border-radius: 10px; text-align: left;
  background: var(--press); color: var(--text); font-size: 15px; line-height: 1.35;
}
.opt-mark {
  flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); font-size: 12px; font-weight: 700; color: var(--muted);
}
.opt.on { box-shadow: inset 0 0 0 2px var(--navy); }
.opt.on .opt-mark { background: var(--navy); color: #fff; }
.opt.ok { box-shadow: inset 0 0 0 2px var(--ok); }
.opt.ok .opt-mark { background: var(--ok); color: #fff; }
.opt.bad { box-shadow: inset 0 0 0 2px var(--stamp); }
.opt.bad .opt-mark { background: var(--stamp); color: #fff; }
.why { align-items: flex-start; gap: 6px; font-size: 14px; color: var(--muted); }
.why b { color: var(--text); }

.model .grow p { margin: 0 0 10px; }
.model .grow p:last-child { margin-bottom: 0; }

.chips { flex-wrap: wrap; gap: 8px; }
.chip-btn {
  padding: 7px 12px; border-radius: 999px; background: var(--press);
  color: var(--text); font-size: 15px; font-weight: 500;
}
.chip-btn.on { background: var(--navy); color: #fff; }

/* ---------- Đề thi thử ---------- */
.gap-input {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 16px;
}
.gap-input:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(61, 81, 153, 0.18); }
.gap-input.ok { border-color: var(--ok); }
.gap-input.bad { border-color: var(--stamp); }
.gap-input:disabled { opacity: 1; }

.scroll-x { overflow-x: auto; }
.data-table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.data-table th, .data-table td { padding: 6px 9px; border: 1px solid var(--line); text-align: right; white-space: nowrap; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { font-weight: 650; background: var(--press); }

.row.col.small span { display: block; }
.link-row .small.ok { color: var(--ok); font-variant-numeric: tabular-nums; }
.link-row .small.accent { color: var(--navy); }
