:root {
  /* Core Brand & Neutral Tokens */
  --bg: #f8fafc;
  --bg-subtle: #f1f5f9;
  --card: #ffffff;
  --card-elevated: #ffffff;
  --text: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  /* EdTech Brand Palette - Deep Teal */
  --brand: #0d9488;
  --brand-hover: #0f766e;
  --brand-active: #115e59;
  --brand-light: #f0fdfa;
  --brand-border: #99f6e4;
  --brand-ring: rgba(13, 148, 136, 0.25);

  /* Semantic Feedback Colors */
  --ok: #16a34a;
  --ok-hover: #15803d;
  --ok-light: #f0fdf4;
  --ok-border: #86efac;
  --ok-text: #14532d;

  --bad: #dc2626;
  --bad-hover: #b91c1c;
  --bad-light: #fef2f2;
  --bad-border: #fca5a5;
  --bad-text: #7f1d1d;

  --accent: #d97706;
  --accent-light: #fffbeb;
  --accent-border: #fde68a;
  --accent-text: #92400e;

  --info: #0284c7;
  --info-light: #f0f9ff;
  --info-border: #bae6fd;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 2px 4px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px -4px rgba(15, 23, 42, 0.12), 0 4px 8px -2px rgba(15, 23, 42, 0.06);

  /* Radii */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Viewport Safe Areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Base Styles & Resets */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

button {
  cursor: pointer;
  border: none;
  background: none;
}

/* Accessibility Focus Ring */
button:focus-visible,
input:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* Shell Layout */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(108px + var(--safe-bottom));
}

/* Topbar Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-top);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.topinner {
  max-width: 900px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  color: var(--brand-hover);
  letter-spacing: -0.02em;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: white;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.3);
  flex-shrink: 0;
}

.brand-logo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 16px;
  font-weight: 800;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  background: var(--brand-light);
  color: var(--brand-hover);
  padding: 5px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--brand-border);
}

/* Main Container */
.main {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  flex: 1;
}

/* Hero Section */
.hero {
  background: linear-gradient(135deg, #0d9488 0%, #0f766e 60%, #115e59 100%);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}

.hero::after {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 180px;
  height: 180px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 70%);
  border-radius: 50%;
  pointer-events: none;
}

.hero-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.hero-title-group h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.hero-title-group p {
  margin: 0;
  font-size: 13.5px;
  color: rgba(255, 255, 255, 0.88);
  line-height: 1.4;
  max-width: 520px;
}

/* Hero Quick CTA */
.hero-cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #ffffff;
  color: var(--brand-hover);
  font-weight: 800;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s ease, background-color 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 14px;
}

.hero-cta-btn:hover {
  background: #f8fafc;
  transform: translateY(-1px);
}

.hero-cta-btn:active {
  transform: translateY(0);
}

/* Progress bar inside Hero */
.progress-wrap {
  margin-top: 16px;
  background: rgba(0, 0, 0, 0.12);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.progress-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  background: #ffffff;
  border-radius: var(--radius-full);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Quick Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.25);
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  text-align: center;
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.stat-box:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

.stat-box b {
  display: block;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
}

.stat-box span {
  font-size: 11.5px;
  font-weight: 600;
  opacity: 0.9;
}

/* Section Header */
.section-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  margin: 22px 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Cards & Actions Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-xs);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.action-card {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
}

.action-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand-border);
}

.action-card:active {
  transform: translateY(0);
}

.action-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.action-card h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.action-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.4;
}

.card-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  background: var(--brand-light);
  color: var(--brand-hover);
  white-space: nowrap;
  flex-shrink: 0;
}

.card-tag.accent {
  background: var(--accent-light);
  color: var(--accent-text);
  border: 1px solid var(--accent-border);
}

.card-tag.danger {
  background: var(--bad-light);
  color: var(--bad-text);
  border: 1px solid var(--bad-border);
}

/* Practice & Question Shell */
.q-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.q-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.q-num {
  font-size: 18px;
  font-weight: 800;
  color: var(--brand-hover);
}

.q-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line);
}

.q-meta.source-badge {
  color: var(--text-secondary);
}

.bookmark-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 700;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--text-secondary);
  transition: all 0.15s ease;
}

.bookmark-btn:hover {
  background: var(--bg-subtle);
}

.bookmark-btn.active {
  background: var(--accent-light);
  border-color: var(--accent-border);
  color: var(--accent-text);
}

/* Question Text & Layout */
.q-text {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--text);
  margin: 12px 0 16px;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

/* Question Visual Image */
.visual-container {
  margin: 12px 0 16px;
  width: 100%;
  text-align: center;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px;
  box-shadow: var(--shadow-xs);
  position: relative;
  overflow: hidden;
}

.visual-img {
  width: 100%;
  max-height: 260px;
  height: auto;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  transition: transform 0.2s ease;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.visual-img:hover {
  transform: scale(1.01);
}

.visual-hint {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* Answer Options */
.options-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: #ffffff;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 13px 15px;
  cursor: pointer;
  transition: all 0.16s ease;
  min-height: 52px;
  user-select: none;
  box-shadow: var(--shadow-xs);
}

.option-btn:hover:not(:disabled) {
  border-color: var(--brand);
  background: var(--brand-light);
}

.option-btn:active {
  transform: scale(0.99);
}

.option-letter {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--line-strong);
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  transition: all 0.15s ease;
}

.option-text {
  flex: 1;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  font-weight: 500;
}

.option-icon {
  flex: 0 0 24px;
  font-size: 18px;
  font-weight: bold;
  display: none;
  text-align: center;
}

/* Option States */
.option-btn.selected {
  border-color: var(--brand);
  background: var(--brand-light);
  box-shadow: 0 0 0 1.5px var(--brand);
}

.option-btn.selected .option-letter {
  border-color: var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.option-btn.correct {
  border-color: var(--ok-border) !important;
  background: var(--ok-light) !important;
  box-shadow: 0 0 0 1px var(--ok) !important;
}

.option-btn.correct .option-letter {
  border-color: var(--ok);
  background: var(--ok);
  color: #ffffff;
}

.option-btn.correct .option-icon {
  display: block;
  color: var(--ok);
}

.option-btn.wrong {
  border-color: var(--bad-border) !important;
  background: var(--bad-light) !important;
  box-shadow: 0 0 0 1px var(--bad) !important;
}

.option-btn.wrong .option-letter {
  border-color: var(--bad);
  background: var(--bad);
  color: #ffffff;
}

.option-btn.wrong .option-icon {
  display: block;
  color: var(--bad);
}

/* Option Tag */
.option-tag {
  display: inline-flex;
  align-items: center;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  margin-left: 8px;
  flex-shrink: 0;
}

.option-tag.tag-correct {
  background: rgba(22, 163, 74, 0.12);
  color: var(--ok-hover);
  border: 1px solid rgba(22, 163, 74, 0.25);
}

.option-tag.tag-wrong {
  background: rgba(220, 38, 38, 0.12);
  color: var(--bad-hover);
  border: 1px solid rgba(220, 38, 38, 0.25);
}

/* Feedback & Explanation Box */
.feedback-box {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  animation: fadeIn 0.2s ease;
}

.feedback-box.ok {
  background: var(--ok-light);
  border: 1px solid var(--ok-border);
  color: var(--ok-text);
}

.feedback-box.bad {
  background: var(--bad-light);
  border: 1px solid var(--bad-border);
  color: var(--bad-text);
}

.feedback-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
  margin-bottom: 6px;
}

.feedback-explanation {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary);
  border-top: 1px dashed rgba(0, 0, 0, 0.1);
  padding-top: 8px;
  margin-top: 6px;
}

/* Buttons System */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
  user-select: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(13, 148, 136, 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--text);
}

.btn-danger {
  background: var(--bad);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--bad-hover);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  min-height: 36px;
  border-radius: var(--radius-xs);
}

/* Practice Bottom Action Bar */
.sticky-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
  padding: 10px 0 4px;
}

.btn-nav-prev,
.btn-nav-next {
  min-height: 48px;
  font-size: 14.5px;
  font-weight: 700;
  border-radius: var(--radius-md);
  flex: 1;
}

.btn-nav-prev {
  background: #ffffff;
  border: 1.5px solid var(--line-strong);
  color: var(--text);
}

.btn-nav-prev:hover:not(:disabled) {
  background: var(--bg-subtle);
}

.btn-nav-next {
  background: var(--brand);
  color: #ffffff;
}

.btn-nav-next:hover:not(:disabled) {
  background: var(--brand-hover);
}

.jump-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.jump-input {
  width: 58px;
  height: 42px;
  padding: 4px 6px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-xs);
  text-align: center;
  font-weight: 800;
  font-size: 14px;
  color: var(--brand-hover);
  background: #ffffff;
}

.jump-input:focus {
  border-color: var(--brand);
  outline: none;
}

/* Exam Mode UI */
.exam-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  box-shadow: var(--shadow-xs);
}

.exam-header-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-nav-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  border: 1.5px solid var(--line);
  background: #ffffff;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-nav-icon:hover:not(:disabled) {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand);
}

.btn-nav-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  border-color: var(--line);
}

.exam-jump-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--bg-subtle);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.exam-jump-trigger:hover {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand);
}

.exam-jump-label {
  color: var(--brand-hover);
  font-weight: 800;
}

.exam-jump-sub {
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
}

.exam-jump-arrow {
  color: var(--text-muted);
  font-size: 10px;
}

.exam-header-actions {
  display: flex;
  align-items: center;
}

.exam-submit-btn {
  height: 38px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 700;
  border-radius: var(--radius-xs);
  white-space: nowrap;
}

/* Exam Popup Modal */
.exam-popup-modal {
  max-width: 440px;
  width: 92%;
  max-height: 85vh;
  padding: 18px;
}

.exam-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

/* Exam Palette Grid */
.exam-palette,
.exam-palette-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  padding: 4px 2px;
}

@media (max-width: 420px) {
  .exam-palette,
  .exam-palette-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
}

.palette-chip {
  padding: 10px 0;
  border-radius: var(--radius-xs);
  border: 1.5px solid var(--line);
  background: #ffffff;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}

.palette-chip:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
}

.palette-chip.current {
  outline: 2px solid var(--brand);
  border-color: var(--brand);
  background: var(--brand-light);
  color: var(--brand-hover);
}

.palette-chip.answered {
  background: #e2f4f1;
  border-color: var(--brand-border);
  color: var(--brand-hover);
}

.palette-chip.done {
  background: var(--ok-light);
  border-color: var(--ok-border);
  color: var(--ok-hover);
}

.palette-chip.bad {
  background: var(--bad-light);
  border-color: var(--bad-border);
  color: var(--bad-hover);
}

/* Exam Result Card */
.result-card {
  text-align: center;
  padding: 32px 20px;
}

.result-badge {
  display: inline-block;
  font-size: 44px;
  margin-bottom: 8px;
}

.result-score {
  font-size: 36px;
  font-weight: 900;
  color: var(--brand-hover);
  margin-bottom: 4px;
}

.result-verdict {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 16px;
}

.result-verdict.pass {
  color: var(--ok);
}

.result-verdict.fail {
  color: var(--bad);
}

.exam-banner {
  background: var(--accent-light);
  border: 1px solid var(--accent-border);
  color: var(--accent-text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.45;
}

/* Exam class picker (Bảng cấu trúc đề thi theo hạng GPLX) */
.class-pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  text-align: left;
}

.class-pick-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.class-pick-card:hover {
  border-color: var(--brand-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.class-pick-card:active {
  transform: translateY(0);
}

.class-pick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.class-pick-label {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.class-pick-total {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-active);
  background: var(--brand-light);
  border: 1px solid var(--brand-border);
  padding: 3px 9px;
  border-radius: var(--radius-full);
}

.class-pick-desc {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-muted);
  min-height: 2.6em;
}

.class-pick-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

/* 600 Review List & Chips */
.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.tab-pill {
  white-space: nowrap;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--line);
  background: #ffffff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-pill.active {
  background: var(--brand-light);
  border-color: var(--brand-border);
  color: var(--brand-hover);
  font-weight: 800;
}

.search-input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  background: #ffffff;
  font-size: 14px;
  margin-bottom: 14px;
}

.search-input:focus {
  outline: none;
  border-color: var(--brand);
}

.chips-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.qchip {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.12s ease;
}

.qchip:hover {
  transform: translateY(-1px);
  border-color: var(--brand);
}

.qchip.done {
  background: var(--ok-light);
  border-color: var(--ok-border);
  color: var(--ok-hover);
}

.qchip.bad {
  background: var(--bad-light);
  border-color: var(--bad-border);
  color: var(--bad-hover);
}

.qchip.book {
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* Bottom Navigation Bar */
.nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.04);
}

.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 2px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s ease, transform 0.15s ease;
  border-radius: var(--radius-sm);
}

.nav-item:hover {
  color: var(--brand-hover);
}

.nav-item:active {
  transform: scale(0.96);
}

.nav-item-icon {
  font-size: 20px;
  line-height: 1;
  margin-bottom: 3px;
}

.nav-item-label {
  font-size: 11px;
  font-weight: 600;
}

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

.nav-item.active .nav-item-label {
  font-weight: 800;
}

.nav-item.active .nav-item-icon {
  transform: translateY(-1px);
}

/* Modals & Overlays */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-lg);
  max-width: 480px;
  width: 100%;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Lightbox Modal */
.lb-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 10, 14, 0.96);
  animation: fadeIn 0.15s ease;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.lb-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.lb-img {
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  -webkit-user-drag: none;
  cursor: grab;
}

.lightbox-close {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: 12px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  color: #111;
  border: none;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  display: grid;
  place-items: center;
}

.lb-toolbar {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 40px);
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.lb-btn {
  min-width: 46px;
  height: 46px;
  border-radius: var(--radius-full);
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
}

.lb-btn.lb-label {
  font-size: 13px;
  min-width: 64px;
}

.lb-btn:active {
  transform: scale(0.94);
}

.lb-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  pointer-events: none;
  z-index: 2;
}

/* Notice Box */
.notice-box {
  font-size: 13px;
  color: var(--text-muted);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 20px;
  line-height: 1.5;
}

/* ============================================================
   Navigation & Action Clusters (icon-first, anti-wrapping)
   Mobile-first: 360px -> 414px, mọi nhãn đều nowrap, icon khóa tỉ lệ.
   ============================================================ */
.nowrap {
  white-space: nowrap;
}

/* Top header: icon actions thay cho cụm nút chữ cồng kềnh */
.icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: var(--radius-full);
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text-secondary);
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--bg-subtle);
  color: var(--brand-hover);
  border-color: var(--brand-border);
}

.icon-btn svg.ic {
  width: 20px;
  height: 20px;
  display: block;
  flex-shrink: 0;
}

/* Badge trạng thái dữ liệu: tích + số gọn, không chiếm chiều ngang */
.icon-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 9px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background: var(--ok-light);
  border: 1px solid var(--ok-border);
  color: var(--ok-hover);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1;
}

.icon-pill svg {
  width: 14px;
  height: 14px;
  display: block;
  flex-shrink: 0;
}

/* Sub-header đề thi: MỘT hàng ngang, co giãn an toàn, tuyệt đối không rớt dòng
   và không gây scroll ngang (nhóm trái co lại được, toàn bộ overflow:hidden). */
.exam-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: nowrap;
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden; /* lưới an toàn: không bao giờ tràn ra gây scroll ngang */
}

.subhead-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;      /* cho phép co lại khi chật */
  flex: 1 1 auto;
}

.nav-arrow {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
  transition: background-color 0.15s ease;
}

.nav-arrow:hover {
  background: var(--bg-subtle);
}

.nav-arrow:disabled {
  opacity: 0.35;
  cursor: default;
}

.subhead-jump {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 0 1 auto;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  transition: background-color 0.15s ease;
}

.subhead-jump:hover {
  background: var(--line);
}

.subhead-jump .qpos {
  white-space: nowrap;
  color: var(--brand-hover);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subhead-jump .qword {
  white-space: nowrap;
}

.subhead-jump .qnum {
  white-space: nowrap;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
}

.subhead-jump .caret {
  color: var(--text-muted);
  font-size: 10px;
  flex-shrink: 0;
}

.subhead-progress {
  display: none; /* ẩn trên mobile, hiện từ >=640px */
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.subhead-progress .ptext {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.subhead-progress .pbar {
  width: 112px;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.subhead-progress .pfill {
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
  transition: width 0.3s ease;
}

.subhead-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-score {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.btn-score:hover {
  background: var(--bg-subtle);
}

@media (min-width: 640px) {
  .subhead-progress {
    display: flex;
  }
}

/* Màn <=430px (bao gồm 414): bỏ số câu nguồn (#n); và khi có chip "Liệt"
   thì bỏ luôn chữ "Câu" để "x/35" khong bi cat bot */
@media (max-width: 430px) {
  .subhead-jump .qnum {
    display: none;
  }
  .subhead-jump.has-crit .qword {
    display: none;
  }
}

/* Màn <=390px: thu gon dong deu de badge va 'Nộp bài' cùng năm 1 hàng */
@media (max-width: 390px) {
  .exam-subhead {
    gap: 6px;
    padding: 8px 10px;
  }
  .nav-arrow {
    width: 30px;
    height: 30px;
    font-size: 15px;
  }
  .subhead-jump {
    height: 30px;
    padding: 0 7px;
    gap: 5px;
  }
  .subhead-actions {
    gap: 6px;
  }
  .progress-badge {
    min-width: 0;
    height: 26px;
    padding: 0 7px;
    font-size: 11.5px;
  }
  .submit-btn {
    height: 32px;
    padding: 0 10px;
    font-size: 12.5px;
    gap: 5px;
  }
  .submit-btn svg {
    width: 14px;
    height: 14px;
  }
}

.progress-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  height: 28px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

/* Exam class chip + countdown timer */
.exam-class-chip {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--brand-light);
  border: 1px solid var(--brand-border);
  color: var(--brand-active);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}

.exam-timer-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 10px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.exam-timer-ic {
  font-size: 13px;
  line-height: 1;
}

.exam-timer {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
}

.exam-timer-wrap.danger,
.exam-timer.danger {
  color: var(--bad);
}

.exam-timer-wrap:has(.exam-timer.danger) {
  background: #fef2f2;
  border-color: #fecaca;
  animation: exam-timer-pulse 1s ease-in-out infinite;
}

@keyframes exam-timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.submit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #ffffff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.submit-btn:hover {
  background: var(--brand-hover);
}

.submit-btn:active {
  transform: scale(0.98);
}

.submit-btn svg {
  width: 15px;
  height: 15px;
  display: block;
  flex-shrink: 0;
}

/* Bottom navigation: icon trên - label 1 dòng dưới, active = pill mờ quanh icon */
.bnav {
  position: fixed;
  bottom: 14px;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  justify-content: center;
  padding: 0 12px calc(env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

.bnav-inner {
  pointer-events: auto;
  display: flex;
  align-items: stretch;
  gap: 2px;
  width: 100%;
  max-width: 400px;
  padding: 6px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(226, 232, 240, 0.85);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.bnav-item {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 2px 5px;
  border-radius: var(--radius-md);
  background: none;
  color: var(--text-muted);
  transition: color 0.15s ease, background-color 0.15s ease;
}

.bnav-item:hover {
  color: var(--text);
}

.bnav-ic {
  width: 34px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: background-color 0.15s ease;
}

.bnav-ic svg.ic {
  width: 21px;
  height: 21px;
  display: block;
  flex-shrink: 0;
}

.bnav-label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.15;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bnav-item.active {
  color: var(--brand-hover);
}

.bnav-item.active .bnav-ic {
  background: var(--brand-light);
  box-shadow: inset 0 0 0 1px var(--brand-border);
}

.bnav-item.active .bnav-label {
  font-weight: 800;
}

/* Nhận diện câu điểm liệt trên UI */
.crit-tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: var(--accent-light);
  border: 1px solid var(--accent-border);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
}

.mini-crit {
  display: inline-flex;
  align-items: center;
  height: 16px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--accent-light);
  border: 1px solid var(--accent-border);
  color: var(--accent-text);
  font-size: 9.5px;
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
}

.palette-chip.critical,
.qchip.critical {
  border-color: var(--accent-border);
}

.chip-crit-dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.palette-chip,
.qchip {
  position: relative;
}

.legend-crit-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 4px;
  vertical-align: middle;
}

.crit-warn {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent-text);
  line-height: 1.45;
}

.critical-alert {
  max-width: 520px;
  margin: 14px auto 0;
  padding: 12px 14px;
  text-align: left;
  font-size: 13px;
  line-height: 1.5;
  color: var(--bad-text);
  background: var(--bad-light);
  border: 1px solid var(--bad-border);
  border-radius: var(--radius-sm);
}

/* Màn hình hẹp: ép chiều rộng tối đa cho cụm điều hướng */
@media (max-width: 400px) {
  .bnav {
    padding-left: 8px;
    padding-right: 8px;
  }
  .bnav-label {
    font-size: 10.5px;
  }
  .submit-btn {
    padding: 0 11px;
    font-size: 12.5px;
  }
  .progress-badge {
    min-width: 42px;
    font-size: 11.5px;
  }
}

/* Keyframes */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  .stat-box {
    padding: 8px 4px;
  }
  .stat-box b {
    font-size: 17px;
  }
  .stat-box span {
    font-size: 10.5px;
  }
  .chips-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  .hero {
    padding: 18px 16px;
  }
  .hero h1 {
    font-size: 20px;
  }
  .main {
    padding: 12px 10px;
  }
  .q-card {
    padding: 16px 14px;
  }
}

@media (max-width: 420px) {
  .hero-header {
    flex-direction: column;
  }
  .hero-cta-btn {
    width: 100%;
    justify-content: center;
  }
  .chips-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
  .qchip {
    font-size: 12px;
    border-radius: var(--radius-xs);
  }
}

@media (max-width: 360px) {
  .chips-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}