:root {
  --primary: #6366f1;
  --primary-light: #818cf8;
  --primary-dark: #4f46e5;
  --success: #10b981;
  --success-light: #34d399;
  --error: #f59e0b;
  --error-light: #fbbf24;
  --warning: #ef4444;
  --warning-light: #f87171;
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --card-bg: rgba(255, 255, 255, 0.95);
  --glass-bg: rgba(255, 255, 255, 0.1);
  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --border: rgba(255, 255, 255, 0.2);
  --shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-gradient);
  min-height: 100vh;
  padding: 20px;
  color: var(--text-primary);
}
 .top-bar {
  position: sticky;
  top: 0;
  left: 0;
  width: 100%;
  background-color: #f2f2f2;
  padding: 10px;
  font-family: sans-serif;
  border-bottom: 1px solid #ccc;
  z-index: 9999; /* đảm bảo nằm trên các thành phần khác */
}
      .top-bar a {
        text-decoration: none;
        color: #333;
        font-weight: bold;
          margin-right: 15px; /* khoảng cách giữa các link */
      }
        .content {
    margin-top: 60px; /* đẩy nội dung xuống để không bị thanh top-bar che mất */
    background-color: #fff; /* màu nền nội dung */
}


.container {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  min-height: calc(100vh - 40px);
}

/* ===== SIDEBAR ===== */
.sidebar {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  height: fit-content;
  position: sticky;
  top: 20px;
  border: 1px solid var(--border);
}

.sidebar h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar h3::before {
  content: "📚";
  font-size: 24px;
}

.quiz-link {
  display: block;
  padding: 12px 16px;
  margin-bottom: 8px;
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-secondary);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
}

.quiz-link::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
  transition: left 0.5s;
}

.quiz-link:hover {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.3);
  border-color: var(--primary-light);
}

.quiz-link:hover::before {
  left: 100%;
}

.quiz-link.active {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  color: white;
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
  transform: translateY(-1px);
}

/* ===== MAIN CONTENT ===== */
.main-content {
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header */
.quiz-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 20px 32px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.quiz-header::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(180deg); }
}

.quiz-title {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.quiz-subtitle {
  font-size: 14px;
  opacity: 0.9;
  position: relative;
  z-index: 1;
}

/* Content Area */
.quiz-content {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
  max-height: calc(100vh - 300px);
}

.quiz-content::-webkit-scrollbar {
  width: 8px;
}

.quiz-content::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}

.quiz-content::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}

.quiz-content::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

/* Question Cards */
.question-card {
  background: white;
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.1);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.question-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  transform: scaleX(0);
  transition: transform 0.3s ease;
  transform-origin: left;
}

.question-card:hover::before {
  transform: scaleX(1);
}

.question-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.15);
  border-color: var(--primary-light);
}

.question-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  border-radius: 50%;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 16px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.question-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  line-height: 1.6;
}

.question-description {
  margin-bottom: 20px;
  line-height: 1.7;
  color: var(--text-secondary);
}

.question-description img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 16px 0;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  transition: transform 0.3s ease;
}

.question-description img:hover {
  transform: scale(1.02);
}

/* Choice Options */
.choices {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.choice-option {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid transparent;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  position: relative;
  overflow: hidden;
}

.choice-option::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
  transition: left 0.5s;
}

.choice-option:hover {
  background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
  border-color: var(--primary-light);
  transform: translateX(8px);
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.2);
}

.choice-option:hover::before {
  left: 100%;
}

.choice-option input[type="radio"],
.choice-option input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

.choice-text {
  flex: 1;
  font-size: 15px;
  color: var(--text-primary);
}

/* Eval Questions */
.eval-question {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  border: 2px solid rgba(14, 165, 233, 0.2);
  transition: all 0.3s ease;
}

.eval-question:hover {
  border-color: rgba(14, 165, 233, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(14, 165, 233, 0.15);
}

.eval-question-text {
  margin-bottom: 16px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.6;
}

.eval-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.eval-button {
  flex: 1;
  max-width: 120px;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.eval-button input[type="radio"] {
  display: none;
}

.eval-button.true-btn {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  color: #065f46;
  border: 2px solid #6ee7b7;
}

.eval-button.false-btn {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  color: #991b1b;
  border: 2px solid #f87171;
}

.eval-button:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.eval-button.true-btn:hover {
  background: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  color: white;
}

.eval-button.false-btn:hover {
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
  color: white;
}

.eval-button.selected {
  transform: scale(1.05);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.eval-button.selected.true-btn {
  background: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  color: white;
}

.eval-button.selected.false-btn {
  background: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
  color: white;
}

/* Fill Input */
.fill-input {
  width: 100%;
  max-width: 400px;
  padding: 16px 20px;
  font-size: 16px;
  border-radius: 12px;
  border: 2px solid #e2e8f0;
  background: white;
  transition: all 0.3s ease;
  margin-top: 8px;
}

.fill-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
  transform: translateY(-2px);
}

/* Controls */
.quiz-controls {
  background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
  padding: 24px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  bottom: 0;
}

.grade-button {
  background: linear-gradient(135deg, var(--success) 0%, var(--success-light) 100%);
  color: white;
  border: none;
  padding: 14px 28px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
  position: relative;
  overflow: hidden;
}

.grade-button::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.grade-button:hover::before {
  width: 300px;
  height: 300px;
}

.grade-button:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 12px 35px rgba(16, 185, 129, 0.4);
}

.grade-button:active {
  transform: translateY(-1px) scale(1.02);
}

.score-display {
  background: linear-gradient(135deg, white 0%, #f8fafc 100%);
  padding: 16px 24px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 18px;
  color: var(--primary-dark);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  border: 2px solid rgba(99, 102, 241, 0.2);
  min-width: 180px;
  text-align: center;
}

/* Question States */
.question-card.correct {
  background: linear-gradient(135deg, #d1fae5 0%, #ecfdf5 100%);
  border-color: var(--success);
  box-shadow: 0 8px 25px rgba(16, 185, 129, 0.2);
}

.question-card.wrong {
  background: linear-gradient(135deg, #fef3c7 0%, #fffbeb 100%);
  border-color: var(--error);
  box-shadow: 0 8px 25px rgba(245, 158, 11, 0.2);
}

.choice-option.correct-choice {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  border-color: var(--success);
  color: #065f46;
}

.choice-option.wrong-choice {
  background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%);
  border-color: var(--warning);
  color: #742a2a;
}

.eval-question.eval-answered-correct {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  border-color: var(--success);
}

.eval-question.eval-answered-wrong {
  background: linear-gradient(135deg, #fed7d7 0%, #fecaca 100%);
  border-color: var(--error);
}

.question-score {
  margin-top: 16px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
  border-radius: 10px;
  font-weight: 600;
  color: var(--primary-dark);
  text-align: center;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

/* Loading and Empty States */
.loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.loading-state::before {
  content: "⏳";
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
  animation: spin 2s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state::before {
  content: "📝";
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 0 10px;
  }
  
  .sidebar {
    position: relative;
    top: 0;
    order: 1;
  }
  
  .main-content {
    order: 2;
  }
  
  .quiz-content {
    padding: 20px;
    max-height: none;
  }
  
  .quiz-header {
    padding: 24px 20px;
  }
  
  .quiz-title {
    font-size: 24px;
  }
  
  .question-card {
    padding: 20px;
    margin-bottom: 20px;
  }
  
  .quiz-controls {
    padding: 20px;
    flex-direction: column;
    gap: 16px;
  }
  
  .grade-button {
    width: 100%;
  }
}

/* Animations */
.fade-in {
  animation: fadeIn 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.slide-in {
  animation: slideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
/* ===== MATHJAX STYLING ===== */
/* Đảm bảo MathJax render đúng trong các container */
.MathJax {
  display: inline-block !important;
  font-size: inherit !important;
}

.MathJax_Display {
  display: block !important;
  text-align: center !important;
  margin: 16px 0 !important;
}

/* Style cho math inline trong question */
.question-description .MathJax,
.question-title .MathJax,
.choice-text .MathJax {
  vertical-align: middle;
  font-size: 1em !important;
}

/* Style cho math display trong question */
.question-description .MathJax_Display {
  background: rgba(99, 102, 241, 0.05);
  border-radius: 8px;
  padding: 16px;
  margin: 20px 0;
  border-left: 4px solid var(--primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Đảm bảo text trong MathJax có màu phù hợp */
.MathJax * {
  color: inherit !important;
}

/* Style đặc biệt cho cases environment */
.MJXc-display {
  overflow-x: auto;
  overflow-y: hidden;
}

/* Responsive cho MathJax trên mobile */
@media (max-width: 768px) {
  .MathJax {
    font-size: 0.9em !important;
  }
  
  .MathJax_Display {
    margin: 12px 0 !important;
    padding: 12px !important;
  }
  
  /* Cho phép scroll ngang nếu công thức quá dài */
  .question-description .MathJax_Display {
    overflow-x: auto;
    overflow-y: hidden;
    max-width: 100%;
  }
}

/* Animation cho MathJax khi load */
.MathJax {
  opacity: 0;
  animation: mathFadeIn 0.5s ease-out forwards;
}

@keyframes mathFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Style cho error MathJax */
.MathJax_Error {
  color: var(--error) !important;
  background: rgba(245, 158, 11, 0.1);
  padding: 4px 8px;
  border-radius: 4px;
  font-family: monospace;
}

/* Đảm bảo MathJax không bị overflow trong cards */
.question-card .MathJax,
.choice-option .MathJax {
  max-width: 100%;
  overflow-x: auto;
}

/* Style cho MathJax trong dark theme nếu cần */
.dark-theme .MathJax_Display {
  background: rgba(99, 102, 241, 0.1);
  border-left-color: var(--primary-light);
}
/* Thêm vào cuối file: styles.css */

/* ===== ACCORDION SIDEBAR STYLES ===== */

.category-group {
  margin-bottom: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.05);
}

.category-header {
  padding: 14px 18px;
  font-weight: 600;
  cursor: pointer;
  color: var(--primary-dark);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.3s ease;
  user-select: none; /* Ngăn bôi đen chữ khi click */
}

.category-header:hover {
  background-color: rgba(99, 102, 241, 0.1);
}

/* Icon mũi tên */
.category-header::after {
  content: '▶';
  font-size: 10px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Container chứa các link, mặc định ẩn đi */
.links-container {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0 8px; /* Thêm padding khi mở ra */
}

/* TRẠNG THÁI MỞ */
.category-group.open .category-header {
  background-color: rgba(99, 102, 241, 0.1);
}

.category-group.open .category-header::after {
  transform: rotate(90deg); /* Xoay mũi tên */
}

.category-group.open .links-container {
  max-height: 500px; /* Đặt một giá trị đủ lớn để chứa hết các link */
  padding: 8px 8px 12px 8px; /* Thêm padding khi mở ra */
}

/* Style lại quiz-link một chút để vừa vặn hơn */
#toc-links .quiz-link {
  margin-bottom: 4px;
  padding: 10px 14px;
}
/* Thêm vào cuối file: styles.css */
/* ===== SIDEBAR TOGGLE FEATURE (REVISED) ===== */

/* Nút ĐÓNG (dấu X) nằm bên trong sidebar */
#sidebar-toggle-btn {
  position: absolute;
  top: 20px;
  right: 20px; /* Chuyển sang phải */
  width: 36px;
  height: 36px;
  background: rgba(0, 0, 0, 0.05); /* Nền hợp với sidebar sáng màu */
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: var(--text-secondary); /* Màu chữ tối */
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all 0.3s ease;
}

#sidebar-toggle-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: var(--primary-dark);
  transform: scale(1.1) rotate(90deg);
}

/* Nút MỞ (dấu ☰) nằm ở header, chỉ hiện khi sidebar đóng */
#sidebar-open-btn {
  position: absolute;
  top: 20px; /* Căn chỉnh lại cho header nhỏ hơn (nếu bạn đã sửa) */
  left: 20px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: all 0.3s ease;
  opacity: 0; /* Mặc định ẩn đi */
  pointer-events: none; /* Mặc định không thể click */
  transform: scale(0.8);
}

#sidebar-open-btn:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: scale(1);
}

/* Thêm transition cho layout container và sidebar (giữ nguyên) */
.container {
  transition: grid-template-columns 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar {
  transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

/* Trạng thái khi sidebar bị thu gọn */
.container.sidebar-collapsed {
  grid-template-columns: 0 1fr; 
  gap: 0;
}

.container.sidebar-collapsed .sidebar {
  margin-left: -304px;
  opacity: 0;
  pointer-events: none;
}

/* Khi sidebar đóng, hiện nút MỞ lên */
.container.sidebar-collapsed #sidebar-open-btn {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}
