/* Đánh Đề PNT — Clinical QBank Stylesheet (UI/UX Pro Max) */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--brand-primary);
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ==================== TOP NAVBAR ==================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-quote-bar {
  border-top: 1px solid var(--border-subtle);
  background-color: transparent;
}

.topbar-quote-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 5px 16px 6px;
  text-align: center;
  font-size: 0.78rem;
  font-style: italic;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.35;
  letter-spacing: 0.01em;
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  padding: 4px 6px;
  border-radius: var(--radius-md);
  text-align: left;
  transition: background-color var(--transition-fast);
}

.brand-btn:hover {
  background-color: var(--bg-subtle);
}

.brand-logo {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 8px;
  object-fit: cover;
}

.brand-text-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text-primary);
}

.brand-sub {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.search-trigger:hover {
  border-color: var(--brand-primary);
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.kbd-hint {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.icon-btn:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.icon-btn.active {
  background-color: var(--brand-soft);
  border-color: var(--brand-primary);
  color: var(--brand-soft-text);
}

/* ==================== MAIN CONTAINER ==================== */
.main-wrap {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  flex: 1;
}

/* ==================== HERO / LEVEL TABS ==================== */
.home-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.home-title {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.home-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.94rem;
}

.stat-pills-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.level-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  padding: 6px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
}

.level-tab {
  flex: 1 1 180px;
  min-height: 46px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.level-tab:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}

.level-tab.active {
  background-color: var(--bg-surface);
  color: var(--brand-primary);
  border-color: var(--border-subtle);
  box-shadow: var(--shadow-sm);
}

.badge-count {
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.level-tab.active .badge-count {
  background-color: var(--brand-soft);
  color: var(--brand-soft-text);
}

/* ==================== SUBJECT CARDS GRID ==================== */
.subjects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.subject-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

.subject-card.ready:hover {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.subject-card.upcoming {
  opacity: 0.82;
  background-color: var(--bg-subtle);
}

.subject-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.subject-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.subject-desc {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  flex: 1;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-chip.ready {
  background-color: var(--status-correct-bg);
  color: var(--status-correct-text);
  border: 1px solid var(--status-correct-border);
}

.status-chip.upcoming {
  background-color: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
}

.status-chip.warn {
  background-color: var(--status-warn-bg);
  color: var(--status-warn-text);
  border: 1px solid var(--status-warn-border);
}

.status-chip.info {
  background-color: var(--brand-soft);
  color: var(--brand-soft-text);
  border: 1px solid transparent;
}

.progress-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-track {
  height: 7px;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background-color: var(--brand-primary);
  border-radius: var(--radius-full);
  transition: width 240ms ease;
}

.subject-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.btn:hover:not(:disabled) {
  background-color: var(--bg-subtle);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 36px;
  padding: 5px 12px;
  font-size: 0.82rem;
}

.btn-primary {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--brand-primary-fg);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
}

.btn-danger-soft {
  background-color: var(--status-wrong-bg);
  border-color: var(--status-wrong-border);
  color: var(--status-wrong-text);
}

.btn-danger-soft:hover:not(:disabled) {
  filter: brightness(0.96);
}

.btn-warn-soft {
  background-color: var(--status-warn-bg);
  border-color: var(--status-warn-border);
  color: var(--status-warn-text);
}

/* ==================== SUBJECT EXPLORER ==================== */
.breadcrumb-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.breadcrumb-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.subject-hero {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.subject-hero h1 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
}

.subject-hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.cat-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.cat-tab {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.cat-tab:hover {
  border-color: var(--brand-primary);
  color: var(--text-primary);
}

.cat-tab.active {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--brand-primary-fg);
}

.year-section {
  margin-bottom: 24px;
}

.year-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
}

.exams-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 12px;
}

/* ==================== CLEAN 2-TRACK GATEWAY & TOPIC LIST ==================== */
.gateway-wrap {
  max-width: 880px;
  margin: 8px auto 0;
}

.gateway-header {
  margin-bottom: 20px;
}

.gateway-header h1 {
  margin: 0 0 4px;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.gateway-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.94rem;
}

.track-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}

.track-card {
  background-color: var(--bg-surface);
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
}

.track-card.ready {
  cursor: pointer;
}

.track-card.ready:hover {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.track-card.empty {
  background-color: var(--bg-subtle);
  opacity: 0.82;
}

.track-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background-color: var(--brand-soft);
  color: var(--brand-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.track-card.empty .track-icon-box {
  background-color: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
}

.track-card-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.track-card-desc {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.55;
  flex: 1;
}

.topic-clean-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topic-clean-row {
  width: 100%;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.topic-clean-row:hover {
  border-color: var(--brand-primary);
  background-color: var(--bg-subtle);
}

.topic-clean-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.topic-clean-title {
  font-size: 0.98rem;
  font-weight: 650;
  color: var(--text-primary);
}

.topic-clean-sub {
  font-size: 0.81rem;
  color: var(--text-muted);
}

.topic-clean-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.exam-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.exam-card:hover {
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-md);
}

.exam-card-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.4;
}

.exam-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.exam-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.exam-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
}

/* ==================== STUDY / EXAM WORKSPACE ==================== */
.study-toolbar {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.study-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.study-exam-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.study-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.quick-filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.filter-select-wrap {
  flex: 1 1 260px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.filter-select-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.filter-select {
  width: 100%;
  min-height: 42px;
  padding: 8px 34px 8px 12px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.filter-select:hover,
.filter-select:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-soft);
  outline: none;
}

.filter-select option,
.filter-select optgroup {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.segmented {
  display: inline-flex;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  min-height: 34px;
  padding: 4px 10px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.seg-btn:hover {
  color: var(--text-primary);
}

.seg-btn.active {
  background-color: var(--bg-surface);
  color: var(--brand-primary);
  box-shadow: var(--shadow-sm);
}

.timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background-color: var(--brand-soft);
  color: var(--brand-soft-text);
  font-weight: 700;
  font-size: 0.9rem;
}

.timer-pill.urgent {
  background-color: var(--status-wrong-bg);
  color: var(--status-wrong-text);
}

.study-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 20px;
  align-items: start;
}

.question-column {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.question-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  scroll-margin-top: 84px;
}

.question-card.highlighted-jump {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.q-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.q-badges-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.q-num-pill {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--brand-primary);
}

.q-orig-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background-color: var(--bg-subtle);
  color: var(--text-muted);
}

.q-freq-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
}

.q-freq-btn:hover {
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

.q-appearances-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.flag-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 4px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
}

.flag-btn.flagged {
  background-color: var(--status-warn-bg);
  border-color: var(--status-warn-border);
  color: var(--status-warn-text);
}

.q-stem {
  font-size: 1.03rem;
  line-height: 1.65;
  color: var(--text-primary);
  max-width: 74ch;
  margin-bottom: 16px;
}

.q-stem p {
  margin: 0 0 10px;
}

.q-stem p:last-child {
  margin-bottom: 0;
}

.q-images-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 16px;
}

.q-img-figure {
  margin: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background-color: var(--bg-subtle);
  max-width: 440px;
  cursor: zoom-in;
}

.q-img-figure img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  object-fit: contain;
  margin: 0 auto;
}

.q-img-caption {
  padding: 6px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.lab-table-wrap {
  margin: 12px 0 16px;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.lab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.lab-table th,
.lab-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.lab-table th {
  background-color: var(--bg-subtle);
  font-weight: 700;
  color: var(--text-secondary);
}

.lab-table tr:last-child td {
  border-bottom: none;
}

/* ==================== CHOICES LIST ==================== */
.choices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.choice-main-btn {
  flex: 1;
  min-height: 48px;
  padding: 11px 14px;
  border: none;
  background: transparent;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  text-align: left;
  font-size: 0.97rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.choice-row:hover:not(.is-locked):not(.is-missing) {
  border-color: var(--brand-primary);
  background-color: var(--bg-subtle);
}

.choice-letter {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.86rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.choice-text {
  flex: 1;
  word-break: break-word;
}

.choice-strike-btn {
  flex-shrink: 0;
  width: 40px;
  border: none;
  border-left: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.choice-strike-btn:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

.choice-row.is-struck .choice-text {
  text-decoration: line-through;
  opacity: 0.45;
}

.choice-row.is-missing {
  opacity: 0.62;
  background-color: var(--bg-subtle);
}

.choice-row.is-selected {
  background-color: var(--status-selected-bg);
  border-color: var(--status-selected-border);
}

.choice-row.is-selected .choice-letter {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
  color: var(--brand-primary-fg);
}

.choice-row.is-correct {
  background-color: var(--status-correct-bg);
  border-color: var(--status-correct-border);
}

.choice-row.is-correct .choice-letter {
  background-color: var(--status-correct);
  border-color: var(--status-correct);
  color: #FFFFFF;
}

.choice-row.is-wrong {
  background-color: var(--status-wrong-bg);
  border-color: var(--status-wrong-border);
}

.choice-row.is-wrong .choice-letter {
  background-color: var(--status-wrong);
  border-color: var(--status-wrong);
  color: #FFFFFF;
}

.choice-status-icon {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  margin-top: 3px;
}

/* ==================== INLINE EXPLANATION PANEL ==================== */
.explanation-box {
  margin-top: 18px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  overflow: hidden;
  animation: fadeSlideIn 180ms ease-out;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.explanation-head {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 700;
  font-size: 0.94rem;
}

.explanation-head.correct {
  background-color: var(--status-correct-bg);
  color: var(--status-correct-text);
}

.explanation-head.wrong {
  background-color: var(--status-wrong-bg);
  color: var(--status-wrong-text);
}

.explanation-head.neutral {
  background-color: var(--brand-soft);
  color: var(--brand-soft-text);
}

.explanation-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.explanation-body {
  padding: 14px 16px;
  font-size: 0.94rem;
  line-height: 1.65;
  color: var(--text-primary);
}

.explanation-body ul,
.explanation-body ol {
  margin: 6px 0 10px;
  padding-left: 20px;
}

.explanation-body li {
  margin-bottom: 6px;
}

.explanation-body p {
  margin: 0 0 8px;
}

.explanation-source {
  padding: 10px 16px;
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  font-size: 0.83rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

/* ==================== QUESTION NAVIGATION FOOTER ==================== */
.q-nav-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 14px;
  margin-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

/* ==================== STICKY QUESTION MATRIX SIDEBAR ==================== */
.matrix-sidebar {
  position: sticky;
  top: 76px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.matrix-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.matrix-title {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
}

.matrix-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.m-stat {
  background-color: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 4px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.m-stat strong {
  display: block;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.m-stat.correct strong { color: var(--status-correct); }
.m-stat.wrong strong { color: var(--status-wrong); }
.m-stat.flag strong { color: var(--status-warn); }

.matrix-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.m-filter-btn {
  padding: 4px 9px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.m-filter-btn.active {
  background-color: var(--brand-soft);
  border-color: var(--brand-primary);
  color: var(--brand-soft-text);
}

.matrix-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  overflow-y: auto;
  padding: 2px;
}

.m-cell {
  position: relative;
  min-height: 40px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.84rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 100ms ease, border-color var(--transition-fast);
}

.m-cell:hover {
  border-color: var(--brand-primary);
}

.m-cell.is-current {
  box-shadow: 0 0 0 2px var(--brand-primary);
  border-color: var(--brand-primary);
}

.m-cell.is-selected {
  background-color: var(--status-selected-bg);
  border-color: var(--status-selected-border);
  color: var(--brand-primary);
}

.m-cell.is-correct {
  background-color: var(--status-correct-bg);
  border-color: var(--status-correct-border);
  color: var(--status-correct-text);
}

.m-cell.is-wrong {
  background-color: var(--status-wrong-bg);
  border-color: var(--status-wrong-border);
  color: var(--status-wrong-text);
}

.m-cell.is-flagged::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--status-warn);
}

.matrix-mobile-trigger {
  display: none;
}

.matrix-close-mobile {
  display: none;
}

/* ==================== SHORT RECALLS & NOTES ==================== */
.recall-search-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.input-text {
  width: 100%;
  min-height: 42px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.94rem;
}

.recall-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px;
}

.recall-item {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.notes-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  line-height: 1.7;
}

/* ==================== MODALS & LIGHTBOX ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background-color: var(--backdrop-modal);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px 24px;
  overflow-y: auto;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: 100%;
  max-width: 760px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.search-result-btn {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.search-result-btn:hover {
  border-color: var(--brand-primary);
  background-color: var(--bg-subtle);
}

.search-result-btn mark {
  background-color: var(--mark-bg);
  color: var(--mark-text);
  padding: 0 2px;
  border-radius: 3px;
}

.lightbox-content {
  max-width: 92vw;
  max-height: 90vh;
  background-color: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: auto;
}

.lightbox-content img {
  max-width: 88vw;
  max-height: 76vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.app-footer {
  border-top: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  padding: 16px 16px calc(68px + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-muted);
}

/* ==================== ANIMATED PHOTO VIDEO BACKGROUND (KEN BURNS + FROSTED GLASS) ==================== */
.bg-slideshow-stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background-color: var(--bg-app);
  opacity: 0;
  transition: opacity 600ms ease;
}

body.has-bg-slideshow .bg-slideshow-stage {
  opacity: 1;
}

.topbar {
  z-index: 40;
}

.main-wrap,
.app-footer {
  position: relative;
  z-index: 1;
  transition: opacity 280ms ease, transform 280ms ease;
}

.bg-slide-layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 950ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bg-slide-layer.is-visible {
  opacity: 1;
}

.bg-slide-ambient {
  position: absolute;
  inset: -6%;
  width: 112%;
  height: 112%;
  object-fit: cover;
  object-position: center center;
  filter: blur(28px) saturate(1.22);
  opacity: 0.88;
  transform: scale(1.06);
}

.bg-slide-fg-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  will-change: transform;
}

.bg-slide-fg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
}

/* Smart framing so portrait/square group photos never get heads cropped on wide screens */
@media (min-aspect-ratio: 10/10) {
  .bg-slideshow-stage[data-fit="smart"] .bg-slide-layer[data-orient="portrait"] .bg-slide-fg,
  .bg-slideshow-stage[data-fit="smart"] .bg-slide-layer[data-orient="square"] .bg-slide-fg,
  .bg-slideshow-stage[data-fit="smart"] .bg-slide-layer[data-lowres="1"] .bg-slide-fg {
    width: auto;
    height: 94vh;
    max-width: 92vw;
    object-fit: contain;
    object-position: center center;
    border-radius: 16px;
    box-shadow: 0 18px 54px rgba(0, 0, 0, 0.42);
  }
}

.bg-slideshow-stage[data-fit="contain"] .bg-slide-fg {
  width: auto;
  height: 94vh;
  max-width: 94vw;
  object-fit: contain;
  object-position: center center;
  border-radius: 16px;
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.42);
}

/* 4 Cinematic Ken Burns Camera Movements */
@keyframes kbMove0 {
  0%   { transform: scale(1.0) translate3d(0, 0, 0); }
  100% { transform: scale(1.09) translate3d(-1.2%, -1.2%, 0); }
}

@keyframes kbMove1 {
  0%   { transform: scale(1.09) translate3d(1.2%, -0.8%, 0); }
  100% { transform: scale(1.01) translate3d(-0.8%, 0.8%, 0); }
}

@keyframes kbMove2 {
  0%   { transform: scale(1.0) translate3d(-1%, 1%, 0); }
  100% { transform: scale(1.085) translate3d(1.1%, -0.9%, 0); }
}

@keyframes kbMove3 {
  0%   { transform: scale(1.08) translate3d(0, 1.1%, 0); }
  100% { transform: scale(1.0) translate3d(0, -1%, 0); }
}

.bg-slideshow-stage:not(.is-paused) .bg-slide-layer.kb-0 .bg-slide-fg-wrap {
  animation: kbMove0 var(--bg-kb-duration, 8.8s) ease-in-out forwards;
}
.bg-slideshow-stage:not(.is-paused) .bg-slide-layer.kb-1 .bg-slide-fg-wrap {
  animation: kbMove1 var(--bg-kb-duration, 8.8s) ease-in-out forwards;
}
.bg-slideshow-stage:not(.is-paused) .bg-slide-layer.kb-2 .bg-slide-fg-wrap {
  animation: kbMove2 var(--bg-kb-duration, 8.8s) ease-in-out forwards;
}
.bg-slideshow-stage:not(.is-paused) .bg-slide-layer.kb-3 .bg-slide-fg-wrap {
  animation: kbMove3 var(--bg-kb-duration, 8.8s) ease-in-out forwards;
}

.bg-stage-veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 35%, rgba(248, 250, 252, var(--bg-veil-center, 0.42)), rgba(248, 250, 252, var(--bg-veil-edge, 0.62)));
  transition: background 300ms ease, opacity 300ms ease;
}

[data-theme="dark"] .bg-stage-veil {
  background: radial-gradient(circle at 50% 35%, rgba(11, 17, 32, var(--bg-veil-center-dark, 0.46)), rgba(11, 17, 32, var(--bg-veil-edge-dark, 0.68)));
}

/* Frosted Glass Blur for Study Surfaces when Slideshow is Active */
body.has-bg-slideshow .topbar,
body.has-bg-slideshow .subject-card,
body.has-bg-slideshow .subject-hero,
body.has-bg-slideshow .track-card,
body.has-bg-slideshow .topic-clean-row,
body.has-bg-slideshow .exam-card,
body.has-bg-slideshow .study-toolbar,
body.has-bg-slideshow .quick-filter-bar,
body.has-bg-slideshow .question-card,
body.has-bg-slideshow .matrix-sidebar,
body.has-bg-slideshow .recall-item,
body.has-bg-slideshow .notes-card,
body.has-bg-slideshow .stat-pill,
body.has-bg-slideshow .level-tabs,
body.has-bg-slideshow .app-footer {
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
}

/* Crisp readable halo for headings directly over background */
body.has-bg-slideshow .home-title,
body.has-bg-slideshow .gateway-header h1,
body.has-bg-slideshow .year-heading {
  text-shadow: 0 1px 12px var(--bg-surface);
}

body.has-bg-slideshow .home-subtitle,
body.has-bg-slideshow .gateway-header p {
  color: var(--text-primary);
  font-weight: 500;
  text-shadow: 0 1px 10px var(--bg-surface);
}

/* ==================== PAGE 1: INTRO SLIDESHOW & PAGE 2 SWITCH ==================== */
html.is-intro-boot,
html.is-intro-boot body,
body.page-intro {
  overflow: hidden;
  height: 100dvh;
}

html.is-intro-boot .topbar,
html.is-intro-boot .main-wrap,
html.is-intro-boot .app-footer,
body.page-intro .topbar,
body.page-intro .main-wrap,
body.page-intro .app-footer {
  display: none !important;
}

body:not(.page-intro) .intro-hud {
  display: none !important;
}

body.page-intro .bg-slideshow-stage,
html.is-intro-boot .bg-slideshow-stage {
  opacity: 1;
  pointer-events: auto;
}

body.page-intro .bg-stage-veil,
html.is-intro-boot .bg-stage-veil {
  opacity: 0;
}

.intro-hud {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.intro-hud[hidden] {
  display: none;
}

.intro-topbar {
  pointer-events: none;
  padding: 16px 20px 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(to bottom, rgba(15, 23, 42, 0.56), transparent);
}

.intro-brand-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px 7px 9px;
  border-radius: var(--radius-full);
  background-color: rgba(15, 23, 42, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #F8FAFC;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.intro-brand-title {
  font-size: 0.96rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.intro-brand-sub {
  font-size: 0.74rem;
  color: #CBD5E1;
}

.intro-page-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background-color: rgba(15, 23, 42, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #E2E8F0;
  font-size: 0.8rem;
  font-weight: 600;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.intro-bottom-wrap {
  pointer-events: none;
  padding: 40px 16px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(to top, rgba(15, 23, 42, 0.74), transparent);
}

.intro-dock {
  pointer-events: auto;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 96vw;
  padding: 8px 10px;
  border-radius: 22px;
  background-color: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #F8FAFC;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

.intro-controls-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.bg-dock-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  min-width: 40px;
  padding: 0 12px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: rgba(255, 255, 255, 0.11);
  color: #F8FAFC;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.bg-dock-btn:hover {
  background-color: rgba(255, 255, 255, 0.22);
}

.bg-dock-btn.intro-enter-btn {
  background: linear-gradient(135deg, #0284C7, #0EA5E9);
  border-color: rgba(125, 211, 252, 0.7);
  color: #FFFFFF;
  padding: 0 18px;
  font-weight: 700;
  font-size: 0.92rem;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.42);
}

.bg-dock-btn.intro-enter-btn:hover {
  background: linear-gradient(135deg, #0369A1, #0284C7);
  transform: translateY(-1px);
}

.bg-dock-counter {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #CBD5E1;
  padding: 0 4px;
  white-space: nowrap;
}

/* Direct Topbar 1-Click Bật/Tắt Background Switch (Page 2) */
.bg-top-toggle {
  gap: 8px;
}

.top-mini-switch {
  position: relative;
  width: 30px;
  height: 17px;
  border-radius: var(--radius-full);
  background-color: var(--border-strong);
  flex-shrink: 0;
  transition: background-color var(--transition-fast);
}

.top-mini-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background-color: #FFFFFF;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
  transition: transform var(--transition-fast);
}

.bg-top-toggle[aria-checked="true"] .top-mini-switch {
  background-color: var(--brand-primary);
}

.bg-top-toggle[aria-checked="true"] .top-mini-switch::after {
  transform: translateX(13px);
}

/* Background Settings Modal Controls */
.bg-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.bg-setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bg-setting-title {
  font-size: 0.93rem;
  font-weight: 650;
  color: var(--text-primary);
}

.bg-setting-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.bg-switch {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-hover);
  padding: 0;
  flex-shrink: 0;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.bg-switch[aria-checked="true"] {
  background-color: var(--brand-primary);
  border-color: var(--brand-primary);
}

.bg-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform var(--transition-fast);
}

.bg-switch[aria-checked="true"] .bg-switch-thumb {
  transform: translateX(20px);
}

.bg-range-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
}

.bg-range-input {
  width: 100%;
  accent-color: var(--brand-primary);
  cursor: pointer;
}

.bg-source-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
}

/* ==================== RESPONSIVE MOBILE & TABLET ==================== */
@media (max-width: 1023px) {
  .study-layout {
    grid-template-columns: 1fr;
  }

  .matrix-sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 65;
    max-height: 78vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(105%);
    transition: transform 200ms ease;
  }

  .matrix-sidebar.open-mobile {
    transform: translateY(0);
  }

  .matrix-close-mobile {
    display: inline-flex;
  }

  .matrix-mobile-trigger {
    display: inline-flex;
  }

  .matrix-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 640px) {
  .topbar-inner {
    padding: 8px 10px;
    gap: 8px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .search-trigger {
    min-width: 38px;
    min-height: 38px;
    padding: 0 10px;
  }

  .icon-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 0 7px;
  }

  .bg-top-toggle {
    gap: 5px;
    padding: 0 8px;
    font-size: 0.78rem;
  }

  .top-mini-switch {
    width: 26px;
    height: 15px;
  }

  .top-mini-switch::after {
    width: 11px;
    height: 11px;
  }

  .bg-top-toggle[aria-checked="true"] .top-mini-switch::after {
    transform: translateX(11px);
  }

  .intro-topbar {
    padding: 12px 12px 24px;
  }

  .intro-brand-sub {
    display: none;
  }

  .brand-sub,
  .kbd-hint,
  .hide-xs {
    display: none;
  }

  .main-wrap {
    padding: 14px 12px 36px;
  }

  .question-card {
    padding: 16px 14px;
  }

  .matrix-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Keep slide captions inside the available space on both pages. */
body.page-intro,
html.is-intro-boot body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100dvh !important;
  background: #10141c;
}
#introHud:not([hidden]) { display: contents; }
.intro-topbar {
  grid-row: 1;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px;
}
.intro-bottom-wrap {
  grid-row: 3;
  padding: 6px 8px calc(48px + env(safe-area-inset-bottom));
}
.intro-controls-group { justify-content: center; flex-wrap: wrap; }
.intro-dock { max-width: 100%; }
body.page-intro #bgSlideshowStage,
html.is-intro-boot #bgSlideshowStage {
  position: relative;
  grid-row: 2;
  min-height: 0;
  background: #10141c;
}
/* Let the question bank photo scroll above its study content. */
body.has-bg-slideshow > .topbar { order: -2; }
body.has-bg-slideshow #bgSlideshowStage {
  order: -1;
  position: relative;
  flex: none;
  height: min(40vh, 75vw);
  height: min(40svh, 75vw);
  background: var(--bg-app);
}
body.has-bg-slideshow #bgSlideshowStage .bg-stage-veil { display: none; }
body.has-bg-slideshow #bgSlideshowStage .bg-slide-ambient,
body.page-intro #bgSlideshowStage .bg-slide-ambient,
html.is-intro-boot #bgSlideshowStage .bg-slide-ambient { display: none; }
body.has-bg-slideshow #bgSlideshowStage .bg-slide-fg-wrap,
body.page-intro #bgSlideshowStage .bg-slide-fg-wrap,
html.is-intro-boot #bgSlideshowStage .bg-slide-fg-wrap { animation: none; }
body.has-bg-slideshow #bgSlideshowStage .bg-slide-fg,
body.page-intro #bgSlideshowStage .bg-slide-fg,
html.is-intro-boot #bgSlideshowStage .bg-slide-fg {
  width: 100%;
  height: 100%;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
  border-radius: 0;
  box-shadow: none;
}

@media (max-width: 1024px), (any-pointer: coarse) {
  .intro-page-pill, .intro-brand-sub { display: none; }
}
