/* ============================================
   English Reading AI — Design System
   Palette: paper/ink neutrals + single emerald accent
   Type: Be Vietnam Pro (UI) / Lora (reading)
   ============================================ */

:root {
  /* Neutrals */
  --paper: #fafaf9;
  --surface: #ffffff;
  --line: #e7e5e4;
  --line-strong: #d6d3d1;
  --ink: #1c1917;
  --ink-soft: #57534e;
  --ink-faint: #a8a29e;

  /* Accent — one family, locked */
  --accent: #047857;
  --accent-strong: #065f46;
  --accent-soft: #ecfdf5;
  --accent-line: #a7f3d0;

  /* Semantic word states */
  --state-unknown: #b45309;
  --state-unknown-bg: #fef3c7;
  --state-learning: #0369a1;
  --state-learning-bg: #e0f2fe;
  --state-known: var(--accent);
  --state-known-bg: var(--accent-soft);

  --danger: #b91c1c;
  --danger-bg: #fee2e2;

  /* Type */
  --font-ui: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  --font-reading: 'Lora', Georgia, serif;

  /* Shape — soft system, locked */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.05);
  --shadow-md: 0 4px 16px rgba(28, 25, 23, 0.07);
  --shadow-pop: 0 8px 32px rgba(28, 25, 23, 0.14);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: inherit; }
button { font-family: inherit; }

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

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

.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 24px; }

.main { flex: 1; padding: 40px 0 80px; }

/* ---------- Top nav ---------- */

.nav {
  height: 64px;
  background: rgba(250, 250, 249, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.nav-inner { height: 100%; display: flex; align-items: center; gap: 32px; }
.nav-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 16px; text-decoration: none; letter-spacing: -0.02em;
}
.nav-brand-mark {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff; display: grid; place-items: center;
  font-family: var(--font-reading); font-style: italic; font-size: 16px; font-weight: 600;
}
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
  padding: 7px 14px; border-radius: 999px;
  font-size: 14px; font-weight: 500; text-decoration: none; color: var(--ink-soft);
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.nav-link:hover { background: #f0efee; color: var(--ink); }
.nav-link.active { background: var(--ink); color: #fff; }
.nav-user { display: flex; align-items: center; gap: 12px; }
.nav-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  border: 1px solid var(--accent-line); overflow: hidden;
}
.nav-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 22px; border-radius: 999px;
  font-size: 14px; font-weight: 600; text-decoration: none;
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: transform 0.15s var(--ease), box-shadow 0.2s var(--ease),
              background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); box-shadow: 0 4px 14px rgba(4, 120, 87, 0.25); }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--ink-faint); background: #fcfcfb; }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: #f0efee; color: var(--ink); }

.btn-lg { padding: 14px 28px; font-size: 15px; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink); }
.input {
  width: 100%; padding: 12px 14px;
  font-size: 15px; font-family: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.12);
}
.field-error { font-size: 13px; color: var(--danger); }

/* ---------- Cards & panels ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.alert {
  padding: 12px 16px; border-radius: var(--r-md);
  font-size: 14px; margin-bottom: 20px;
}
.alert-success { background: var(--accent-soft); color: var(--accent-strong); border: 1px solid var(--accent-line); }
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }

/* ---------- Auth pages ---------- */

.auth-wrap {
  min-height: 100dvh; display: grid; place-items: center;
  padding: 32px 20px;
  background:
    radial-gradient(800px 400px at 85% -10%, rgba(4, 120, 87, 0.07), transparent),
    var(--paper);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: var(--shadow-md);
  animation: rise 0.5s var(--ease) both;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; font-weight: 700; }
.auth-title { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 6px; }
.auth-sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 28px; }
.auth-alt { text-align: center; font-size: 14px; color: var(--ink-soft); margin-top: 24px; }
.auth-alt a { color: var(--accent); font-weight: 600; text-decoration: none; }

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--ink-faint); font-size: 12px; margin: 22px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.btn-google {
  background: var(--surface); color: var(--ink); border-color: var(--line-strong);
  width: 100%;
}
.btn-google:hover { border-color: var(--ink-faint); background: #fcfcfb; }

/* Code input (verify email) */
.code-input {
  font-size: 28px; letter-spacing: 14px; text-align: center;
  font-variant-numeric: tabular-nums; font-weight: 600;
  padding: 16px;
}

/* ---------- Onboarding wizard ---------- */

.onb-wrap { max-width: 640px; margin: 0 auto; padding: 48px 24px 80px; }
.onb-progress {
  height: 4px; background: var(--line); border-radius: 999px;
  overflow: hidden; margin-bottom: 40px;
}
.onb-progress-bar {
  height: 100%; background: var(--accent); border-radius: 999px;
  transition: width 0.45s var(--ease);
}
.onb-step { display: none; animation: rise 0.4s var(--ease) both; }
.onb-step.active { display: block; }
.onb-kicker { font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 8px; }
.onb-title { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin-bottom: 8px; }
.onb-sub { color: var(--ink-soft); margin-bottom: 32px; }
.onb-nav { display: flex; justify-content: space-between; margin-top: 36px; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }

.choice {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 16px 44px 16px 18px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); cursor: pointer;
  font-size: 15px; font-weight: 500;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease),
              transform 0.15s var(--ease), box-shadow 0.2s var(--ease);
}
.choice:hover { border-color: var(--ink-faint); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice.selected {
  border-color: var(--accent); background: var(--accent-soft);
  color: var(--accent-strong); font-weight: 600;
}

/* Tick icon khi được chọn */
.choice::after {
  content: "";
  position: absolute; right: 14px; top: 50%;
  width: 22px; height: 22px; border-radius: 50%;
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center; background-size: 12px;
  opacity: 0; transform: translateY(-50%) scale(0.5);
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}
.choice.selected::after { opacity: 1; transform: translateY(-50%) scale(1); }
.choice .choice-big { font-size: 20px; font-weight: 700; }

.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice-stack { flex-direction: column; align-items: flex-start; gap: 3px; }
.choice-stack-title { font-weight: 700; font-size: 15px; }
.choice-stack-desc { font-size: 13px; color: var(--ink-soft); font-weight: 400; }
.choice-stack.selected .choice-stack-desc { color: var(--accent-strong); opacity: 0.8; }

/* ---------- Dashboard ---------- */

.dash-hero { margin-bottom: 36px; }
.dash-greeting { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.dash-sub { color: var(--ink-soft); margin-top: 4px; }

.stat-row {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 0;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--surface); overflow: hidden;
  margin-bottom: 36px;
}
.stat {
  padding: 22px 24px;
  border-left: 1px solid var(--line);
}
.stat:first-child { border-left: none; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-value .unit { font-size: 15px; font-weight: 500; color: var(--ink-faint); margin-left: 2px; }
.stat-label { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.stat-streak .stat-value { color: var(--accent); }

.dash-actions { display: flex; gap: 12px; margin-bottom: 44px; flex-wrap: wrap; }

.section-title { font-size: 17px; font-weight: 700; margin-bottom: 16px; letter-spacing: -0.01em; }

/* Reading list */
.reading-list { display: flex; flex-direction: column; }
.reading-row {
  display: flex; align-items: center; gap: 18px;
  padding: 18px 4px;
  border-top: 1px solid var(--line);
  text-decoration: none;
  transition: background 0.15s var(--ease);
}
.reading-row:last-child { border-bottom: 1px solid var(--line); }
.reading-row:hover { background: #f5f5f4; }
.reading-row-body { flex: 1; min-width: 0; }
.reading-row-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading-row-meta { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }

.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge-level { background: #f0efee; color: var(--ink-soft); }
.badge-completed { background: var(--state-known-bg); color: var(--accent-strong); }
.badge-reading { background: var(--state-learning-bg); color: var(--state-learning); }
.badge-new { background: #f0efee; color: var(--ink-soft); }

/* ---------- Reading page ---------- */

.read-layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 48px;
  align-items: start;
}

.read-head { margin-bottom: 28px; }
.read-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 13px; color: var(--ink-soft); }
.read-title {
  font-family: var(--font-reading);
  font-size: 34px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2;
}
.read-summary {
  margin-top: 12px; color: var(--ink-soft); font-size: 15px;
  padding-left: 14px; border-left: 3px solid var(--accent-line);
}

.read-progress {
  position: sticky; top: 64px; z-index: 30;
  height: 3px; background: transparent; margin: 0 -24px;
}
.read-progress-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }

.read-content {
  font-family: var(--font-reading);
  font-size: 19px; line-height: 1.85; color: #292524;
  max-width: 65ch;
}
.read-content p { margin-bottom: 1.4em; }

/* Interactive words — mọi từ đều tra được */
.read-single { max-width: 68ch; margin: 0 auto; }
.read-hint { margin-top: 14px; font-size: 13px; color: var(--ink-faint); }

.w {
  cursor: pointer; border-radius: 3px;
  padding: 0 1px; margin: 0 -1px;
  transition: background-color 0.15s var(--ease);
}
.w:hover { background-color: var(--state-unknown-bg); }
.w[data-status="unknown"], .w[data-status="learning"] {
  background-image: linear-gradient(transparent 78%, var(--state-learning-bg) 78%);
}
.w[data-status="unknown"]:hover, .w[data-status="learning"]:hover { background-color: var(--state-learning-bg); }
.w[data-status="known"] { background-image: linear-gradient(transparent 78%, var(--state-known-bg) 78%); }
.w[data-status="known"]:hover { background-color: var(--state-known-bg); }

/* Bản dịch tiếng Việt xen kẽ */
.read-content .vi-para {
  display: none;
  font-family: var(--font-ui);
  font-size: 15.5px; line-height: 1.7;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-left: 3px solid var(--accent-line);
  padding: 12px 16px; border-radius: 0 var(--r-md) var(--r-md) 0;
  margin-top: -0.7em;
}
.read-content.show-vi .vi-para { display: block; animation: rise 0.3s var(--ease) both; }

/* Chip tra cụm từ khi bôi đen */
.selection-chip {
  position: absolute; z-index: 70;
  padding: 7px 14px; border-radius: 999px;
  background: var(--ink); color: #fff;
  font-size: 13px; font-weight: 600; font-family: var(--font-ui);
  border: none; cursor: pointer;
  box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(4px); pointer-events: none;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease);
}
.selection-chip.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.selection-chip:hover { background: #000; }

/* Toolbar cuối bài */
.read-toolbar { display: flex; gap: 12px; flex-wrap: wrap; }

/* Popover loading */
.pop-loading {
  display: none; align-items: center; gap: 10px;
  color: var(--ink-soft); font-size: 14px; padding: 6px 0;
}

/* Word popover */
.popover {
  position: absolute; z-index: 60;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-pop);
  padding: 18px;
  opacity: 0; transform: translateY(6px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s var(--ease), transform 0.18s var(--ease);
}
.popover.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.pop-word { font-family: var(--font-reading); font-size: 20px; font-weight: 600; }
.pop-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; font-size: 13px; color: var(--ink-soft); }
.pop-ipa { font-family: var(--font-ui); }
.pop-pos { font-style: italic; }
.pop-meaning { margin-top: 10px; font-size: 15px; font-weight: 500; }
.pop-example {
  margin-top: 8px; font-size: 13.5px; color: var(--ink-soft);
  font-style: italic; padding-left: 10px; border-left: 2px solid var(--line);
}
.pop-status { margin-top: 10px; font-size: 12px; font-weight: 600; }
.pop-status.learning { color: var(--state-learning); }
.pop-status.known { color: var(--state-known); }
.pop-actions { display: flex; gap: 8px; margin-top: 14px; }
.pop-btn {
  flex: 1; padding: 8px 10px; border-radius: var(--r-sm);
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease);
}
.pop-btn:active { transform: scale(0.97); }
.pop-btn-unknown:hover { background: var(--state-unknown-bg); border-color: var(--state-unknown); color: var(--state-unknown); }
.pop-btn-known:hover { background: var(--state-known-bg); border-color: var(--accent); color: var(--accent-strong); }

/* Vocab side panel */
.vocab-panel { position: sticky; top: 88px; }
.vocab-panel-title {
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft); margin-bottom: 14px;
}
.vocab-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 10px 0; border-top: 1px solid var(--line);
  cursor: pointer; transition: background 0.15s var(--ease);
}
.vocab-item:hover { background: #f5f5f4; }
.vocab-item-word { font-weight: 600; font-size: 14px; }
.vocab-item-meaning {
  font-size: 13px; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;
}

.read-done { margin-top: 44px; padding-top: 28px; border-top: 1px solid var(--line); }

/* ---------- Vocabulary page ---------- */

.filter-tabs { display: flex; gap: 6px; margin-bottom: 24px; }
.filter-tab {
  padding: 7px 16px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; text-decoration: none;
  color: var(--ink-soft); border: 1px solid transparent;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.filter-tab:hover { background: #f0efee; }
.filter-tab.active { background: var(--ink); color: #fff; }
.filter-tab .count { font-weight: 500; opacity: 0.65; margin-left: 4px; }

/* Ajax list container (Reading/Writing tabs + pagination không load lại trang) */
[data-list-container] { transition: opacity 0.15s var(--ease); }
[data-list-container].is-loading { opacity: 0.45; pointer-events: none; }

.vocab-table { width: 100%; border-collapse: collapse; }
.vocab-table th {
  text-align: left; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-faint); padding: 0 14px 10px 4px;
}
.vocab-table td {
  padding: 13px 14px 13px 4px; border-top: 1px solid var(--line);
  font-size: 14.5px; vertical-align: middle;
}
.vocab-word-cell { font-weight: 600; }
.vocab-ipa-cell { color: var(--ink-faint); font-size: 13px; }

.mastery {
  display: inline-flex; align-items: center; gap: 8px;
  font-variant-numeric: tabular-nums; font-size: 13px; color: var(--ink-soft);
}
.mastery-bar { width: 56px; height: 4px; border-radius: 999px; background: var(--line); overflow: hidden; }
.mastery-fill { height: 100%; background: var(--accent); border-radius: 999px; }

.status-pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-unknown { background: var(--state-unknown-bg); color: var(--state-unknown); }
.status-learning { background: var(--state-learning-bg); color: var(--state-learning); }
.status-known { background: var(--state-known-bg); color: var(--accent-strong); }

/* ---------- Empty states ---------- */

.empty {
  text-align: center; padding: 72px 24px;
  border: 1px dashed var(--line-strong); border-radius: var(--r-lg);
}
.empty-icon {
  width: 52px; height: 52px; margin: 0 auto 16px;
  border-radius: 50%; background: var(--accent-soft);
  display: grid; place-items: center;
  font-family: var(--font-reading); font-style: italic; font-size: 22px; color: var(--accent);
}
.empty-title { font-weight: 700; font-size: 16px; }
.empty-sub { color: var(--ink-soft); font-size: 14px; margin: 6px 0 20px; }

/* ---------- Pagination ---------- */

.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 32px; }
.page-link {
  min-width: 36px; height: 36px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm); font-size: 14px; text-decoration: none;
  color: var(--ink-soft); border: 1px solid transparent;
}
.page-link:hover { background: #f0efee; }
.page-link.active { background: var(--ink); color: #fff; }
.page-link.disabled { opacity: 0.4; pointer-events: none; }

/* ---------- Quiz modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(28, 25, 23, 0.45);
  backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s var(--ease);
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.modal {
  width: 100%; max-width: 640px; max-height: 86dvh;
  background: var(--surface); border-radius: 20px;
  box-shadow: var(--shadow-pop);
  display: flex; flex-direction: column;
  transform: translateY(14px) scale(0.98);
  transition: transform 0.25s var(--ease);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 34px; height: 34px; border-radius: 50%;
  border: none; background: #f0efee; color: var(--ink-soft);
  font-size: 20px; line-height: 1; cursor: pointer;
  transition: background 0.15s var(--ease);
}
.modal-close:hover { background: var(--line); color: var(--ink); }

.modal-body { padding: 20px 24px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 24px; border-top: 1px solid var(--line);
}

.quiz-loading { display: flex; align-items: center; gap: 12px; color: var(--ink-soft); padding: 24px 0; }
.quiz-error { color: var(--danger); padding: 12px 0; }
.quiz-score { font-weight: 700; font-size: 15px; }

.quiz-q { padding: 18px 0; border-top: 1px solid var(--line); }
.quiz-q:first-child { border-top: none; padding-top: 4px; }
.quiz-q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.quiz-num { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.quiz-question { font-weight: 600; font-size: 15.5px; margin-bottom: 12px; }

/* ---------- Lịch sử trả lời (collapse) ---------- */

.collapse {
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.collapse summary {
  padding: 14px 18px;
  font-size: 14px; font-weight: 600;
  cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 8px;
  user-select: none;
  transition: background 0.15s var(--ease);
}
.collapse summary::-webkit-details-marker { display: none; }
.collapse summary::before {
  content: "";
  width: 8px; height: 8px;
  border-right: 2px solid var(--ink-faint);
  border-bottom: 2px solid var(--ink-faint);
  transform: rotate(-45deg);
  transition: transform 0.2s var(--ease);
  flex-shrink: 0;
}
.collapse[open] summary::before { transform: rotate(45deg); }
.collapse summary:hover { background: #f5f5f4; }
.collapse-count {
  margin-left: auto;
  min-width: 24px; height: 24px; padding: 0 8px;
  border-radius: 999px;
  background: #f0efee; color: var(--ink-soft);
  font-size: 12.5px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}

.history-list { border-top: 1px solid var(--line); padding: 4px 18px 10px; }
.history-row {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}
.history-row:first-child { border-top: none; }
.history-date { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.history-score { font-weight: 600; }
.history-detail { margin-left: auto; }
.history-empty { padding: 12px 0; color: var(--ink-faint); font-size: 14px; }

.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 14px; border: 1px solid var(--line-strong); border-radius: var(--r-md);
  font-size: 14.5px; cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.quiz-opt:hover { border-color: var(--ink-faint); }
.quiz-opt input { position: absolute; opacity: 0; pointer-events: none; }
.quiz-letter {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  background: #f0efee; font-size: 12.5px; font-weight: 700; color: var(--ink-soft);
}
.quiz-opt.picked { border-color: var(--accent); background: var(--accent-soft); }
.quiz-opt.picked .quiz-letter { background: var(--accent); color: #fff; }
.quiz-opt.correct { border-color: var(--accent); background: var(--state-known-bg); }
.quiz-opt.correct .quiz-letter { background: var(--accent); color: #fff; }
.quiz-opt.wrong { border-color: var(--danger); background: var(--danger-bg); }
.quiz-opt.wrong .quiz-letter { background: var(--danger); color: #fff; }

.quiz-explain {
  margin-top: 12px; padding: 12px 14px; border-radius: var(--r-md);
  font-size: 13.5px; line-height: 1.6;
}
.quiz-explain.is-correct { background: var(--state-known-bg); color: var(--accent-strong); }
.quiz-explain.is-wrong { background: var(--danger-bg); color: #7f1d1d; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translate(-50%, 16px);
  background: var(--ink); color: #fff;
  padding: 12px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  opacity: 0; pointer-events: none; z-index: 80;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Loading overlay (generate) ---------- */

.gen-loading { display: none; align-items: center; gap: 12px; color: var(--ink-soft); font-size: 14px; }
.gen-loading.show { display: inline-flex; }
.spinner-dots { display: inline-flex; gap: 4px; }
.spinner-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
.spinner-dots span:nth-child(2) { animation-delay: 0.15s; }
.spinner-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes pulse-dot {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Dashboard module chooser (Reading / Writing) ---------- */

.module-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin: 28px 0 36px;
}
.module-card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 24px; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--line);
  text-decoration: none; box-shadow: var(--shadow-sm);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), transform 0.2s var(--ease);
}
.module-card:hover {
  border-color: var(--accent-line); box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.module-icon {
  width: 40px; height: 40px; border-radius: var(--r-md);
  display: grid; place-items: center;
  font-family: var(--font-reading); font-style: italic; font-size: 19px; font-weight: 600;
}
.module-card-reading .module-icon { background: var(--accent-soft); color: var(--accent-strong); }
.module-card-writing .module-icon { background: var(--state-learning-bg); color: var(--state-learning); }
.module-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.module-desc { font-size: 13.5px; color: var(--ink-soft); line-height: 1.55; flex: 1; }
.module-meta { font-size: 13px; color: var(--ink-faint); }
.module-cta {
  margin-top: 2px; font-size: 14px; font-weight: 600; color: var(--accent);
  display: inline-flex; align-items: center; gap: 6px;
}
.module-card-writing .module-cta { color: var(--state-learning); }

/* ---------- Writing: blocks nhập câu ---------- */

.write-score {
  display: none; align-items: center; gap: 16px;
  margin-bottom: 24px; padding: 18px 22px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  animation: rise 0.35s var(--ease);
}
.write-score.show { display: flex; }
.score-num {
  flex-shrink: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
  color: var(--accent-strong);
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  padding: 8px 16px; border-radius: var(--r-md);
}
.score-text { font-size: 14.5px; color: var(--ink-soft); line-height: 1.55; }

.write-blocks { display: flex; flex-direction: column; gap: 20px; margin-bottom: 32px; }

.write-block {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}
.write-label {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 6px;
}
.write-vn { margin-bottom: 14px; }
.write-vn-sentence {
  font-family: var(--font-reading); font-size: 17px; line-height: 1.65;
}
.write-input-wrap { position: relative; }
.write-input {
  width: 100%; resize: vertical; min-height: 58px;
  padding: 12px 14px; border-radius: var(--r-md);
  border: 1.5px solid var(--line-strong);
  font-family: var(--font-ui); font-size: 15px; line-height: 1.6; color: var(--ink);
  background: var(--paper);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.write-input:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.12);
  background: var(--surface);
}

/* ---------- Writing: autocomplete ---------- */

.ac-menu {
  display: none; position: absolute; left: 0; top: calc(100% + 4px);
  min-width: 180px; max-width: 100%;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop);
  z-index: 60; overflow: hidden; padding: 4px;
}
.ac-menu.open { display: block; }
.ac-item {
  padding: 8px 12px; border-radius: var(--r-sm);
  font-size: 14.5px; cursor: pointer;
}
.ac-item:hover, .ac-item.active { background: var(--accent-soft); color: var(--accent-strong); }
.ac-item-priority { font-weight: 600; }
.ac-item-priority::after {
  content: '★'; margin-left: 8px; font-size: 11px; color: var(--state-unknown);
}

/* ---------- Writing: feedback sau khi chấm ---------- */

.write-feedback { display: none; }
.write-feedback.show { display: block; animation: rise 0.35s var(--ease); }

.fb-head { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.fb-head.fb-ok { color: var(--accent-strong); }
.fb-head.fb-bad { color: var(--danger); }
.fb-head.fb-empty { color: var(--ink-faint); }

.fb-answer {
  font-family: var(--font-reading); font-size: 16.5px; line-height: 1.9;
  padding: 12px 14px; border-radius: var(--r-md);
  background: var(--paper); border: 1px solid var(--line);
  margin-bottom: 10px;
}
.fb-answer-ok { border-color: var(--accent-line); background: var(--accent-soft); }

.err-mark { border-radius: 4px; padding: 1px 3px; font-weight: 500; }
.err-mark sup { font-size: 10px; font-weight: 700; margin-left: 1px; }
.err-wrong { background: var(--danger-bg); color: var(--danger); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.err-wrong sup { color: var(--danger); }
.err-missing { background: var(--state-unknown-bg); color: var(--state-unknown); text-decoration: underline dotted; text-underline-offset: 3px; }
.err-missing sup { color: var(--state-unknown); }

.fb-label {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-faint); margin-bottom: 3px;
}
.fb-corrected {
  font-family: var(--font-reading); font-size: 16px; line-height: 1.7;
  padding: 12px 14px; border-radius: var(--r-md);
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  color: var(--accent-strong); margin-bottom: 12px;
}

.fb-errors { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.fb-error { display: flex; gap: 10px; align-items: flex-start; }
.fb-error-num {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; margin-top: 1px;
  background: var(--danger-bg); color: var(--danger);
  font-size: 11.5px; font-weight: 700;
}
.fb-error-body { flex: 1; min-width: 0; }
.fb-error-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.fb-error-type {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  background: #f0efee; color: var(--ink-soft);
  padding: 2px 8px; border-radius: 999px;
}
.fb-wrong { color: var(--danger); text-decoration: line-through; }
.fb-arrow { color: var(--ink-faint); }
.fb-right { color: var(--accent-strong); font-weight: 600; }
.fb-explain { font-size: 13.5px; color: var(--ink-soft); line-height: 1.6; margin-top: 3px; }

.fb-note {
  font-size: 13.5px; color: var(--ink-soft); line-height: 1.6;
  padding: 10px 14px; border-radius: var(--r-md);
  background: var(--paper); border: 1px solid var(--line);
  margin-bottom: 8px;
}

.write-after { display: none; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 16px; }


/* ============================================
   Beginner Program — lộ trình tĩnh cho người mới
   ============================================ */

.bgn-track-note {
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
  padding: 12px 16px;
  margin: 16px 0 8px;
  color: var(--accent-strong);
  font-size: 14px;
}

.bgn-roadmap { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.bgn-lesson {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--ink);
  transition: border-color .15s, transform .15s;
}
a.bgn-lesson:hover { border-color: var(--accent-line); transform: translateX(2px); }
.bgn-lesson-locked { opacity: .55; background: var(--paper); }
.bgn-lesson-completed { border-color: var(--accent-line); }

.bgn-lesson-order {
  flex: 0 0 34px;
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}
.bgn-lesson-locked .bgn-lesson-order { background: var(--line); color: var(--ink-faint); }

.bgn-lesson-body { flex: 1; min-width: 0; }
.bgn-lesson-title { font-weight: 600; }
.bgn-lesson-meta { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.bgn-lock { font-size: 18px; }

.bgn-progress {
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  margin-top: 8px;
  overflow: hidden;
}
.bgn-progress-bar { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

/* --- Lesson page --- */
.bgn-lesson-head { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 18px; flex-wrap: wrap; }
.bgn-lesson-head > div:nth-child(2) { flex: 1; min-width: 220px; }
.bgn-overall { min-width: 200px; text-align: right; }
.bgn-overall .bgn-progress { margin-top: 6px; }
.bgn-overall-value { font-size: 28px; font-weight: 700; color: var(--accent-strong); }

.bgn-sections { display: flex; flex-direction: column; gap: 18px; }
.bgn-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px 20px;
}
.bgn-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.bgn-section-title { font-size: 17px; font-weight: 700; }
.bgn-intro { color: var(--ink-soft); font-size: 14px; margin-bottom: 12px; }
.bgn-hint { color: var(--ink-faint); font-size: 13px; margin-bottom: 10px; }

.bgn-vocab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.bgn-vocab-card {
  border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; background: var(--paper);
  cursor: pointer; transition: border-color 0.15s var(--ease), transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.bgn-vocab-card:hover, .bgn-vocab-card:focus-visible { border-color: var(--accent-line); transform: translateY(-1px); box-shadow: var(--shadow-sm); outline: none; }
.bgn-vocab-word { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 6px; }
.bgn-vocab-phonetic { color: var(--ink-faint); font-size: 13px; }
.bgn-vocab-meaning { color: var(--accent-strong); font-size: 14px; margin-top: 4px; }
.bgn-vocab-example { font-size: 13px; color: var(--ink-soft); margin-top: 6px; }
.bgn-example-vi { display: block; color: var(--ink-faint); font-size: 12px; font-style: italic; }
.bgn-target-text { font-weight: 600; }
.bgn-zoom-hint { font-size: 13px; opacity: 0.45; margin-left: auto; }

.bgn-tts { background: none; border: none; cursor: pointer; font-size: 14px; padding: 0 2px; }
.bgn-chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); padding: 4px 10px; margin: 2px 4px 2px 0;
  font-size: 13px; cursor: pointer;
}
.bgn-chip:hover { border-color: var(--accent-line); }

.bgn-pron-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.bgn-pron-row:last-child { border-bottom: none; }
.bgn-pron-sound { font-weight: 700; font-size: 18px; color: var(--accent-strong); min-width: 56px; }
.bgn-pron-tip { font-size: 14px; }

.bgn-grammar-point { margin-bottom: 14px; }
.bgn-grammar-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.bgn-grammar-explain { font-size: 14px; color: var(--ink-soft); }
.bgn-grammar-examples { list-style: none; margin-top: 8px; padding-left: 10px; border-left: 3px solid var(--accent-line); }
.bgn-grammar-examples li { margin-bottom: 6px; font-size: 14px; }

.bgn-passage { background: var(--paper); border-radius: var(--r-sm); padding: 14px 16px; }
.bgn-passage-text { font-family: var(--font-reading); font-size: 17px; line-height: 1.8; margin-bottom: 10px; }
.bgn-translation { margin-top: 10px; font-size: 14px; color: var(--ink-soft); }
.bgn-translation summary { cursor: pointer; color: var(--accent-strong); }

.bgn-listen-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; }
.bgn-listen-row details { font-size: 14px; }
.bgn-listen-row summary { cursor: pointer; color: var(--ink-faint); font-size: 13px; }

.bgn-speak-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.bgn-speak-row:last-child { border-bottom: none; }

.bgn-exercises { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 14px; }
.bgn-study-only { border-top: none; padding-top: 4px; }
.bgn-exercise { margin-bottom: 14px; }
.bgn-exercise-q { font-size: 15px; margin-bottom: 8px; }
.bgn-exercise-num { font-weight: 700; color: var(--accent-strong); }
.bgn-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
.bgn-option { font-size: 14px; padding: 10px 44px 10px 14px; }
.bgn-answer-input { width: 100%; max-width: 480px; }
.bgn-exercise-feedback { font-size: 14px; margin-top: 6px; }
.bgn-fb-ok { color: var(--accent-strong); font-weight: 600; }
.bgn-fb-bad { color: var(--danger); font-weight: 600; }

/* ---------- Beginner: popup phóng to từ vựng + luyện viết ---------- */
.bgn-word-modal { max-width: 520px; }
.bgn-word-modal-title { font-size: 32px; font-weight: 800; line-height: 1.2; }
.bgn-word-modal-top { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.bgn-word-modal-tts { font-size: 20px; }
.bgn-word-modal-phonetic { color: var(--ink-faint); font-size: 15px; }
.bgn-word-modal-meaning { font-size: 17px; font-weight: 600; color: var(--accent-strong); margin-bottom: 8px; }
.bgn-word-modal-example { font-size: 14px; color: var(--ink-soft); margin-bottom: 4px; }

.bgn-write-practice { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.bgn-write-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.bgn-write-head h3 { font-size: 15px; font-weight: 700; }
.bgn-write-actions { display: flex; gap: 8px; }
.bgn-write-canvas-wrap {
  position: relative; width: 100%; max-width: 400px; aspect-ratio: 1 / 1;
  margin: 0 auto; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: #fff; overflow: hidden; touch-action: none;
}
.bgn-write-canvas-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.bgn-fb-explain { color: var(--ink-soft); font-size: 13px; margin-top: 2px; }

/* --- Dashboard: thẻ ngôn ngữ + module khóa --- */
.dash-lang-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600;
}
.module-card-locked { opacity: .6; pointer-events: none; filter: grayscale(.3); }
.module-card-beginner .module-icon { background: #fef3c7; color: #b45309; }

/* ---------- Responsive ---------- */

/* Tablet */
@media (max-width: 900px) {
  .read-layout { grid-template-columns: 1fr; gap: 32px; }
  .vocab-panel { position: static; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(odd) { border-left: none; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .onb-wrap { padding: 36px 24px 64px; }
}

/* Mobile */
@media (max-width: 640px) {
  .container { padding: 0 16px; }

  /* Nav gọn lại: ẩn tên app, giữ logo */
  .nav-inner { gap: 10px; }
  .nav-brand span:last-child { display: none; }
  .nav-links { gap: 0; flex: 1; justify-content: center; }
  .nav-link { padding: 6px 10px; font-size: 13px; }
  .nav-user { gap: 8px; }
  .nav-user .btn { padding: 6px 10px; font-size: 12.5px; }

  /* Dashboard */
  .dash-greeting { font-size: 22px; }
  .dash-actions { flex-direction: column; align-items: stretch; }
  .dash-actions form { display: flex; }
  .dash-actions .btn { width: 100%; justify-content: center; }
  .stat { padding: 16px 18px; }
  .stat-value { font-size: 24px; }

  /* Reading list: badge xuống dòng gọn gàng */
  .reading-row { flex-wrap: wrap; gap: 8px 10px; padding: 14px 4px; }
  .reading-row-body { flex-basis: 100%; }
  .badge { font-size: 11.5px; padding: 2px 9px; }

  /* Trang đọc */
  .read-title { font-size: 25px; }
  .read-content { font-size: 17.5px; line-height: 1.8; }
  .read-summary { font-size: 14px; }
  .read-toolbar { flex-direction: column; align-items: stretch; }
  .read-toolbar form { display: flex; }
  .read-toolbar .btn { width: 100%; justify-content: center; }

  /* Popover không tràn màn hình */
  .popover { width: min(300px, calc(100vw - 24px)); }

  /* Modal quiz full-width thoải mái hơn */
  .modal-backdrop { padding: 10px; }
  .modal { max-height: 94dvh; border-radius: 16px; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 12px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }
  .quiz-opt { padding: 10px 12px; font-size: 14px; }

  /* Lịch sử */
  .history-row { flex-wrap: wrap; gap: 4px 12px; }
  .history-detail { margin-left: 0; flex-basis: 100%; justify-content: flex-start; padding-left: 0; }

  /* Vocabulary */
  .filter-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .filter-tab { white-space: nowrap; flex-shrink: 0; }
  .vocab-table .hide-sm { display: none; }
  .vocab-table td { padding: 12px 10px 12px 2px; }

  /* Onboarding + auth */
  .choice-grid, .choice-grid.cols-3 { grid-template-columns: 1fr; }
  .onb-title { font-size: 23px; }
  .onb-nav { position: sticky; bottom: 0; padding: 12px 0;
             background: linear-gradient(transparent, var(--paper) 30%); }
  .auth-card { padding: 30px 22px; }
  .code-input { font-size: 24px; letter-spacing: 10px; }

  .main { padding: 28px 0 64px; }

  /* Writing */
  .module-grid { grid-template-columns: 1fr; }
  .write-block { padding: 16px; }
  .write-vn-sentence { font-size: 16px; }
  .write-score { flex-direction: column; align-items: flex-start; gap: 10px; }
  .write-after { flex-direction: column; align-items: stretch; }
  .write-after .btn { width: 100%; justify-content: center; }
  .write-after form { display: flex; }

  /* Beginner lesson */
  .bgn-overall { text-align: left; width: 100%; }
  .bgn-overall-value { font-size: 24px; }
  .bgn-section { padding: 14px 16px; }
  .bgn-section-title { font-size: 15.5px; }
  .bgn-vocab-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .bgn-vocab-card { padding: 10px 12px; }
  .bgn-options { grid-template-columns: 1fr; }
  .bgn-submit { width: 100%; }
  .bgn-pron-row, .bgn-listen-row, .bgn-speak-row { gap: 8px; }

  .bgn-word-modal-title { font-size: 25px; }
  .bgn-write-canvas-wrap { max-width: 100%; }
}

/* Màn hình rất nhỏ */
@media (max-width: 420px) {
  .nav-avatar { display: none; }
  .nav-link { padding: 6px 8px; font-size: 12.5px; }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .read-meta { flex-wrap: wrap; row-gap: 4px; }
}

/* Touch: vùng chạm tối thiểu cho từ trong bài */
@media (hover: none) {
  .w { padding: 2px 1px; }
  .pop-btn { padding: 11px 10px; }
  .bgn-tts { padding: 6px; }
  .bgn-option { padding: 12px 44px 12px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
