/* ========== CSS Reset & Variables ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Colors - Modern Deep Blue + White + Accent */
  --primary: #1e40af;
  --primary-light: #eff6ff;
  --primary-dark: #1e3a8a;
  --primary-50: #dbeafe;
  --primary-100: #bfdbfe;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;
  --accent: #f59e0b;
  --accent-light: #fef3c7;
  --accent-dark: #d97706;
  --success: #10b981;
  --success-light: #d1fae5;
  --success-dark: #059669;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --info: #06b6d4;
  --info-light: #cffafe;

  /* Neutrals */
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-tertiary: #9ca3af;
  --text-quaternary: #d1d5db;
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --bg-code: #f8fafc;
  --border: #e5e7eb;
  --border-light: #f3f4f6;
  --border-focus: #93c5fd;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.08), 0 10px 10px -5px rgba(0,0,0,0.02);

  /* Layout */
  --sidebar-width: 300px;
  --header-height: 56px;

  /* Typography */
  --font-sans: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Transitions */
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========== Base ========== */
html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-secondary);
  overflow-x: hidden;
}

/* ========== Toast Notification ========== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-primary);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-xl);
  white-space: nowrap;
}

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

/* ========== Mobile Header ========== */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.92);
}

.mobile-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.menu-toggle,
.search-toggle {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.menu-toggle:hover,
.search-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ========== Overlay ========== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 199;
  backdrop-filter: blur(2px);
}

.overlay.active {
  display: block;
}

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-light);
}

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

.logo-icon {
  font-size: 32px;
  line-height: 1;
}

.logo-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.logo-subtitle {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

/* ========== Search ========== */
.search-box {
  padding: 12px 16px;
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  height: 36px;
  padding: 0 60px 0 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-sans);
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: var(--transition);
  outline: none;
}

.search-box input:focus {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
  background: var(--bg-primary);
}

.search-box input::placeholder {
  color: var(--text-tertiary);
}

.search-kbd {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-tertiary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--font-sans);
  pointer-events: none;
}

/* ========== Progress ========== */
.progress-bar-container {
  padding: 0 20px 12px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.progress-bar {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-600), var(--accent));
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* ========== Navigation ========== */
.nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nav::-webkit-scrollbar {
  width: 4px;
}

.nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.nav-module {
  margin-bottom: 4px;
}

.nav-module-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  user-select: none;
}

.nav-module-title:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-module-title .module-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.nav-module-title .module-arrow {
  margin-left: auto;
  transition: transform 0.2s;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.nav-module-title.expanded .module-arrow {
  transform: rotate(90deg);
}

.nav-chapters {
  display: none;
  padding: 2px 0 6px 0;
}

.nav-chapters.visible {
  display: block;
}

.nav-chapter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  line-height: 1.4;
}

.nav-chapter:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.nav-chapter.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.nav-chapter .chapter-status {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 10px;
  transition: var(--transition);
}

.nav-chapter.completed .chapter-status {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.nav-chapter.active .chapter-status {
  border-color: var(--primary);
  background: var(--primary);
}

/* ========== Main Content ========== */
.main {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  padding: 40px 48px 80px;
  max-width: 100%;
}

/* ========== Welcome ========== */
.welcome {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 120px);
}

.welcome-inner {
  text-align: center;
  max-width: 640px;
}

.welcome-emoji {
  font-size: 64px;
  margin-bottom: 24px;
}

.welcome h2 {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  letter-spacing: -0.02em;
}

.welcome p {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 32px;
}

.welcome strong {
  color: var(--primary);
}

.welcome-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-bottom: 40px;
}

.stat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 32px;
  text-align: center;
  transition: var(--transition);
}

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

.stat-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 13px;
  color: var(--text-tertiary);
}

.btn-start {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-lg);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 14px rgba(30, 64, 175, 0.25);
}

.btn-start:hover {
  background: var(--primary-dark);
  box-shadow: 0 6px 20px rgba(30, 64, 175, 0.35);
  transform: translateY(-1px);
}

.welcome-hint {
  margin-top: 16px !important;
  font-size: 13px !important;
  color: var(--text-tertiary) !important;
}

/* ========== Chapter Progress ========== */
.chapter-progress {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
}

.chapter-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.chapter-progress-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.chapter-progress-pct {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
}

.chapter-progress-bar {
  display: flex;
  gap: 6px;
}

.chapter-progress-segments {
  display: flex;
  width: 100%;
  gap: 6px;
}

.segment {
  flex: 1;
  height: 28px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.segment-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0%;
  border-radius: var(--radius-sm);
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.segment-read .segment-fill {
  background: linear-gradient(90deg, #dbeafe, #93c5fd);
}

.segment-quiz .segment-fill {
  background: linear-gradient(90deg, #fef3c7, #fbbf24);
}

.segment-action .segment-fill {
  background: linear-gradient(90deg, #d1fae5, #6ee7b7);
}

.segment-label {
  position: relative;
  z-index: 1;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  transition: var(--transition);
}

.segment.completed .segment-label {
  color: var(--text-primary);
}

.segment.completed .segment-fill {
  width: 100% !important;
}

.segment-read.completed .segment-fill {
  background: linear-gradient(90deg, #93c5fd, #3b82f6);
}

.segment-quiz.completed .segment-fill {
  background: linear-gradient(90deg, #fbbf24, #f59e0b);
}

.segment-action.completed .segment-fill {
  background: linear-gradient(90deg, #6ee7b7, #10b981);
}

.segment.completed .segment-label {
  color: white;
}

/* ========== Chapter Content ========== */
.chapter-content {
  max-width: 780px;
  margin: 0 auto;
}

.chapter-header {
  margin-bottom: 40px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
}

.chapter-breadcrumb {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chapter-breadcrumb .breadcrumb-sep {
  color: var(--border);
}

.chapter-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.chapter-purpose {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 16px 20px;
  background: var(--primary-light);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--primary-dark);
  line-height: 1.6;
  border-left: 3px solid var(--primary-500);
}

.chapter-purpose::before {
  content: '🎯';
  flex-shrink: 0;
  font-size: 16px;
}

/* ========== Chapter Body ========== */
.chapter-body {
  font-size: 16px;
  line-height: 1.85;
  color: var(--text-primary);
}

.section {
  margin-bottom: 48px;
}

.section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 16px;
  padding-left: 16px;
  border-left: 3px solid var(--primary-500);
  letter-spacing: -0.01em;
}

.section-content {
  color: var(--text-primary);
  line-height: 1.85;
}

.section-content p {
  margin-bottom: 16px;
}

.section-content p:last-child {
  margin-bottom: 0;
}

.section-content strong {
  font-weight: 600;
  color: var(--text-primary);
}

.section-content em {
  font-style: italic;
  color: var(--text-secondary);
}

.section-content ul,
.section-content ol {
  margin: 12px 0;
  padding-left: 24px;
}

.section-content li {
  margin-bottom: 6px;
}

.section-content code {
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: var(--font-mono);
  color: #c026d3;
  border: 1px solid var(--border-light);
}

.section-content pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 20px 24px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 16px 0;
  font-size: 13px;
  line-height: 1.6;
  font-family: var(--font-mono);
  border: 1px solid #1e293b;
}

.section-content pre code {
  background: none;
  padding: 0;
  color: inherit;
  border: none;
}

.section-content blockquote {
  border-left: 3px solid var(--accent);
  background: var(--accent-light);
  padding: 16px 20px;
  margin: 16px 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font-size: 14px;
  color: #92400e;
}

.section-content blockquote p {
  margin-bottom: 8px;
}

.section-content blockquote p:last-child {
  margin-bottom: 0;
}

/* Table styles */
.section-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
}

.section-content th {
  background: var(--bg-tertiary);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
}

.section-content td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
}

.section-content tr:hover td {
  background: var(--bg-secondary);
}

/* Summary box */
.summary-box {
  margin-top: 48px;
  padding: 24px 28px;
  background: linear-gradient(135deg, var(--primary-light), #f0f4ff);
  border: 1px solid rgba(30, 64, 175, 0.12);
  border-radius: var(--radius-lg);
}

.summary-box p {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-primary);
}

/* ========== Prompt Copy Box ========== */
.prompt-box {
  position: relative;
  margin: 16px 0;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  padding-right: 52px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  font-family: var(--font-sans);
  transition: var(--transition);
}

.prompt-box:hover {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

.prompt-box-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.prompt-copy-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-tertiary);
  transition: var(--transition);
  font-size: 16px;
}

.prompt-copy-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-500);
  color: var(--primary);
  transform: scale(1.05);
}

.prompt-copy-btn.copied {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

/* ========== Quiz Section ========== */
.quiz-section {
  margin-top: 48px;
  padding-top: 40px;
  border-top: 2px dashed var(--border);
}

.quiz-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.quiz-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-light);
  border-radius: var(--radius-md);
  font-size: 24px;
  flex-shrink: 0;
}

.quiz-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.quiz-desc {
  font-size: 13px;
  color: var(--text-tertiary);
}

.quiz-desc strong {
  color: var(--accent-dark);
}

/* Score display */
.quiz-score {
  margin-bottom: 28px;
  padding: 20px 24px;
  border-radius: var(--radius-lg);
  text-align: center;
  animation: scoreSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes scoreSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.quiz-score.passed {
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  border: 1px solid #6ee7b7;
}

.quiz-score.failed {
  background: linear-gradient(135deg, #fee2e2, #fecaca);
  border: 1px solid #fca5a5;
}

.score-display {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 4px;
}

.quiz-score.passed .score-display { color: var(--success-dark); }
.quiz-score.failed .score-display { color: var(--danger); }

.score-message {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 12px;
}

.quiz-score.passed .score-message { color: #065f46; }
.quiz-score.failed .score-message { color: #991b1b; }

.score-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
}

.btn-retry {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
}

.btn-retry:hover {
  border-color: var(--primary-500);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Questions */
.quiz-question {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
  transition: var(--transition);
}

.quiz-question.answered-correct {
  border-color: var(--success);
  background: linear-gradient(to right, #f0fdf4, var(--bg-primary));
}

.quiz-question.answered-wrong {
  border-color: var(--danger);
  background: linear-gradient(to right, #fef2f2, var(--bg-primary));
}

.question-number {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.question-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  line-height: 1.5;
}

.question-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  line-height: 1.5;
}

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

.option-btn:disabled {
  cursor: default;
}

.option-letter {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition: var(--transition);
}

.option-btn.selected {
  border-color: var(--primary-500);
  background: var(--primary-light);
}

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

.option-btn.correct {
  border-color: var(--success);
  background: #f0fdf4;
}

.option-btn.correct .option-letter {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: #fef2f2;
}

.option-btn.wrong .option-letter {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
}

/* Explanation */
.question-explanation {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.6;
  display: none;
}

.question-explanation.show {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.question-explanation.correct {
  background: #f0fdf4;
  border-left: 3px solid var(--success);
  color: #065f46;
}

.question-explanation.wrong {
  background: #fef2f2;
  border-left: 3px solid var(--danger);
  color: #991b1b;
}

.explanation-icon {
  flex-shrink: 0;
  font-size: 16px;
}

.btn-submit-quiz {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.25);
}

.btn-submit-quiz:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.35);
  transform: translateY(-1px);
}

.btn-submit-quiz:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== Action Section ========== */
.action-section {
  margin-top: 40px;
  padding-top: 40px;
  border-top: 2px dashed var(--border);
}

.action-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.action-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--success-light);
  border-radius: var(--radius-md);
  font-size: 24px;
  flex-shrink: 0;
}

.action-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.action-desc {
  font-size: 13px;
  color: var(--text-tertiary);
}

.action-items {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.action-item:hover {
  border-color: var(--primary-500);
  box-shadow: var(--shadow-sm);
}

.action-item.checked {
  border-color: var(--success);
  background: #f0fdf4;
}

.action-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
  transition: var(--transition);
  font-size: 12px;
  color: transparent;
}

.action-item.checked .action-checkbox {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.action-text {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  transition: var(--transition);
}

.action-item.checked .action-text {
  text-decoration: line-through;
  color: var(--text-tertiary);
}

.action-complete-msg {
  margin-top: 16px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #d1fae5, #a7f3d0);
  border: 1px solid #6ee7b7;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: #065f46;
  animation: scoreSlideIn 0.4s ease;
}

.action-complete-icon {
  font-size: 20px;
}

/* ========== Chapter Footer ========== */
.chapter-footer {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.btn-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
}

.btn-nav:hover:not(:disabled) {
  border-color: var(--primary-500);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

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

.btn-complete {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--success);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.25);
}

.btn-complete:hover {
  background: var(--success-dark);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

.btn-complete.completed {
  background: var(--bg-primary);
  color: var(--success);
  box-shadow: none;
  border: 1px solid var(--success);
}

/* ========== Search Modal ========== */
.search-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(6px);
  align-items: flex-start;
  justify-content: center;
  padding-top: 120px;
}

.search-modal.active {
  display: flex;
}

.search-modal-content {
  width: 600px;
  max-width: calc(100vw - 32px);
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.search-modal-input-wrap {
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.search-modal-input-wrap .search-icon {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.search-modal-input-wrap input {
  flex: 1;
  height: 56px;
  border: none;
  padding: 0 16px;
  font-size: 16px;
  font-family: var(--font-sans);
  background: transparent;
  color: var(--text-primary);
  outline: none;
}

.search-modal-input-wrap input::placeholder {
  color: var(--text-tertiary);
}

.search-modal-input-wrap .search-kbd {
  position: static;
  transform: none;
}

.search-results {
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
}

.search-result-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.search-result-item:hover {
  background: var(--bg-tertiary);
}

.search-result-icon {
  width: 32px;
  height: 32px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.search-result-text h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.search-result-text p {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.search-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .mobile-header {
    display: flex;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    width: 280px;
    top: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    padding: calc(var(--header-height) + 16px) 20px 60px;
  }

  .welcome h2 {
    font-size: 24px;
  }

  .welcome-stats {
    flex-direction: column;
    gap: 12px;
    align-items: center;
  }

  .stat-card {
    width: 100%;
    max-width: 200px;
    padding: 16px 24px;
  }

  .chapter-title {
    font-size: 22px;
  }

  .section-title {
    font-size: 18px;
  }

  .chapter-nav {
    flex-direction: column;
  }

  .btn-nav, .btn-complete {
    width: 100%;
    justify-content: center;
  }

  .section-content table {
    font-size: 12px;
  }

  .section-content th,
  .section-content td {
    padding: 8px 10px;
  }

  .section-content pre {
    font-size: 12px;
    padding: 16px;
    margin-left: -20px;
    margin-right: -20px;
    border-radius: 0;
  }

  .chapter-progress-segments {
    gap: 4px;
  }

  .segment-label {
    font-size: 10px;
  }

  .quiz-question {
    padding: 16px;
  }

  .action-item {
    padding: 12px 16px;
  }
}

@media (max-width: 480px) {
  .main {
    padding: calc(var(--header-height) + 12px) 16px 48px;
  }

  .welcome-emoji {
    font-size: 48px;
  }

  .btn-start {
    padding: 12px 24px;
    font-size: 15px;
  }
}

/* ========== Print ========== */
@media print {
  .sidebar, .mobile-header, .chapter-footer, .quiz-section, .action-section, .chapter-progress {
    display: none !important;
  }
  .main {
    margin-left: 0;
    padding: 20px;
  }
}

/* ========== Animations ========== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chapter-content {
  animation: fadeIn 0.3s ease;
}

/* ========== Scrollbar ========== */
.main::-webkit-scrollbar {
  width: 6px;
}

.main::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ========== Selection ========== */
::selection {
  background: rgba(59, 130, 246, 0.15);
  color: var(--text-primary);
}

/* ========== Celebration ========== */
@keyframes celebrationIn {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes celebrationOut {
  from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
}
