/* ==========================================================================
   Đích — luyện thi tiếng Anh có AI
   Hệ thiết kế "học tập có thưởng": nút có gờ bấm lún, viền 2px, bo góc lớn,
   màu mã hoá theo kỹ năng. Mobile-first, không phone frame, chỉ theme sáng.
   ========================================================================== */

:root {
  /* ---- nền và chữ ---- */
  --bg:        oklch(97.5% 0.005 250);
  --surface:   oklch(100% 0 0);
  --surface-2: oklch(96% 0.007 250);
  --surface-sub: oklch(93.5% 0.009 250);
  --fg:        oklch(32% 0.025 258);
  --fg-soft:   oklch(43% 0.022 258);
  --muted:     oklch(46% 0.02 258);
  --border:        oklch(90.5% 0.008 255);
  --border-strong: oklch(85% 0.012 255);

  /* ---- hành động chính: xanh ngọc "đi tiếp" ----
     Mọi nền đặc mang chữ trắng đều giữ L = 48%: đó là mức sáng cao nhất
     mà chữ trắng 15px vẫn vượt 4.5:1. Độ rực do chroma gánh, không do L. */
  --primary:      oklch(48% 0.15 155);
  --primary-edge: oklch(38% 0.13 155);
  --primary-soft: oklch(95.5% 0.045 155);
  --primary-ink:  oklch(41% 0.13 155);

  /* ---- sai / cảnh báo ---- */
  --danger:      oklch(48% 0.19 27);
  --danger-edge: oklch(38% 0.16 27);
  --danger-soft: oklch(96% 0.035 27);
  --danger-ink:  oklch(43% 0.18 27);

  /* ---- XP, chuỗi ngày ---- */
  --gold:      oklch(70% 0.145 82);
  --gold-soft: oklch(96% 0.05 88);
  --gold-ink:  oklch(45% 0.11 75);

  /* ---- bốn kỹ năng: danh tính màu, không phải trang trí ---- */
  --sk-listen: oklch(48% 0.185 295);  --sk-listen-soft: oklch(96% 0.035 295);
  --sk-read:   oklch(48% 0.155 250);  --sk-read-soft:   oklch(96% 0.032 250);
  --sk-write:  oklch(48% 0.115 68);   --sk-write-soft:  oklch(96% 0.035 75);
  --sk-speak:  oklch(48% 0.185 345);  --sk-speak-soft:  oklch(96% 0.035 345);

  /* ---- bí danh giữ tương thích với style riêng của từng trang ---- */
  --accent:     var(--primary);
  --accent-solid: var(--primary);
  --accent-solid-hover: var(--primary-edge);
  --success:    var(--primary-ink);
  --success-bg: var(--primary-soft);
  --warn:       var(--gold);
  --warn-bg:    var(--gold-soft);
  --danger-bg:  var(--danger-soft);

  --font-display: 'Baloo 2', 'Avenir Next', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-body:    'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;

  --r-sm: 12px;
  --r:    16px;
  --r-lg: 22px;
  --r-pill: 999px;

  --edge: 4px;              /* độ dày gờ dưới nút */
  --pad: 16px;
  --nav-h: 66px;
  --shadow-card: 0 2px 0 var(--border-strong);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 800;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.005em;
}
h1 { font-size: clamp(28px, 7vw, 38px); line-height: 1.14; letter-spacing: -0.015em; }
h2 { font-size: clamp(21px, 5vw, 26px); letter-spacing: -0.01em; }
h3 { font-size: 18.5px; font-weight: 700; }
p  { margin: 0; }
a  { color: inherit; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--sk-read);
  outline-offset: 2px;
  border-radius: 6px;
}

.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------------------------------------------------- */

.app { min-height: 100dvh; display: flex; flex-direction: column; }

.wrap { width: 100%; max-width: 560px; margin: 0 auto; padding: 0 var(--pad); }

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
}
.topbar-in {
  display: flex; align-items: center; gap: 12px;
  min-height: 60px; padding-top: 7px; padding-bottom: 7px;
}
.topbar-title {
  font-family: var(--font-display);
  font-weight: 700; font-size: 17px;
  min-width: 0; flex: 1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-sub {
  display: block;
  font-family: var(--font-body);
  font-weight: 400; font-size: 12.5px;
  letter-spacing: 0.01em; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.screen { flex: 1; padding-top: 20px; padding-bottom: calc(var(--nav-h) + 30px); }
.screen--nonav { padding-bottom: 44px; }

/* ---------- wordmark + linh vật hình học ------------------------------ */

.mark {
  display: inline-flex; align-items: center; gap: 9px;
  text-decoration: none;
  font-family: var(--font-display); font-weight: 800; font-size: 19px;
  letter-spacing: -0.01em;
}
.mark-glyph {
  width: 32px; height: 32px; flex: none;
  border-radius: 11px;
  background: var(--primary);
  box-shadow: 0 3px 0 var(--primary-edge);
  color: oklch(100% 0 0);
  display: grid; place-items: center;
}
.mark-glyph svg { width: 18px; height: 18px; }

/* avatar trợ lý: khối bo tròn + hai mắt, dựng bằng hình học chứ không vẽ tay */
.avatar {
  width: 36px; height: 36px; flex: none;
  border-radius: 12px;
  background: var(--sk-read);
  box-shadow: 0 3px 0 oklch(38% 0.14 250);
  color: oklch(100% 0 0);
  display: grid; place-items: center;
  margin-top: 2px;
}
.avatar svg { width: 20px; height: 20px; }

/* ---------- nút có gờ : chuyển động chủ đạo --------------------------- */

.btn {
  --btn-bg:   var(--surface-2);
  --btn-fg:   var(--fg);
  --btn-edge: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 52px; padding: 13px 22px;
  line-height: 1.25; text-align: center;
  border: 0; border-radius: var(--r);
  background: var(--btn-bg); color: var(--btn-fg);
  box-shadow: 0 var(--edge) 0 var(--btn-edge);
  font-family: var(--font-display);
  font-weight: 700; font-size: 15px;
  text-transform: uppercase; letter-spacing: 0.06em;
  cursor: pointer; text-decoration: none;
  transition: filter .12s ease, transform .06s ease, box-shadow .06s ease;
}
.btn:hover { filter: brightness(0.94); }
.btn:active { transform: translateY(var(--edge)); box-shadow: 0 0 0 var(--btn-edge); }

.btn--primary { --btn-bg: var(--primary); --btn-fg: oklch(100% 0 0); --btn-edge: var(--primary-edge); }
.btn--danger  { --btn-bg: var(--danger);  --btn-fg: oklch(100% 0 0); --btn-edge: var(--danger-edge); }

.btn--outline {
  --btn-bg: var(--surface);
  --btn-fg: var(--fg-soft);
  --btn-edge: var(--border-strong);
  border: 2px solid var(--border-strong);
  box-shadow: 0 var(--edge) 0 var(--border-strong);
}
.btn--outline:hover { --btn-fg: var(--fg); background: var(--surface-2); filter: none; }

.btn--ghost {
  --btn-bg: transparent; --btn-edge: transparent;
  color: var(--muted); box-shadow: none;
}
.btn--ghost:hover { background: var(--surface-2); color: var(--fg); filter: none; }
.btn--ghost:active { transform: none; }

.btn--block { width: 100%; }
.btn--sm { min-height: 44px; padding: 10px 16px; font-size: 13.5px; --edge: 3px; }

.btn:disabled, .btn[aria-disabled="true"] {
  --btn-bg: var(--surface-sub);
  --btn-fg: oklch(64% 0.012 258);
  --btn-edge: transparent;
  cursor: not-allowed; transform: none; filter: none;
}

.icon-btn {
  width: 46px; height: 46px; flex: none;
  display: grid; place-items: center;
  border-radius: 14px;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-soft);
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--fg); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:disabled { color: oklch(70% 0.01 258); background: var(--surface-sub); border-color: var(--border); cursor: not-allowed; }

/* ---------- thanh XP / chuỗi ngày ------------------------------------- */

.hud { display: flex; gap: 8px; align-items: center; }
.hud-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px 5px 8px;
  border-radius: var(--r-pill);
  font-family: var(--font-display); font-weight: 700; font-size: 14.5px;
  font-variant-numeric: tabular-nums;
  border: 2px solid transparent;
}
.hud-pill svg { width: 17px; height: 17px; flex: none; }
.hud-pill--streak { background: var(--gold-soft); border-color: oklch(89% 0.07 85); color: var(--gold-ink); }
.hud-pill--xp     { background: var(--sk-read-soft); border-color: oklch(89% 0.06 250); color: oklch(41% 0.15 250); }

/* ---------- chat ------------------------------------------------------ */

.thread { display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 11px; align-items: flex-start; }
.msg--user { justify-content: flex-end; }

.bubble {
  max-width: min(84%, 430px);
  padding: 13px 16px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 2px solid var(--border);
  font-size: 15.5px; line-height: 1.55;
}
.bubble p + p { margin-top: 9px; }
.msg--ai .bubble { border-bottom-left-radius: 7px; }
.msg--user .bubble {
  background: var(--primary-soft);
  border-color: oklch(88% 0.07 155);
  color: var(--primary-ink);
  font-weight: 500;
  border-bottom-right-radius: 7px;
}
.bubble strong { font-weight: 600; }
.bubble .hint { display: block; margin-top: 7px; font-size: 13px; color: var(--muted); letter-spacing: 0.01em; }

/* ---------- form-card : khối form nằm trong luồng chat ---------------- */

.form-card {
  margin-left: 47px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.form-card--full { margin-left: 0; }

.form-card__head {
  padding: 13px 17px 11px;
  background: var(--surface-2);
  border-bottom: 2px solid var(--border);
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.form-card__eyebrow {
  font-family: var(--font-display);
  font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.09em; font-weight: 700; color: var(--muted);
}
.form-card__step { margin-left: auto; font-size: 12px; letter-spacing: 0.02em; color: var(--muted); }
.form-card__body { padding: 16px 17px 18px; }
.form-card__foot {
  padding: 14px 17px 16px;
  border-top: 2px solid var(--border);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
}
.form-card__foot .btn { flex: 1 1 auto; }

.field + .field { margin-top: 18px; }
.field__label {
  display: block;
  font-family: var(--font-display); font-weight: 700;
  font-size: 14.5px; margin-bottom: 10px;
}
.field__note { font-size: 12.5px; color: var(--muted); letter-spacing: 0.01em; margin-top: 9px; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 9px; }

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 46px; padding: 0 16px;
  border-radius: var(--r-pill);
  border: 2px solid var(--border-strong);
  box-shadow: 0 3px 0 var(--border-strong);
  background: var(--surface);
  color: var(--fg-soft);
  font-family: var(--font-display); font-weight: 700;
  font-size: 14.5px; letter-spacing: 0.015em;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, background-color .12s ease, color .12s ease, border-color .12s ease;
}
.chip:hover { background: var(--surface-2); color: var(--fg); }
.chip:active { transform: translateY(3px); box-shadow: 0 0 0 var(--border-strong); }
.chip[aria-pressed="true"], .chip.is-on {
  background: var(--primary-soft);
  border-color: var(--primary);
  box-shadow: 0 3px 0 var(--primary);
  color: var(--primary-ink);
}
.chip[aria-pressed="true"]:hover { background: oklch(93% 0.06 155); color: var(--primary-ink); }
.chip__meta { font-family: var(--font-body); font-size: 12px; font-weight: 400; opacity: .78; }

/* ---------- hàng lựa chọn / đáp án ------------------------------------ */

.opts { display: flex; flex-direction: column; gap: 10px; }

.opt {
  display: flex; gap: 13px; align-items: flex-start;
  width: 100%; text-align: left;
  padding: 14px 15px;
  border-radius: var(--r);
  border: 2px solid var(--border-strong);
  box-shadow: 0 3px 0 var(--border-strong);
  background: var(--surface);
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, background-color .12s ease, border-color .12s ease;
}
.opt:hover { background: var(--surface-2); }
.opt:active { transform: translateY(3px); box-shadow: 0 0 0 var(--border-strong); }

.opt__key {
  width: 30px; height: 30px; flex: none;
  border-radius: 10px;
  background: var(--surface-sub);
  color: var(--fg-soft);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 14px;
  margin-top: 1px;
}
.opt__text { min-width: 0; flex: 1; }
.opt__title { font-size: 15.5px; font-weight: 500; }
.opt__desc { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }

.opt.is-on {
  border-color: var(--sk-read); box-shadow: 0 3px 0 var(--sk-read);
  background: var(--sk-read-soft);
}
.opt.is-on .opt__key { background: var(--sk-read); color: oklch(100% 0 0); }

.opt.is-correct {
  border-color: var(--primary); box-shadow: 0 3px 0 var(--primary);
  background: var(--primary-soft);
}
.opt.is-correct .opt__key { background: var(--primary); color: oklch(100% 0 0); }
.opt.is-wrong {
  border-color: var(--danger); box-shadow: 0 3px 0 var(--danger);
  background: var(--danger-soft);
}
.opt.is-wrong .opt__key { background: var(--danger); color: oklch(100% 0 0); }

.opt__tag {
  margin-left: auto; flex: none; align-self: center;
  font-family: var(--font-display);
  font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase;
}
.opt.is-correct .opt__tag { color: var(--primary-ink); }
.opt.is-wrong .opt__tag { color: var(--danger-ink); }

/* ---------- ô nhập ---------------------------------------------------- */

.input, .textarea {
  width: 100%; min-height: 52px;
  padding: 13px 16px;
  border-radius: var(--r);
  border: 2px solid var(--border-strong);
  background: var(--surface);
  transition: border-color .12s ease;
}
.textarea { min-height: 112px; resize: vertical; line-height: 1.55; }
.input:hover, .textarea:hover { border-color: oklch(75% 0.015 255); }
.input::placeholder, .textarea::placeholder { color: var(--muted); }

.err { display: none; margin-top: 8px; font-size: 13.5px; font-weight: 500; color: var(--danger-ink); }
.field.has-err .input, .field.has-err .textarea { border-color: var(--danger); }
.field.has-err .err { display: block; }

/* ---------- thẻ ------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
}
.card__title { font-size: 17px; }

.section { margin-top: 28px; }
.section__head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 13px; }
.section__head h2 { font-size: 20px; }
.section__more {
  margin-left: auto;
  font-family: var(--font-display); font-weight: 700;
  font-size: 13.5px; color: var(--primary-ink);
  text-decoration: none;
  border-bottom: 2px solid oklch(88% 0.07 155);
  padding-bottom: 1px;
}
.section__more:hover { border-color: var(--primary); }

.eyebrow {
  font-family: var(--font-display);
  font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.09em; font-weight: 700; color: var(--muted);
}

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 2px solid var(--border);
  font-family: var(--font-display); font-weight: 700;
  font-size: 12.5px; letter-spacing: 0.02em;
  color: var(--fg-soft);
}
.badge--live { background: var(--primary-soft); border-color: oklch(88% 0.07 155); color: var(--primary-ink); }
.badge--warn { background: var(--gold-soft); border-color: oklch(89% 0.07 85); color: var(--gold-ink); }
.badge--demo { background: transparent; border-style: dashed; color: var(--muted); }

/* ---------- số liệu và thanh ------------------------------------------ */

.stat-row { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
  flex: 1 1 120px; min-width: 0;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r);
  padding: 13px 14px;
}
.stat__k { font-size: 12px; color: var(--muted); letter-spacing: 0.02em; }
.stat__v {
  font-family: var(--font-display); font-size: 28px; font-weight: 800;
  letter-spacing: -0.02em; line-height: 1.1; margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.stat__d { font-size: 12.5px; color: var(--muted); margin-top: 3px; letter-spacing: 0.01em; }

.bar-list { display: flex; flex-direction: column; gap: 17px; }
.bar-row__top { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.bar-row__name { font-family: var(--font-display); font-weight: 700; font-size: 15.5px; }
.bar-row__val {
  margin-left: auto;
  font-family: var(--font-display); font-weight: 800; font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.bar {
  position: relative; height: 16px;
  border-radius: var(--r-pill);
  background: var(--surface-sub);
  overflow: hidden;
}
.bar__fill {
  position: absolute; inset: 0 auto 0 0;
  border-radius: var(--r-pill);
  background: var(--fg-soft);
}
/* vệt sáng mỏng phía trên — làm thanh trông dày và tròn khối */
.bar__fill::after {
  content: ""; position: absolute;
  left: 5px; right: 5px; top: 3px; height: 4px;
  border-radius: var(--r-pill);
  background: oklch(100% 0 0 / 0.34);
}
.bar__fill--focus { background: var(--primary); }
.bar__fill--listen { background: var(--sk-listen); }
.bar__fill--read   { background: var(--sk-read); }
.bar__fill--write  { background: var(--sk-write); }
.bar__fill--speak  { background: var(--sk-speak); }
.bar-row__foot { display: flex; gap: 8px; margin-top: 7px; font-size: 12.5px; color: var(--muted); letter-spacing: 0.01em; }
.bar-row__foot span:last-child { margin-left: auto; }

/* ô icon kỹ năng */
.sk-tile {
  width: 44px; height: 44px; flex: none;
  border-radius: 14px;
  display: grid; place-items: center;
  color: oklch(100% 0 0);
}
.sk-tile svg { width: 22px; height: 22px; }
.sk-tile--sm { width: 34px; height: 34px; border-radius: 11px; }
.sk-tile--sm svg { width: 18px; height: 18px; }
.sk-tile--listen { background: var(--sk-listen); box-shadow: 0 3px 0 oklch(38% 0.16 295); }
.sk-tile--read   { background: var(--sk-read);   box-shadow: 0 3px 0 oklch(38% 0.14 250); }
.sk-tile--write  { background: var(--sk-write);  box-shadow: 0 3px 0 oklch(38% 0.10 68); }
.sk-tile--speak  { background: var(--sk-speak);  box-shadow: 0 3px 0 oklch(38% 0.16 345); }

/* ---------- danh sách ------------------------------------------------- */

.rows { display: flex; flex-direction: column; }
.row {
  display: flex; gap: 13px; align-items: center;
  padding: 14px 0;
  border-bottom: 2px solid var(--border);
  text-decoration: none; color: inherit;
}
.row:last-child { border-bottom: 0; }
.row__main { min-width: 0; flex: 1; }
.row__title { font-family: var(--font-display); font-weight: 700; font-size: 15.5px; }
.row__sub { font-size: 13px; color: var(--muted); margin-top: 2px; letter-spacing: 0.01em; }
.row__end { text-align: right; flex: none; }
.row__val {
  font-family: var(--font-display); font-weight: 800; font-size: 17px;
  font-variant-numeric: tabular-nums;
}
a.row:hover { background: var(--surface-2); }

/* ---------- tabs ------------------------------------------------------ */

.tabs {
  display: flex; gap: 5px; padding: 5px;
  background: var(--surface-sub);
  border-radius: var(--r-pill);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; min-height: 44px; padding: 0 16px;
  border: 0; border-radius: var(--r-pill);
  background: transparent; color: var(--fg-soft);
  font-family: var(--font-display); font-weight: 700;
  font-size: 14px; letter-spacing: 0.02em;
  cursor: pointer; white-space: nowrap;
  transition: background-color .12s ease, color .12s ease;
}
.tab:hover { background: oklch(89% 0.01 255); color: var(--fg); }
.tab[aria-selected="true"] {
  background: var(--surface); color: var(--fg);
  box-shadow: 0 2px 0 var(--border-strong);
}

/* ---------- điều hướng dưới ------------------------------------------- */

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface);
  border-top: 2px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-in { display: flex; max-width: 560px; margin: 0 auto; }
.nav-item {
  flex: 1; min-height: var(--nav-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--muted);
  font-family: var(--font-display); font-weight: 700;
  font-size: 11.5px; letter-spacing: 0.02em;
  transition: color .12s ease;
}
.nav-item__i {
  width: 46px; height: 30px;
  border-radius: var(--r-pill);
  display: grid; place-items: center;
  transition: background-color .12s ease;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item:hover { color: var(--fg); }
.nav-item:hover .nav-item__i { background: var(--surface-2); }
.nav-item[aria-current="page"] { color: var(--primary-ink); }
.nav-item[aria-current="page"] .nav-item__i { background: var(--primary-soft); }

/* ---------- sheet ----------------------------------------------------- */

.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: oklch(32% 0.025 258 / 0.44); display: none; }
.sheet-backdrop.is-open { display: block; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-width: 560px; margin: 0 auto;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border: 2px solid var(--border); border-bottom: 0;
  transform: translateY(102%);
  visibility: hidden;
  transition: transform .22s cubic-bezier(.32,.72,0,1), visibility .22s;
  max-height: 86dvh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.is-open { transform: translateY(0); visibility: visible; }
.sheet__grab { width: 44px; height: 5px; border-radius: 5px; background: var(--border-strong); margin: 11px auto 4px; }
.sheet__body { padding: 8px 17px 22px; }

/* ---------- thanh tiến độ --------------------------------------------- */

.progress {
  position: relative; height: 14px;
  border-radius: var(--r-pill);
  background: var(--surface-sub);
  overflow: hidden;
}
.progress__fill {
  height: 100%; background: var(--primary);
  border-radius: var(--r-pill);
  transition: width .35s cubic-bezier(.34,1.2,.64,1);
  position: relative;
}
.progress__fill::after {
  content: ""; position: absolute;
  left: 5px; right: 5px; top: 3px; height: 3px;
  border-radius: var(--r-pill);
  background: oklch(100% 0 0 / 0.34);
}
.progress--xp .progress__fill { background: var(--gold); }
.progress--slim { height: 8px; }
.progress--slim .progress__fill::after { display: none; }

/* ---------- bảng câu hỏi ---------------------------------------------- */

.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
.pal-btn {
  aspect-ratio: 1; min-height: 46px;
  border-radius: 13px;
  border: 2px solid var(--border-strong);
  box-shadow: 0 2px 0 var(--border-strong);
  background: var(--surface); color: var(--fg-soft);
  font-family: var(--font-display); font-weight: 700; font-size: 14.5px;
  font-variant-numeric: tabular-nums; cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}
.pal-btn:hover { background: var(--surface-2); color: var(--fg); }
.pal-btn.is-done { background: var(--primary); border-color: var(--primary); box-shadow: 0 2px 0 var(--primary-edge); color: oklch(100% 0 0); }
.pal-btn.is-flag { border-color: var(--gold); background: var(--gold-soft); box-shadow: 0 2px 0 var(--gold); color: var(--gold-ink); }
.pal-btn.is-now  { outline: 3px solid var(--fg); outline-offset: 2px; }

/* ---------- đường đi bài học ------------------------------------------ */

.path { display: flex; flex-direction: column; align-items: center; gap: 34px; padding: 36px 0 10px; }

/* mỗi chặng lệch ngang một chút để đường đi uốn cong thay vì xếp thẳng cột */
.path-step {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  width: 148px;
  transform: translateX(var(--dx, 0));
}
.path-step__cap { text-align: center; }

.path-node {
  position: relative;
  width: 78px; height: 72px;
  border: 0; border-radius: 50% / 46%;
  display: grid; place-items: center;
  cursor: pointer;
  color: oklch(100% 0 0);
  background: var(--surface-sub);
  box-shadow: 0 6px 0 var(--border-strong);
  transition: transform .07s ease, box-shadow .07s ease;
}
.path-node:active { transform: translateY(6px); box-shadow: 0 0 0 var(--border-strong); }
.path-node svg { width: 30px; height: 30px; }
.path-node--listen { background: var(--sk-listen); box-shadow: 0 6px 0 oklch(38% 0.16 295); }
.path-node--read   { background: var(--sk-read);   box-shadow: 0 6px 0 oklch(38% 0.14 250); }
.path-node--write  { background: var(--sk-write);  box-shadow: 0 6px 0 oklch(38% 0.10 68); }
.path-node--speak  { background: var(--sk-speak);  box-shadow: 0 6px 0 oklch(38% 0.16 345); }
.path-node--done   { background: var(--primary);   box-shadow: 0 6px 0 var(--primary-edge); }
.path-node--lock   { background: var(--surface-sub); color: oklch(50% 0.015 258); box-shadow: 0 6px 0 var(--border-strong); cursor: not-allowed; }
.path-node--lock:active { transform: none; box-shadow: 0 6px 0 var(--border-strong); }

.path-step__n { font-family: var(--font-display); font-weight: 700; font-size: 14.5px; line-height: 1.3; }
.path-step__d { font-size: 12.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.path-now {
  position: absolute; top: -28px; left: 50%; transform: translateX(-50%);
  padding: 4px 11px; border-radius: var(--r-pill);
  background: var(--surface); border: 2px solid var(--border-strong);
  font-family: var(--font-display); font-weight: 700; font-size: 11px;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--fg); white-space: nowrap;
}

/* ---------- mã chương trình ------------------------------------------- */

.code-box {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 15px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--r);
  background: var(--surface-2);
}
.code-box__t { min-width: 0; flex: 1; }
.code-box__k {
  font-family: var(--font-display); font-weight: 700;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted);
}
.code-box__v {
  display: block; margin-top: 3px;
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(21px, 5.6vw, 26px);
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* hàng chương trình: ô icon + tên + siêu dữ liệu, dùng chung ở hub và sheet */
.prog {
  display: flex; gap: 13px; align-items: flex-start;
  width: 100%; text-align: left;
  padding: 14px 15px;
  border: 2px solid var(--border-strong);
  box-shadow: 0 3px 0 var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  cursor: pointer;
  transition: transform .06s ease, box-shadow .06s ease, background-color .12s ease, border-color .12s ease;
}
.prog:hover { background: var(--surface-2); }
.prog:active { transform: translateY(3px); box-shadow: 0 0 0 var(--border-strong); }
.prog.is-on {
  border-color: var(--primary); box-shadow: 0 3px 0 var(--primary);
  background: var(--primary-soft);
}
.prog--static { cursor: default; }
.prog--static:hover { background: var(--surface); }
.prog--static:active { transform: none; box-shadow: 0 3px 0 var(--border-strong); }

.prog__t { min-width: 0; flex: 1; }
.prog__n { font-family: var(--font-display); font-weight: 700; font-size: 15.5px; line-height: 1.3; }
.prog__o { font-size: 13px; color: var(--muted); margin-top: 3px; }
.prog__m { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 9px; }
.prog__end { flex: none; align-self: center; color: var(--muted); }
.prog__end svg { width: 18px; height: 18px; display: block; }

.empty-note {
  padding: 22px 16px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--r);
  text-align: center;
  font-size: 14px; color: var(--muted); line-height: 1.55;
}

/* ---------- công tắc -------------------------------------------------- */

.switch-row {
  display: flex; gap: 13px; align-items: flex-start;
  padding: 14px 15px;
  border: 2px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
}
.switch-row__t { min-width: 0; flex: 1; }
.switch-row__n { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.switch-row__d { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }

.switch {
  flex: none; position: relative;
  width: 58px; height: 34px;
  border: 0; border-radius: var(--r-pill);
  background: var(--surface-sub);
  /* viền tắt phải đạt 3:1 với nền thẻ trắng, nếu không trạng thái tắt gần như vô hình */
  box-shadow: inset 0 0 0 2px oklch(58% 0.018 258);
  cursor: pointer; padding: 0;
  transition: background-color .14s ease, box-shadow .14s ease;
}
.switch::after {
  content: ""; position: absolute;
  top: 4px; left: 4px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 2px 0 var(--border-strong);
  transition: transform .16s cubic-bezier(.34,1.3,.64,1);
}
.switch[aria-checked="true"] {
  background: var(--primary);
  box-shadow: inset 0 0 0 2px var(--primary-edge);
}
.switch[aria-checked="true"]::after { transform: translateX(24px); box-shadow: 0 2px 0 var(--primary-edge); }
.switch:disabled { cursor: not-allowed; opacity: .55; }

/* ---------- trình phát video ------------------------------------------ */

.vplayer {
  border: 2px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  overflow: hidden;
}
.vplayer__stage {
  position: relative;
  aspect-ratio: 16 / 9;
  background: oklch(26% 0.022 258);
  display: grid; place-items: center;
}
/* vùng bấm phủ kín khung; nút tròn chỉ là hình, hiện khi đang dừng —
   nhờ vậy dải phụ đề không bao giờ đè lên nút */
.vplayer__hit {
  position: absolute; inset: 0;
  border: 0; background: transparent;
  cursor: pointer; padding: 0;
}
.vplayer__play {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: var(--sk-listen);
  box-shadow: 0 5px 0 oklch(38% 0.16 295);
  color: oklch(100% 0 0);
  display: grid; place-items: center;
  pointer-events: none;
  transition: opacity .16s ease, transform .07s ease, box-shadow .07s ease;
}
.vplayer__play svg { width: 30px; height: 30px; }
.vplayer.is-playing .vplayer__play { opacity: 0; }
.vplayer__hit:active + .vplayer__play,
.vplayer__hit:active ~ .vplayer__play { transform: translateY(5px); box-shadow: 0 0 0 oklch(38% 0.16 295); }
.vplayer__hit:focus-visible { outline-offset: -4px; }

.vplayer__time {
  position: absolute; right: 10px; bottom: 10px;
  padding: 3px 10px; border-radius: var(--r-pill);
  background: oklch(18% 0.02 258 / 0.82);
  color: oklch(97% 0 0);
  font-family: var(--font-display); font-weight: 700; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
/* Phụ đề chỉ hiện khi clip đang chạy — lúc dừng, nút phát chiếm giữa khung
   nên hai thứ này không bao giờ cùng lúc chiếm một chỗ. */
.vplayer__cc {
  display: none;
  position: absolute; left: 12px; right: 12px; bottom: 40px;
  padding: 9px 13px; border-radius: 12px;
  background: oklch(18% 0.02 258 / 0.88);
  color: oklch(97% 0 0);
  font-size: 14px; line-height: 1.45; text-align: center;
}
.vplayer.is-playing .vplayer__cc { display: block; }
.vplayer.is-playing .vplayer__cc:empty { display: none; }

.vplayer__bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: oklch(34% 0.02 258); }
/* trên nền tối, tím L48 chỉ hơn rãnh 1.6:1 — nâng lên L68 để đạt 3:1 */
.vplayer__bar span { display: block; height: 100%; width: 0; background: oklch(68% 0.16 295); }

.vplayer__meta {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-top: 2px solid var(--border);
  flex-wrap: wrap;
}
.vplayer__title { min-width: 0; flex: 1; font-family: var(--font-display); font-weight: 700; font-size: 14.5px; }
.vplayer__sub { display: block; font-family: var(--font-body); font-weight: 400; font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- màn ăn mừng ----------------------------------------------- */

.celebrate {
  text-align: center;
  padding: 26px 18px 22px;
  border-radius: var(--r-lg);
  border: 2px solid var(--border);
  background: var(--surface);
}
.celebrate__ring {
  width: 108px; height: 108px; margin: 0 auto 16px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary-soft);
  border: 5px solid var(--primary);
}
.celebrate__ring span {
  font-family: var(--font-display); font-weight: 800; font-size: 34px;
  color: var(--primary-ink); font-variant-numeric: tabular-nums; line-height: 1;
}
.celebrate__ring--warn { background: var(--gold-soft); border-color: var(--gold); }
.celebrate__ring--warn span { color: var(--gold-ink); }
.reward-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }
.reward {
  flex: 1 1 110px; max-width: 190px;   /* 110 để hai ô vẫn nằm cạnh nhau bên trong form-card ở 360px */
  border: 2px solid var(--border); border-radius: var(--r);
  padding: 12px 10px;
}
.reward__k { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; font-family: var(--font-display); color: var(--muted); }
.reward__v { font-family: var(--font-display); font-weight: 800; font-size: 24px; margin-top: 4px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.reward--xp .reward__v { color: var(--gold-ink); }
.reward--streak .reward__v { color: var(--sk-speak); }

/* ---------- linh tinh -------------------------------------------------- */

.divider { height: 2px; background: var(--border); border: 0; margin: 24px 0; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; letter-spacing: 0.01em; }
.stack-8  { display: flex; flex-direction: column; gap: 8px; }
.stack-12 { display: flex; flex-direction: column; gap: 12px; }
.stack-16 { display: flex; flex-direction: column; gap: 16px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.passage {
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: var(--r);
  padding: 15px;
  font-size: 15px; line-height: 1.62;
  max-height: 220px; overflow-y: auto;
}
.passage h4 { font-size: 14.5px; margin-bottom: 9px; }
.passage p + p { margin-top: 10px; }

.q-stem { font-size: 18px; line-height: 1.48; font-weight: 500; }

.note {
  border: 2px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 14px 15px;
  font-size: 14.5px; line-height: 1.58;
}
.note__head {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--font-display);
  font-size: 11.5px; text-transform: uppercase;
  letter-spacing: 0.09em; font-weight: 700; color: var(--muted);
  margin-bottom: 9px;
}
.note__head svg { width: 15px; height: 15px; }
.note--good { background: var(--primary-soft); border-color: oklch(88% 0.07 155); }
.note--good .note__head { color: var(--primary-ink); }

.kbd {
  display: inline-block; padding: 2px 7px;
  border-radius: 7px; border: 2px solid var(--border-strong);
  background: var(--surface);
  font-family: var(--font-display); font-size: 12px; font-weight: 700;
  letter-spacing: 0.02em; color: var(--fg-soft);
}

/* ---------- responsive ------------------------------------------------- */

@media (min-width: 900px) {
  :root { --pad: 24px; }
  .wrap { max-width: 720px; }
  .nav-in { max-width: 720px; }
  .sheet { max-width: 720px; border-radius: var(--r-lg); }
  .bubble { max-width: min(76%, 520px); }
}

@media (min-width: 1180px) {
  .wrap { max-width: 860px; }
  .nav-in { max-width: 860px; }
}

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