/* ==========================================================================
   Lingo — components.css (WP0). Nguồn: design/components.css (bỏ phần chỉ dành cho mockup:
   .theme-fab, .modal-preview; reset chuyển sang base.css). Chỉ dùng biến trong base.css.
   Quy ước tên: BEM rút gọn — .block, .block__elem, .block--modifier;
   trạng thái do JS bật/tắt: .is-* (is-flipped, is-correct, is-wrong, is-active, is-locked…)
   Không hex trực tiếp ở file này (ngoại trừ trắng/đen trong hiệu ứng).
   ========================================================================== */

/* ---------- 1. Icon ---------- */
.icon { width: var(--icon-md); height: var(--icon-md); flex: none; }
.icon--sm { width: var(--icon-sm); height: var(--icon-sm); }
.icon--lg { width: var(--icon-lg); height: var(--icon-lg); }
.icon--xl { width: var(--icon-xl); height: var(--icon-xl); }
.icon--fill { fill: currentColor; }

/* ---------- 2. Typography helpers cho ngôn ngữ ---------- */
.text-muted { color: var(--text-muted); }
.text-subtle { color: var(--text-subtle); font-size: var(--text-sm); }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); }
.text-center { text-align: center; }
.display { font-family: var(--font-display); font-weight: var(--weight-black); }
.eyebrow { font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-subtle); }

.han { font-family: var(--font-han); line-height: var(--leading-han); font-weight: 500; }
.pinyin { font-family: var(--font-pinyin); letter-spacing: 0.01em; }
.ipa { font-family: var(--font-ipa); color: var(--text-muted); }
.hv { /* âm Hán-Việt */ font-family: var(--font-body); font-weight: var(--weight-semibold); text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--text-sm); color: var(--text-muted); }
.word-en { font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-word); line-height: 1.1; }

/* Thanh điệu: dùng cho cả span pinyin, chữ Hán, nút, đường đồ thị */
.tone-1 { color: var(--tone-1); } .tone-2 { color: var(--tone-2); }
.tone-3 { color: var(--tone-3); } .tone-4 { color: var(--tone-4); } .tone-5 { color: var(--tone-5); }
.tone-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.5rem; height: 1.5rem; padding: 0 var(--space-1); border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); font-family: var(--font-body); }
.tone-badge.tone-1 { background: var(--tone-1-bg); } .tone-badge.tone-2 { background: var(--tone-2-bg); }
.tone-badge.tone-3 { background: var(--tone-3-bg); } .tone-badge.tone-4 { background: var(--tone-4-bg); }
.tone-badge.tone-5 { background: var(--tone-5-bg); }
/* Trên thẻ: gạch dưới theo màu thanh để không chỉ dựa vào màu (dấu thanh + gạch) */
.syl { border-bottom: 3px solid currentColor; padding-bottom: 1px; }

/* ---------- 3. Layout ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.container { width: 100%; max-width: var(--content-max); margin-inline: auto; padding-inline: var(--gutter); }
.container--wide { max-width: var(--content-wide); }
.main { flex: 1; padding-block: var(--space-4) calc(var(--space-16) + 32px + env(safe-area-inset-bottom)); }
.main--no-nav { padding-bottom: var(--space-8); }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.stack--sm { gap: var(--space-2); } .stack--lg { gap: var(--space-6); } .stack--xl { gap: var(--space-8); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: var(--space-4); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.section-title h2 { font-size: var(--text-lg); }
@media (min-width: 1024px) {
  .layout-dash { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: var(--space-6); align-items: start; }
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: var(--z-sticky);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar__inner { display: flex; align-items: center; gap: var(--space-2); min-height: 56px; }
.topbar__title { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-lg); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: inline-flex; align-items: center; gap: var(--space-2); font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-xl); color: var(--primary); text-decoration: none; }
.brand__mark { width: 32px; height: 32px; border-radius: 10px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: 18px; box-shadow: 0 3px 0 var(--primary-shadow); }

/* ---------- 4. Buttons — "khối" có đáy dày, nhấn lún ---------- */
.btn {
  --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-edge: var(--primary-shadow); --btn-border: transparent;
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 48px; padding: 0 var(--space-5);
  border: 2px solid var(--btn-border); border-radius: var(--radius-md);
  background: var(--btn-bg); color: var(--btn-fg);
  font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-md); letter-spacing: 0.02em;
  text-decoration: none; user-select: none; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 var(--press-depth) 0 var(--btn-edge);
  transform: translateY(0);
  transition: transform var(--dur-instant) var(--ease-out), box-shadow var(--dur-instant) var(--ease-out), background-color var(--dur-fast), filter var(--dur-fast);
  margin-bottom: var(--press-depth); /* giữ chỗ cho đáy => không xô layout khi nhấn */
}
.btn:hover { filter: brightness(1.06); color: var(--btn-fg); }
.btn:active:not(:disabled) { transform: translateY(var(--press-depth)); box-shadow: 0 0 0 var(--btn-edge); }
.btn:disabled, .btn[aria-disabled="true"] { --btn-bg: var(--surface-3); --btn-fg: var(--text-subtle); --btn-edge: var(--border); cursor: not-allowed; filter: none; }
.btn--secondary { --btn-bg: var(--secondary); --btn-fg: var(--text); --btn-edge: var(--secondary-shadow); --btn-border: var(--secondary-border); }
.btn--ghost { --btn-bg: transparent; --btn-fg: var(--primary); --btn-edge: transparent; box-shadow: none; margin-bottom: 0; }
.btn--ghost:hover { background: var(--primary-soft); }
.btn--ghost:active:not(:disabled) { transform: none; }
.btn--success { --btn-bg: var(--success-strong); --btn-fg: var(--text-inverse); --btn-edge: var(--success-shadow); }
.btn--danger { --btn-bg: var(--danger-strong); --btn-fg: var(--text-inverse); --btn-edge: var(--danger-shadow); }
[data-theme="light"] .btn--success, [data-theme="light"] .btn--danger { --btn-fg: #fff; }
.btn--block { width: 100%; }
.btn--lg { min-height: 56px; font-size: var(--text-lg); border-radius: var(--radius-lg); }
.btn--sm { min-height: 40px; padding: 0 var(--space-4); font-size: var(--text-sm); --press-depth: 3px; }
.btn--icon { width: 48px; min-height: 48px; padding: 0; }
.btn--icon.btn--sm { width: 40px; }
.icon-btn { /* nút icon phẳng trên topbar */
  display: inline-grid; place-items: center; width: var(--tap-min); height: var(--tap-min);
  border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--text-muted);
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { background: var(--surface-3); }
.btn.is-loading { color: transparent; pointer-events: none; }
.btn.is-loading::after { content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--btn-fg); border-right-color: transparent; animation: spin 0.8s linear infinite; }

/* Nút nghe (âm thanh) */
.audio-btn {
  display: inline-grid; place-items: center; width: 56px; height: 56px; border-radius: var(--radius-pill);
  border: 0; background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 0 var(--primary-shadow);
  margin-bottom: 4px; transition: transform var(--dur-instant), box-shadow var(--dur-instant);
}
.audio-btn:active { transform: translateY(var(--press-depth)); box-shadow: 0 0 0 var(--primary-shadow); }
.audio-btn--sm { width: 44px; height: 44px; }
.audio-btn--lg { width: 88px; height: 88px; }
.audio-btn--lg .icon { width: 40px; height: 40px; }
.audio-btn--soft { background: var(--primary-soft); color: var(--primary-soft-text); box-shadow: 0 4px 0 var(--border); }
.audio-btn.is-playing { animation: pulse-ring 1.2s var(--ease-out) infinite; }

/* ---------- 5. Form ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.label { font-weight: var(--weight-semibold); font-size: var(--text-sm); }
.help { font-size: var(--text-sm); color: var(--text-subtle); }
.input {
  width: 100%; min-height: 52px; padding: var(--space-3) var(--space-4);
  border: 2px solid var(--border-input); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); font-size: var(--text-md); /* >=16px để iOS không zoom */
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input::placeholder { color: var(--text-subtle); }
.input:hover { border-color: var(--text-subtle); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.input[aria-invalid="true"] { border-color: var(--danger); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px var(--danger-bg); }
.input--answer { font-size: var(--text-xl); text-align: center; font-weight: var(--weight-semibold); min-height: 60px; }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 52px; }
.input-wrap__btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.field-error { display: flex; gap: var(--space-2); align-items: flex-start; color: var(--danger); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.field-error .icon { margin-top: 2px; }
.checkbox { display: inline-flex; align-items: center; gap: var(--space-3); min-height: var(--tap-min); cursor: pointer; }
.checkbox input { width: 22px; height: 22px; accent-color: var(--primary); }
.alert { display: flex; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--text-sm); }
.alert--danger { background: var(--danger-bg); color: var(--danger); }
.alert--info { background: var(--info-bg); color: var(--info); }
.alert--warning { background: var(--warning-bg); color: var(--warning); }

/* ---------- 6. Card ---------- */
.card {
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-5); box-shadow: var(--shadow-card-base);
}
.card--flat { box-shadow: none; }
.card--soft { background: var(--surface-2); border-color: transparent; box-shadow: none; }
.card--primary { background: var(--primary); color: var(--on-primary); border-color: transparent; box-shadow: 0 4px 0 var(--primary-shadow); }
.card--primary .text-muted { color: inherit; opacity: 0.85; }
.card--interactive { display: block; color: inherit; text-decoration: none; transition: transform var(--dur-instant), box-shadow var(--dur-instant), border-color var(--dur-fast); }
.card--interactive:hover { border-color: var(--primary); color: inherit; }
.card--interactive:active { transform: translateY(4px); box-shadow: 0 0 0 var(--border); }
.card__title { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-lg); }

/* ---------- 7. Thẻ từ vựng (lật) ---------- */
.vocab-card { perspective: 1200px; width: 100%; max-width: 26rem; margin-inline: auto; }
.vocab-card__inner {
  position: relative; display: grid; min-height: 22rem;
  transform-style: preserve-3d; transition: transform var(--dur-slow) var(--ease-out);
}
.vocab-card.is-flipped .vocab-card__inner { transform: rotateY(180deg); }
.vocab-card__face {
  grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-3);
  padding: var(--space-6) var(--space-5); text-align: center;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: 0 6px 0 var(--border), var(--shadow-md);
}
.vocab-card__face--back { transform: rotateY(180deg); justify-content: flex-start; }
.vocab-card__lang { position: absolute; top: var(--space-4); left: var(--space-4); }
.vocab-card__audio { position: absolute; top: var(--space-3); right: var(--space-3); }
.vocab-card__han { font-family: var(--font-han); font-size: var(--text-han); line-height: 1.1; font-weight: 500; }
.vocab-card__pinyin { font-family: var(--font-pinyin); font-size: var(--text-xl); font-weight: var(--weight-medium); }
.vocab-card__meaning { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-xl); }
.vocab-card__example { width: 100%; text-align: left; background: var(--surface-2); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); display: flex; gap: var(--space-3); align-items: flex-start; }
.vocab-card__example p { font-size: var(--text-md); }
.vocab-card__example .trans { color: var(--text-muted); font-size: var(--text-sm); }
.vocab-card__hint { font-size: var(--text-sm); color: var(--text-subtle); display: inline-flex; gap: var(--space-2); align-items: center; }
.cloze-blank { display: inline-block; min-width: 3.5em; border-bottom: 3px solid var(--primary); color: var(--primary); font-weight: var(--weight-semibold); text-align: center; }
.mark { background: var(--warning-bg); color: var(--text); border-radius: 4px; padding: 0 3px; font-weight: var(--weight-semibold); }
@media (prefers-reduced-motion: reduce) {
  .vocab-card__inner { transform: none !important; }
  .vocab-card__face--back { transform: none; visibility: hidden; }
  .vocab-card.is-flipped .vocab-card__face--front { visibility: hidden; }
  .vocab-card.is-flipped .vocab-card__face--back { visibility: visible; }
}

/* ---------- 8. 4 nút đánh giá ôn (FSRS) ---------- */
.rate-group { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
.rate-btn {
  --c: var(--text); --c-bg: var(--surface-2);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 64px; padding: var(--space-2) var(--space-1);
  border: 2px solid var(--c); border-radius: var(--radius-md);
  background: var(--c-bg); color: var(--c);
  font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-md);
  box-shadow: 0 4px 0 var(--c); margin-bottom: 4px;
  transition: transform var(--dur-instant), box-shadow var(--dur-instant);
}
.rate-btn:active { transform: translateY(var(--press-depth)); box-shadow: 0 0 0 var(--c); }
.rate-btn__interval { font-family: var(--font-body); font-weight: var(--weight-medium); font-size: var(--text-xs); opacity: 0.95; }
.rate-btn__key { display: none; }
.rate-btn--again { --c: var(--rate-again); --c-bg: var(--rate-again-bg); }
.rate-btn--hard  { --c: var(--rate-hard);  --c-bg: var(--rate-hard-bg); }
.rate-btn--good  { --c: var(--rate-good);  --c-bg: var(--rate-good-bg); }
.rate-btn--easy  { --c: var(--rate-easy);  --c-bg: var(--rate-easy-bg); }
@media (hover: hover) and (pointer: fine) {
  .rate-btn__key { display: inline; font-family: var(--font-mono); font-size: 11px; color: var(--text-subtle); }
}

/* ---------- 9. Tiến độ ---------- */
.progress { --value: 0%; position: relative; height: 16px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.progress__bar {
  height: 100%; width: var(--value); border-radius: inherit; background: var(--success-strong);
  transition: width var(--dur-slow) var(--ease-out);
  background-image: linear-gradient(180deg, rgb(255 255 255 / 0.28) 0 35%, transparent 35%);
}
.progress--primary .progress__bar { background-color: var(--primary); }
.progress--xp .progress__bar { background-color: var(--xp-fill); }
.progress--sm { height: 10px; }
.progress-label { display: flex; justify-content: space-between; font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-1); }
.ring { --value: 0; --size: 72px; --thick: 8px; width: var(--size); height: var(--size); border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--ring-color, var(--primary)) calc(var(--value) * 1%), var(--surface-3) 0); position: relative; }
.ring::before { content: ""; position: absolute; inset: var(--thick); border-radius: 50%; background: var(--surface); }
.ring > * { position: relative; font-family: var(--font-display); font-weight: var(--weight-black); }
/* Thanh thời gian trong game */
.timer-bar { height: 8px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.timer-bar__fill { height: 100%; width: 100%; background: var(--primary); transform-origin: left; animation: timer-drain var(--timer, 10s) linear forwards; }
.timer-bar.is-low .timer-bar__fill { background: var(--danger-strong); }

/* ---------- 10. Chip: chuỗi ngày, XP, tim, nhãn ---------- */
.chip {
  display: inline-flex; align-items: center; gap: var(--space-1); min-height: 36px; padding: 0 var(--space-3);
  border-radius: var(--radius-pill); background: var(--surface-2); color: var(--text);
  font-weight: var(--weight-semibold); font-size: var(--text-sm); white-space: nowrap; border: 0; text-decoration: none;
}
button.chip, a.chip { min-height: var(--tap-min); }
.chip .icon { width: 18px; height: 18px; }
.chip--streak { background: var(--streak-bg); color: var(--streak); }
.chip--streak .icon { fill: var(--streak-fill); stroke: var(--streak); }
.chip--streak.is-off { background: var(--surface-2); color: var(--text-subtle); }
.chip--streak.is-off .icon { fill: none; stroke: currentColor; }
.chip--xp { background: var(--warning-bg); color: var(--xp); }
.chip--xp .icon { fill: var(--xp-fill); stroke: var(--xp); }
.chip--freeze { background: var(--freeze-bg); color: var(--freeze); }
.chip--en { background: var(--lang-en-bg); color: var(--lang-en); }
.chip--zh { background: var(--lang-zh-bg); color: var(--lang-zh); }
.chip--success { background: var(--success-bg); color: var(--success); }
.chip--danger { background: var(--danger-bg); color: var(--danger); }
.chip--outline { background: transparent; border: 2px solid var(--border); }
.badge { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--danger-strong); color: var(--text-inverse); font-size: 12px; font-weight: var(--weight-semibold); }
[data-theme="light"] .badge { color: #fff; }

/* Tuần chuỗi ngày (7 ô) */
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: var(--space-2); text-align: center; }
.week__day { display: flex; flex-direction: column; align-items: center; gap: var(--space-1); font-size: var(--text-xs); color: var(--text-subtle); font-weight: var(--weight-semibold); }
.week__dot { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-subtle); border: 2px dashed var(--border-strong); }
.week__day.is-done .week__dot { background: var(--streak-fill); color: var(--text-inverse); border: 0; }
[data-theme="light"] .week__day.is-done .week__dot { color: #fff; }
.week__day.is-done .week__dot .icon { fill: currentColor; }
.week__day.is-freeze .week__dot { background: var(--freeze-bg); color: var(--freeze); border: 2px solid var(--freeze); }
.week__day.is-today { color: var(--text); }
.week__day.is-today .week__dot { border: 3px solid var(--streak); border-style: solid; }

/* ---------- 11. Toast / Feedback ---------- */
.toast-region { position: fixed; inset-inline: 0; top: calc(var(--space-3) + env(safe-area-inset-top)); z-index: var(--z-toast); display: flex; flex-direction: column; align-items: center; gap: var(--space-2); pointer-events: none; padding-inline: var(--gutter); }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: var(--space-3); max-width: 26rem; width: 100%;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--surface); color: var(--text); border: 2px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur-base) var(--ease-out);
}
.toast__icon { width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; }
.toast--success { border-color: var(--success); }
.toast--success .toast__icon { background: var(--success-bg); color: var(--success); }
.toast--error { border-color: var(--danger); }
.toast--error .toast__icon { background: var(--danger-bg); color: var(--danger); }
.toast--info .toast__icon { background: var(--info-bg); color: var(--info); }
.toast__title { font-weight: var(--weight-semibold); }
.toast.is-leaving { animation: toast-out var(--dur-fast) var(--ease-in) forwards; }

/* Thanh phản hồi đáp án (đáy màn hình trong buổi học) */
.answer-bar {
  position: fixed; inset-inline: 0; bottom: 0; z-index: var(--z-nav);
  background: var(--surface); border-top: 2px solid var(--border);
  padding: var(--space-4) var(--gutter) calc(var(--space-4) + env(safe-area-inset-bottom));
}
.answer-bar__inner { max-width: var(--content-max); margin-inline: auto; display: flex; flex-direction: column; gap: var(--space-3); }
.answer-bar__head { display: flex; align-items: center; gap: var(--space-3); }
.answer-bar__icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); flex: none; }
.answer-bar__title { font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-xl); }
.answer-bar.is-correct { background: var(--success-bg); border-color: transparent; color: var(--success); animation: slide-up var(--dur-base) var(--ease-out); }
.answer-bar.is-wrong { background: var(--danger-bg); border-color: transparent; color: var(--danger); animation: slide-up var(--dur-base) var(--ease-out); }
.answer-bar__detail { color: var(--text); font-size: var(--text-md); }
@media (min-width: 768px) {
  .answer-bar__inner { flex-direction: row; align-items: center; justify-content: space-between; }
  /* Nút thường mang btn--block (width:100% cho mobile). Trên hàng ngang phải bỏ 100% và cấm co,
     còn khối nội dung giãn ra — nếu không nút chiếm hết, chữ bị ép còn vài chục px. */
  .answer-bar__inner > .btn { flex: none; width: auto; min-width: 12rem; }
  .answer-bar__inner > :not(.btn) { flex: 1 1 auto; min-width: 0; }
}

/* ---------- 12. Modal (dùng <dialog>) ---------- */
.modal { border: 0; padding: 0; background: transparent; color: var(--text); max-width: min(28rem, calc(100vw - 2 * var(--gutter))); width: 100%; }
.modal::backdrop { background: var(--overlay); }
.modal[open] { animation: pop-in var(--dur-base) var(--ease-out); }
.modal__panel { background: var(--surface); border-radius: var(--radius-xl); padding: var(--space-6); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: var(--space-4); text-align: center; }
.modal__art { width: 96px; height: 96px; margin-inline: auto; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.modal__art .icon { width: 48px; height: 48px; }
.modal__actions { display: flex; flex-direction: column; gap: var(--space-2); }

/* ---------- 13. Tab chuyển ngôn ngữ (segmented) ---------- */
.seg { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: var(--radius-pill); }
.seg__btn {
  display: inline-flex; align-items: center; gap: var(--space-2); min-height: 40px; padding: 0 var(--space-4);
  border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--text-muted);
  font-weight: var(--weight-semibold); font-size: var(--text-sm); transition: background-color var(--dur-fast), color var(--dur-fast);
}
.seg__btn:hover { color: var(--text); }
.seg__btn[aria-selected="true"], .seg__btn[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg--block { display: flex; } .seg--block .seg__btn { flex: 1; justify-content: center; }
.flag { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 800; font-family: var(--font-display); flex: none; }
.flag--en { background: var(--lang-en-bg); color: var(--lang-en); }
.flag--zh { background: var(--lang-zh-bg); color: var(--lang-zh); font-family: var(--font-han); font-size: 13px; }
.flag--lg { width: 48px; height: 48px; font-size: 18px; } .flag--lg.flag--zh { font-size: 24px; }

/* Tabs gạch chân */
.tabs { display: flex; gap: var(--space-1); border-bottom: 2px solid var(--border); overflow-x: auto; }
.tabs__btn { min-height: var(--tap-min); padding: 0 var(--space-4); border: 0; background: none; color: var(--text-muted); font-weight: var(--weight-semibold); border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs__btn[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- 14. Bottom nav (mobile) / side rail (desktop) ---------- */
.bottom-nav {
  position: fixed; inset-inline: 0; bottom: 0; z-index: var(--z-nav);
  background: var(--surface); border-top: 2px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav__list { display: grid; grid-template-columns: repeat(5, 1fr); max-width: var(--content-max); margin: 0 auto; padding: 0; list-style: none; }
.bottom-nav__link {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 60px; color: var(--text-subtle); text-decoration: none; font-size: 12px; font-weight: var(--weight-semibold);
  position: relative;
}
.bottom-nav__link .icon { width: 26px; height: 26px; }
.bottom-nav__link:hover { color: var(--text); }
.bottom-nav__link[aria-current="page"] { color: var(--primary); }
.bottom-nav__link[aria-current="page"]::before { content: ""; position: absolute; top: 0; width: 32px; height: 4px; border-radius: 0 0 4px 4px; background: var(--primary); }
@media (min-width: 1024px) {
  .has-rail { padding-left: 15rem; }
  .bottom-nav { top: 0; right: auto; width: 15rem; border-top: 0; border-right: 2px solid var(--border); padding: var(--space-6) var(--space-3); }
  .bottom-nav::before { content: "Lingo"; display: block; font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-2xl); color: var(--primary); padding: 0 var(--space-3) var(--space-6); }
  .bottom-nav__list { grid-template-columns: 1fr; gap: var(--space-1); }
  .bottom-nav__link { flex-direction: row; justify-content: flex-start; gap: var(--space-3); min-height: 52px; padding: 0 var(--space-4); border-radius: var(--radius-md); font-size: var(--text-md); border: 2px solid transparent; }
  .bottom-nav__link:hover { background: var(--surface-2); }
  .bottom-nav__link[aria-current="page"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-soft-text); }
  .bottom-nav__link[aria-current="page"]::before { display: none; }
  .has-rail .main { padding-bottom: var(--space-8); }
}

/* ---------- 15. Lựa chọn đáp án ---------- */
.options { display: grid; gap: var(--space-3); }
.options--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.option {
  display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 60px; padding: var(--space-3) var(--space-4);
  border: 2px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text);
  text-align: left; font-size: var(--text-lg); font-weight: var(--weight-medium);
  box-shadow: 0 4px 0 var(--border); margin-bottom: 4px;
  transition: transform var(--dur-instant), box-shadow var(--dur-instant), border-color var(--dur-fast), background-color var(--dur-fast);
}
.option:hover { border-color: var(--border-strong); background: var(--surface-2); }
.option:active { transform: translateY(var(--press-depth)); box-shadow: 0 0 0 var(--border); }
.option__key { display: inline-grid; place-items: center; width: 28px; height: 28px; flex: none; border-radius: 8px; border: 2px solid var(--border); font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--text-subtle); }
.option__mark { margin-left: auto; display: none; }
.option.is-selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 4px 0 var(--primary); }
.option.is-selected .option__key { border-color: var(--primary); color: var(--primary); }
.option.is-correct { border-color: var(--success); background: var(--success-bg); color: var(--success); box-shadow: 0 4px 0 var(--success); animation: pop var(--dur-base) var(--ease-spring); }
.option.is-wrong { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); box-shadow: 0 4px 0 var(--danger); animation: shake 360ms var(--ease-out); }
.option.is-correct .option__mark, .option.is-wrong .option__mark { display: inline-flex; }
.option:disabled { cursor: default; }
.option:disabled:not(.is-correct):not(.is-wrong) { opacity: 0.6; }
.option--center { justify-content: center; text-align: center; flex-direction: column; gap: var(--space-1); }

/* Prompt (câu hỏi) */
.prompt { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); text-align: center; padding-block: var(--space-4); }
.prompt__label { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-lg); align-self: flex-start; text-align: left; }
.speech { position: relative; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); }

/* ---------- 16. Xếp từ / word bank ---------- */
.answer-line { min-height: 64px; display: flex; flex-wrap: wrap; gap: var(--space-2); align-content: flex-start; padding: var(--space-2) 0; border-bottom: 2px solid var(--border); }
.answer-line + .answer-line { margin-top: var(--space-1); }
.word-bank { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-2); }
.tile {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-height: 48px; min-width: 48px; padding: var(--space-2) var(--space-3);
  border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font-size: var(--text-lg); font-weight: var(--weight-medium); box-shadow: 0 3px 0 var(--border); margin-bottom: 3px;
  transition: transform var(--dur-instant), box-shadow var(--dur-instant);
}
.tile:active { transform: translateY(3px); box-shadow: 0 0 0 var(--border); }
.tile .han { font-size: var(--text-han-sm); line-height: 1.1; }
.tile .pinyin { font-size: var(--text-xs); }
.tile.is-used { background: var(--surface-3); color: transparent; box-shadow: none; border-color: var(--surface-3); pointer-events: none; }
.tile.is-used * { visibility: hidden; }
.tile.is-correct { border-color: var(--success); background: var(--success-bg); }
.tile.is-wrong { border-color: var(--danger); background: var(--danger-bg); }

/* Bàn phím pinyin dấu thanh (gõ) */
.tone-keys { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--space-2); }

/* ---------- 17. Bản đồ level ---------- */
.unit-header { border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 0 var(--primary-shadow); display: flex; align-items: center; gap: var(--space-3); }
.unit-header--zh { background: var(--lang-zh); box-shadow: 0 4px 0 color-mix(in srgb, var(--lang-zh) 60%, black); color: var(--text-inverse); }
[data-theme="light"] .unit-header--zh { color: #fff; }
.unit-header .eyebrow { color: inherit; opacity: 0.85; }
.path { list-style: none; margin: 0; padding: var(--space-6) 0; display: flex; flex-direction: column; align-items: center; gap: var(--space-5); }
.path__item { --x: 0px; transform: translateX(var(--x)); display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.path__item:nth-child(4n+2) { --x: 56px; } .path__item:nth-child(4n+3) { --x: 80px; } .path__item:nth-child(4n+4) { --x: 40px; }
.path__item:nth-child(8n+5) { --x: -40px; } .path__item:nth-child(8n+6) { --x: -80px; } .path__item:nth-child(8n+7) { --x: -56px; }
.path__item:has(.map-node__tip) { margin-top: var(--space-8); }
.map-node {
  position: relative; width: 72px; height: 68px; border-radius: 50%; border: 0; display: grid; place-items: center;
  background: var(--surface-3); color: var(--locked); box-shadow: 0 6px 0 var(--border-strong);
  text-decoration: none; transition: transform var(--dur-instant), box-shadow var(--dur-instant);
}
.map-node .icon { width: 30px; height: 30px; }
.map-node:active { transform: translateY(6px); box-shadow: 0 0 0 transparent; }
.map-node.is-done { background: var(--xp-fill); color: var(--text); box-shadow: 0 6px 0 var(--xp); }
.map-node.is-done .icon { fill: currentColor; }
[data-theme="dark"] .map-node.is-done { color: var(--text-inverse); }
.map-node.is-current { background: var(--primary); color: var(--on-primary); box-shadow: 0 6px 0 var(--primary-shadow), 0 0 0 8px var(--primary-soft); }
.map-node.is-locked { cursor: not-allowed; }
.map-node--boss { width: 88px; height: 80px; border-radius: 28px; }
.map-node__label { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--text-muted); text-align: center; max-width: 9rem; }
.map-node__tip { position: absolute; bottom: calc(100% + 14px); left: 50%; transform: translateX(-50%); white-space: nowrap; padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm); background: var(--surface); border: 2px solid var(--primary); color: var(--primary); font-weight: var(--weight-bold); font-family: var(--font-display); font-size: var(--text-sm); animation: bob 2s var(--ease-out) infinite; }
.map-node__tip::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 7px solid transparent; border-top-color: var(--primary); }
.map-node .ring-progress { position: absolute; inset: -10px; border-radius: 50%; background: conic-gradient(var(--primary) calc(var(--value, 0) * 1%), transparent 0); -webkit-mask: radial-gradient(circle closest-side, transparent 86%, black 87%); mask: radial-gradient(circle closest-side, transparent 86%, black 87%); }

/* Mini map (dashboard) */
.mini-map { display: flex; align-items: center; gap: 0; overflow-x: auto; padding: var(--space-3) var(--space-1) var(--space-4); }
.mini-map .map-node { width: 52px; height: 50px; flex: none; }
.mini-map .map-node .icon { width: 22px; height: 22px; }
.mini-map__line { flex: 1; min-width: 20px; height: 6px; background: var(--surface-3); border-radius: 3px; }
.mini-map__line.is-done { background: var(--xp-fill); }

/* ---------- 18. List rows, avatar, stat ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: var(--space-3); min-height: 60px; padding: var(--space-2) 0; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.list-row:last-child { border-bottom: 0; }
a.list-row:hover { color: inherit; background: var(--surface-2); }
.list-row__icon { width: 44px; height: 44px; border-radius: var(--radius-sm); display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--text-muted); }
.list-row__icon--primary { background: var(--primary-soft); color: var(--primary-soft-text); }
.list-row__icon--streak { background: var(--streak-bg); color: var(--streak); }
.list-row__icon--success { background: var(--success-bg); color: var(--success); }
.list-row__icon--xp { background: var(--warning-bg); color: var(--xp); }
.list-row__title { font-weight: var(--weight-semibold); }
.list-row__meta { font-size: var(--text-sm); color: var(--text-subtle); }
.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--primary-soft); color: var(--primary-soft-text); font-family: var(--font-display); font-weight: var(--weight-black); }
.avatar--lg { width: 88px; height: 88px; font-size: var(--text-2xl); box-shadow: 0 4px 0 var(--border); }
.avatar--a { background: var(--tone-1-bg); color: var(--tone-1); } .avatar--b { background: var(--tone-2-bg); color: var(--tone-2); }
.avatar--c { background: var(--tone-3-bg); color: var(--tone-3); } .avatar--d { background: var(--tone-4-bg); color: var(--tone-4); }
.stat { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: 2px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.stat__value { font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-xl); line-height: 1.1; }
.stat__label { font-size: var(--text-sm); color: var(--text-subtle); }
.task { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0; }
.task__check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; flex: none; color: transparent; }
.task.is-done .task__check { background: var(--success-strong); border-color: var(--success-strong); color: var(--text-inverse); }
[data-theme="light"] .task.is-done .task__check { color: #fff; }
.task.is-done .task__title { text-decoration: line-through; color: var(--text-subtle); }

/* ---------- 19. Leaderboard ---------- */
.lb-row { display: flex; align-items: center; gap: var(--space-3); min-height: 64px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); }
.lb-row__rank { width: 32px; text-align: center; font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-lg); color: var(--text-muted); flex: none; }
.lb-row__xp { font-weight: var(--weight-semibold); color: var(--text-muted); white-space: nowrap; }
.lb-row.is-me { background: var(--primary-soft); border: 2px solid var(--primary); }
.lb-row--1 .lb-row__rank { color: var(--gold); } .lb-row--2 .lb-row__rank { color: var(--silver); } .lb-row--3 .lb-row__rank { color: var(--bronze); }
.medal { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-sm); color: var(--text); }
.medal--1 { background: var(--gold); } .medal--2 { background: var(--silver); } .medal--3 { background: var(--bronze); color: var(--text-inverse); }
[data-theme="light"] .medal--3 { color: #fff; }
.zone-divider { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); font-weight: var(--weight-semibold); text-transform: uppercase; letter-spacing: 0.06em; margin: var(--space-2) 0; }
.zone-divider::before, .zone-divider::after { content: ""; flex: 1; height: 2px; background: currentColor; opacity: 0.35; }
.zone-divider--up { color: var(--success); } .zone-divider--down { color: var(--danger); }

/* ---------- 20. Chat (hội thoại kịch bản) ---------- */
.chat { display: flex; flex-direction: column; gap: var(--space-3); }
.bubble-row { display: flex; align-items: flex-end; gap: var(--space-2); max-width: 88%; }
.bubble-row--me { align-self: flex-end; flex-direction: row-reverse; }
.bubble { padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg); border-bottom-left-radius: 6px; background: var(--surface); border: 2px solid var(--border); }
.bubble-row--me .bubble { background: var(--primary); color: var(--on-primary); border-color: transparent; border-bottom-left-radius: var(--radius-lg); border-bottom-right-radius: 6px; }
.bubble__trans { font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-1); }
.bubble-row--me .bubble__trans { color: inherit; opacity: 0.85; }
.bubble .han { font-size: var(--text-xl); }
.bubble__tools { display: flex; gap: var(--space-1); margin-top: var(--space-2); }
.typing { display: inline-flex; gap: 4px; padding: var(--space-3) var(--space-4); }
.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--text-subtle); animation: typing 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.15s; } .typing span:nth-child(3) { animation-delay: 0.3s; }
.reply-choices { display: flex; flex-direction: column; gap: var(--space-2); }
.scene { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--surface-2); font-size: var(--text-sm); }

/* ---------- 21. Thanh điệu: đồ thị cao độ + tone pad ---------- */
.pitch { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-lg); padding: var(--space-3); }
.pitch svg { width: 100%; height: auto; overflow: visible; }
.pitch__grid { stroke: var(--border); stroke-width: 1; stroke-dasharray: 4 4; }
.pitch__axis { fill: var(--text-subtle); font-size: 11px; font-family: var(--font-body); }
.pitch__ref { fill: none; stroke-width: 10; stroke-linecap: round; opacity: 0.28; }
.pitch__user { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.pitch__legend { display: flex; gap: var(--space-4); font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--space-2); flex-wrap: wrap; }
.legend-swatch { display: inline-block; width: 18px; height: 6px; border-radius: 3px; vertical-align: middle; margin-right: var(--space-1); background: currentColor; }
.tone-pad { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.tone-btn {
  --c: var(--tone-1); --c-bg: var(--tone-1-bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1);
  min-height: 96px; border: 3px solid var(--c); border-radius: var(--radius-lg); background: var(--c-bg); color: var(--c);
  font-family: var(--font-display); font-weight: var(--weight-black); box-shadow: 0 5px 0 var(--c); margin-bottom: 5px;
  transition: transform var(--dur-instant), box-shadow var(--dur-instant);
}
.tone-btn:active { transform: translateY(5px); box-shadow: 0 0 0 var(--c); }
.tone-btn svg { width: 56px; height: 28px; }
.tone-btn__name { font-size: var(--text-md); }
.tone-btn__desc { font-family: var(--font-body); font-weight: var(--weight-medium); font-size: var(--text-xs); color: var(--text-muted); }
.tone-btn--2 { --c: var(--tone-2); --c-bg: var(--tone-2-bg); }
.tone-btn--3 { --c: var(--tone-3); --c-bg: var(--tone-3-bg); }
.tone-btn--4 { --c: var(--tone-4); --c-bg: var(--tone-4-bg); }
.tone-btn.is-correct { animation: pop var(--dur-base) var(--ease-spring); outline: 4px solid var(--success); outline-offset: 3px; }
.tone-btn.is-wrong { animation: shake 360ms var(--ease-out); outline: 4px solid var(--danger); outline-offset: 3px; }

/* ---------- 22. Game: nối cặp / HUD ---------- */
.hud { display: flex; align-items: center; gap: var(--space-3); }
.combo { display: inline-flex; align-items: baseline; gap: 2px; font-family: var(--font-display); font-weight: var(--weight-black); color: var(--streak); }
.combo__num { font-size: var(--text-2xl); line-height: 1; }
.combo.is-bump { animation: combo-bump var(--dur-slow) var(--ease-spring); }
.match-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.match-tile {
  min-height: 72px; padding: var(--space-2); border: 2px solid var(--border); border-radius: var(--radius-md); background: var(--surface); color: var(--text);
  font-size: var(--text-lg); font-weight: var(--weight-medium); box-shadow: 0 4px 0 var(--border); margin-bottom: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  transition: transform var(--dur-instant), box-shadow var(--dur-instant), opacity var(--dur-base), border-color var(--dur-fast);
}
.match-tile .han { font-size: var(--text-han-sm); }
.match-tile:active { transform: translateY(4px); box-shadow: 0 0 0 var(--border); }
.match-tile.is-selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 4px 0 var(--primary); }
.match-tile.is-correct { border-color: var(--success); background: var(--success-bg); color: var(--success); box-shadow: 0 4px 0 var(--success); }
.match-tile.is-wrong { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); animation: shake 360ms var(--ease-out); }
.match-tile.is-cleared { opacity: 0; pointer-events: none; transform: scale(0.9); }
.score-pop { position: absolute; font-family: var(--font-display); font-weight: var(--weight-black); color: var(--xp); animation: float-up 700ms var(--ease-out) forwards; pointer-events: none; }

/* Màn kết quả / lên level */
.celebrate { position: relative; text-align: center; display: flex; flex-direction: column; align-items: center; gap: var(--space-4); padding-block: var(--space-8); overflow: hidden; }
.celebrate__badge { width: 128px; height: 128px; border-radius: 40px; display: grid; place-items: center; background: var(--xp-fill); color: var(--text); box-shadow: 0 8px 0 var(--xp); animation: level-up var(--dur-celebrate) var(--ease-spring) both; }
[data-theme="dark"] .celebrate__badge { color: var(--text-inverse); }
.celebrate__badge .icon { width: 64px; height: 64px; fill: currentColor; }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -12px; width: 10px; height: 14px; border-radius: 3px; animation: confetti-fall 1.6s var(--ease-in) forwards; }
.confetti i:nth-child(4n+1) { background: var(--tone-1); } .confetti i:nth-child(4n+2) { background: var(--tone-2); }
.confetti i:nth-child(4n+3) { background: var(--tone-3); } .confetti i:nth-child(4n+4) { background: var(--tone-4); }
.result-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); width: 100%; }
.result-stat { border: 2px solid var(--c, var(--border)); border-radius: var(--radius-md); overflow: hidden; }
.result-stat__head { background: var(--c, var(--surface-2)); color: var(--text-inverse); font-size: var(--text-xs); font-weight: var(--weight-semibold); padding: var(--space-1); text-transform: uppercase; letter-spacing: 0.05em; }
[data-theme="light"] .result-stat__head { color: #fff; }
.result-stat__val { padding: var(--space-3) var(--space-1); font-family: var(--font-display); font-weight: var(--weight-black); font-size: var(--text-xl); display: flex; align-items: center; justify-content: center; gap: var(--space-1); }

/* ---------- 23. Session header ---------- */
.session-top { display: flex; align-items: center; gap: var(--space-3); min-height: 60px; }
.session-top .progress { flex: 1; }
.step-tag { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--primary-soft-text); background: var(--primary-soft); padding: var(--space-1) var(--space-3); border-radius: var(--radius-pill); }
.level-steps { display: flex; gap: 4px; }
.level-steps span { width: 18px; height: 6px; border-radius: 3px; background: var(--surface-3); }
.level-steps span.is-on { background: var(--primary); }

/* Auth layout */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-6) var(--gutter); }
.auth__card { width: 100%; max-width: 26rem; }
.auth__hero { display: none; }
@media (min-width: 1024px) {
  .auth { grid-template-columns: 1fr 1fr; padding: 0; }
  .auth__hero { display: flex; flex-direction: column; justify-content: center; gap: var(--space-6); height: 100%; padding: var(--space-16); background: var(--primary); color: var(--on-primary); }
  .auth__panel { display: grid; place-items: center; padding: var(--space-8); }
}
.hero-card { background: color-mix(in srgb, var(--surface) 14%, transparent); border: 2px solid color-mix(in srgb, var(--on-primary) 25%, transparent); border-radius: var(--radius-lg); padding: var(--space-5); max-width: 22rem; }
.divider-text { display: flex; align-items: center; gap: var(--space-3); color: var(--text-subtle); font-size: var(--text-sm); }
.divider-text::before, .divider-text::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.strength { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.strength span { height: 6px; border-radius: 3px; background: var(--surface-3); }
.strength[data-level="2"] span:nth-child(-n+2) { background: var(--warning); }
.strength[data-level="3"] span:nth-child(-n+3) { background: var(--success); }

/* Choice card (onboarding) */
.choice { position: relative; display: flex; align-items: center; gap: var(--space-4); width: 100%; padding: var(--space-4) var(--space-5); border: 2px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); color: var(--text); text-align: left; box-shadow: 0 4px 0 var(--border); margin-bottom: 4px; transition: transform var(--dur-instant), box-shadow var(--dur-instant), border-color var(--dur-fast); cursor: pointer; }
.choice:hover { border-color: var(--border-strong); }
.choice:active { transform: translateY(4px); box-shadow: 0 0 0 var(--border); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 4px 0 var(--primary); }
.choice:has(input:focus-visible) { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.choice__check { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; color: transparent; flex: none; }
.choice:has(input:checked) .choice__check { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.choice__title { font-family: var(--font-display); font-weight: var(--weight-bold); font-size: var(--text-lg); }


/* ---------- 24. Keyframes ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.92) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px); } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pulse-ring { 0% { box-shadow: 0 4px 0 var(--primary-shadow), 0 0 0 0 color-mix(in srgb, var(--primary) 45%, transparent); } 100% { box-shadow: 0 4px 0 var(--primary-shadow), 0 0 0 16px transparent; } }
@keyframes timer-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes bob { 0%,100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -4px); } }
@keyframes typing { 0%,60%,100% { opacity: 0.3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes combo-bump { 0% { transform: scale(1); } 40% { transform: scale(1.35) rotate(-4deg); } 100% { transform: scale(1); } }
@keyframes float-up { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-40px); } }
@keyframes level-up { 0% { opacity: 0; transform: scale(0.4) rotate(-12deg); } 70% { opacity: 1; transform: scale(1.08) rotate(3deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes confetti-fall { to { transform: translateY(110vh) rotate(540deg); opacity: 0.6; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .confetti, .map-node__tip { animation: none !important; }
  .confetti { display: none; }
  .timer-bar__fill { animation-duration: var(--timer, 10s) !important; } /* đồng hồ vẫn chạy — là thông tin, không trang trí */
}
@media (forced-colors: active) {
  .btn, .option, .tile, .rate-btn, .tone-btn, .match-tile, .choice { border: 2px solid ButtonText; }
  .option.is-correct, .option.is-wrong { outline: 3px solid Highlight; }
}

/* ---------- 25. Bổ sung WP0 (thay cho style="" inline của mockup — CSP style-src 'self') ---------- */
/* Giá trị động (vd --value của .progress/.ring): đặt data-value="33%" trên phần tử; js/core/app.js gán bằng CSSOM. */
.stack--center { align-items: center; }
.fieldset-reset { border: 0; padding: 0; margin: 0; min-width: 0; }
.u-mt-2 { margin-top: var(--space-2); }
.u-mt-4 { margin-top: var(--space-4); }
.u-mb-2 { margin-bottom: var(--space-2); }
.brand--inverse { color: inherit; }
.brand--inverse .brand__mark { background: var(--surface); color: var(--primary); box-shadow: none; }
.auth__hero-title { font-size: var(--text-3xl); max-width: 26rem; }
.auth__hero-list { list-style: none; padding: 0; margin: 0; }
.hero-card__han { font-size: var(--text-3xl); }
.hero-card__hv { text-transform: uppercase; letter-spacing: 0.06em; font-size: var(--text-sm); }
.choice--stack { flex-direction: column; text-align: center; gap: var(--space-1); padding: var(--space-3) var(--space-2); }
.seg__btn { white-space: nowrap; }
.card--primary .eyebrow { color: inherit; opacity: 0.85; }
.card--primary .btn--secondary { --btn-fg: var(--primary-soft-text); }
.title-md { font-size: var(--text-xl); }
.title-sm { font-size: var(--text-lg); }
/* Công tắc hồ sơ: mục đang chọn là <span aria-current>, mục khác là nút submit */
.seg__btn[aria-current="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.topbar .seg { margin-right: var(--space-1); }
/* Honeypot chống bot (AUTH-11): ẩn khỏi người dùng và trình đọc màn hình nhưng bot vẫn điền */
.hp-field { position: absolute !important; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
/* Banner mất kết nối (NFR-PWA-03) */
.offline-banner { position: fixed; inset-inline: 0; top: 0; z-index: var(--z-toast); padding: var(--space-2) var(--gutter); padding-top: calc(var(--space-2) + env(safe-area-inset-top)); background: var(--warning-bg); color: var(--warning); font-weight: var(--weight-semibold); font-size: var(--text-sm); text-align: center; border-bottom: 2px solid var(--warning); }
/* Nội dung Markdown (Privacy, ghi công, lý thuyết bài) */
.prose { line-height: var(--leading-normal); }
.prose > * + * { margin-top: var(--space-3); }
.prose h2 { font-size: var(--text-xl); margin-top: var(--space-6); }
.prose h3 { font-size: var(--text-lg); margin-top: var(--space-5); }
.prose ul, .prose ol { padding-left: var(--space-6); margin: 0; }
.prose li + li { margin-top: var(--space-1); }
.prose table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.prose th, .prose td { border: 1px solid var(--border); padding: var(--space-2) var(--space-3); text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose code { font-family: var(--font-mono); background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.prose a { word-break: break-word; }
/* Trang trạng thái (404 "Sắp ra mắt", lỗi) */
.status-page { min-height: 60dvh; display: grid; place-items: center; text-align: center; }
.status-page__art { width: 96px; height: 96px; margin-inline: auto; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.status-page__art .icon { width: 48px; height: 48px; }
/* Thanh trên cùng của màn hình tập trung (onboarding) */
.focus-top { padding-top: env(safe-area-inset-top); }
/* Nút cài PWA: chỉ hiện khi trình duyệt bắn beforeinstallprompt */
[data-install-app][hidden] { display: none !important; }
.strength[data-level="1"] span:first-child { background: var(--danger); }
