/* ============================================
   LEARNERIS AI V3 - DESIGN SYSTEM
   Exact copy of TH0 visual system
   No interactive mode — static student book
   ============================================ */

/* Fonts: Be Vietnam Pro */
@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&display=swap');

/* ============================================
   CSS VARIABLES (TH0 exact)
   ============================================ */
:root {
  /* Colors - Learneris Brand */
  --primary: #6541F2;
  --primary-light: #ede9fe;
  --primary-dark: #4c1d95;
  --accent: #14b8a6;
  --accent-light: #ccfbf1;

  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;

  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border: #e2e8f0;
  --border-light: #f1f5f9;

  /* Theme Colors for Chapters */
  --theme-1: #10b981;
  --theme-1-light: #d1fae5;
  --theme-2: #3b82f6;
  --theme-2-light: #dbeafe;
  --theme-3: #f59e0b;
  --theme-3-light: #fef3c7;
  --theme-4: #ec4899;
  --theme-4-light: #fce7f3;

  /* Chapter color aliases (used by chapter headers, lessons, etc.) */
  --ch1-main: #10b981;
  --ch1-light: #d1fae5;
  --ch1-gradient: linear-gradient(135deg, #10b981, #059669);
  --ch2-main: #3b82f6;
  --ch2-light: #dbeafe;
  --ch2-gradient: linear-gradient(135deg, #3b82f6, #2563eb);
  --ch3-main: #f59e0b;
  --ch3-light: #fef3c7;
  --ch3-gradient: linear-gradient(135deg, #f59e0b, #d97706);
  --ch4-main: #ec4899;
  --ch4-light: #fce7f3;
  --ch4-gradient: linear-gradient(135deg, #ec4899, #db2777);

  --font-family: 'Be Vietnam Pro', -apple-system, sans-serif;

  /* Grade 1-2: Larger fonts */
  --font-size-goc-body: 21px;
  --font-size-goc-h1: 36px;
  --font-size-goc-h2: 28px;
  --font-size-goc-h3: 24px;
  --line-height-goc: 1.8;

  /* Grade 3-5: Standard fonts */
  --font-size-nc-body: 17px;
  --font-size-nc-h1: 30px;
  --font-size-nc-h2: 24px;
  --font-size-nc-h3: 20px;
  --line-height-nc: 1.7;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Status Colors */
  --warning: #f59e0b;
  --danger: #ef4444;
  --success: #22c55e;
  --info: #3b82f6;

  /* Gray Scale */
  --gray-50: #f8fafc;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-500: #64748b;
  --gray-700: #334155;

  /* Borders */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

/* Callout variants - fun and danger */
.callout-fun {
  background: #f0fdf4;
  border-left: 4px solid #22c55e;
}
.callout-danger {
  background: #fef2f2;
  border-left: 4px solid #ef4444;
}

/* ============================================
   RESET & BASE
   ============================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-family);
  background: var(--surface-subtle);
  color: var(--text-primary);
  line-height: var(--line-height-nc);
  font-size: var(--font-size-nc-body);
  margin: 0;
  padding: 0;
}

/* Grade-specific typography */
body.version-g1, body.version-g2 {
  font-size: var(--font-size-goc-body);
  line-height: var(--line-height-goc);
}

p {
  margin-bottom: var(--space-md);
}

/* Lucide icon base styling */
.lucide-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  display: inline-block;
  margin-right: 0.3em;
}

/* ============================================
   APP SHELL LAYOUT (TH0 exact)
   ============================================ */
.textbook-container {
  display: flex;
  min-height: 100%;
}

/* Sidebar */
.sidebar {
  width: 282px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.3s ease;
  box-sizing: border-box;
}

.sidebar-header {
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  min-height: 56px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.sidebar-close-btn {
  display: none;
}

.sidebar-home-link {
  display: inline-block;
  margin-bottom: 4px;
  transition: opacity 0.2s;
}
.sidebar-home-link:hover {
  opacity: 1 !important;
}
.sidebar-home-link img {
  filter: brightness(0) invert(1);
}

.sidebar-title {
  font-size: 20px;
  font-weight: 800;
}

.sidebar-subtitle {
  font-size: 14px;
  opacity: 0.85;
  margin-top: var(--space-xs);
}

.sidebar-back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 4px 12px 4px 8px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.1);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.sidebar-back-link:hover {
  background: rgba(255,255,255,0.2);
  color: white;
}

/* Navigation Menu */
.nav-menu {
  padding: var(--space-md) 0;
}

.nav-chapter {
  margin-bottom: var(--space-sm);
}

.nav-chapter-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.nav-chapter-title:hover {
  background: var(--surface-subtle);
  color: var(--text-primary);
}

.nav-chapter-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.nav-chapter[data-theme="1"] .nav-chapter-icon { background: var(--theme-1-light); }
.nav-chapter[data-theme="2"] .nav-chapter-icon { background: var(--theme-2-light); }
.nav-chapter[data-theme="3"] .nav-chapter-icon { background: var(--theme-3-light); }
.nav-chapter[data-theme="4"] .nav-chapter-icon { background: var(--theme-4-light); }

.nav-lessons {
  display: none;
  padding-left: calc(var(--space-md) + 28px + var(--space-sm));
}

.nav-chapter.expanded .nav-lessons {
  display: block;
}

.nav-lesson {
  display: block;
  padding: var(--space-sm) var(--space-md);
  font-size: 14px;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 2px solid transparent;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-lesson:hover {
  color: var(--primary);
  background: var(--primary-light);
  border-left-color: var(--primary);
}

.nav-lesson.active {
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
  background: var(--primary-light);
}

/* Lesson Sections - Show/Hide (TH0 style) */
.lesson-section {
  display: none !important;
}

.lesson-section.active {
  display: block !important;
  animation: fadeInUp 0.4s ease-out;
}

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

/* Main Content Area */
.main-content {
  flex: 1;
  margin-left: 282px;
  display: flex;
  flex-direction: column;
  background: var(--surface-subtle);
  padding-top: 76px;
}

/* Top Bar */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-md) var(--space-xl);
  padding-left: 300px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 99;
  height: 56px;
  box-sizing: border-box;
}

.topbar-home-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
  margin-right: 4px;
}
.topbar-home-btn:hover {
  background: var(--primary-light, #ede9fe);
  color: var(--primary);
}

.breadcrumb {
  font-size: 14px;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.breadcrumb .bc-sep {
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
}

.breadcrumb .bc-chapter {
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.2s;
  flex-shrink: 0;
}

.breadcrumb .bc-chapter:hover {
  color: var(--primary);
}

.breadcrumb .bc-lesson {
  color: var(--text-primary);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breadcrumb a {
  color: var(--text-secondary);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--primary);
}

.top-bar-actions {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  flex-shrink: 0;
}

/* Search Bar (TH0 style) */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  overflow: visible;
  transition: width 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              background 0.2s ease,
              border-color 0.2s ease,
              border-radius 0.2s ease,
              box-shadow 0.2s ease;
}

.search-container.expanded {
  width: 300px;
  background: white;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(101, 65, 242, 0.15);
}

.search-toggle-btn {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all 0.2s;
}

.search-container.expanded .search-toggle-btn {
  border: none;
  background: transparent;
  border-radius: 0;
  width: 36px;
  height: 36px;
}

.search-toggle-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
  background: var(--primary-light);
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  flex: 1;
  padding: 0 8px 0 0;
  gap: 6px;
  min-width: 0;
  opacity: 0;
  transition: opacity 0.3s;
}

.search-container.expanded .search-input-wrapper {
  opacity: 1;
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 15px;
  font-family: inherit;
  color: var(--text-primary);
  padding: 10px 0;
  min-width: 0;
}

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

.search-clear {
  width: 24px;
  height: 24px;
  border: none;
  background: var(--surface-subtle);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all 0.2s;
}

.search-clear:hover {
  background: var(--border);
  color: var(--text-primary);
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 350px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 48px rgba(0,0,0,0.18);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: all 0.25s ease;
}

.search-results.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.search-results-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.search-result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.15s;
}

.search-result-item:hover {
  background: var(--surface-subtle);
}

.search-result-item:last-child {
  border-bottom: none;
}

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

.search-result-text {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
}

.search-result-text mark {
  background: #fef08a;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}

/* ---- Export / PDF Dropdown ---- */
.export-container {
  position: relative;
}
.export-toggle-btn {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: all 0.2s;
}
.export-toggle-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.export-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  padding: 16px;
  z-index: 1000;
}
.export-dropdown.active { display: block; }
.export-dropdown-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}
.export-scope-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.export-scope-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s;
}
.export-scope-option:hover { background: var(--surface-subtle); }
.export-scope-option input[type="radio"] {
  accent-color: var(--primary);
  margin: 0;
}
.export-actions {
  display: flex;
  gap: 8px;
}
.export-btn {
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}
.export-btn-preview {
  background: var(--surface-subtle);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.export-btn-preview:hover { background: var(--border-light); }
.export-btn-pdf {
  background: var(--primary);
  color: white;
}
.export-btn-pdf:hover { background: var(--primary-dark); }

.search-kbd {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Page Wrapper - TH0 exact: max-width 800px */
.page-wrapper {
  flex: 1;
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-xl);
  background: var(--surface-subtle);
}

/* G1-2 uses same max-width as G3-5 to prevent layout jump on grade switch */

/* ============================================
   PAGE TITLE (TH0 exact)
   ============================================ */
.page-title {
  margin-bottom: var(--space-xl);
}

.page-title-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--space-xs);
}

.page-title h1 {
  font-size: var(--font-size-nc-h1);
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

body:where(.version-g1, .version-g2) .page-title h1 {
  font-size: var(--font-size-goc-h1);
}

.page-title-meta {
  font-size: 16px;
  color: var(--text-secondary);
}

.page-title-meta .yccd {
  background: #dbeafe;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'Be Vietnam Pro', monospace;
  font-size: 11px;
  font-weight: 500;
}

/* ============================================
   SECTION HEADINGS (TH0 exact)
   ============================================ */
.section-heading {
  font-size: var(--font-size-nc-h2);
  font-weight: 700;
  color: var(--text-primary);
  margin: var(--space-xl) 0 var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-radius: 8px;
  border-left: 4px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease;
}

.section-heading .lucide-icon {
  flex-shrink: 0;
}

body:where(.version-g1, .version-g2) .section-heading {
  font-size: var(--font-size-goc-h2);
}

.section-heading::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

.section-heading.theme-1 {
  border-left-color: var(--theme-1);
  background: linear-gradient(135deg, #fef3f2 0%, #fee2e2 100%);
}
.section-heading.theme-2 {
  border-left-color: var(--theme-2);
  background: linear-gradient(135deg, #fefbf0 0%, #fef3c7 100%);
}
.section-heading.theme-3 {
  border-left-color: var(--theme-3);
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
}
.section-heading.theme-4 {
  border-left-color: var(--theme-4);
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}

.section-heading.section-objective {
  background: linear-gradient(135deg, #faf5ff 0%, #ede9fe 100%);
  border-left-color: #8b5cf6;
}
.section-heading.section-activity {
  background: linear-gradient(135deg, #fff7ed 0%, #fed7aa 100%);
  border-left-color: #f97316;
}
.section-heading.section-remember {
  background: linear-gradient(135deg, #ecfeff 0%, #cffafe 100%);
  border-left-color: #06b6d4;
}
.section-heading.section-assessment {
  background: linear-gradient(135deg, #fefce8 0%, #fef08a 100%);
  border-left-color: #eab308;
}

/* Sub-headings */
.sub-heading {
  font-size: var(--font-size-nc-h3);
  font-weight: 600;
  color: var(--text-primary);
  margin: var(--space-lg) 0 var(--space-md);
}

body:where(.version-g1, .version-g2) .sub-heading {
  font-size: var(--font-size-goc-h3);
}

/* ============================================
   KEY CONCEPT (TH0 exact)
   ============================================ */
.key-concept {
  background: var(--accent-light);
  border-left: 4px solid var(--accent);
  padding: var(--space-md);
  margin: var(--space-lg) 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  position: relative;
}

.key-concept-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: var(--space-xs);
  font-size: 15px;
  letter-spacing: 0.3px;
}

body:where(.version-g1, .version-g2) .key-concept-title {
  font-size: 16px;
}

.key-concept-title .lucide-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* ============================================
   LESSON ILLUSTRATION (TH0 exact)
   ============================================ */
.lesson-illustration {
  text-align: center;
  margin: 16px 0 24px 0;
  padding: 0;
  position: relative;
}

.lesson-illustration img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12);
  border: 1px solid var(--border-light);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.lesson-illustration:hover img {
  transform: scale(1.01);
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.18);
}

.illustration-caption {
  background: linear-gradient(135deg, var(--surface-subtle), var(--surface));
  padding: 12px 16px;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  margin-top: 0;
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-top: none;
  font-style: italic;
  font-weight: 500;
}

.lesson-illustration.full-bleed img {
  max-width: calc(100% + 64px);
  margin-left: -32px;
  margin-right: -32px;
  border-radius: 0;
}

/* Example images — inline illustrations inside content */
/* --- Error example: centered image + short source caption --- */
.lesson-illustration.example {
  margin: 20px auto 8px;
  max-width: 360px;
}
.lesson-illustration.example.wide {
  max-width: 520px;
}
.lesson-illustration.example img {
  max-width: 100%;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
.lesson-illustration.example:hover img {
  transform: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}
.lesson-illustration.example .caption {
  font-size: 12px;
  color: #71717a;
  padding: 6px 4px 0;
  line-height: 1.45;
  text-align: center;
}
@media (max-width: 600px) {
  .lesson-illustration.example,
  .lesson-illustration.example.wide {
    max-width: 100%;
  }
  /* Horizontal scroll for wide tables on mobile */
  .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table th, .data-table td {
    white-space: nowrap;
    min-width: 80px;
  }
  .data-table td:first-child {
    white-space: normal;
    min-width: 140px;
  }
}

/* --- Answer reveal: hidden by default --- */
details.answer-reveal {
  margin-top: 12px;
}
details.answer-reveal summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
  padding: 6px 0;
  user-select: none;
  list-style: none;
}
details.answer-reveal summary::-webkit-details-marker {
  display: none;
}
details.answer-reveal summary::before {
  content: "▸ ";
}
details.answer-reveal[open] summary::before {
  content: "▾ ";
}
details.answer-reveal summary:hover {
  color: var(--primary);
}
details.answer-reveal .callout {
  margin-top: 8px;
}

/* ============================================
   ACTIVITY (TH0 exact)
   ============================================ */
.activity {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin: var(--space-xl) 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  transition: box-shadow 0.2s ease;
}

.activity:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.activity-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.activity-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 4px 12px rgba(101, 65, 242, 0.3);
}

body:where(.version-g1, .version-g2) .activity-icon {
  width: 40px;
  height: 40px;
  font-size: 20px;
}

.activity-title {
  font-size: var(--font-size-nc-h3);
  font-weight: 700;
  color: var(--primary-dark);
}

body:where(.version-g1, .version-g2) .activity-title {
  font-size: var(--font-size-goc-h3);
}

.activity-instruction {
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

/* ============================================
   DATA TABLE (TH0 exact)
   ============================================ */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: var(--space-md) 0;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
  border: 2px solid var(--border);
  font-size: 15px;
  line-height: 1.6;
}

.data-table th {
  background: linear-gradient(135deg, var(--primary-light), #ede9fe);
  font-weight: 700;
  font-size: 15px;
  color: var(--primary-dark);
  text-align: left;
  padding: 14px 16px;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
}

.data-table th:last-child {
  border-right: none;
}

.data-table th.emoji-header {
  font-size: 32px;
  line-height: 1.2;
  padding: 10px;
  text-align: center;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  vertical-align: middle;
}

.data-table td:last-child {
  border-right: none;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: #f0f4ff;
}

.data-table tr:nth-child(even) td {
  background: var(--surface-subtle);
}

.data-table tr:nth-child(even):hover td {
  background: #f0f4ff;
}

.data-table img {
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.table-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

body:where(.version-g1, .version-g2) .table-checkbox {
  width: 24px;
  height: 24px;
}

/* Larger table text for young grades */
body:where(.version-g1, .version-g2) .data-table {
  font-size: 17px;
}
body:where(.version-g1, .version-g2) .data-table th {
  font-size: 17px;
  padding: 16px;
}
body:where(.version-g1, .version-g2) .data-table td {
  padding: 14px 16px;
}
body:where(.version-g1, .version-g2) .content-box {
  padding: 24px 32px;
}
body:where(.version-g1, .version-g2) .activity {
  padding: 28px 32px;
}
body:where(.version-g1, .version-g2) .callout,
body:where(.version-g1, .version-g2) .remember,
body:where(.version-g1, .version-g2) .discussion {
  padding: 20px 28px;
}

/* ============================================
   WRITE AREA (TH0 exact — lined for handwriting)
   ============================================ */
.write-area {
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  min-height: 100px;
  background: repeating-linear-gradient(
    var(--surface),
    var(--surface) 31px,
    var(--border-light) 31px,
    var(--border-light) 32px
  );
  margin: var(--space-md) 0;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.04);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

body:where(.version-g1, .version-g2) .write-area {
  min-height: 120px;
  padding: var(--space-lg);
  background: repeating-linear-gradient(
    var(--surface),
    var(--surface) 39px,
    var(--border-light) 39px,
    var(--border-light) 40px
  );
}

.write-area:focus-within {
  border-color: var(--primary);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.04), 0 0 0 3px var(--primary-light);
}

.write-area-lg {
  min-height: 150px !important;
}

body:where(.version-g1, .version-g2) .write-area-lg {
  min-height: 180px !important;
}

/* Draw Area */
.draw-area {
  border: 2px dashed var(--primary);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  min-height: 150px;
  background:
    linear-gradient(90deg, var(--border-light) 1px, transparent 1px),
    linear-gradient(var(--border-light) 1px, transparent 1px);
  background-size: 20px 20px;
  background-color: var(--surface);
  margin: var(--space-md) 0;
  position: relative;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);
}

body:where(.version-g1, .version-g2) .draw-area {
  min-height: 200px;
  background-size: 25px 25px;
}

.draw-area::before {
  content: 'Vẽ ở đây';
  position: absolute;
  top: 8px;
  right: 12px;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--surface);
  padding: 2px 8px;
  border-radius: 4px;
}

.draw-area:hover {
  border-color: var(--accent);
}

/* ============================================
   MCQ OPTIONS (TH0 exact)
   ============================================ */
.mcq-options {
  margin: var(--space-md) 0;
}

.mcq-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  transition: all 0.2s ease;
  cursor: pointer;
}

.mcq-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateX(4px);
}

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

/* ============================================
   CALLOUTS (TH0 exact)
   ============================================ */
.callout {
  padding: var(--space-lg);
  margin: var(--space-lg) 0;
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}

.callout-tip {
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  border-left: 4px solid #10b981;
}

.callout-warning {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border-left: 4px solid #f59e0b;
}

.callout-info {
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border-left: 4px solid #3b82f6;
}

.callout-icon {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.callout-tip .callout-icon { color: #10b981; }
.callout-warning .callout-icon { color: #f59e0b; }
.callout-info .callout-icon { color: #3b82f6; }

.callout-content {
  padding-left: 40px;
}

/* ============================================
   DROP CAP (TH0 exact)
   ============================================ */
.lesson-intro::first-letter,
.drop-cap::first-letter {
  font-size: 3.5em;
  font-weight: 800;
  float: left;
  line-height: 0.85;
  margin-right: 0.1em;
  margin-top: 0.05em;
  color: var(--primary);
  text-shadow: 2px 2px 0 var(--primary-light);
}

body:where(.version-g1, .version-g2) .lesson-intro::first-letter,
body:where(.version-g1, .version-g2) .drop-cap::first-letter {
  font-size: 4em;
}

/* ============================================
   SECTION DIVIDER
   ============================================ */
.section-divider {
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: var(--space-2xl) 0;
}

.section-divider.decorated {
  position: relative;
  background: none;
  height: auto;
  text-align: center;
}

.section-divider.decorated::before {
  content: '---';
  color: var(--text-muted);
  font-size: 14px;
  letter-spacing: 8px;
}

/* ============================================
   TRUE/FALSE BUTTONS (TH0 exact)
   ============================================ */
.tf-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.tf-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
  user-select: none;
}

.tf-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

body:where(.version-g1, .version-g2) .tf-btn {
  padding: 10px 20px;
  font-size: 16px;
}

/* ============================================
   BRAINSTORM AREA (TH0)
   ============================================ */
.brainstorm-area {
  border: 3px solid var(--accent);
  border-radius: 30px;
  padding: var(--space-lg);
  min-height: 140px;
  background: var(--accent-light);
  margin: var(--space-md) 0;
  position: relative;
}

body:where(.version-g1, .version-g2) .brainstorm-area {
  min-height: 180px;
  padding: var(--space-xl);
}

/* ============================================
   CHAPTER HEADER (kept for v3 content structure)
   ============================================ */
/* Chapter divider — compact colored bar between chapters */
/* Hidden on screen, restorable by print CSS */
.screen-hidden { display: none !important; }

.chapter-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  margin: 32px 0 16px 0;
  color: white;
  position: relative;
}
.chapter-header::before,
.chapter-header::after { display: none; }
.chapter-header .chapter-icon {
  font-size: 22px;
  flex-shrink: 0;
  line-height: 1;
  position: static;
  transform: none;
  opacity: 1;
}
.chapter-header .chapter-number {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  opacity: 0.85;
  margin: 0;
}
.chapter-header h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  position: relative;
}
.chapter-header .theme {
  font-style: italic;
  opacity: 0.85;
  font-size: 12px;
  margin: 0;
  margin-left: auto;
  white-space: nowrap;
}
.chapter-header .codes { display: none; }

/* ============================================
   CHAPTER INTRO & WRAPUP PAGES (print only)
   ============================================ */
/* Hidden on screen — shown only in print/PDF */
.chapter-intro,
.chapter-wrapup {
  display: none;
}

/* ============================================
   LESSON TITLE (TH0-style: clean, large title)
   ============================================ */
.lesson {
  margin: 0;
  padding: 0;
  scroll-margin-top: 72px;
}
.lesson-title {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0 0 24px 0;
  margin-bottom: 28px;
  border-radius: 0;
}
.lesson-title .lesson-number {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  background: none;
  padding: 0;
  border-radius: 0;
}
.lesson-title h3 {
  font-size: 32px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.2;
  margin: 0;
}
.lesson-title .meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 10px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}
.lesson-title .meta .yccd,
.lesson-title .meta .qd {
  background: none;
  padding: 0;
  border-radius: 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-muted);
}

/* Grade 1-2: even larger title */
.version-g1 .lesson-title h3,
.version-g2 .lesson-title h3 {
  font-size: 36px;
}

/* Self-check component */
.self-check {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 1px solid #7dd3fc;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.self-check h4 {
  color: #0369a1;
  font-size: 1em;
  font-weight: 600;
  margin-bottom: 8px;
}
.self-check p {
  margin-bottom: 4px;
  color: #0c4a6e;
}

/* Transition boxes between chapters */
.chapter-transition {
  display: none !important;
}
.chapter-transition.active {
  display: block !important;
}

/* Chapter-specific lesson-number color */
.ch1 .lesson-title .lesson-number { color: var(--ch1-main); }
.ch2 .lesson-title .lesson-number { color: var(--ch2-main); }
.ch3 .lesson-title .lesson-number { color: var(--ch3-main); }
.ch4 .lesson-title .lesson-number { color: var(--ch4-main); }

/* ============================================
   LEGACY HERO (v3 content compat)
   ============================================ */
.lesson-hero {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 20px;
  position: relative;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
}
.lesson-hero img {
  width: 100%;
  height: auto;
  display: block;
  max-height: 240px;
  object-fit: cover;
}
.lesson-hero .hero-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.6));
  color: white;
  padding: 20px 16px 10px;
  font-size: 12px;
  font-style: italic;
}

/* SVG Scene Hero */
.hero-scene {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--gray-200);
}
.hero-scene svg {
  width: 100%;
  height: auto;
  min-height: 200px;
  display: block;
}
.hero-scene .hero-caption {
  background: var(--gray-50);
  color: var(--gray-600);
  padding: 8px 16px;
  font-size: 12px;
  font-style: italic;
  font-weight: 500;
  border-top: 1px solid var(--gray-200);
}

/* ============================================
   LEGACY COMPONENTS (v3 content compat)
   ============================================ */
.objectives {
  background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
  border: 1px solid #86efac;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.objectives h4 {
  color: #15803d;
  font-size: 1em;
  font-weight: 600;
  margin-bottom: 8px;
}
.objectives ul {
  padding-left: 36px;
  margin: 0;
}
.objectives li {
  margin-bottom: 6px;
  color: #166534;
}
.objectives li::marker {
  color: #22c55e;
}

.content-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px 28px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.content-box h4 {
  color: var(--gray-700);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
}
.content-box p {
  margin-bottom: 10px;
  line-height: 1.7;
}
.content-box ul,
.activity ul,
.callout ul,
.remember ul,
.discussion ul {
  padding-left: 24px;
  margin-bottom: 12px;
}
.content-box li,
.activity li,
.callout li,
.remember li,
.discussion li {
  margin-bottom: 8px;
  line-height: 1.7;
}

.activity p + ul,
.activity ul + p {
  margin-top: 12px;
}
.activity p b {
  color: var(--primary-dark);
}

.discussion {
  background: linear-gradient(135deg, #faf5ff, #f5f3ff);
  border: 1px solid #c4b5fd;
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.discussion h4 {
  color: #6d28d9;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}

.remember {
  background: linear-gradient(135deg, #fefce8, #fef9c3);
  border: 2px solid #fbbf24;
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 16px;
  box-shadow: 0 2px 8px rgba(251, 191, 36, 0.15);
}
.remember h4 {
  color: #92400e;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}
.remember p {
  color: #78350f;
  line-height: 1.7;
}

.self-eval {
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
  border: 2px solid #93c5fd;
  border-radius: 12px;
  padding: 18px 22px;
  margin-bottom: 20px;
}
.self-eval h4 {
  color: #1e40af;
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}

.blank {
  display: inline-block;
  border-bottom: 2px dotted #9ca3af;
  min-width: 80px;
  height: 22px;
  margin: 0 2px;
}

.fill-in {
  display: inline-block;
  min-width: 100px;
  border-bottom: 1px dashed #999;
  min-height: 1.2em;
}

/* Fix ALL empty table cells — fill-in class OR bare empty <td> */
.data-table td.fill-in,
.data-table td:empty {
  display: table-cell;
  min-height: 48px;
  height: 48px;
  min-width: 80px;
}

/* Ensure table columns distribute width evenly when cells are empty */
.data-table {
  table-layout: fixed;
}

/* Safety Rules (numbered card layout) */
.safety-rules {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: var(--space-md) 0;
}
.safety-rule {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 20px;
  background: var(--surface-subtle);
  border-radius: 12px;
  border: 1px solid var(--border);
  line-height: 1.6;
}
.safety-num {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ef4444;
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  border-radius: 50%;
  margin-top: 2px;
}
body:where(.version-g1, .version-g2) .safety-num {
  width: 44px;
  height: 44px;
  font-size: 22px;
}
.safety-rule-img {
  display: block;
  width: 100%;
  max-width: 360px;
  margin: 10px 0 0;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* Flow Diagram */
.flow-diagram {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 18px 0;
  flex-wrap: wrap;
}
.flow-step {
  background: white;
  border: 2px solid var(--ch1-main);
  border-radius: 12px;
  padding: 12px 18px;
  text-align: center;
  font-weight: 600;
  min-width: 80px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.flow-step .step-icon { font-size: 26px; display: block; margin-bottom: 4px; }
.flow-step .step-label { font-size: 12px; color: var(--gray-500); font-weight: 400; }
.flow-arrow { font-size: 22px; color: var(--ch1-main); font-weight: 700; }
.flow-step.green { border-color: var(--ch3-main); background: #f0fdf4; }
.flow-step.amber { border-color: var(--ch2-main); background: #fffbeb; }
.flow-step.red { border-color: var(--danger); background: #fef2f2; }
.flow-step.purple { border-color: var(--ch4-main); background: #f5f3ff; }

/* T-Chart */
.t-chart {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  margin: 14px 0;
}
.t-chart .t-header { padding: 12px 16px; font-weight: 700; font-size: 14px; text-align: center; }
.t-chart .t-header.positive { background: #dcfce7; color: #166534; border-bottom: 2px solid #86efac; }
.t-chart .t-header.negative { background: #fee2e2; color: #991b1b; border-bottom: 2px solid #fca5a5; }
.t-chart .t-body { padding: 12px 16px; line-height: 1.8; }
.t-chart .t-body.left { border-right: 2px solid var(--border); background: #f0fdf4; }
.t-chart .t-body.right { background: #fff1f2; }

/* Icon Grid */
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.icon-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}
.icon-item .icon-emoji { font-size: 30px; display: block; margin-bottom: 4px; }
.icon-item .icon-label { font-weight: 500; color: var(--gray-700); }
.icon-item.smart { border-color: var(--ch1-main); background: var(--ch1-light); }
.icon-item.not-smart { border-color: var(--gray-300); background: var(--gray-50); }

/* Compare Grid */
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 14px 0; }
.compare-card { border-radius: 10px; padding: 14px 16px; border: 2px solid; }
.compare-card.good { background: #f0fdf4; border-color: #86efac; }
.compare-card.good h5 { color: #166534; }
.compare-card.bad { background: #fef2f2; border-color: #fca5a5; }
.compare-card.bad h5 { color: #991b1b; }
.compare-card h5 { font-size: 14px; margin-bottom: 8px; }

/* Speech Bubble */
.speech-bubble {
  background: white;
  border: 2px solid var(--ch1-main);
  border-radius: 16px;
  padding: 12px 16px;
  margin: 10px 0;
  max-width: 80%;
}
.speech-bubble.ai {
  border-color: var(--accent);
  margin-left: auto;
  background: #f0fdfa;
}

/* Scenario Cards */
.scenario-card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 16px 18px;
  margin-bottom: 12px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.scenario-card .scenario-icon { font-size: 30px; flex-shrink: 0; }
.scenario-card .scenario-content { flex: 1; }

/* App Grid */
.app-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin: 14px 0; }
.app-card { background: white; border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; box-shadow: 0 1px 4px rgba(0,0,0,0.06); }
.app-card .app-icon { font-size: 34px; margin-bottom: 6px; display: block; }
.app-card .app-name { font-weight: 600; font-size: 13px; color: var(--gray-700); margin-bottom: 2px; }
.app-card .app-desc { font-size: 11px; color: var(--gray-500); line-height: 1.4; }

/* Steps */
.steps { margin: 14px 0; }
.step-item { display: flex; gap: 14px; margin-bottom: 12px; align-items: flex-start; }
.step-num { width: 34px; height: 34px; border-radius: 50%; background: var(--ch1-main); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.step-content { flex: 1; padding-top: 4px; }
.step-content strong { display: block; margin-bottom: 2px; }

/* Emoji Scale */
.emoji-scale { display: flex; gap: 18px; justify-content: center; margin: 12px 0; }
.emoji-option { text-align: center; }
.emoji-option .emoji { font-size: 30px; display: block; margin-bottom: 2px; }
.emoji-option .label { font-size: 11px; color: var(--gray-500); }

/* Pill Badges */
.pill { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin: 2px; }
.pill.blue { background: #dbeafe; color: #1e40af; }
.pill.green { background: #dcfce7; color: #166534; }
.pill.amber { background: #fef3c7; color: #92400e; }
.pill.red { background: #fee2e2; color: #991b1b; }
.pill.purple { background: #ede9fe; color: #5b21b6; }

/* ============================================
   PAGE FOOTER NAV (prev/next)
   ============================================ */
.page-footer-nav {
  display: flex;
  justify-content: space-between;
  padding: var(--space-lg) 0;
  margin-top: var(--space-xl);
  border-top: 2px solid var(--border-light);
}

.page-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  font-family: inherit;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--text-secondary);
}

.page-nav-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

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

/* Page Footer text */
.page-footer {
  font-size: 11px;
  color: #9ca3af;
  text-align: center;
  margin-top: 24px;
  padding-top: 10px;
  border-top: 2px solid var(--border-light);
}
.page-footer p {
  margin-bottom: 2px;
}

/* Mobile Menu Button */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 8px;
  left: 12px;
  z-index: 300;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: white;
  border: none;
  font-size: 24px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

/* Sidebar Overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}

.sidebar-overlay.show {
  display: block;
}

/* Cover (hidden in app mode) */
.cover {
  display: none;
}

/* ============================================
   RESPONSIVE (TH0 exact breakpoints)
   ============================================ */
@media screen and (max-width: 1200px) {
  .sidebar { width: 240px; }
  .main-content { margin-left: 240px; }
  .top-bar { padding-left: 260px; }
}

@media screen and (max-width: 1024px) {
  .mobile-menu-btn { display: flex; }
  .sidebar {
    width: 280px;
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0 !important; width: 100% !important; }
  .top-bar { padding-left: 60px; }
  body.sidebar-open .mobile-menu-btn { opacity: 0; pointer-events: none; }

  .sidebar-close-btn {
    display: flex;
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    color: white;
    z-index: 10;
  }
  .sidebar-close-btn:hover { background: rgba(255,255,255,0.3); }
  .sidebar-header { position: relative; padding-left: 60px; }
  .sidebar.open + .sidebar-overlay, .sidebar-overlay.show { display: block; }

  .nav-lesson {
    padding: 12px 16px 12px 28px;
    font-size: 15px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .nav-chapter-title { padding: 14px 16px; min-height: 48px; }
}

@media screen and (min-width: 768px) and (max-width: 1024px) {
  :root { --font-size-goc-body: 20px; --font-size-nc-body: 18px; }
  .main-content { margin-left: 0 !important; padding: var(--space-lg); padding-top: 76px !important; width: 100% !important; }
  .page-wrapper { max-width: 100%; padding: 0 var(--space-md); }
}

@media screen and (max-width: 768px) {
  :root { --font-size-goc-body: 18px; --font-size-nc-body: 16px; }
  .page-wrapper { max-width: 100% !important; padding: 12px !important; overflow-x: hidden !important; }
  .main-content { overflow-x: hidden !important; max-width: 100vw !important; padding-top: 68px !important; }
  .top-bar { padding: 8px 12px !important; padding-left: 50px !important; }
  .breadcrumb { font-size: 12px; }
  .breadcrumb .bc-chapter { display: none; }
  .breadcrumb .bc-sep:first-of-type { display: none; }
  .top-bar-actions { gap: 2px; flex-shrink: 0; margin-left: auto; }
  .search-container.expanded { width: 200px; }
  .search-results { width: 280px; }
  .flow-diagram { flex-direction: column; }
  .flow-arrow { transform: rotate(90deg); }
  .t-chart { grid-template-columns: 1fr; }
  .compare-grid { grid-template-columns: 1fr; }
  .app-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================
   PRINT / PDF STYLES
   ============================================ */

/* @page rule — sets PDF margins, page size, and running headers/footers.
   Note: Playwright's page.pdf() margin option overrides these when exporting,
   but these apply for browser Ctrl+P. */
@page {
  size: A4 portrait;
  margin: 20mm 18mm 25mm 18mm;
}

/* First page (cover) — no header/footer margins */
@page :first {
  margin-top: 0;
  margin-bottom: 0;
}

/* ---- TABLE OF CONTENTS (print only — hidden on screen) ---- */
.toc {
  display: none;
  page-break-after: always;
  padding: 40px 30px;
  font-family: 'Be Vietnam Pro', sans-serif;
}
.toc h2 {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 8px;
  text-align: center;
}
.toc .toc-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
}
.toc-chapter {
  margin-bottom: 16px;
}
.toc-chapter-title {
  font-weight: 700;
  font-size: 15px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toc-chapter-title.ch1 { background: var(--ch1-light); color: #065f46; }
.toc-chapter-title.ch2 { background: var(--ch2-light); color: #1e3a8a; }
.toc-chapter-title.ch3 { background: var(--ch3-light); color: #78350f; }
.toc-chapter-title.ch4 { background: var(--ch4-light); color: #831843; }

.toc-lessons {
  list-style: none;
  padding: 0;
  margin: 0;
}
.toc-lessons li {
  display: flex;
  align-items: baseline;
  padding: 5px 12px 5px 28px;
  font-size: 13px;
  color: var(--text-primary);
}
.toc-lessons li .toc-num {
  font-weight: 600;
  color: var(--primary);
  min-width: 50px;
  font-size: 12px;
}
.toc-lessons li .toc-title {
  flex: 1;
}
.toc-lessons li .toc-dots {
  flex: 1;
  border-bottom: 1px dotted var(--text-muted);
  margin: 0 6px;
  min-width: 30px;
}
.toc-lessons li .toc-page {
  display: none; /* hidden on web, shown in print via v3-print-styles.css */
}
.toc-lessons li .toc-yccd {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
  white-space: nowrap;
}

/* ---- PAGE NUMBERING (CSS counter) ---- */
body {
  counter-reset: page-num;
}
.cover, .toc {
  counter-reset: none;
}
/* Each major section increments page counter is handled by the
   running footer below using CSS counters on print */

/* ============================================
   PHỤ LỤC (Appendix) — print-only pages
   ============================================ */
/* Hidden on screen — shown in print/PDF */
.appendix {
  display: none;
}

.appendix-section {
  margin-bottom: 32px;
}

.appendix-section h3 {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  margin: 0 0 16px 0;
  padding-bottom: 8px;
  border-bottom: 3px solid var(--primary);
}

.appendix-section h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 20px 0 8px 0;
}

/* Vocab index */
.vocab-list {
  columns: 2;
  column-gap: 32px;
  list-style: none;
  padding: 0;
  margin: 0;
}
.vocab-list li {
  padding: 5px 0;
  border-bottom: 1px dotted var(--border);
  break-inside: avoid;
  font-size: 14px;
  line-height: 1.5;
}
.vocab-list .vocab-term {
  font-weight: 700;
  color: var(--primary-dark);
}
.vocab-list .vocab-def {
  color: var(--text-secondary);
  margin-left: 4px;
}
body:where(.version-g1, .version-g2) .vocab-list {
  columns: 1;
  font-size: 16px;
}

/* YCCD mapping table (compact) */
.yccd-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.4;
}
.yccd-table th {
  background: var(--primary);
  color: white;
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
}
.yccd-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
.yccd-table tr:nth-child(even) td {
  background: var(--surface-subtle);
}
.yccd-table .code {
  font-family: monospace;
  font-weight: 600;
  white-space: nowrap;
  font-size: 11px;
}

/* References */
.ref-list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: ref;
}
.ref-list li {
  padding: 6px 0 6px 32px;
  position: relative;
  font-size: 13px;
  line-height: 1.5;
  border-bottom: 1px dotted var(--border-light);
  counter-increment: ref;
}
.ref-list li::before {
  content: "[" counter(ref) "]";
  position: absolute;
  left: 0;
  font-weight: 700;
  color: var(--primary);
  font-size: 12px;
}

/* Image credits */
.credits-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.credits-table th {
  background: var(--surface-subtle);
  padding: 5px 8px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.credits-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-light);
}

/* ---- PRINT FOOTER with page number ---- */
.print-footer {
  display: none;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }

  html, body {
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    overflow-x: visible !important;
  }

  body {
    background: white !important;
    font-size: 11pt;
    line-height: 1.5;
    margin: 0;
    padding: 0;
  }

  /* --- Hide non-print elements --- */
  .sidebar, .top-bar, .mobile-menu-btn, .sidebar-overlay,
  .page-footer-nav, .no-print, .export-container { display: none !important; }

  /* --- Remove layout constraints for proper pagination --- */
  .main-content {
    margin-left: 0 !important;
    padding-top: 0 !important;
    display: block !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    width: 100% !important;
  }
  .page-wrapper {
    max-width: 100% !important;
    padding: 20px !important;
    margin: 0 !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
  }
  .textbook-container {
    display: block !important;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
  }

  /* --- Cover page --- */
  .cover {
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    page-break-after: always;
    min-height: 100vh;
    padding: 60px 40px;
    box-sizing: border-box;
    text-align: center;
    background: white;
  }
  .cover .logo-area {
    margin-bottom: 20px;
  }
  .cover .logo-area svg {
    width: 64px;
    height: 64px;
  }
  .cover h1 {
    font-size: 32pt !important;
    font-weight: 800 !important;
    color: var(--text-primary) !important;
    margin: 0 0 8px 0 !important;
    letter-spacing: -0.5px;
  }
  .cover h2 {
    font-size: 11pt !important;
    font-weight: 500 !important;
    color: var(--text-secondary) !important;
    margin: 0 0 28px 0 !important;
  }
  .cover .grade-badge {
    display: inline-block !important;
    background: var(--primary) !important;
    color: white !important;
    font-size: 22pt !important;
    font-weight: 800 !important;
    padding: 14px 48px !important;
    border-radius: 14px !important;
    margin-bottom: 28px !important;
  }
  .cover .subtitle {
    font-size: 13pt;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    margin-bottom: 8px;
  }
  .cover .cover-stats {
    display: flex !important;
    gap: 36px !important;
    justify-content: center !important;
    margin: 28px 0 !important;
  }
  .cover .stat-item {
    text-align: center;
  }
  .cover .stat-number {
    display: block;
    font-size: 22pt;
    font-weight: 800;
    color: var(--primary);
    line-height: 1.2;
  }
  .cover .stat-label {
    display: block;
    font-size: 8pt;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
  }
  .cover .cover-info {
    font-size: 9pt !important;
    color: var(--text-muted) !important;
    max-width: 460px;
    line-height: 1.7;
    margin-top: 8px;
  }
  .cover .footer {
    margin-top: 36px;
    font-size: 9pt;
    color: var(--text-muted);
  }

  /* --- TOC (restore for print) --- */
  .toc { display: block !important; page-break-after: always; }

  /* --- Restore hidden elements for print --- */
  .screen-hidden { display: block !important; }
  .chapter-header.screen-hidden { display: flex !important; }

  /* --- Guide page (print only) --- */
  .guide-page { page-break-after: always; padding: 40px 32px; }

  /* Override JS show/hide — all lesson-sections visible in print */
  .lesson-section { display: block !important; }
  .chapter-transition { display: none !important; }

  /* --- Chapter headers (compact bar — keep for structure, hidden if intro exists) --- */
  .chapter-header {
    display: flex !important;
    page-break-before: always;
    page-break-after: avoid;
    page-break-inside: avoid;
  }
  /* When an intro page exists, hide the compact header in print */
  .chapter-intro + .chapter-header {
    display: none !important;
  }

  /* --- Chapter Intro Page (full page) --- */
  .chapter-intro {
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 85vh;
    page-break-before: always;
    page-break-after: always;
    page-break-inside: avoid;
    text-align: center;
    padding: 40px 30px;
    border-radius: 0;
  }
  .chapter-intro .ci-icon {
    font-size: 48pt;
    margin-bottom: 16px;
  }
  .chapter-intro .ci-number {
    font-size: 11pt;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0.7;
    margin-bottom: 4px;
  }
  .chapter-intro .ci-title {
    font-size: 24pt;
    font-weight: 800;
    margin: 0 0 8px 0;
    color: var(--text-primary);
  }
  .chapter-intro .ci-theme {
    font-size: 13pt;
    font-style: italic;
    color: var(--text-secondary);
    margin-bottom: 32px;
  }
  .chapter-intro .ci-lessons {
    list-style: none;
    padding: 0;
    margin: 0;
    text-align: left;
    width: 100%;
    max-width: 400px;
  }
  .chapter-intro .ci-lessons li {
    padding: 8px 0;
    font-size: 11pt;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    gap: 10px;
  }
  .chapter-intro .ci-lessons li .ci-lesson-num {
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 45px;
  }
  .chapter-intro .ci-divider {
    width: 60px;
    height: 3px;
    border-radius: 2px;
    margin: 20px auto 24px auto;
  }

  /* --- Chapter Wrapup Page --- */
  .chapter-wrapup {
    display: block !important;
    page-break-before: always;
    page-break-after: always;
    page-break-inside: avoid;
    padding: 40px 30px;
  }
  .chapter-wrapup .cw-header {
    text-align: center;
    margin-bottom: 28px;
  }
  .chapter-wrapup .cw-icon {
    font-size: 32pt;
    margin-bottom: 8px;
  }
  .chapter-wrapup .cw-title {
    font-size: 18pt;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0 0 4px 0;
  }
  .chapter-wrapup .cw-subtitle {
    font-size: 11pt;
    color: var(--text-secondary);
    font-style: italic;
  }
  .chapter-wrapup .cw-section {
    margin-bottom: 24px;
  }
  .chapter-wrapup .cw-section h4 {
    font-size: 12pt;
    font-weight: 700;
    margin: 0 0 10px 0;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--border);
  }
  .chapter-wrapup .cw-checklist {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  .chapter-wrapup .cw-checklist li {
    padding: 6px 0 6px 28px;
    position: relative;
    font-size: 11pt;
  }
  .chapter-wrapup .cw-checklist li::before {
    content: "☐";
    position: absolute;
    left: 0;
    font-size: 14pt;
  }
  .chapter-wrapup .cw-reflect {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  .chapter-wrapup .cw-reflect li {
    padding: 10px 0 10px 28px;
    position: relative;
    font-size: 11pt;
    border-bottom: 1px dotted var(--border);
  }
  .chapter-wrapup .cw-reflect li::before {
    content: "💭";
    position: absolute;
    left: 0;
  }

  /* --- Lessons --- */
  .lesson {
    page-break-before: always;
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
    background: white !important;
  }
  .lesson:first-of-type {
    page-break-before: avoid;
  }
  .lesson-title {
    page-break-after: avoid;
    border-bottom: none;
    border-left: 4px solid var(--ch1-main);
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: 0;
  }
  .ch2 .lesson-title { border-left-color: var(--ch2-main); }
  .ch3 .lesson-title { border-left-color: var(--ch3-main); }
  .ch4 .lesson-title { border-left-color: var(--ch4-main); }
  .lesson-title h3 { font-size: 16pt; }
  .lesson-title .lesson-number {
    font-size: 10pt;
    display: block;
    margin-bottom: 2px;
  }

  /* --- Content blocks: keep together, never split across pages --- */
  .key-concept, .activity, .data-table,
  .remember-box, .content-box, .objectives,
  .lesson-illustration, .compare-grid,
  .self-check, .self-eval, .remember,
  .discussion, .icon-grid, .fill-in,
  .write-area, .compare-grid, .flow-diagram,
  .step-item {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* --- Headings must stay with following content --- */
  h3, h4, h5,
  .section-heading,
  .lesson-title {
    page-break-after: avoid;
    break-after: avoid;
  }

  /* --- Orphan/widow control --- */
  p, li {
    orphans: 3;
    widows: 3;
  }

  /* --- Never leave a heading stranded at bottom of page --- */
  h4 {
    page-break-inside: avoid;
    break-inside: avoid;
    page-break-after: avoid;
    break-after: avoid;
  }

  /* --- Clean up shadows & decorations --- */
  .key-concept, .activity, .data-table, .content-box,
  .lesson-illustration img, .remember-box {
    box-shadow: none !important;
  }

  /* --- Images: constrain height so they never dominate a page --- */
  .lesson-illustration img {
    max-height: 45vh;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    border-radius: 8px;
    border: 1px solid var(--border);
  }
  /* Hero / full-bleed images: still capped */
  .lesson-illustration.full-bleed img {
    max-height: 50vh;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
  }

  /* --- Write areas: enlarge for real handwriting (≈5–6 cm) --- */
  .write-area {
    min-height: 180px !important;
    padding: 16px !important;
    border: 1.5pt solid #cbd5e1 !important;
    border-radius: 6px !important;
    background: repeating-linear-gradient(
      white, white 23px, #e2e8f0 23px, #e2e8f0 24px
    ) !important;
  }
  body:where(.version-g1, .version-g2) .write-area {
    min-height: 220px !important;
    background: repeating-linear-gradient(
      white, white 31px, #e2e8f0 31px, #e2e8f0 32px
    ) !important;
  }
  .write-area-lg {
    min-height: 280px !important;
  }
  body:where(.version-g1, .version-g2) .write-area-lg {
    min-height: 320px !important;
  }

  /* --- Draw areas: enlarge for actual drawing --- */
  .draw-area {
    min-height: 200px !important;
    border: 1.5pt dashed var(--primary) !important;
  }

  /* --- Blank/fill-in lines: wider for writing --- */
  .blank {
    min-width: 120px !important;
    border-bottom-width: 1.5pt !important;
  }
  .fill-in {
    min-width: 140px !important;
  }

  /* --- Content blocks: add breathing room between sections --- */
  .key-concept, .activity, .content-box,
  .remember-box, .self-check, .self-eval,
  .discussion {
    margin-bottom: 20px !important;
    padding: 14px 18px !important;
  }

  /* --- Callout boxes: clean borders for PDF clarity --- */
  .callout-fun, .callout-danger {
    border-left-width: 4pt !important;
    box-shadow: none !important;
  }

  /* --- Tables: clean borders for PDF --- */
  .data-table table {
    border-collapse: collapse;
    width: 100%;
  }
  .data-table th, .data-table td {
    border: 1pt solid #cbd5e1 !important;
    padding: 8px 10px !important;
  }

  /* --- Transition pages --- */
  .transition-page {
    page-break-before: always;
    page-break-after: always;
  }

  /* --- Print footer: HIDDEN in @media print ---
       Playwright/Puppeteer generates proper per-page headers & footers
       via displayHeaderFooter + headerTemplate/footerTemplate.
       The CSS fixed-position footer only renders on page 1, so hide it. */
  .print-footer {
    display: none !important;
  }

  /* --- Links: show URL in print --- */
  a[href^="http"]::after {
    content: none; /* keep clean for textbook */
  }

  /* --- Print Scope: lesson only --- */
  .print-scope-lesson .cover,
  .print-scope-lesson .toc { display: none !important; }
  .print-scope-lesson .lesson-section { display: none !important; }
  .print-scope-lesson .lesson.print-target { display: block !important; page-break-before: avoid; }
  .print-scope-lesson .chapter-header { display: none !important; }
  .print-scope-lesson .chapter-intro,
  .print-scope-lesson .chapter-wrapup { display: none !important; }

  /* --- Print Scope: chapter --- */
  .print-scope-chapter .cover { display: none !important; }
  .print-scope-chapter .toc { display: none !important; }
  .print-scope-chapter .lesson-section { display: none !important; }
  .print-scope-chapter .lesson.print-target { display: block !important; }
  .print-scope-chapter .chapter-header { display: none !important; }
  .print-scope-chapter .chapter-header.print-target { display: flex !important; }
  .print-scope-chapter .chapter-intro { display: none !important; }
  .print-scope-chapter .chapter-intro.print-target { display: flex !important; }
  .print-scope-chapter .chapter-intro.print-target + .chapter-header { display: none !important; }
  .print-scope-chapter .chapter-wrapup { display: none !important; }
  .print-scope-chapter .chapter-wrapup.print-target { display: block !important; }

  /* --- Appendix: show in print, start on new page --- */
  .appendix {
    display: block !important;
    page-break-before: always;
  }
  .appendix-section {
    page-break-inside: avoid;
  }

  /* Hide appendix when printing single lesson or chapter */
  .print-scope-lesson .appendix,
  .print-scope-chapter .appendix {
    display: none !important;
  }

  /* --- Print Scope: book — everything shows (default) --- */
}

/* ============================================
   PREVIEW MODE (on-screen print preview)
   ============================================ */
.preview-mode .sidebar,
.preview-mode .top-bar,
.preview-mode .mobile-menu-btn,
.preview-mode .sidebar-overlay,
.preview-mode .page-footer-nav { display: none !important; }

.preview-mode .main-content {
  margin-left: 0 !important;
  padding-top: 0 !important;
}
.preview-mode .page-wrapper {
  max-width: 800px !important;
  margin: 0 auto !important;
  padding: 40px 30px !important;
  background: white;
  min-height: 100vh;
}

/* In preview mode, show all content regardless of lesson-section active state */
.preview-mode .lesson-section { display: block !important; }
.preview-mode .screen-hidden { display: block !important; }
.preview-mode .chapter-header.screen-hidden { display: flex !important; }
.preview-mode .chapter-transition { display: none !important; }
/* Restore print-style lesson-title in preview */
.preview-mode .lesson-title {
  border-bottom: none;
  border-left: 4px solid var(--ch1-main);
  padding: 12px 16px;
  border-radius: 0;
}
.preview-mode .ch2 .lesson-title { border-left-color: var(--ch2-main); }
.preview-mode .ch3 .lesson-title { border-left-color: var(--ch3-main); }
.preview-mode .ch4 .lesson-title { border-left-color: var(--ch4-main); }

/* Show chapter-intro and chapter-wrapup in preview */
.preview-mode .chapter-intro {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 60px 30px;
  margin: 40px 0;
  background: var(--ci-bg, var(--surface-subtle));
  border-radius: var(--radius-lg);
}
.preview-mode .chapter-intro .ci-icon { font-size: 48px; margin-bottom: 12px; }
.preview-mode .chapter-intro .ci-number {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 2px; opacity: 0.7; margin-bottom: 4px;
}
.preview-mode .chapter-intro .ci-title {
  font-size: 24px; font-weight: 800; margin: 0 0 6px 0;
}
.preview-mode .chapter-intro .ci-theme {
  font-size: 14px; font-style: italic; color: var(--text-secondary); margin-bottom: 24px;
}
.preview-mode .chapter-intro .ci-divider {
  width: 60px; height: 3px; border-radius: 2px; margin: 0 auto 20px auto;
}
.preview-mode .chapter-intro .ci-lessons {
  list-style: none; padding: 0; text-align: left; max-width: 400px; width: 100%;
}
.preview-mode .chapter-intro .ci-lessons li {
  padding: 8px 0; font-size: 14px; border-bottom: 1px solid var(--border-light);
  display: flex; gap: 10px;
}
.preview-mode .chapter-intro .ci-lessons li .ci-lesson-num {
  font-weight: 700; color: var(--text-secondary); min-width: 45px;
}

.preview-mode .chapter-wrapup {
  display: block !important;
  padding: 40px 30px;
  margin: 40px 0;
  background: var(--surface-subtle);
  border-radius: var(--radius-lg);
}
.preview-mode .chapter-wrapup .cw-header { text-align: center; margin-bottom: 24px; }
.preview-mode .chapter-wrapup .cw-icon { font-size: 32px; margin-bottom: 8px; }
.preview-mode .chapter-wrapup .cw-title {
  font-size: 20px; font-weight: 800; margin: 0 0 4px 0;
}
.preview-mode .chapter-wrapup .cw-subtitle {
  font-size: 13px; color: var(--text-secondary); font-style: italic;
}
.preview-mode .chapter-wrapup .cw-section { margin-bottom: 20px; }
.preview-mode .chapter-wrapup .cw-section h4 {
  font-size: 14px; font-weight: 700; margin: 0 0 10px 0;
  padding-bottom: 6px; border-bottom: 2px solid var(--border);
}
.preview-mode .chapter-wrapup .cw-checklist {
  list-style: none; padding: 0;
}
.preview-mode .chapter-wrapup .cw-checklist li {
  padding: 5px 0 5px 28px; position: relative; font-size: 14px;
}
.preview-mode .chapter-wrapup .cw-checklist li::before {
  content: "☐"; position: absolute; left: 0; font-size: 16px;
}
.preview-mode .chapter-wrapup .cw-reflect {
  list-style: none; padding: 0;
}
.preview-mode .chapter-wrapup .cw-reflect li {
  padding: 8px 0 8px 28px; position: relative; font-size: 14px;
  border-bottom: 1px dotted var(--border);
}
.preview-mode .chapter-wrapup .cw-reflect li::before {
  content: "💭"; position: absolute; left: 0;
}

/* Preview scope filtering (mirrors print scope rules for screen) */
.preview-mode.print-scope-lesson .lesson-section { display: none !important; }
.preview-mode.print-scope-lesson .lesson.print-target { display: block !important; }
.preview-mode.print-scope-lesson .chapter-header { display: none !important; }
.preview-mode.print-scope-lesson .chapter-intro,
.preview-mode.print-scope-lesson .chapter-wrapup { display: none !important; }
.preview-mode.print-scope-lesson .cover,
.preview-mode.print-scope-lesson .toc { display: none !important; }

.preview-mode.print-scope-chapter .lesson-section { display: none !important; }
.preview-mode.print-scope-chapter .lesson.print-target { display: block !important; }
.preview-mode.print-scope-chapter .chapter-header { display: none !important; }
.preview-mode.print-scope-chapter .chapter-header.print-target { display: flex !important; }
.preview-mode.print-scope-chapter .chapter-intro { display: none !important; }
.preview-mode.print-scope-chapter .chapter-intro.print-target { display: flex !important; }
.preview-mode.print-scope-chapter .chapter-intro.print-target + .chapter-header { display: none !important; }
.preview-mode.print-scope-chapter .chapter-wrapup { display: none !important; }
.preview-mode.print-scope-chapter .chapter-wrapup.print-target { display: block !important; }
.preview-mode.print-scope-chapter .cover,
.preview-mode.print-scope-chapter .toc { display: none !important; }

/* Preview mode: exit button */
.preview-exit-bar {
  display: none;
}
.preview-mode .preview-exit-bar {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  background: var(--primary);
  color: white;
  padding: 10px 20px;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-family);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.preview-exit-bar button {
  background: white;
  color: var(--primary);
  border: none;
  padding: 6px 16px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.preview-exit-bar button:hover {
  background: var(--primary-light);
}

/* ============================================
   GRADE SWITCHER (top bar)
   ============================================ */
.grade-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 4px;
  flex-shrink: 0;
  margin-left: 4px;
}

.grade-switcher-home {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  flex-shrink: 0;
}

.grade-switcher-home:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.grade-switcher-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 2px;
}

.grade-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-family);
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
  user-select: none;
  line-height: 1;
}

.grade-pill:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.grade-pill.active {
  background: var(--primary);
  color: white;
  cursor: default;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(101, 65, 242, 0.3);
}

/* Mobile adjustments for grade switcher */
@media screen and (max-width: 768px) {
  .grade-switcher {
    padding: 2px 3px;
    gap: 1px;
  }
  .grade-pill {
    width: 24px;
    height: 24px;
    font-size: 11px;
  }
  .grade-switcher-home {
    width: 24px;
    height: 24px;
  }
  .grade-switcher-home svg {
    width: 13px;
    height: 13px;
  }
  .grade-switcher-sep {
    height: 14px;
    margin: 0 1px;
  }
}

@media screen and (max-width: 480px) {
  .grade-switcher {
    padding: 2px;
    gap: 0;
    border-radius: 16px;
  }
  .grade-pill {
    width: 22px;
    height: 22px;
    font-size: 10px;
  }
  .grade-switcher-home {
    width: 22px;
    height: 22px;
  }
  .grade-switcher-home svg {
    width: 12px;
    height: 12px;
  }
  .grade-switcher-sep {
    height: 12px;
  }
}

/* Hide grade switcher in print / preview */
@media print {
  .grade-switcher { display: none !important; }
}
.preview-mode .grade-switcher { display: none !important; }

/* ============================================
   WELCOME BACK MODAL
   ============================================ */
.welcome-back-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
  padding: var(--space-md);
}
.welcome-back-modal.show {
  opacity: 1;
}
.welcome-back-modal.closing {
  opacity: 0;
}
.welcome-back-content {
  background: #ffffff;
  border-radius: 20px;
  padding: 40px 36px 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  transform: translateY(20px) scale(0.95);
  transition: transform 0.3s ease;
  position: relative;
}
.welcome-back-modal.show .welcome-back-content {
  transform: translateY(0) scale(1);
}
.welcome-back-modal.closing .welcome-back-content {
  transform: translateY(20px) scale(0.95);
}
.welcome-back-icon {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 12px;
}
.welcome-back-content h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px;
}
.welcome-back-content > p {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0 0 12px;
}
.last-lesson-info {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  padding: 10px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
}
.wb-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.wb-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.wb-progress-text {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 20px;
}
.welcome-back-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.wb-btn-continue,
.wb-btn-restart {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.wb-btn-continue {
  background: var(--primary);
  color: #fff;
}
.wb-btn-continue:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}
.wb-btn-restart {
  background: var(--surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.wb-btn-restart:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

/* ============================================
   SIDEBAR VISITED INDICATORS
   ============================================ */
.nav-lesson.visited {
  position: relative;
}
.nav-lesson.visited::after {
  content: '✓';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--accent);
  font-weight: 700;
  opacity: 0.7;
}
.nav-lesson.active.visited::after {
  color: var(--primary);
  opacity: 1;
}

/* Mobile adjustments for welcome-back modal */
@media (max-width: 480px) {
  .welcome-back-content {
    padding: 28px 20px 24px;
  }
  .welcome-back-icon {
    font-size: 40px;
  }
  .welcome-back-content h2 {
    font-size: 18px;
  }
  .welcome-back-buttons {
    flex-direction: column;
  }
  .wb-btn-continue,
  .wb-btn-restart {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================
   ANSWER KEY STYLES
   ============================================ */

/* Student book: small reference note pointing to appendix */
.answer-ref {
  font-size: 12px;
  color: var(--text-secondary, #71717a);
  font-style: italic;
  margin-top: 6px;
  padding: 4px 8px;
  background: var(--primary-light, #ede9fe);
  border-radius: 6px;
  display: inline-block;
}
.answer-ref::before {
  content: "\01F4D6 ";
}

/* Appendix answer key section */
.appendix-answer-key h4 {
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid #e5e7eb;
  color: var(--primary, #6541F2);
}
.appendix-answer-key h4:first-of-type {
  border-top: none;
  padding-top: 0;
}
.answer-table td:last-child {
  font-weight: 600;
  color: var(--primary-dark, #4c1d95);
}

/* Teaching guide: inline answer key box */
.tg-answer-key {
  margin: 12px 0 16px;
  padding: 12px 16px;
  background: #f0fdf4;
  border: 2px solid #86efac;
  border-radius: 10px;
  page-break-inside: avoid;
}
.tg-answer-key h5 {
  font-size: 14px;
  font-weight: 700;
  color: #166534;
  margin: 0 0 8px;
}
.tg-answer-key ul {
  margin: 0;
  padding-left: 20px;
}
.tg-answer-key li {
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 4px;
  color: #15803d;
}
.tg-answer-key li b {
  color: #166534;
}
.tg-answer-key p {
  font-size: 13px;
  line-height: 1.6;
  color: #15803d;
  margin: 4px 0;
}
