/* ==========================================================================
   Web Thi Trắc Nghiệm Tay Nghề - Compact 1-Screen Dashboard & Responsive CSS
   ========================================================================== */

:root {
  --primary: #059669;         /* Emerald Green */
  --primary-hover: #047857;
  --primary-light: #ecfdf5;
  --primary-border: #a7f3d0;
  
  --secondary: #0f172a;       /* Slate / Navy */
  --secondary-light: #f8fafc;
  
  --accent: #2563eb;          /* Blue accent */
  --accent-light: #eff6ff;
  
  --success: #10b981;
  --success-bg: #d1fae5;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --radius: 10px;
}

/* ==================== BẢO VỆ CHỐNG BÔI ĐEN & CHỐNG SAO CHÉP ==================== */
::selection {
  background: transparent !important;
  color: inherit !important;
}
::-moz-selection {
  background: transparent !important;
  color: inherit !important;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

html, body, div, p, span, h1, h2, h3, h4, h5, h6, table, tr, td, th, label, aside, main, section, header, article {
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

html, body {
  height: 100%;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Cho phép bôi đen & nhập liệu duy nhất tại các ô input / textarea */
input, textarea {
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  user-select: text !important;
  -webkit-touch-callout: default !important;
}
input::selection, textarea::selection {
  background: #2563eb !important;
  color: #ffffff !important;
}
input::-moz-selection, textarea::-moz-selection {
  background: #2563eb !important;
  color: #ffffff !important;
}

body {
  display: flex;
  flex-direction: column;
}

/* ==================== NAVBAR ==================== */
.navbar {
  height: 52px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  z-index: 50;
  flex-shrink: 0;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #065f46;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease;
}

.brand:hover {
  opacity: 0.82;
}

.brand-icon {
  width: 30px;
  height: 30px;
  background: linear-gradient(135deg, var(--primary), #10b981);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: bold;
}

.nav-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-practice {
  background-color: #dbeafe;
  color: #1d4ed8;
}

.badge-exam {
  background-color: #fef3c7;
  color: #b45309;
}

/* ==================== MAIN VIEWPORT ==================== */
.app-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 52px);
  overflow: hidden;
}

.screen {
  display: none;
  height: 100%;
  width: 100%;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* Standard Container for Welcome, Result, Re-check */
.standard-container {
  max-width: 580px;
  width: 100%;
  margin: 0 auto;
  padding: 22px 16px;
  overflow-y: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 22px 26px;
  margin-bottom: 0;
  transition: background 0.2s ease, border-color 0.2s ease;
}

/* ==================== SCREEN 1: WELCOME & LOGIN BACKGROUND ==================== */
#screen-welcome {
  position: relative;
  background-image: linear-gradient(135deg, rgba(11, 15, 25, 0.86), rgba(6, 78, 59, 0.82)), url('../assets/quiz_background.jpg');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  overflow-y: auto;
}

[data-theme="dark"] #screen-welcome {
  background-image: linear-gradient(135deg, rgba(11, 15, 25, 0.86), rgba(6, 78, 59, 0.82)), url('../assets/quiz_background.jpg');
}

html:not([data-theme="dark"]) #screen-welcome {
  background-image: linear-gradient(135deg, rgba(240, 253, 244, 0.88), rgba(209, 250, 229, 0.84)), url('../assets/quiz_background.jpg');
}

#screen-welcome .standard-container {
  max-width: 620px;
  min-height: 100%;
  padding: 10px 16px;
}

#screen-welcome .card {
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 16px;
  box-shadow: 0 20px 42px -6px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(16, 185, 129, 0.28);
  animation: fadeInWelcome 0.25s ease-out;
  padding: 15px 22px;
}

[data-theme="dark"] #screen-welcome .card {
  background: rgba(22, 30, 46, 0.90);
  border-color: rgba(16, 185, 129, 0.35);
}

html:not([data-theme="dark"]) #screen-welcome .card {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(5, 150, 105, 0.3);
  box-shadow: 0 16px 36px -6px rgba(5, 150, 105, 0.2), 0 0 0 1px rgba(5, 150, 105, 0.25);
}

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

/* ==================== SCREEN 1: WELCOME ==================== */
.welcome-hero {
  text-align: center;
  padding: 10px 0 16px;
}

.welcome-hero h1 {
  font-size: 1.35rem;
  color: #065f46;
  margin-bottom: 6px;
}

.welcome-hero p {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.welcome-auth-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

.welcome-auth-left {
  display: flex;
  align-items: center;
}

.welcome-auth-title {
  color: var(--success);
  font-weight: 700;
  font-size: 0.96rem;
}

.welcome-auth-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
}

.welcome-auth-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.welcome-auth-actions .btn {
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-logout {
  margin-left: auto !important; /* Đẩy nút đăng xuất sang sát lề phải */
  color: #ef4444 !important;
  border-color: rgba(239, 68, 68, 0.35) !important;
}

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: #ef4444 !important;
}

[data-theme="dark"] .btn-logout {
  color: #f87171 !important;
  border-color: rgba(248, 113, 113, 0.35) !important;
}

[data-theme="dark"] .btn-logout:hover {
  background: rgba(239, 68, 68, 0.18) !important;
  border-color: #f87171 !important;
}

.form-group {
  margin-bottom: 8px;
}

.form-label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  color: #334155;
  font-size: 0.88rem;
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border-color);
  border-radius: 9px;
  font-size: 0.92rem;
  background: #f8fafc;
  transition: all 0.2s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

.radio-cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.radio-card {
  border: 1.5px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  background: #ffffff;
  transition: all 0.15s ease;
  user-select: none;
}

.radio-card:hover {
  border-color: #94a3b8;
  background: #f8fafc;
}

.radio-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 1px var(--primary);
}

.radio-card-title {
  font-weight: 700;
  color: var(--text-main);
  font-size: 0.88rem;
  margin-bottom: 1px;
  line-height: 1.25;
}

.radio-card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.25;
}

.welcome-submit-wrapper {
  margin-top: 10px;
}

#btn-start-exam {
  padding: 12px 20px;
  font-size: 1.08rem;
  font-weight: 700;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.28);
  width: 100%;
  border-radius: 10px;
}

/* ==================== BUTTONS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  user-select: none;
  touch-action: manipulation;
}

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

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: #e2e8f0;
  color: #334155;
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-full {
  width: 100%;
}

/* ==================== SCREEN 2: QUIZ COMPACT 2-COLUMN DASHBOARD ==================== */
.quiz-dashboard {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* --- Left Sidebar (Always Visible on PC) --- */
.quiz-sidebar {
  width: 320px;
  min-width: 300px;
  max-width: 340px;
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  box-shadow: 2px 0 6px rgba(0,0,0,0.02);
  flex-shrink: 0;
  height: 100%;
  transition: background 0.2s ease, border-color 0.2s ease;
}

/* Timer & Status Box */
.sidebar-timer-box {
  background: linear-gradient(135deg, #065f46, #047857);
  color: white;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-timer-label {
  font-size: 0.8rem;
  opacity: 0.9;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.sidebar-timer-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 1px;
}

/* Sidebar Nav Controls (Next / Prev / Finish) */
.sidebar-nav-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-nav-row {
  display: flex;
  gap: 8px;
}

.sidebar-nav-row .btn {
  flex: 1;
  padding: 10px 12px;
}

.btn-next-main {
  background: var(--primary);
  color: white;
  font-weight: 700;
}

.btn-next-main:hover {
  background: var(--primary-hover);
}

.btn-submit-sidebar {
  background: #fee2e2;
  color: #991b1b;
  border: 1.5px solid #fca5a5;
  font-weight: 700;
  padding: 9px 12px;
}

.btn-submit-sidebar:hover {
  background: #fecaca;
}

/* Sidebar Palette Header & Legend */
.sidebar-palette-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid var(--border-color);
  padding-top: 10px;
}

.sidebar-palette-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.sidebar-palette-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: #334155;
}

.sidebar-palette-count {
  font-size: 0.8rem;
  font-weight: 700;
  background: #e2e8f0;
  color: #334155;
  padding: 2px 8px;
  border-radius: 9999px;
}

.palette-legend-compact {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
}

/* Palette Grid (Scrollable inside sidebar) */
.sidebar-palette-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 40px;
  gap: 8px;
  padding-right: 4px;
  padding-bottom: 8px;
  align-content: start;
}

/* Sleek thin scrollbar for question palette */
.sidebar-palette-grid::-webkit-scrollbar {
  width: 6px;
}
.sidebar-palette-grid::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-palette-grid::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 9999px;
}
.sidebar-palette-grid::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.7);
}

.q-num-btn {
  width: 100%;
  height: 40px;
  min-height: 40px;
  max-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  background: #f8fafc;
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
  box-sizing: border-box;
  padding: 0;
  line-height: 1;
}

.q-num-btn:hover {
  background: #e2e8f0;
}

.q-num-btn.active {
  border: 2px solid var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 800;
  box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.2);
}

.q-num-btn.answered {
  background: #dbeafe;
  color: #1e40af;
  border-color: #93c5fd;
}

.q-num-btn.correct {
  background: #d1fae5;
  color: #065f46;
  border-color: #6ee7b7;
}

.q-num-btn.wrong {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}

/* Mobile Question Palette Modal */
#mobile-palette-grid {
  grid-template-columns: repeat(6, 1fr) !important;
  grid-auto-rows: 38px !important;
  gap: 6px !important;
}

#mobile-palette-grid .q-num-btn {
  height: 38px !important;
  min-height: 38px !important;
  max-height: 38px !important;
  font-size: 0.82rem;
}

/* --- Right Main Area (Compact, No Scrolling Needed on PC) --- */
.quiz-main-content {
  flex: 1;
  height: 100%;
  overflow-y: auto;
  padding: 10px 58px 12px;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* KHU VỰC ĐIỀU HƯỚNG CÂU HỎI TRÁI / PHẢI (PC NEXT & BACK) */
.quiz-nav-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 40;
  transition: background 0.2s ease, opacity 0.2s ease;
  user-select: none;
}

.nav-zone-prev {
  left: 0;
}

.nav-zone-next {
  right: 0;
}

.nav-zone-prev:hover {
  background: linear-gradient(to right, rgba(16, 185, 129, 0.12), transparent);
}

.nav-zone-next:hover {
  background: linear-gradient(to left, rgba(16, 185, 129, 0.12), transparent);
}

.nav-zone-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.quiz-nav-zone:hover .nav-zone-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  transform: scale(1.18);
  box-shadow: 0 6px 20px rgba(5, 150, 105, 0.4);
}

.quiz-nav-zone:active .nav-zone-btn {
  transform: scale(0.95);
}

.quiz-content-wrapper {
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Quiz Top Meta */
.quiz-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.session-number {
  font-size: 1.12rem;
  font-weight: 800;
  color: #065f46;
}

.original-number {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 600;
}

/* Progress bar */
.progress-bar-container {
  width: 100%;
  height: 3px;
  background: #e2e8f0;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #10b981);
  transition: width 0.25s ease;
}

/* Question box */
.question-box {
  margin-bottom: 12px;
}

.question-text {
  font-size: 1.38rem;
  font-weight: 600;
  line-height: 1.5;
  color: #0f172a;
  white-space: pre-line;
}

/* Options List (Clean & Readable) */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 15px;
  border: 1.5px solid var(--border-color);
  border-radius: 9px;
  cursor: pointer;
  background: #ffffff;
  transition: all 0.12s ease;
  user-select: none;
  touch-action: manipulation;
}

.option-item:hover:not(.locked) {
  border-color: #94a3b8;
  background: #f8fafc;
}

.option-item:active:not(.locked) {
  transform: scale(0.995);
}

.option-letter {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #f1f5f9;
  border: 1.5px solid #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  flex-shrink: 0;
  color: #475569;
  margin-top: 2px;
}

.option-content {
  font-size: 1.22rem;
  line-height: 1.48;
  color: #1e293b;
  flex: 1;
  white-space: pre-line;
}

/* Selected in Exam Mode */
.option-item.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  box-shadow: 0 0 0 1px var(--accent);
}

.option-item.selected .option-letter {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Practice Mode & Review States */
.option-item.is-correct {
  border-color: var(--success) !important;
  background: var(--success-bg) !important;
  box-shadow: 0 0 0 1px var(--success);
}

.option-item.is-correct .option-letter {
  background: var(--success) !important;
  color: white !important;
  border-color: var(--success) !important;
}

.option-item.is-wrong {
  border-color: var(--danger) !important;
  background: var(--danger-bg) !important;
  box-shadow: 0 0 0 1px var(--danger);
}

.option-item.is-wrong .option-letter {
  background: var(--danger) !important;
  color: white !important;
  border-color: var(--danger) !important;
}

/* Practice Explanation Box (Clean & Minimal) */
.explanation-card {
  padding: 8px 12px;
  border-radius: 8px;
  background: #f0fdf4;
  border: 1.5px solid #bbf7d0;
  margin-bottom: 6px;
  display: none;
}

.explanation-card.show {
  display: block;
  animation: fadeIn 0.18s ease-in;
}

.explanation-title {
  font-weight: 700;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1.35;
}

.official-answer-box {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed #86efac;
  font-size: 0.92rem;
  color: #15803d;
  line-height: 1.38;
}

.official-answer-box strong {
  color: #166534;
  display: inline;
  margin-right: 6px;
  font-size: 0.90rem;
}

#official-answer-text {
  display: inline;
  white-space: pre-line;
}

.reference-box {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed #86efac;
  font-size: 0.90rem;
  color: #15803d;
  line-height: 1.35;
}

.reference-box strong {
  color: #166534;
  display: inline;
  margin-right: 6px;
  font-size: 0.90rem;
}

#reference-text {
  display: inline;
}

/* Bottom Hint & Mobile Controls */
.quiz-bottom-hint {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-muted);
  font-size: 0.76rem;
  border-top: 1px solid var(--border-color);
}

.mobile-nav-bar {
  display: none;
}

/* ==================== MODAL ALERTS ==================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
  animation: fadeIn 0.2s ease-in-out;
}

.modal-card {
  background: white;
  border-radius: 14px;
  max-width: 480px;
  width: 100%;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

.modal-icon-alert {
  width: 48px;
  height: 48px;
  background: #fef3c7;
  color: #d97706;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  margin: 0 auto 12px;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
  color: #0f172a;
}

.modal-desc {
  font-size: 0.92rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 16px;
}

.unanswered-list {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  max-height: 140px;
  overflow-y: auto;
  font-size: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.unanswered-badge {
  background: #fee2e2;
  color: #991b1b;
  padding: 3px 7px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.82rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

/* ==================== RESULT SCREEN ==================== */
.result-header {
  text-align: center;
  padding: 14px 0;
}

.score-circle {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #10b981);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  box-shadow: 0 8px 20px -4px rgba(5, 150, 105, 0.35);
}

.score-num {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
}

.score-total {
  font-size: 0.85rem;
  opacity: 0.95;
  margin-top: 3px;
}

.result-badge-text {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
}

.stat-box {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 2px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

.stat-correct { color: var(--success); }
.stat-wrong { color: var(--danger); }
.stat-time { color: var(--accent); }

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ==================== RE-CHECK SCREEN ==================== */
.recheck-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
  flex-wrap: wrap;
}

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

.recheck-item {
  background: white;
  border-radius: var(--radius);
  border: 1.5px solid var(--border-color);
  padding: 16px;
  margin-bottom: 14px;
}

.recheck-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.recheck-answer-comparison {
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ans-row {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-line;
}

.ans-user-wrong {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

.ans-correct {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #0f172a;
  color: white;
  padding: 10px 20px;
  border-radius: 9999px;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  opacity: 0;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ==================== DARK MODE THEME ==================== */
[data-theme="dark"] {
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-light: #064e3b;
  --primary-border: #047857;

  --secondary: #0f172a;
  --secondary-light: #1e293b;

  --accent: #3b82f6;
  --accent-light: #1e3a8a;

  --success: #34d399;
  --success-bg: rgba(6, 95, 70, 0.35);
  --danger: #f87171;
  --danger-bg: rgba(153, 27, 27, 0.35);
  --warning: #fbbf24;
  --warning-bg: rgba(180, 83, 9, 0.35);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --bg-page: #0b0f19;
  --bg-card: #161e2e;
}

[data-theme="dark"] body {
  background-color: #0b0f19;
  color: #f8fafc;
}

[data-theme="dark"] .navbar {
  background: #111827;
  border-bottom-color: #374151;
}

[data-theme="dark"] .card {
  background: #161e2e;
  border-color: #2e3c51;
}

[data-theme="dark"] .brand {
  color: #34d399;
}

[data-theme="dark"] .welcome-hero h1 {
  color: #34d399;
}

[data-theme="dark"] .form-label {
  color: #e2e8f0;
}

[data-theme="dark"] .form-input {
  background: #0f172a;
  border-color: #374151;
  color: #ffffff;
}

[data-theme="dark"] .radio-card {
  background: #161e2e;
  border-color: #334155;
}

[data-theme="dark"] .radio-card:hover {
  background: #1e293b;
  border-color: #64748b;
}

[data-theme="dark"] .radio-card.selected {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.15);
  box-shadow: 0 0 0 1px #10b981;
}

[data-theme="dark"] .radio-card-title {
  color: #f1f5f9;
}

[data-theme="dark"] .radio-card-desc {
  color: #94a3b8;
}

[data-theme="dark"] .quiz-sidebar {
  background: #111827;
  border-right-color: #374151;
}

[data-theme="dark"] .sidebar-palette-title {
  color: #e2e8f0;
}

[data-theme="dark"] .sidebar-palette-count {
  background: #1e293b;
  color: #94a3b8;
}

[data-theme="dark"] .q-num-btn {
  background: #1e293b;
  border-color: #374151;
  color: #cbd5e1;
}

[data-theme="dark"] .q-num-btn:hover {
  background: #283548;
}

[data-theme="dark"] .q-num-btn.active {
  background: rgba(16, 185, 129, 0.25);
  color: #34d399;
  border-color: #10b981;
}

[data-theme="dark"] .q-num-btn.answered {
  background: rgba(59, 130, 246, 0.25);
  color: #93c5fd;
  border-color: #3b82f6;
}

[data-theme="dark"] .q-num-btn.correct {
  background: rgba(16, 185, 129, 0.25);
  color: #6ee7b7;
  border-color: #10b981;
}

[data-theme="dark"] .q-num-btn.wrong {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  border-color: #ef4444;
}

[data-theme="dark"] .btn-secondary {
  background: #334155;
  color: #f1f5f9;
}

[data-theme="dark"] .btn-secondary:hover {
  background: #475569;
}

[data-theme="dark"] .btn-outline {
  border-color: #475569;
  color: #e2e8f0;
}

[data-theme="dark"] .btn-outline:hover {
  background: #1e293b;
  border-color: #64748b;
}

[data-theme="dark"] .nav-zone-btn {
  background: #161e2e;
  border-color: #334155;
  color: #10b981;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .quiz-nav-zone:hover .nav-zone-btn {
  background: #10b981;
  border-color: #10b981;
  color: #0b0f19;
  box-shadow: 0 6px 22px rgba(16, 185, 129, 0.5);
}

[data-theme="dark"] .btn-submit-sidebar {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border-color: #ef4444;
}

[data-theme="dark"] .btn-submit-sidebar:hover {
  background: rgba(239, 68, 68, 0.3);
}

[data-theme="dark"] .session-number {
  color: #34d399;
}

[data-theme="dark"] .original-number {
  background: #1e293b;
  border-color: #374151;
  color: #94a3b8;
}

[data-theme="dark"] .question-text {
  color: #f8fafc;
}

[data-theme="dark"] .options-list .option-item {
  background: #161e2e;
  border-color: #334155;
}

[data-theme="dark"] .options-list .option-item:hover:not(.locked) {
  background: #1e293b;
  border-color: #64748b;
}

[data-theme="dark"] .option-letter {
  background: #0f172a;
  border-color: #475569;
  color: #cbd5e1;
}

[data-theme="dark"] .option-content {
  color: #f1f5f9;
}

[data-theme="dark"] .option-item.selected {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.2);
}

[data-theme="dark"] .option-item.selected .option-letter {
  background: #3b82f6;
  color: #ffffff;
  border-color: #3b82f6;
}

[data-theme="dark"] .option-item.is-correct {
  border-color: #10b981 !important;
  background: rgba(16, 185, 129, 0.2) !important;
}

[data-theme="dark"] .option-item.is-correct .option-letter {
  background: #10b981 !important;
  color: #ffffff !important;
  border-color: #10b981 !important;
}

[data-theme="dark"] .option-item.is-wrong {
  border-color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.2) !important;
}

[data-theme="dark"] .option-item.is-wrong .option-letter {
  background: #ef4444 !important;
  color: #ffffff !important;
  border-color: #ef4444 !important;
}

[data-theme="dark"] .explanation-card {
  background: rgba(6, 78, 59, 0.35);
  border-color: #059669;
}

[data-theme="dark"] .official-answer-box {
  border-top-color: #047857;
  color: #a7f3d0;
}

[data-theme="dark"] .official-answer-box strong {
  color: #6ee7b7;
}

[data-theme="dark"] .reference-box {
  border-top-color: #047857;
  color: #a7f3d0;
}

[data-theme="dark"] .reference-box strong {
  color: #6ee7b7;
}

[data-theme="dark"] .stat-box {
  background: #161e2e;
  border-color: #334155;
}

[data-theme="dark"] .recheck-item {
  background: #161e2e;
  border-color: #334155;
}

[data-theme="dark"] .modal-card {
  background: #161e2e;
  border-color: #334155;
}

[data-theme="dark"] .modal-title {
  color: #f8fafc;
}

[data-theme="dark"] .unanswered-list {
  background: #0f172a;
  border-color: #334155;
}

[data-theme="dark"] .mobile-nav-bar {
  background: #111827;
  border-top-color: #374151;
}

/* ==================== MOBILE QUIZ HEADER & 1-SCREEN LAYOUT (< 860px) ==================== */
.mobile-quiz-header,
.mobile-quiz-footer {
  display: none; /* Mặc định ẩn trên Desktop */
}

@media (max-width: 860px) {
  /* Bỏ tiêu đề web trên điện thoại khi đang ở màn hình thi */
  body.in-quiz .navbar {
    display: none !important;
  }

  body.in-quiz .app-viewport {
    height: 100% !important;
    min-height: 100vh !important;
    overflow: hidden !important;
  }

  /* Ẩn sidebar và navbar cũ trên điện thoại */
  .quiz-sidebar {
    display: none !important;
  }
  .mobile-nav-bar {
    display: none !important;
  }
  .quiz-bottom-hint {
    display: none !important;
  }
  .quiz-meta-bar {
    display: none !important;
  }

  /* THANH CÔNG CỤ TRÊN CÙNG: STT (ID) bên trái, Đồng hồ canh giữa, Cài đặt canh phải */
  .mobile-quiz-header {
    display: flex !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 48px !important;
    padding: env(safe-area-inset-top, 0px) 10px 0 !important;
    background: var(--bg-card) !important;
    border-bottom: 1.5px solid var(--border-color) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06) !important;
    z-index: 9999 !important;
    justify-content: space-between !important;
    align-items: center !important;
  }

  .mq-left {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    flex: 1 !important;
    min-width: 0 !important;
    justify-content: flex-start !important;
  }

  .mq-session {
    font-size: 0.90rem !important;
    font-weight: 800 !important;
    color: var(--primary) !important;
    white-space: nowrap !important;
  }

  .mq-qid {
    font-size: 0.82rem !important;
    font-weight: 700 !important;
    color: var(--text-muted) !important;
    white-space: nowrap !important;
  }

  .mq-center {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    flex-shrink: 0 !important;
  }

  .mq-timer {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
    font-size: 0.88rem !important;
    font-weight: 700 !important;
    background: var(--bg-page) !important;
    border: 1px solid var(--border-color) !important;
    padding: 3px 8px !important;
    border-radius: 6px !important;
    color: var(--text-main) !important;
    text-align: center !important;
    white-space: nowrap !important;
  }

  .mq-right {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    flex: 1 !important;
    min-width: 0 !important;
  }

  .mq-settings-btn {
    font-size: 0.82rem !important;
    font-weight: 600 !important;
    height: 32px !important;
    padding: 0 8px !important;
    border-radius: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 3px !important;
    white-space: nowrap !important;
  }

  /* THANH CỐ ĐỊNH CẠNH DƯỚI: Trước, Nộp bài, Sau (Luôn cố định 100% tại đáy màn hình) */
  .mobile-quiz-footer {
    display: flex !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 52px !important;
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px)) !important;
    background: var(--bg-card) !important;
    border-top: 1.5px solid var(--border-color) !important;
    box-shadow: 0 -3px 12px rgba(0, 0, 0, 0.12) !important;
    z-index: 9999 !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 8px !important;
  }

  .mob-nav-btn {
    flex: 1 !important;
    height: 38px !important;
    font-size: 0.92rem !important;
    font-weight: 700 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 8px !important;
    padding: 0 !important;
  }

  .mob-submit-btn {
    flex: 1.15 !important;
    height: 38px !important;
    font-size: 0.92rem !important;
    font-weight: 800 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 8px !important;
    background: #ef4444 !important;
    color: #ffffff !important;
    border: 1px solid #dc2626 !important;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.25) !important;
  }

  .mob-submit-btn:hover, .mob-submit-btn:active {
    background: #dc2626 !important;
  }

  /* Tối ưu Welcome Screen trên mobile: Tăng cỡ chữ và chiều cao nút vừa vặn, đẹp mắt */
  #screen-welcome .standard-container,
  .standard-container {
    max-width: 100% !important;
    padding: 10px 12px calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    justify-content: flex-start !important;
  }
  #screen-welcome .card,
  .card {
    padding: 14px 12px !important;
    margin-bottom: 0 !important;
  }
  .welcome-auth-bar {
    margin-bottom: 7px !important;
    padding-bottom: 5px !important;
  }
  .welcome-auth-title {
    font-size: 0.88rem !important;
  }
  .welcome-auth-actions .btn {
    padding: 4px 9px !important;
    font-size: 0.80rem !important;
  }
  .form-group {
    margin-bottom: 8px !important;
  }
  .form-label {
    font-size: 0.84rem !important;
    margin-bottom: 3px !important;
    font-weight: 600 !important;
  }
  .radio-cards-grid {
    gap: 7px !important;
  }
  .radio-card {
    padding: 8px 10px !important;
    border-radius: 7px !important;
  }
  .radio-card-title {
    font-size: 0.86rem !important;
    margin-bottom: 2px !important;
    line-height: 1.25 !important;
  }
  .radio-card-desc {
    font-size: 0.74rem !important;
    line-height: 1.22 !important;
  }
  .welcome-submit-wrapper {
    margin-top: 9px !important;
  }
  #btn-start-exam {
    padding: 11px 16px !important;
    font-size: 1.02rem !important;
    border-radius: 9px !important;
  }

  /* KHU VỰC CÂU HỎI VÀ ĐÁP ÁN: Vừa vặn giữa thanh đỉnh (48px) và thanh đáy (52px) */
  .quiz-dashboard {
    height: 100% !important;
    width: 100% !important;
  }

  .quiz-main-content {
    padding: 0 !important;
    height: 100% !important;
    width: 100% !important;
    position: relative !important;
    overflow: hidden !important;
    display: block !important;
  }

  .quiz-nav-zone {
    display: none !important;
  }

  .quiz-content-wrapper {
    position: fixed !important;
    top: 48px !important;
    bottom: calc(52px + env(safe-area-inset-bottom, 0px)) !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    overflow-y: auto !important;
    padding: 10px 12px 10px !important;
    display: flex !important;
    flex-direction: column !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
  }

  .progress-bar-container {
    height: 3px !important;
    margin-bottom: 6px !important;
    border-radius: 2px;
  }

  .question-box {
    margin-bottom: 6px !important;
  }

  .question-text {
    font-size: 1.08rem !important;
    line-height: 1.45 !important;
    font-weight: 600 !important;
    color: var(--text-main);
  }

  .options-list {
    gap: 6px !important;
    margin-bottom: 6px !important;
  }

  .option-item {
    padding: 6px 10px !important;
    min-height: 36px !important;
    border-radius: 8px !important;
    gap: 8px !important;
  }

  .option-letter {
    width: 25px !important;
    height: 25px !important;
    font-size: 0.84rem !important;
  }

  .option-content {
    font-size: 0.94rem !important;
    line-height: 1.32 !important;
  }

  .explanation-card {
    padding: 4px 8px !important;
    margin-bottom: 3px !important;
    font-size: 0.76rem !important;
  }

  .explanation-title {
    font-size: 0.78rem !important;
    margin-bottom: 1px !important;
    line-height: 1.25 !important;
  }

  .official-answer-box {
    margin-top: 2px !important;
    padding-top: 2px !important;
    font-size: 0.75rem !important;
    line-height: 1.28 !important;
  }

  .official-answer-box strong {
    font-size: 0.75rem !important;
    display: inline !important;
    margin-right: 4px !important;
    margin-bottom: 0 !important;
  }

  .reference-box {
    margin-top: 2px !important;
    padding-top: 2px !important;
    font-size: 0.73rem !important;
    line-height: 1.26 !important;
  }

  .reference-box strong {
    font-size: 0.73rem !important;
    display: inline !important;
    margin-right: 4px !important;
    margin-bottom: 0 !important;
  }

  .explanation-yellow-card {
    padding: 5px 8px !important;
    margin-top: 3px !important;
    margin-bottom: 3px !important;
    font-size: 0.78rem !important;
  }

  .explanation-yellow-header {
    font-size: 0.76rem !important;
    margin-bottom: 2px !important;
    line-height: 1.22 !important;
  }

  .explanation-yellow-content {
    font-size: 0.76rem !important;
    line-height: 1.28 !important;
    white-space: pre-line;
  }

  .explanation-yellow-meo {
    margin-top: 3px !important;
    padding-top: 2px !important;
    font-size: 0.76rem !important;
    line-height: 1.26 !important;
  }
}

[data-theme="dark"] .mobile-quiz-header {
  background: #1e293b !important;
  border-bottom-color: #334155 !important;
}

[data-theme="dark"] .mobile-quiz-footer {
  background: #1e293b !important;
  border-top-color: #334155 !important;
}

[data-theme="dark"] .mob-submit-btn {
  background: #dc2626 !important;
  color: #ffffff !important;
  border-color: #b91c1c !important;
}

[data-theme="dark"] .mq-timer {
  background: #1e293b;
  border-color: #374151;
  color: #f1f5f9;
}

/* ==================== SCREEN 5: QUESTION LIBRARY TABLE ==================== */
.library-container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 40px;
  overflow-y: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.library-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.library-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.library-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.library-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.library-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.library-search-box {
  position: relative;
  flex: 1;
}

.library-search-box .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 1rem;
  opacity: 0.7;
}

.library-search-box input {
  padding-left: 36px;
  width: 100%;
}

.library-table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
  flex: 1;
}

.library-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  text-align: left;
}

.library-table thead th {
  background: #f1f5f9;
  color: var(--text-main);
  font-weight: 700;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.library-table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.12s;
}

.library-table tbody tr:hover {
  background-color: rgba(5, 150, 105, 0.03);
}

.library-table td {
  padding: 14px;
  vertical-align: top;
}

.lib-stt {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary);
  text-align: center;
}

.lib-col-stt {
  text-align: center;
}

.lib-question-text {
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.45;
  margin-bottom: 10px;
  white-space: pre-line;
}

.lib-options-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lib-option-item {
  padding: 6px 10px;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text-main);
}

.lib-option-item.is-correct {
  background: #d1fae5;
  border-color: #6ee7b7;
  color: #065f46;
  font-weight: 600;
}

.lib-correct-check {
  display: inline-block;
  font-size: 0.75rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--primary);
  color: white;
  margin-left: 6px;
  font-weight: 700;
}

.lib-correct-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #d1fae5;
  color: #065f46;
  border: 1.5px solid #10b981;
  font-weight: 800;
  font-size: 1.1rem;
  margin: 0 auto;
}

.lib-col-correct {
  text-align: center;
}

/* Dark theme support for library */
[data-theme="dark"] .library-table-wrapper {
  background: #161e2e;
  border-color: #334155;
}

[data-theme="dark"] .library-table thead th {
  background: #1e293b;
  color: #f1f5f9;
  border-bottom-color: #334155;
}

[data-theme="dark"] .library-table tbody tr {
  border-bottom-color: #334155;
}

[data-theme="dark"] .library-table tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .lib-option-item {
  background: #111827;
  border-color: #374151;
  color: #cbd5e1;
}

[data-theme="dark"] .lib-option-item.is-correct {
  background: rgba(16, 185, 129, 0.2);
  border-color: #10b981;
  color: #a7f3d0;
}

[data-theme="dark"] .lib-correct-badge {
  background: rgba(16, 185, 129, 0.25);
  border-color: #10b981;
  color: #34d399;
}

[data-theme="dark"] .lib-col-ref .reference-box {
  background: rgba(6, 78, 59, 0.25) !important;
  border: 1px solid #059669;
  color: #a7f3d0;
}

/* Mobile responsive card format (< 768px) */
@media (max-width: 768px) {
  .library-container {
    padding: 10px 8px 30px;
  }
  .library-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
  }
  .library-header-left {
    flex-direction: row;
    align-items: center;
    width: 100%;
    gap: 10px;
  }
  .library-title {
    font-size: 1.1rem;
  }
  .library-subtitle {
    font-size: 0.78rem;
  }
  .library-toolbar {
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
  }
  .library-search-box {
    width: 100%;
  }
  .library-table-wrapper {
    background: transparent;
    border: none;
    box-shadow: none;
  }
  .library-table, .library-table tbody, .library-table tr, .library-table td {
    display: block;
    width: 100%;
  }
  .library-table thead {
    display: none;
  }
  .library-table tbody tr {
    margin-bottom: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 12px;
    box-shadow: var(--shadow-sm);
  }
  .library-table td {
    padding: 2px 0;
    border: none;
  }
  .lib-col-stt {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    border-bottom: 1px solid var(--border-color) !important;
    padding: 0 0 6px 0 !important;
    margin-bottom: 8px !important;
    width: 100% !important;
  }
  .lib-stt {
    font-size: 0.95rem !important;
    font-weight: 800 !important;
    color: var(--primary) !important;
    text-align: left !important;
  }
  .lib-col-stt .original-number {
    margin-top: 0 !important;
    font-size: 0.75rem !important;
    padding: 2px 8px !important;
    font-weight: 600 !important;
  }
  .lib-col-question {
    padding: 0 0 6px 0 !important;
    width: 100% !important;
  }
  .lib-question-text {
    font-size: 0.98rem !important;
    font-weight: 600 !important;
    line-height: 1.45 !important;
    margin-bottom: 8px !important;
    color: var(--text-main) !important;
  }
  .lib-options-list {
    gap: 5px !important;
  }
  .lib-option-item {
    font-size: 0.88rem !important;
    padding: 6px 10px !important;
    line-height: 1.38 !important;
  }
  .lib-col-correct {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    margin-top: 6px !important;
    padding-top: 6px !important;
    border-top: 1px dashed var(--border-color) !important;
    text-align: left !important;
  }
  .lib-col-correct::before {
    content: "Đáp án chuẩn: " !important;
    font-weight: 700 !important;
    color: var(--text-muted) !important;
    font-size: 0.84rem !important;
  }
  .lib-correct-badge {
    margin: 0 !important;
    width: 28px !important;
    height: 28px !important;
    font-size: 0.9rem !important;
  }
  .lib-col-ref .reference-box {
    padding: 6px 10px !important;
    font-size: 0.82rem !important;
    margin-top: 6px !important;
  }
}

/* Triệt tiêu và tự động ẩn hoàn toàn badge Netlify và các iframe nổi */
iframe[src*="netlify"],
iframe[id*="netlify"],
iframe[title*="Netlify"],
div[data-netlify-deploy-id],
.netlify-badge,
#netlify-badge {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  width: 0 !important;
  height: 0 !important;
  max-width: 0 !important;
  max-height: 0 !important;
  position: absolute !important;
  left: -9999px !important;
  bottom: -9999px !important;
  z-index: -9999 !important;
}

/* ==================== KEYWORD HỌC VẸT (CHỮ MÀU VÀNG, KHÔNG HIGHLIGHT NỀN, KHÔNG GẠCH CHÂN) ==================== */
.kw-highlight,
mark.kw-highlight,
span.kw-highlight {
  background: transparent !important;
  background-color: transparent !important;
  box-shadow: none !important;
  border: none !important;
  border-bottom: none !important;
  outline: none !important;
  text-decoration: none !important;
  -webkit-text-decoration: none !important;
  font-weight: 800 !important;
  display: inline !important;
  padding: 0 !important;
  margin: 0 !important;
  color: #ca8a04 !important;            /* Chữ vàng hổ phách đậm nét trên nền sáng */
}

[data-theme="light"] .kw-highlight,
[data-theme="light"] mark.kw-highlight,
[data-theme="light"] span.kw-highlight {
  color: #ca8a04 !important;
  text-decoration: none !important;
  -webkit-text-decoration: none !important;
  border: none !important;
  border-bottom: none !important;
}

[data-theme="dark"] .kw-highlight,
[data-theme="dark"] mark.kw-highlight,
[data-theme="dark"] span.kw-highlight {
  background: transparent !important;
  background-color: transparent !important;
  box-shadow: none !important;
  border: none !important;
  border-bottom: none !important;
  padding: 0 !important;
  color: #facc15 !important;            /* Chữ vàng tươi sáng rực trên nền tối */
  font-weight: 800 !important;
  text-decoration: none !important;
  -webkit-text-decoration: none !important;
  text-shadow: 0 0 1px rgba(250, 204, 21, 0.4);
}

/* ==================== THẺ GIẢI THÍCH MÀU VÀNG (EXPLANATION YELLOW) ==================== */
.explanation-yellow-card {
  display: none;
  background: #fefce8;
  border: 1px solid #fde047;
  border-left: 5px solid #eab308;
  border-radius: 8px;
  padding: 8px 12px;
  margin-top: 4px;
  margin-bottom: 6px;
  color: #713f12;
  font-size: 0.92rem;
  line-height: 1.42;
  box-shadow: 0 2px 8px rgba(234, 179, 8, 0.1);
  animation: fadeIn 0.25s ease-out;
}

.explanation-yellow-card.show {
  display: block;
}

.explanation-yellow-header {
  font-weight: 700;
  color: #854d0e;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
  font-size: 0.90rem;
  line-height: 1.3;
}

.explanation-yellow-content {
  color: #713f12;
  font-size: 0.90rem;
  line-height: 1.4;
  white-space: pre-line;
}

.explanation-yellow-meo {
  margin-top: 5px;
  padding-top: 4px;
  border-top: 1px dashed rgba(202, 138, 4, 0.45);
  font-weight: 500;
  color: #854d0e;
  line-height: 1.38;
}

.explanation-yellow-meo strong {
  color: #78350f;
}

[data-theme="dark"] .explanation-yellow-card {
  background: #2b2105;
  border: 1px solid #854d0e;
  border-left: 5px solid #facc15;
  color: #fef08a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

[data-theme="dark"] .explanation-yellow-header {
  color: #fde047;
}

[data-theme="dark"] .explanation-yellow-content {
  color: #fef9c3;
}

[data-theme="dark"] .explanation-yellow-meo {
  border-top-color: rgba(234, 179, 8, 0.35);
  color: #fde047;
}

[data-theme="dark"] .explanation-yellow-meo strong {
  color: #fef08a;
}

/* ==================== BADGE DANH MỤC CÂU HỎI ==================== */
.q-category-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e0e7ff;
  color: #3730a3;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid #c7d2fe;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="dark"] .q-category-badge {
  background: #1e1b4b;
  color: #c7d2fe;
  border-color: #4338ca;
}

/* ==================== PRACTICE SETTINGS TOGGLES ==================== */
.practice-settings-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.practice-settings-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.switch-control {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.switch-control input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: 0.25s;
  border-radius: 20px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.25s;
  border-radius: 50%;
}

.switch-control input:checked + .switch-slider {
  background-color: var(--primary);
}

.switch-control input:checked + .switch-slider:before {
  transform: translateX(16px);
}

[data-theme="dark"] .switch-slider {
  background-color: #475569;
}

/* ==================== WELCOME COMPACT TOGGLE BUTTONS (KÍCH CỠ NHỎ GỌN NHƯ NÚT ĐĂNG XUẤT) ==================== */
.welcome-compact-toggles-bar {
  margin-bottom: 8px;
  padding: 2px 0 6px 0;
  border-bottom: 1px solid var(--border-color);
}

.compact-toggles-label {
  display: block;
  font-size: 0.79rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 4px;
}

.compact-toggles-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.btn-toggle-sm {
  padding: 4px 10px !important;
  font-size: 0.81rem !important;
  font-weight: 600 !important;
  height: 31px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 6px !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  user-select: none !important;
  transition: all 0.15s ease !important;
  background: transparent;
  border: 1.5px solid var(--border-color) !important;
  color: var(--text-main);
  text-decoration: none !important;
  box-sizing: border-box !important;
  white-space: nowrap !important;
  min-width: 0 !important;
}

.btn-toggle-icon {
  flex-shrink: 0;
  font-size: 0.88rem;
  line-height: 1;
}

.btn-toggle-text {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.btn-toggle-sm:hover {
  background: rgba(0, 0, 0, 0.03);
  border-color: #94a3b8 !important;
}

/* Nút ở trạng thái BẬT */
.btn-toggle-sm.active {
  border-color: #059669 !important;
  color: #047857 !important;
  background: rgba(5, 150, 105, 0.08) !important;
}

/* Nút ở trạng thái TẮT */
.btn-toggle-sm:not(.active) {
  opacity: 0.72;
  border-color: var(--border-color) !important;
  color: var(--text-muted) !important;
}

[data-theme="dark"] .btn-toggle-sm:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: #64748b !important;
}

[data-theme="dark"] .btn-toggle-sm.active {
  border-color: #10b981 !important;
  color: #34d399 !important;
  background: rgba(16, 185, 129, 0.12) !important;
}

/* Mini Switch Indicator */
.switch-control-mini {
  position: relative;
  display: inline-block;
  width: 25px;
  height: 14px;
  flex-shrink: 0;
  pointer-events: none;
}

.switch-control-mini input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-slider-mini {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: 0.2s ease;
  border-radius: 14px;
}

.switch-slider-mini:before {
  position: absolute;
  content: "";
  height: 10px;
  width: 10px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: 0.2s ease;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.switch-control-mini input:checked + .switch-slider-mini {
  background-color: var(--primary);
}

.switch-control-mini input:checked + .switch-slider-mini:before {
  transform: translateX(11px);
}

[data-theme="dark"] .switch-slider-mini {
  background-color: #475569;
}

[data-theme="dark"] .switch-control-mini input:checked + .switch-slider-mini {
  background-color: #10b981;
}

/* Nút bị vô hiệu hóa khi ở chế độ Thi thử */
.btn-toggle-sm.disabled-mode {
  opacity: 0.42 !important;
  filter: grayscale(1) !important;
  cursor: not-allowed !important;
  background: rgba(148, 163, 184, 0.08) !important;
  border-color: #cbd5e1 !important;
  color: #94a3b8 !important;
}

[data-theme="dark"] .btn-toggle-sm.disabled-mode {
  border-color: #334155 !important;
  color: #64748b !important;
  background: rgba(30, 41, 59, 0.4) !important;
}

.btn-toggle-sm.disabled-mode .switch-slider-mini {
  background-color: #cbd5e1 !important;
  cursor: not-allowed !important;
}

[data-theme="dark"] .btn-toggle-sm.disabled-mode .switch-slider-mini {
  background-color: #334155 !important;
}

.btn-toggle-sm.disabled-mode .switch-slider-mini:before {
  transform: translateX(0) !important;
  background-color: #94a3b8 !important;
}

.disabled-toggles-bar .compact-toggles-label {
  color: var(--text-muted) !important;
}

@media (max-width: 640px) {
  .welcome-compact-toggles-bar {
    margin-bottom: 6px !important;
    padding-bottom: 4px !important;
  }
  .compact-toggles-label {
    width: 100%;
    font-size: 0.75rem !important;
    margin-bottom: 3px;
  }
  .compact-toggles-btns {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
  }
  .btn-toggle-sm {
    padding: 4px 6px !important;
    font-size: 0.70rem !important; /* Giảm 0.5 size (~11px) */
    line-height: 1.25 !important;
    height: auto !important;
    min-height: 42px !important;   /* Tăng chiều cao tương đương 2 dòng */
    gap: 4px !important;
    white-space: normal !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
  }
  .btn-toggle-icon {
    font-size: 0.80rem !important;
    flex-shrink: 0 !important;
    line-height: 1 !important;
  }
  .btn-toggle-text {
    flex: 1 1 auto !important;
    font-size: 0.70rem !important;
    line-height: 1.25 !important;
    white-space: normal !important;
    word-break: break-word !important;
    text-align: left !important;
  }
  .switch-control-mini {
    width: 22px !important;
    height: 12px !important;
    flex-shrink: 0 !important;
  }
  .switch-slider-mini:before {
    height: 8px;
    width: 8px;
    left: 2px;
    bottom: 2px;
  }
  .switch-control-mini input:checked + .switch-slider-mini:before {
    transform: translateX(10px);
  }
}

/* ==================== CỬ CHỈ VUỐT TRÊN SMARTPHONE (SWIPE GESTURES) ==================== */
@keyframes swipeInRight {
  from {
    opacity: 0.65;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes swipeInLeft {
  from {
    opacity: 0.65;
    transform: translateX(-24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.swipe-in-right {
  animation: swipeInRight 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.swipe-in-left {
  animation: swipeInLeft 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
}


