/* Khung app (sidebar, topbar, thanh tab mobile, tìm nhanh) và lớp hoàn thiện cho các component dùng chung.
   Nạp sau cùng: style.css / trainer.css / gv.css giữ bố cục từng màn luyện, file này lo phần nhìn chung. */

/* ---------- Nền tảng ---------- */
:root {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

a {
  color: var(--brand-ink);
}

button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, select, textarea {
  color: var(--ink);
  background-color: var(--surface);
  border-color: var(--line-strong);
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: -60px;
  z-index: 100;
  background: var(--brand);
  color: var(--on-brand);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.loading {
  color: var(--ink-3);
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 40;
}

.sidebar-head {
  padding: 18px 18px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), var(--brand-strong));
  color: var(--on-brand);
  font: 700 22px/1 var(--font-serif);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--shadow) 18%, transparent);
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.3px;
  line-height: 1.1;
}

.brand-name small {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--ink-4);
  margin-top: 3px;
}

.search-trigger {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 6px 14px 8px;
  padding: 9px 10px 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-4);
  font-size: 13.5px;
  text-align: left;
  transition: border-color .15s, background .15s;
}

.search-trigger:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}

.search-trigger-label {
  flex: 1;
}

kbd {
  font: 600 11px var(--font);
  color: var(--ink-3);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  white-space: nowrap;
}

#nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.nav-group {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--ink-4);
  margin: 18px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: 9px;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.3;
  transition: background .12s, color .12s;
}

.nav-item .icon {
  color: var(--ink-4);
  transition: color .12s;
}

.nav-item:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.nav-item:hover .icon {
  color: var(--ink-2);
}

.nav-item.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 600;
}

.nav-item.active .icon {
  color: var(--brand-ink);
}

.nav-label {
  flex: 1;
  min-width: 0;
}

.nav-meta {
  font-size: 11.5px;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.nav-badge {
  font-size: 11px;
  font-weight: 650;
  color: var(--amber-ink);
  background: var(--amber-soft);
  border: 1px solid var(--amber-line);
  border-radius: 999px;
  padding: 1px 8px;
  white-space: nowrap;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 12px 18px 14px;
  display: grid;
  gap: 10px;
}

.sidebar-progress small {
  display: block;
  margin-top: 7px;
  font-size: 12px;
  color: var(--ink-3);
}

#backup-row small {
  display: block;
  font-size: 12px;
  color: var(--ink-4);
  margin-bottom: 7px;
}

#backup-row small.warn {
  color: var(--amber-ink);
}

.backup-buttons {
  display: flex;
  gap: 6px;
}

.backup-buttons .tr-chip {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12.5px;
  padding: 6px 8px;
}

.backup-buttons .icon {
  width: 15px;
  height: 15px;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: color-mix(in srgb, var(--shadow) 40%, transparent);
  backdrop-filter: blur(2px);
}

/* ---------- Topbar + vùng nội dung ---------- */
.workspace {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.crumb {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crumb strong {
  font-weight: 600;
}

.topbar-right {
  display: flex;
  gap: 4px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-3);
  transition: background .12s, color .12s;
}

.icon-button:hover {
  background: var(--surface-3);
  color: var(--ink);
}

.icon-button .icon {
  width: 20px;
  height: 20px;
}

#menu-toggle {
  display: none;
}

main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 36px 56px;
}

.page-footer {
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 0 36px 28px;
  font-size: 12px;
  color: var(--ink-4);
}

.page-footer span {
  margin: 0 6px;
}

/* ---------- Kiểu chữ chung ---------- */
.page-head {
  margin: 4px 0 24px;
}

.page-head h1 {
  font-size: clamp(26px, 3.2vw, 34px);
  line-height: 1.2;
  letter-spacing: -.6px;
  color: var(--ink);
  margin: 6px 0 8px;
}

.eyebrow {
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 1.1px;
  text-transform: uppercase;
  color: var(--brand-ink);
}

.subtitle {
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink-3);
  max-width: 760px;
  margin: 0;
}

.section-title {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -.2px;
  color: var(--ink);
  margin: 36px 0 14px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.section-head .text-button {
  font-size: 13.5px;
  color: var(--brand-ink);
  text-decoration: none;
  white-space: nowrap;
}

.section-head .text-button:hover {
  text-decoration: underline;
}

.muted {
  line-height: 1.7;
}

/* ---------- Nút, chip, tab ---------- */
.primary-button, .secondary-button {
  font-size: 14px;
  font-weight: 550;
  padding: 10px 18px;
  border-radius: 10px;
  min-height: 42px;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
}

.primary-button {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  box-shadow: var(--shadow-sm), inset 0 1px 0 color-mix(in srgb, #fff 14%, transparent);
}

.primary-button:hover {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
}

.secondary-button {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
}

.secondary-button:hover {
  border-color: var(--brand-line);
  background: var(--surface-2);
  color: var(--ink);
}

.primary-button:active, .secondary-button:active {
  transform: translateY(1px);
}

.tr-chip {
  font-size: 13px;
  padding: 6px 13px;
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  transition: background .12s, border-color .12s, color .12s;
}

.tr-chip:hover {
  border-color: var(--brand-line);
  color: var(--ink);
}

.tr-chip.active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.lesson-tabs {
  gap: 6px;
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}

.lesson-tabs a, .lesson-tabs button {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 11px 12px;
  font-size: 14px;
  color: var(--ink-3);
  text-decoration: none;
  white-space: nowrap;
  border: 0;
  background: none;
  border-radius: 8px 8px 0 0;
}

.lesson-tabs a:hover, .lesson-tabs button:hover {
  color: var(--ink);
  background: var(--surface-3);
}

.lesson-tabs a.active, .lesson-tabs button.active {
  color: var(--brand-ink);
  font-weight: 600;
}

.lesson-tabs a.active::after, .lesson-tabs button.active::after {
  content: '';
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand-ink);
}

.lesson-breadcrumb {
  font-size: 13px;
  color: var(--ink-4);
}

.lesson-breadcrumb .text-button, .lesson-breadcrumb a {
  font-size: 13px;
  color: var(--ink-3);
  text-decoration: none;
}

.lesson-breadcrumb .text-button:hover, .lesson-breadcrumb a:hover {
  color: var(--brand-ink);
}

.status-pill {
  font-size: 11.5px;
  font-weight: 550;
  padding: 3px 10px;
}

.progress-track {
  height: 6px;
  background: var(--surface-3);
}

.progress-track>div {
  background: linear-gradient(90deg, var(--accent), var(--brand));
  border-radius: inherit;
}

/* ---------- Thẻ, khối ---------- */
.task-card, .topic-card, .format-card, .tr-toolbar, .guide-link, .part-info {
  border-color: var(--line);
  border-radius: var(--radius);
}

.task-card, .topic-card, .guide-link {
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.task-card:hover, .topic-card:hover, .guide-link:hover {
  border-color: var(--brand-line);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.task-card h3 {
  font-size: 15.5px;
  color: var(--ink);
}

.guide-link {
  font-size: 14px;
  color: var(--ink-2);
}

.related-guides {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  gap: 0;
}

.related-guides h4 {
  font-size: 11.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 8px;
}

.related-guides a {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  border-top: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink-2);
  line-height: 1.5;
}

.related-guides a:first-of-type {
  border-top: 0;
}

.related-guides a::after {
  content: '→';
  color: var(--ink-4);
}

.related-guides a:hover {
  color: var(--brand-ink);
}

.empty-copy {
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  font-size: 14.5px;
  color: var(--ink-3);
}

/* ---------- Trang chủ ---------- */
.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 28px;
  padding: 30px 32px;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 55%),
    linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}

.home-hero h1 {
  font-size: clamp(28px, 3.6vw, 38px);
  line-height: 1.15;
  letter-spacing: -.8px;
  margin: 8px 0 8px;
}

.home-hero .eyebrow::first-letter {
  text-transform: uppercase;
}

.next-up {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 22px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--brand);
  color: var(--on-brand);
  text-decoration: none;
  box-shadow: 0 10px 24px -12px color-mix(in srgb, var(--brand) 80%, transparent);
  transition: background .15s, transform .15s;
  max-width: 560px;
}

.next-up:hover {
  background: var(--brand-strong);
  transform: translateY(-1px);
}

.next-up .tile-icon {
  background: color-mix(in srgb, var(--on-brand) 16%, transparent);
  color: var(--on-brand);
}

.next-up .tile-text small {
  color: color-mix(in srgb, var(--on-brand) 78%, transparent);
}

.next-up .tile-text strong {
  font-size: 16px;
  color: var(--on-brand);
}

.next-up .tile-go {
  color: var(--on-brand);
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.hero-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-content: center;
}

.hero-stat {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 8px;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}

.hero-stat .icon {
  color: var(--accent);
  width: 16px;
  height: 16px;
}

.hero-stat strong {
  font-size: 21px;
  letter-spacing: -.4px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.hero-stat span {
  grid-column: 1 / -1;
  font-size: 12.5px;
  color: var(--ink-3);
  margin-top: 2px;
}

.hero-stat:first-child .icon {
  color: var(--amber-base);
}

/* Ô "Ôn tập hôm nay" / thẻ điều hướng */
.today-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}

.today-tile {
  --tone: var(--brand-ink);
  --tone-soft: var(--brand-soft);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.today-tile:hover {
  border-color: color-mix(in srgb, var(--tone) 40%, var(--line));
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.today-tile.tone-amber {
  --tone: var(--amber-ink);
  --tone-soft: var(--amber-soft);
}

.today-tile.tone-blue {
  --tone: var(--blue-ink);
  --tone-soft: var(--blue-soft);
}

.today-tile.tone-violet {
  --tone: var(--violet-ink);
  --tone-soft: var(--violet-soft);
}

.today-tile.tone-red {
  --tone: var(--red-ink);
  --tone-soft: var(--red-soft);
}

.today-tile.is-done {
  --tone: var(--brand-ink);
  --tone-soft: var(--brand-soft);
}

.today-tile.is-done .tile-text strong {
  color: var(--ink-3);
}

.tile-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  background: var(--tone-soft, var(--brand-soft));
  color: var(--tone, var(--brand-ink));
}

.tile-icon .icon {
  width: 21px;
  height: 21px;
}

.tile-text {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.tile-text strong {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}

.tile-text small {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.45;
}

.tile-count {
  min-width: 28px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--tone-soft);
  color: var(--tone);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tile-go {
  color: var(--ink-4);
  transition: transform .15s, color .15s;
}

.today-tile:hover .tile-go, .next-up:hover .tile-go {
  transform: translateX(3px);
  color: var(--tone, currentColor);
}

/* Thẻ 4 kỹ năng */
.skill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.skill-card {
  --skill: var(--speaking);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.skill-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--skill);
  opacity: .85;
}

.skill-card.writing {
  --skill: var(--writing);
}

.skill-card.reading {
  --skill: var(--reading);
}

.skill-card.listening {
  --skill: var(--listening);
}

.skill-card:hover {
  border-color: color-mix(in srgb, var(--skill) 45%, var(--line));
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.skill-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.skill-head>div {
  flex: 1;
  min-width: 0;
}

.skill-head h3 {
  margin: 0;
  font-size: 17px;
  color: var(--ink);
}

.skill-head small {
  font-size: 12.5px;
  color: var(--ink-3);
}

.skill-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--skill) 13%, transparent);
  color: var(--skill);
}

.skill-icon .icon {
  width: 21px;
  height: 21px;
}

.skill-ring {
  --pct: 0%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 650;
  color: var(--ink-2);
  background:
    radial-gradient(closest-side, var(--surface) 76%, transparent 78%),
    conic-gradient(var(--skill) var(--pct), var(--surface-3) 0);
  font-variant-numeric: tabular-nums;
}

.skill-parts {
  display: grid;
  gap: 8px;
}

.skill-parts>div {
  display: grid;
  grid-template-columns: 74px 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-3);
}

.skill-parts small {
  text-align: right;
  font-size: 12px;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}

.skill-parts .progress-track>div {
  background: var(--skill);
}

.format-details {
  margin-top: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 4px 18px;
}

.format-details>summary {
  padding: 13px 0;
  font-weight: 600;
  color: var(--ink-2);
}

.format-details[open]>summary {
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.format-details .format-grid {
  margin-bottom: 14px;
}

/* ---------- Tìm nhanh (⌘K) ---------- */
.palette {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 12vh 16px 16px;
  background: color-mix(in srgb, var(--shadow) 42%, transparent);
  backdrop-filter: blur(3px);
}

.palette[hidden] {
  display: none;
}

.palette-box {
  width: min(640px, 100%);
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop .14s ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(.985);
  }
}

.palette-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-4);
}

.palette-field input {
  flex: 1;
  min-width: 0;
  height: 56px;
  border: 0;
  outline: 0;
  background: none;
  font-size: 16px;
  color: var(--ink);
}

.palette-field input::-webkit-search-cancel-button {
  display: none;
}

.palette-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
}

.palette-group {
  padding: 10px 10px 4px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--ink-4);
}

.palette-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink-3);
}

.palette-row.active {
  background: var(--brand-soft);
  color: var(--brand-ink);
}

.palette-text {
  display: grid;
  min-width: 0;
}

.palette-text strong {
  font-size: 14.5px;
  font-weight: 550;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.palette-text small {
  font-size: 12.5px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.palette-empty {
  padding: 18px;
  text-align: center;
  color: var(--ink-4);
}

.palette-foot {
  margin: 0;
  padding: 9px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-4);
  background: var(--surface-2);
}

body.palette-open, body.menu-open {
  overflow: hidden;
}

/* ---------- Thanh tab dưới (mobile) ---------- */
.tabbar {
  display: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  :root {
    --sidebar-w: 248px;
  }

  main {
    padding: 24px 26px 48px;
  }

  .topbar {
    padding: 0 20px;
  }

  .home-hero {
    grid-template-columns: 1fr;
  }

  .hero-stats {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 860px) {
  .sidebar {
    width: min(300px, 86vw);
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open {
    transform: none;
  }

  .workspace {
    margin-left: 0;
  }

  #menu-toggle {
    display: inline-grid;
  }

  .search-trigger kbd {
    display: none;
  }

  .topbar {
    padding: 0 10px;
  }

  main {
    padding: 20px 16px calc(96px + env(safe-area-inset-bottom));
  }

  .page-footer {
    display: none;
  }

  .tabbar {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(1.4) blur(14px);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--line);
  }

  .tab {
    position: relative;
    display: grid;
    justify-items: center;
    gap: 3px;
    padding: 6px 2px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--ink-4);
    font-size: 11px;
    font-weight: 550;
    text-decoration: none;
  }

  .tab .icon {
    width: 22px;
    height: 22px;
  }

  .tab.active {
    color: var(--brand-ink);
  }

  .tab.active .icon {
    stroke-width: 2.2;
  }

  .tab-badge {
    position: absolute;
    top: 2px;
    left: calc(50% + 6px);
    min-width: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--amber-base);
    color: #fff;
    font: 700 10.5px/18px var(--font);
    text-align: center;
  }
}

@media (max-width: 600px) {
  .home-hero {
    padding: 22px 18px;
    gap: 20px;
  }

  .hero-stats {
    grid-template-columns: 1fr 1fr;
  }

  .hero-links .secondary-button {
    flex: 1;
  }

  .today-grid, .skill-grid {
    grid-template-columns: 1fr;
  }

  .section-title {
    margin-top: 30px;
  }

  .palette {
    padding: 10px;
  }

  .palette-box {
    max-height: 80vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .palette-box {
    transition: none;
    animation: none;
  }
}

/* ---------- Trang đề Reading / Listening ---------- */
[hidden] {
  display: none !important;
}

.exam-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.exam-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.exam-head .mix-link {
  margin: 0;
}

.task-page>.exam-panel, .task-page>section.exam-panel {
  margin: 0;
  padding: 22px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
}

@media (max-width: 600px) {
  .task-page>.exam-panel, .task-page>section.exam-panel {
    padding: 16px 14px;
    margin: 0 -4px;
  }

  .hero-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .hero-stat {
    padding: 10px 6px;
    text-align: center;
    grid-template-columns: 1fr;
  }

  .hero-stat .icon {
    display: none;
  }

  .hero-stat strong {
    font-size: 16px;
  }

  .hero-stat span {
    font-size: 11px;
    line-height: 1.3;
  }
}

/* Thẻ kỹ năng dạng đơn giản (trang Thi thử): icon, tiêu đề, mô tả */
.skill-card>h3 {
  margin: 0;
  font-size: 16.5px;
  line-height: 1.35;
  color: var(--ink);
}

.skill-card>p.muted {
  margin: -8px 0 0;
  font-size: 14px;
  color: var(--ink-3);
}

/* Công tắc giao diện Sáng / Tối / Tự động ở cuối menu */
.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-3);
}

.theme-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 4px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 550;
}

.theme-option .icon {
  width: 14px;
  height: 14px;
}

.theme-option:hover {
  color: var(--ink);
}

.theme-option.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* Luyện theo Part: một bộ mỗi Part, xếp lưới */
.part-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.part-card>div {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.part-card h3 {
  font-size: 18px;
}

.part-card .exam-strip {
  max-height: 64px;
  overflow: hidden;
}

@media (max-width: 600px) {
  .exam-head .mix-link {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 13px;
  }
}

/* Thẻ chủ điểm Grammar & Vocab: câu nhớ đầy đủ ở trang chi tiết, trên thẻ chỉ 3 dòng */
.gv-topic p {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Ảnh trong đề / lời giải (inline style bị bộ lọc an toàn bỏ): luôn vừa khung, không cao quá màn hình */
.practice-reference img, .quiz-content img, .mix-item img {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  height: auto;
  object-fit: contain;
  margin: 10px 0;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

/* Band CEFR cạnh điểm /50, bảng ngưỡng và lịch sử thi */
.cefr-pill {
  display: inline-block;
  margin: 0 8px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-ink);
  font-weight: 650;
  font-size: 13px;
}

.test-log-wrap {
  overflow-x: auto;
  margin: 8px 0 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.cefr-table, .test-log {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.cefr-table th, .cefr-table td, .test-log th, .test-log td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.cefr-table tr:first-child th, .test-log tr:first-child th {
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-3);
  background: var(--surface-2);
}

.test-log-note td {
  padding-top: 0;
  white-space: normal;
}

.test-log-acts {
  display: flex;
  gap: 6px;
}

.test-history .today-grid {
  margin-bottom: 12px;
}

/* Lịch sử thi: cột tên đề và điểm từng Part được xuống dòng để cả bảng vừa khung */
.test-log td:nth-child(3), .test-log td:nth-child(6) {
  white-space: normal;
  min-width: 150px;
}

.test-log td.test-log-acts {
  white-space: nowrap;
}

/* Luyện nói với Gemini */
.gem-box {
  margin-top: 22px;
  padding: 18px 20px;
  border: 1px solid var(--violet-line);
  border-radius: var(--radius-lg);
  background: var(--violet-soft);
}

.gem-box h3 {
  margin: 0 0 6px;
  font-size: 17px;
}

.gem-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.gem-timer {
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
}

.gem-status {
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--violet-ink);
}

.gem-log {
  max-height: 320px;
  overflow-y: auto;
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.gem-line {
  margin: 0;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface);
  line-height: 1.55;
}

.gem-line.you {
  background: var(--brand-soft);
}

/* Học nói cùng gia sư */
.talk-box {
  margin-top: 22px;
  padding: 18px 20px;
  border: 1px solid var(--brand-line);
  border-radius: var(--radius-lg);
  background: var(--brand-soft);
}

.talk-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.talk-head h3 {
  margin: 0;
  font-size: 17px;
}

.talk-progress, .talk-status {
  font-size: 13.5px;
  color: var(--brand-ink);
}

.talk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.talk-mic.recording {
  background: var(--red-base);
  border-color: var(--red-base);
}

.talk-log {
  max-height: 420px;
  overflow-y: auto;
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.talk-line {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  line-height: 1.6;
}

.talk-line.you {
  background: var(--surface-2);
  margin-left: 32px;
}

.talk-en {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: var(--brand-soft);
  border-radius: 6px;
  font-weight: 600;
  color: var(--ink);
}

.talk-type {
  display: flex;
  gap: 8px;
}

.talk-type input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
}

.talk-live.on {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.talk-score {
  margin: 4px 0 0;
  font-size: 12.5px;
  font-weight: 600;
}

.talk-score.good {
  color: var(--ok-ink);
}

.talk-score.ok {
  color: var(--amber-ink);
}

.talk-score.low {
  color: var(--red-ink);
}

.talk-dock {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  gap: 8px;
  margin: 0 -20px -18px;
  padding: 12px 20px 14px;
  border-top: 1px solid var(--brand-line);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: color-mix(in srgb, var(--brand-soft) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.talk-dock-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.talk-dock .talk-mic,
.talk-dock .talk-start {
  flex: 1;
  min-height: 48px;
  font-size: 16px;
}

.talk-dock .talk-status {
  margin: 0;
}

@media (max-width: 860px) {
  .talk-dock {
    bottom: calc(64px + env(safe-area-inset-bottom));
  }
}

.exam-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 4px;
}

.exam-group {
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.exam-group.here {
  border-color: var(--brand);
}

.exam-group.active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.logout-btn { margin-top: 10px; width: 100%; padding: 8px; border: 1px solid var(--line, #dfe7e1); border-radius: 10px; background: transparent; color: inherit; font: inherit; font-size: 13px; cursor: pointer; }
.logout-btn:disabled { opacity: .6; cursor: default; }

/* Màn hình rộng: nút menu thu gọn / mở lại thanh trái (nhất là khi làm bài). */
@media (min-width: 861px) {
  #menu-toggle { display: inline-grid; }
  .sidebar { transition: transform .22s ease; }
  .workspace { transition: margin-left .22s ease; }
  body.sidebar-hidden .sidebar { transform: translateX(-102%); box-shadow: none; }
  body.sidebar-hidden .workspace { margin-left: 0; }
}
