/* ==========================================================================
   Đích — luyện thi tiếng Anh có AI
   Backbone dùng chung cho mọi màn hình. Mobile-first, không phone frame.
   ========================================================================== */

:root {
  --bg:      oklch(98% 0.004 240);
  --surface: oklch(100% 0 0);
  --fg:      oklch(20% 0.02 240);
  --muted:   oklch(46% 0.018 240);   /* hạ từ 50% để chữ 12–13px vượt 4.5:1 trên nền */
  --border:  oklch(90% 0.006 240);
  --accent:  oklch(56% 0.12 170);
  /* biến thể đậm dùng khi accent làm nền cho chữ trắng — accent gốc chỉ đạt 4.28:1 */
  --accent-solid: oklch(48% 0.115 170);
  --accent-solid-hover: oklch(41% 0.105 170);

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

  /* dẫn xuất */
  --surface-2:   oklch(96.5% 0.005 240);
  --surface-sub: oklch(94.5% 0.006 240);
  --fg-soft:     oklch(34% 0.02 240);
  --border-strong: oklch(83% 0.008 240);

  --success: oklch(45% 0.12 150);
  --success-bg: oklch(96% 0.03 150);
  --warn:    oklch(58% 0.14 70);
  --warn-bg: oklch(96.5% 0.04 80);
  --danger:  oklch(45% 0.18 25);
  --danger-bg: oklch(96% 0.03 25);

  --r-sm: 10px;
  --r:    14px;
  --r-lg: 18px;
  --r-pill: 999px;

  --pad: 16px;
  --nav-h: 62px;
  --shadow-card: 0 1px 2px oklch(20% 0.02 240 / 0.05), 0 8px 24px -12px oklch(20% 0.02 240 / 0.16);
}

* { 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: 600;
  margin: 0;
  letter-spacing: -0.015em;
  line-height: 1.18;
}
h1 { font-size: clamp(26px, 6.4vw, 34px); letter-spacing: -0.022em; }
h2 { font-size: clamp(20px, 4.6vw, 25px); }
h3 { font-size: 17px; letter-spacing: -0.01em; line-height: 1.3; }
p  { margin: 0; }

a { color: inherit; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.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: oklch(98% 0.004 240 / 0.92);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-in {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding-top: 6px;
  padding-bottom: 6px;
}
.topbar-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.012em;
  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: 18px;
  padding-bottom: calc(var(--nav-h) + 28px);
}
.screen--nonav { padding-bottom: 40px; }

/* ---------- wordmark ------------------------------------------------- */

.mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.mark-glyph {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--fg);
  color: var(--surface);
  display: grid;
  place-items: center;
  flex: none;
}
.mark-glyph svg { width: 15px; height: 15px; }

/* ---------- buttons -------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--fg);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .14s ease, transform .08s ease, border-color .14s ease;
}
.btn:hover { background: var(--surface-sub); }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--accent-solid);
  color: oklch(100% 0 0);
}
.btn--primary:hover { background: var(--accent-solid-hover); color: oklch(100% 0 0); }

.btn--outline { background: var(--surface); border-color: var(--border-strong); }
.btn--outline:hover { background: var(--surface-2); }

.btn--ghost { background: transparent; }
.btn--ghost:hover { background: var(--surface-sub); }

.btn--block { width: 100%; }
.btn--sm { min-height: 44px; padding: 0 15px; font-size: 14px; }

.btn:disabled,
.btn[aria-disabled="true"] {
  background: var(--surface-2);
  color: oklch(66% 0.012 240);
  cursor: not-allowed;
  transform: none;
}

.icon-btn {
  width: 44px; height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg-soft);
  cursor: pointer;
  transition: background-color .14s ease, color .14s ease;
}
.icon-btn:hover { background: var(--surface-sub); color: var(--fg); }
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:disabled {
  color: oklch(72% 0.01 240);
  background: var(--surface-2);
  cursor: not-allowed;
}

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

.thread { display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg--user { justify-content: flex-end; }

.avatar {
  width: 30px; height: 30px;
  flex: none;
  border-radius: 9px;
  background: var(--fg);
  color: var(--surface);
  display: grid;
  place-items: center;
  margin-top: 2px;
}
.avatar svg { width: 16px; height: 16px; }

.bubble {
  max-width: min(85%, 430px);
  padding: 11px 14px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 15.5px;
  line-height: 1.55;
}
.bubble p + p { margin-top: 8px; }
.msg--user .bubble {
  background: var(--fg);
  color: oklch(97% 0.004 240);
  border-color: var(--fg);
  border-bottom-right-radius: 5px;
}
.msg--ai .bubble { border-bottom-left-radius: 5px; }

.bubble strong { font-weight: 600; }
.bubble .hint { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); letter-spacing: 0.01em; }

/* ---------- form-card : điểm nhấn của app ---------------------------- */

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

.form-card__head {
  padding: 12px 16px 10px;
  border-bottom: 1px dashed var(--border);
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.form-card__eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--muted);
}
.form-card__step {
  margin-left: auto;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.form-card__body { padding: 14px 16px 16px; }
.form-card__foot {
  padding: 12px 16px;
  background: var(--surface-2);
  border-top: 1px 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: 16px; }
.field__label {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.01em;
  margin-bottom: 9px;
}
.field__note { font-size: 12.5px; color: var(--muted); letter-spacing: 0.01em; margin-top: 8px; }

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 15px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-soft);
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0.015em;
  cursor: pointer;
  transition: background-color .14s ease, color .14s ease, border-color .14s ease;
}
.chip:hover { background: var(--surface-sub); color: var(--fg); }
.chip[aria-pressed="true"],
.chip.is-on {
  background: var(--fg);
  border-color: var(--fg);
  color: oklch(97% 0.004 240);
}
.chip[aria-pressed="true"]:hover { background: oklch(28% 0.02 240); color: oklch(99% 0.004 240); }
.chip__meta { font-size: 12px; opacity: .72; font-weight: 400; }

/* option rows (mode thi, đáp án) */
.opts { display: flex; flex-direction: column; gap: 8px; }

.opt {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  padding: 13px 14px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  cursor: pointer;
  transition: background-color .14s ease, border-color .14s ease;
}
.opt:hover { background: var(--surface-2); }
.opt__key {
  width: 26px; height: 26px;
  flex: none;
  border-radius: 8px;
  background: var(--surface-sub);
  color: var(--fg-soft);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-top: 1px;
}
.opt__text { min-width: 0; flex: 1; }
.opt__title { font-size: 15px; font-weight: 500; letter-spacing: 0.005em; }
.opt__desc { font-size: 13px; color: var(--muted); margin-top: 3px; line-height: 1.45; }

.opt.is-on { border-color: var(--fg); background: var(--surface-2); }
.opt.is-on .opt__key { background: var(--fg); color: oklch(97% 0.004 240); }

.opt.is-correct { border-color: var(--success); background: var(--success-bg); }
.opt.is-correct .opt__key { background: var(--success); color: oklch(99% 0 0); }
.opt.is-wrong { border-color: var(--danger); background: var(--danger-bg); }
.opt.is-wrong .opt__key { background: var(--danger); color: oklch(99% 0 0); }

.opt__tag {
  margin-left: auto;
  flex: none;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  align-self: center;
}
.opt.is-correct .opt__tag { color: var(--success); }
.opt.is-wrong .opt__tag { color: var(--danger); }

/* text input */
.input, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 11px 14px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  transition: border-color .14s ease;
}
.textarea { min-height: 108px; resize: vertical; line-height: 1.55; }
.input:hover, .textarea:hover { border-color: oklch(74% 0.01 240); }
.input::placeholder, .textarea::placeholder { color: var(--muted); }

.err { display: none; margin-top: 7px; font-size: 13px; color: var(--danger); letter-spacing: 0.01em; }
.field.has-err .input, .field.has-err .textarea { border-color: var(--danger); }
.field.has-err .err { display: block; }

/* ---------- generic cards -------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
}
.card--flat { box-shadow: none; }
.card__title { font-size: 16px; }

.section { margin-top: 26px; }
.section__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
}
.section__head h2 { font-size: 19px; }
.section__more {
  margin-left: auto;
  font-size: 13.5px;
  color: var(--fg-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 1px;
  letter-spacing: 0.01em;
}
.section__more:hover { color: var(--fg); border-color: var(--fg); }

.eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-sub);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--fg-soft);
}
.badge--live { background: var(--success-bg); border-color: oklch(88% 0.05 150); color: var(--success); }
.badge--warn { background: var(--warn-bg); border-color: oklch(88% 0.06 80); color: oklch(46% 0.12 70); }
.badge--demo { background: transparent; border-style: dashed; color: var(--muted); }

/* ---------- stats & bars --------------------------------------------- */

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

.bar-list { display: flex; flex-direction: column; gap: 14px; }
.bar-row__top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 7px;
}
.bar-row__name { font-size: 14.5px; font-weight: 500; letter-spacing: 0.005em; }
.bar-row__val {
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.bar {
  position: relative;
  height: 10px;
  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);
}
.bar__fill--focus { background: var(--accent); }
.bar-row__foot {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.bar-row__foot span:last-child { margin-left: auto; }

/* ---------- lists ----------------------------------------------------- */

.rows { display: flex; flex-direction: column; }
.row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}
.row:last-child { border-bottom: 0; }
.row__main { min-width: 0; flex: 1; }
.row__title { font-size: 15px; font-weight: 500; letter-spacing: 0.005em; }
.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: 600;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
a.row:hover { background: var(--surface-2); }

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

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  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 14px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  color: var(--fg-soft);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .14s ease, color .14s ease;
}
.tab:hover { background: oklch(90% 0.006 240); color: var(--fg); }
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 1px 2px oklch(20% 0.02 240 / 0.1);
}

/* ---------- bottom nav ------------------------------------------------ */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: oklch(100% 0 0 / 0.94);
  backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px 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-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  position: relative;
  transition: color .14s ease;
}
.nav-item svg { width: 21px; height: 21px; }
.nav-item:hover { color: var(--fg); background: var(--surface-2); }
.nav-item[aria-current="page"] { color: var(--fg); font-weight: 600; }
.nav-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  width: 26px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}

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

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: oklch(20% 0.02 240 / 0.42);
  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: 1px solid var(--border);
  border-bottom: 0;
  transform: translateY(102%);
  visibility: hidden;                       /* lúc đóng không tab được vào bên trong */
  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: 38px; height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
  margin: 10px auto 4px;
}
.sheet__body { padding: 8px 16px 20px; }

/* ---------- progress -------------------------------------------------- */

.progress {
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--surface-sub);
  overflow: hidden;
}
.progress__fill {
  height: 100%;
  background: var(--fg);
  border-radius: var(--r-pill);
  transition: width .3s ease;
}

/* ---------- question palette ------------------------------------------ */

.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 7px;
}
.pal-btn {
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg-soft);
  font-size: 13.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color .14s ease, color .14s ease;
}
.pal-btn:hover { background: var(--surface-2); color: var(--fg); }
.pal-btn.is-done { background: var(--fg-soft); border-color: var(--fg-soft); color: oklch(97% 0.004 240); }
.pal-btn.is-flag { border-color: var(--warn); background: var(--warn-bg); color: oklch(44% 0.12 70); }
.pal-btn.is-now { outline: 2px solid var(--fg); outline-offset: 1px; }

/* ---------- misc ------------------------------------------------------- */

.divider { height: 1px; background: var(--border); border: 0; margin: 22px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; 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: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  font-size: 15px;
  line-height: 1.62;
  max-height: 210px;
  overflow-y: auto;
}
.passage h4 { font-size: 14px; margin-bottom: 8px; }
.passage p + p { margin-top: 10px; }

.q-stem {
  font-size: 17px;
  line-height: 1.5;
  letter-spacing: -0.003em;
  font-weight: 500;
}

.note {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  padding: 13px 14px;
  font-size: 14.5px;
  line-height: 1.58;
}
.note__head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}
.note__head svg { width: 14px; height: 14px; }

.kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--surface);
  font-size: 11.5px;
  font-weight: 600;
  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; }
}
