/* ═══════════════════════════════════════════════════════════════
   ONTARIO MATHEMATICS TEXTBOOK SERIES — DESIGN SYSTEM v2.0
   Print-ready • Child-friendly • Curriculum-aligned
   ═══════════════════════════════════════════════════════════════ */

/* === FONT IMPORTS === */
@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400;1,700&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Open+Sans:ital,wght@0,400;0,600;0,700;0,800;1,400&family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,600;0,8..60,700;1,8..60,400&display=swap');

/* === CSS VARIABLES === */
:root {
  /* Unit theme — override these per-unit or per-grade */
  --unit-color: #2563eb;
  --unit-accent: #06b6d4;
  --heading-color: #1d4ed8;

  /* Fixed palette */
  --unit-highlight: #f0a500;
  --bg-page: #fafaf9;
  --text-main: #1e1e2e;
  --text-muted: #64748b;

  /* Practice badge colours */
  --badge-l1: #15803d;
  --badge-l2: #b45309;
  --badge-l3: #b91c1c;

  /* Section backgrounds & borders */
  --bg-warmup: #f0fdf4;      --border-warmup: #16a34a;
  --bg-keyidea: #fffbeb;      --border-keyidea: #d97706;
  --bg-challenge: #f5f3ff;    --border-challenge: #7c3aed;
  --bg-journal: #fdf4ff;      --border-journal: #9333ea;
  --bg-concrete: #ecfdf5;
  --bg-pictorial: #fefce8;
  --bg-abstract: #eff6ff;
  --bg-practice: #f0f9ff;     --border-practice: #0ea5e9;
  --bg-success: #f0fdf4;      --border-success: #15803d;
  --bg-goal: #ffffff;          --border-goal: var(--unit-accent);
}

/* === UNIT THEME PRESETS — vibrant, child-friendly palette === */
/* Islamic Studies themes */
.theme-islamic   { --unit-color:#15803d; --unit-accent:#d97706; --heading-color:#14532d; }  /* green-gold (Tawheed) */
.theme-pillars   { --unit-color:#dc2626; --unit-accent:#f59e0b; --heading-color:#991b1b; }  /* red-amber (Five Pillars) */
.theme-prophet   { --unit-color:#b45309; --unit-accent:#fbbf24; --heading-color:#92400e; }  /* amber-gold (Prophet) */
.theme-quran     { --unit-color:#1e40af; --unit-accent:#7c3aed; --heading-color:#1e3a8a; }  /* blue-indigo (Quran) */
.theme-akhlaq    { --unit-color:#0891b2; --unit-accent:#0d9488; --heading-color:#164e63; }  /* cyan-teal (Manners) */
.theme-salah     { --unit-color:#7c3aed; --unit-accent:#a78bfa; --heading-color:#5b21b6; }  /* violet (Salah) */
/* Maths themes */
.theme-number    { --unit-color:#e85d04; --unit-accent:#f48c06; --heading-color:#c2410c; }  /* bright orange */
.theme-operations { --unit-color:#d62828; --unit-accent:#f77f00; --heading-color:#b91c1c; } /* red-orange */
.theme-patterns  { --unit-color:#2563eb; --unit-accent:#06b6d4; --heading-color:#1d4ed8; } /* bright blue-cyan */
.theme-algebra   { --unit-color:#4f46e5; --unit-accent:#7c3aed; --heading-color:#4338ca; } /* indigo-purple */
.theme-data      { --unit-color:#0891b2; --unit-accent:#14b8a6; --heading-color:#0e7490; } /* cyan-teal */
.theme-probability { --unit-color:#0d9488; --unit-accent:#10b981; --heading-color:#0f766e; } /* teal-emerald */
.theme-geometry  { --unit-color:#8b5cf6; --unit-accent:#a78bfa; --heading-color:#6d28d9; } /* violet-lavender */
.theme-measurement { --unit-color:#059669; --unit-accent:#34d399; --heading-color:#047857; } /* emerald-green */
.theme-financial { --unit-color:#d97706; --unit-accent:#fbbf24; --heading-color:#b45309; } /* amber-gold */

/* === PAGE / PRINT SETUP === */
@page {
  size: letter portrait;
  margin: 0.75in 0.6in 0.75in 0.9in;
}

/* === BASE RESET === */
*, *::before, *::after {
  box-sizing: border-box;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

body {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-main);
  max-width: min(960px, 95vw);
  margin: 0 auto;
  padding: 0 20px;
  background-color: var(--bg-page);
}

img, svg { max-width: 100%; }
a { color: var(--unit-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === TYPOGRAPHY === */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Open Sans', Arial, sans-serif;
  color: var(--heading-color, var(--unit-color));
  margin-top: 1.4em;
  margin-bottom: 0.5em;
  font-weight: 700;
  line-height: 1.3;
}

p, ul, ol, table { margin-bottom: 1.1em; }
ul, ol { padding-left: 24px; }
li { margin-bottom: 0.45em; }
strong { color: var(--heading-color, var(--unit-color)); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; border: 1px solid #e2e8f0; text-align: left; font-size: 0.95rem; }
th { background: var(--unit-color); color: white; font-family: 'Open Sans', sans-serif; font-weight: 700; }
tr:nth-child(even) td { background: #f8fafc; }

/* === PAGE BREAK CONTROL === */
.page-break {
  page-break-before: always;
  break-before: page;
  clear: both;
}

/* === NAVIGATION BAR === */
.unit-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--unit-color), var(--unit-accent));
  padding: 14px 24px;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  z-index: 100;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  margin-bottom: 8px;
}
.unit-nav a {
  color: #fff;
  text-decoration: none;
  padding: 6px 16px;
  border-radius: 8px;
  font-weight: 600;
  transition: background 0.2s;
}
.unit-nav a:hover { background: rgba(255,255,255,0.2); text-decoration: none; }
.unit-nav .nav-title { color: rgba(255,255,255,0.92); font-weight: 700; letter-spacing: 0.5px; }
.unit-nav .disabled { opacity: 0.35; pointer-events: none; }

/* ═══════════════════════════════════════
   COVER BANNER
   ═══════════════════════════════════════ */
.cover-banner {
  background: linear-gradient(135deg, var(--unit-color), var(--unit-accent));
  border-radius: 12px;
  padding: 80px 40px;
  text-align: center;
  color: white;
  margin-top: 24px;
  margin-bottom: 32px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.cover-svg {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  opacity: 0.2; pointer-events: none;
}
.cover-content { position: relative; z-index: 2; }
.cover-unit-num {
  font-family: 'Open Sans', sans-serif;
  font-size: 5rem; font-weight: 800;
  margin: 0; line-height: 1;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.cover-title {
  font-family: 'Open Sans', sans-serif;
  font-size: 2.5rem; font-weight: 700;
  margin: 16px 0 24px; color: white !important;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}
.cover-banner h1, .cover-banner h2, .cover-banner h3,
.cover-banner p, .cover-banner div, .cover-banner span { color: white !important; }
.cover-subtitle {
  font-size: 1.15rem; font-family: 'Open Sans', sans-serif;
  font-weight: 600; opacity: 0.95;
  text-transform: uppercase; letter-spacing: 2px;
  margin-bottom: 32px;
}
.cover-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.curriculum-pill {
  background: rgba(255,255,255,0.25);
  border: 1px solid rgba(255,255,255,0.5);
  padding: 6px 16px; border-radius: 999px;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.9rem; font-weight: 700;
}

/* === LEGACY UNIT HEADER (Grades 1-7 compat) === */
.unit-header {
  background: linear-gradient(135deg, var(--unit-color), var(--unit-accent));
  border-radius: 12px;
  padding: 60px 40px 40px;
  text-align: center;
  color: white;
  margin-top: 24px;
  margin-bottom: 32px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}
.unit-number {
  font-family: 'Open Sans', sans-serif;
  font-size: 1rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 2px;
  opacity: 0.9; margin-bottom: 8px;
}
.unit-title {
  font-family: 'Open Sans', sans-serif;
  font-size: 2.5rem; font-weight: 700;
  margin: 8px 0 16px; color: white !important;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.3);
}
.unit-header h1, .unit-header h2, .unit-header h3,
.unit-header p, .unit-header div { color: white !important; }
.unit-description {
  font-size: 1.1rem; opacity: 0.95;
  max-width: 600px; margin: 0 auto;
  line-height: 1.6;
}

/* === DESCRIPTION & TOC CARDS === */
.cover-desc-card {
  background: white; padding: 28px 32px;
  border-radius: 12px; margin-bottom: 32px;
  font-size: 1.05rem; line-height: 1.8;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  border: 1px solid #e2e8f0;
}
.toc-card {
  background: white; padding: 28px 32px;
  border-radius: 12px; margin-bottom: 32px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  border: 1px solid #e2e8f0;
}
.toc-card h2 {
  margin-top: 0;
  border-bottom: 3px solid var(--unit-color);
  padding-bottom: 16px; margin-bottom: 24px;
}
.toc-list { list-style: none; padding: 0; margin: 0; }
.toc-item {
  display: flex; align-items: center;
  padding: 12px 16px; border-radius: 8px;
  margin-bottom: 8px; background: var(--bg-page);
  font-family: 'Open Sans', sans-serif;
  border: 1px solid #e2e8f0;
  transition: box-shadow 0.2s;
}
.toc-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.toc-num {
  background: var(--unit-color); color: white;
  font-weight: bold; width: 36px; height: 36px;
  border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center;
  margin-right: 16px; flex-shrink: 0; font-size: 0.95rem;
}
.toc-title { font-weight: 600; color: var(--text-main); flex: 1; }
.toc-code {
  margin-left: auto; color: white;
  font-size: 0.82rem; font-weight: 700;
  background: var(--unit-accent);
  padding: 4px 12px; border-radius: 999px;
  white-space: nowrap;
}

/* ═══════════════════════════════════════
   INDEX PAGE (Grade-level)
   ═══════════════════════════════════════ */
.index-hero {
  background: linear-gradient(135deg, var(--unit-color), var(--unit-accent));
  border-radius: 16px; padding: 60px 40px;
  text-align: center; color: white;
  margin: 24px 0 40px; position: relative;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,0.18);
}
.index-hero h1 {
  font-family: 'Open Sans', sans-serif;
  font-size: 3.2rem; font-weight: 800;
  color: white; margin: 0 0 8px;
  text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.index-hero .tagline {
  font-size: 1.3rem; font-weight: 600;
  opacity: 0.95; font-family: 'Open Sans', sans-serif;
  margin-bottom: 16px;
}
.index-hero .subtitle {
  font-size: 1rem; opacity: 0.85;
  font-family: 'Source Serif 4', serif;
}

.strand-section { margin-bottom: 40px; }
.strand-label {
  font-family: 'Open Sans', sans-serif;
  font-size: 0.85rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 2px;
  color: var(--text-muted); margin-bottom: 16px;
  padding-left: 4px;
}
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.unit-card {
  background: white; border-radius: 12px;
  padding: 24px; border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none; color: inherit;
  display: block;
}
.unit-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
  text-decoration: none;
}
.unit-card-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--unit-color); color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight: 800; font-size: 1.1rem;
  margin-bottom: 12px;
}
.unit-card-title {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 1.1rem;
  color: var(--unit-color); margin-bottom: 6px;
}
.unit-card-desc {
  font-size: 0.9rem; color: var(--text-muted);
  line-height: 1.5; margin-bottom: 12px;
}
.unit-card-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.unit-card-pill {
  font-family: 'Open Sans', sans-serif;
  font-size: 0.75rem; font-weight: 700;
  background: var(--unit-accent); color: white;
  padding: 2px 10px; border-radius: 999px;
}

/* ═══════════════════════════════════════
   LESSON HEADER
   ═══════════════════════════════════════ */
.lesson-header {
  background: linear-gradient(to right, var(--unit-color), var(--unit-accent));
  color: white; padding: 32px 40px;
  border-radius: 12px; margin: 32px 0 28px;
  box-shadow: 0 6px 15px rgba(0,0,0,0.1);
  page-break-after: avoid;
  break-after: avoid;
}
.lesson-header h2 {
  color: white !important; margin: 10px 0 8px;
  font-size: 2rem;
}
.lesson-header > p, .lesson-header > span, .lesson-header > div:not(.section-box) { color: white !important; }
.lesson-header .section-box, .lesson-header .section-box p,
.lesson-header .section-box li, .lesson-header .section-box span,
.lesson-header .section-box div { color: #334155 !important; }
.lesson-header .section-box .section-title { color: var(--unit-accent) !important; }
.lesson-header .success-criteria .section-title { color: var(--border-success) !important; }
.lesson-pill {
  display: inline-block;
  background: rgba(255,255,255,0.25);
  padding: 5px 16px; border-radius: 999px;
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 0.9rem;
}
.lesson-code {
  font-family: 'Open Sans', sans-serif;
  opacity: 0.9; font-size: 0.9rem; font-weight: 600;
}
.lesson-title {
  font-family: 'Open Sans', sans-serif;
  font-size: 2rem; font-weight: 700;
  margin: 10px 0 8px; line-height: 1.3;
}
.lesson-subtitle {
  font-size: 1rem; opacity: 0.85;
  font-family: 'Source Serif 4', serif; margin: 0;
}
.lesson-badge, .lesson-number {
  display: inline-block;
  background: rgba(255,255,255,0.25);
  padding: 5px 16px; border-radius: 999px;
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 0.9rem;
}
.lesson-divider {
  border: none; border-top: 2px solid #e2e8f0;
  margin: 32px 0;
}
.curriculum-tag {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 3px 10px; border-radius: 6px;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.78rem; font-weight: 700;
  letter-spacing: 0.5px;
}
.star { color: #fbbf24; margin-right: 4px; }

/* ═══════════════════════════════════════
   SECTION BOXES (all lesson sections)
   ═══════════════════════════════════════ */
.section-box {
  padding: 24px 28px; border-radius: 12px;
  margin-bottom: 24px; background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid #e2e8f0;
  page-break-inside: avoid;
  break-inside: avoid;
}

.section-title {
  font-family: 'Open Sans', sans-serif;
  font-size: 1.25rem; font-weight: 700;
  margin-top: 0; margin-bottom: 14px;
  display: flex; align-items: center; gap: 10px;
}

/* --- Learning Goal --- */
.learning-goal { border-left: 7px solid var(--border-goal); }
.learning-goal .section-title { color: var(--unit-accent); }

/* --- Success Criteria --- */
.success-criteria {
  border-left: 7px solid var(--border-success);
  background: var(--bg-success);
}
.success-criteria .section-title { color: var(--border-success); }
.success-criteria ul { list-style: none; padding: 0; margin: 6px 0 0; }
.success-criteria li {
  padding: 5px 0 5px 32px; position: relative;
  font-size: 0.98rem; line-height: 1.6;
}
.success-criteria li::before {
  content: '\2705'; position: absolute; left: 0; font-size: 0.95rem;
}

/* --- Warm Up / Try It --- */
.warm-up, .try-it {
  background: var(--bg-warmup);
  border-left: 7px solid var(--border-warmup);
}
.warm-up .section-title, .try-it .section-title { color: var(--border-warmup); }

/* --- Learn Section & Examples --- */
.learn-section {
  padding: 24px 28px; border-radius: 12px;
  margin-bottom: 24px; background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid #e2e8f0;
}
.example-box {
  background: #f8fafc; border: 1px solid #e2e8f0;
  border-radius: 10px; padding: 20px 24px;
  margin: 16px 0;
}
.worked-example {
  background: #fffbeb; border: 1px solid #fde68a;
  border-radius: 10px; padding: 20px 24px;
  margin: 16px 0;
}
.worked-example__label {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 0.92rem;
  color: var(--border-keyidea); margin-bottom: 8px;
}
.prompt {
  background: #eff6ff; border-left: 4px solid var(--unit-accent);
  padding: 14px 20px; border-radius: 0 10px 10px 0;
  margin: 16px 0; font-style: italic;
  color: #1e40af;
}

/* --- CPA Sections --- */
.cpa-concrete { background: var(--bg-concrete); border-left: 7px solid #047857; }
.cpa-concrete .section-title { color: #047857; }

.cpa-pictorial { background: var(--bg-pictorial); border-left: 7px solid #a16207; }
.cpa-pictorial .section-title { color: #a16207; }

.cpa-abstract { background: var(--bg-abstract); border-left: 7px solid #1d4ed8; }
.cpa-abstract .section-title { color: #1d4ed8; }

/* --- CPA Model Cards (Concrete-Pictorial-Abstract) --- */
.cpa-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin: 20px 0;
}
.concrete-model, .pictorial-model, .abstract-model {
  background: white; border-radius: 10px;
  padding: 18px; border: 1px solid #e2e8f0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.concrete-model { border-top: 4px solid #047857; }
.pictorial-model { border-top: 4px solid #a16207; }
.abstract-model { border-top: 4px solid #1d4ed8; }
.cpa-label {
  display: inline-block;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 2px 10px; border-radius: 999px;
  color: white; margin-bottom: 10px;
}
.concrete-model .cpa-label { background: #047857; }
.pictorial-model .cpa-label { background: #a16207; }
.abstract-model .cpa-label { background: #1d4ed8; }
.cpa-content { font-size: 0.95rem; line-height: 1.6; }

/* --- Step Flow --- */
.step-flow {
  display: flex; align-items: flex-start;
  gap: 8px; margin: 20px 0; flex-wrap: wrap;
  justify-content: center;
}
.step-flow__step {
  background: white; border: 1px solid #e2e8f0;
  border-radius: 10px; padding: 14px 16px;
  min-width: 120px; text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
.step-flow__step-number {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--unit-color); color: white;
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 0.85rem;
  margin-bottom: 8px;
}
.step-flow__step-text { font-size: 0.9rem; line-height: 1.5; }
.step-flow__arrow {
  display: flex; align-items: center;
  font-size: 1.4rem; color: var(--unit-color);
  padding-top: 10px;
}

/* --- Section Card (alternate header) --- */
.section-card {
  padding: 24px 28px; border-radius: 12px;
  margin-bottom: 24px; background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid #e2e8f0;
  page-break-inside: avoid;
}
.section-card__header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px;
}
.section-card__emoji { font-size: 1.5rem; flex-shrink: 0; }
.section-card__title {
  font-family: 'Open Sans', sans-serif;
  font-size: 1.25rem; font-weight: 700;
  margin: 0; color: var(--heading-color);
}

/* --- Key Idea --- */
.key-idea {
  background: var(--bg-keyidea);
  border: 2.5px solid var(--border-keyidea);
  box-shadow: 0 6px 16px rgba(217,119,6,0.12);
}
.key-idea .section-title { color: var(--border-keyidea); }

/* --- Practice --- */
.practice-section {
  background: var(--bg-practice);
  border-top: 7px solid var(--border-practice);
  page-break-inside: auto;
  break-inside: auto;
}
.practice-section .section-title {
  color: var(--border-practice);
  border-bottom: 2px solid #bae6fd;
  padding-bottom: 10px; margin-bottom: 20px;
}

/* --- Design Challenge --- */
.design-challenge {
  background: var(--bg-challenge);
  border: 2.5px dashed var(--border-challenge);
}
.design-challenge .section-title { color: var(--border-challenge); }

/* --- Math Journal --- */
.math-journal {
  background: var(--bg-journal);
  border-left: 7px solid var(--border-journal);
}
.math-journal .section-title { color: var(--border-journal); }
.math-journal p { font-style: italic; }

/* ═══════════════════════════════════════
   PRACTICE BADGES & LISTS
   ═══════════════════════════════════════ */
.practice-level {
  margin: 20px 0;
  page-break-inside: avoid;
  break-inside: avoid;
}
.badge {
  display: inline-block; color: white;
  padding: 5px 16px; border-radius: 999px;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.85rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.badge-l1 { background: var(--badge-l1); }
.badge-l2 { background: var(--badge-l2); }
.badge-l3 { background: var(--badge-l3); }

.practice-list { padding-left: 20px; }
.practice-list li {
  padding: 8px 0;
  border-bottom: 1px dashed #cbd5e1;
}
.practice-list li:last-child { border-bottom: none; }

/* --- Question-Set Practice Layout --- */
.question-set {
  margin-bottom: 22px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.question-set__label {
  margin-bottom: 10px;
}
.level-badge {
  display: inline-block;
  color: white;
  padding: 5px 16px;
  border-radius: 999px;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.level-badge--1 { background: var(--badge-l1); }
.level-badge--2 { background: var(--badge-l2); }
.level-badge--3 { background: var(--badge-l3); }

.question {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed #cbd5e1;
}
.question:last-child { border-bottom: none; }

.question__number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  background: var(--unit-color, #2563eb);
  color: white;
  border-radius: 50%;
  font-family: 'Open Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}
.question__body {
  flex: 1;
  padding-top: 4px;
  line-height: 1.7;
}

/* --- Blanks & Answer Lines --- */
.blank, .answer-blank {
  display: inline-block;
  min-width: 60px; border-bottom: 2px solid #334155;
  margin: 0 4px; padding: 2px 8px;
}
.answer-line {
  display: inline-block;
  border-bottom: 2px solid var(--unit-color);
  padding: 2px 12px; margin: 0 4px;
  font-weight: 600; color: var(--unit-color);
}
.draw-box, .workspace {
  border: 2px dashed #cbd5e1; border-radius: 10px;
  min-height: 120px; padding: 16px; margin: 16px 0;
  background: #fafaf9;
}
.workspace-label {
  font-family: 'Open Sans', sans-serif;
  font-size: 0.85rem; font-weight: 700;
  color: var(--text-muted); margin-bottom: 8px;
}
.writing-line, .writing-lines, .write-lines, .journal-line {
  border-bottom: 1px solid #cbd5e1;
  min-height: 2em; margin-bottom: 8px;
}

/* ═══════════════════════════════════════
   SVG CONTAINERS
   ═══════════════════════════════════════ */
.svg-container {
  text-align: center; margin: 20px 0;
  background: white; padding: 20px;
  border-radius: 12px; border: 1px solid #e2e8f0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
  page-break-inside: avoid;
  break-inside: avoid;
}
.svg-container svg {
  display: inline-block;
  max-width: 100%; height: auto;
}

/* --- SVG Variants --- */
.svg-diagram, .svg-center, .svg-figure, .generated-image,
.diagram-container {
  text-align: center; margin: 20px 0;
}
.svg-diagram svg, .svg-center svg, .svg-figure svg,
.generated-image svg, .diagram-container svg {
  display: inline-block; max-width: 100%; height: auto;
}
.diagram-caption {
  text-align: center; font-size: 0.9rem;
  color: var(--text-muted); margin-top: 8px;
  font-style: italic;
}

/* ═══════════════════════════════════════
   CALLOUT BOXES
   ═══════════════════════════════════════ */
.callout {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 16px 20px; border-radius: 10px;
  margin: 16px 0; border: 1px solid #e2e8f0;
  background: white;
  page-break-inside: avoid;
}
.callout-icon { font-size: 1.4rem; flex-shrink: 0; }
.callout-content { flex: 1; }
.callout-label {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 0.92rem;
  margin-bottom: 4px;
}
.callout-text { font-size: 0.95rem; color: var(--text-muted); line-height: 1.6; }

.callout-tip { background: #eff6ff; border-left: 4px solid #3b82f6; }
.callout-tip .callout-label { color: #1d4ed8; }
.callout-warning { background: #fffbeb; border-left: 4px solid #d97706; }
.callout-warning .callout-label { color: #92400e; }

/* --- Callout BEM Variants (double-underscore naming) --- */
.callout__icon { font-size: 1.4rem; flex-shrink: 0; }
.callout__content { flex: 1; }
.callout__label {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 0.92rem;
  margin-bottom: 4px;
}
.callout__text { font-size: 0.95rem; color: var(--text-muted); line-height: 1.6; }

/* --- Callout Variant Themes --- */
.math-tip { background: #eff6ff; border-left: 4px solid #3b82f6; }
.math-tip .callout-label, .math-tip .callout__label { color: #1d4ed8; }
.try-this { background: var(--bg-warmup); border-left: 4px solid var(--border-warmup); }
.try-this .callout-label, .try-this .callout__label { color: #15803d; }
.did-you-know { background: #fefce8; border-left: 4px solid #ca8a04; }
.did-you-know .callout-label, .did-you-know .callout__label { color: #854d0e; }

/* --- Speech Bubble --- */
.speech-bubble-wrapper {
  display: flex; align-items: flex-start; gap: 14px;
  margin: 16px 0;
}
.speech-bubble__character { font-size: 2rem; flex-shrink: 0; }
.speech-bubble {
  background: white; border: 1px solid #e2e8f0;
  border-radius: 12px; padding: 14px 20px;
  position: relative; flex: 1;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
.speech-bubble::before {
  content: ''; position: absolute; left: -8px; top: 16px;
  border: 8px solid transparent;
  border-right-color: #e2e8f0;
  border-left: 0;
}

/* --- Symbol Cards --- */
.symbol-cards {
  display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: center; margin: 20px 0;
}
.symbol-card {
  background: white; border-radius: 10px;
  padding: 16px 20px; min-width: 100px;
  text-align: center; border: 2px solid #e2e8f0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
.symbol-card--green { border-color: #16a34a; }
.symbol-card--blue { border-color: #2563eb; }
.symbol-card--orange { border-color: #ea580c; }
.symbol-card--purple { border-color: #7c3aed; }
.symbol-card--red { border-color: #dc2626; }
.symbol-card__symbol {
  font-size: 2rem; font-weight: 700;
  color: var(--heading-color); margin-bottom: 6px;
}
.symbol-card__name {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; font-size: 0.9rem;
}
.symbol-card__meaning {
  font-size: 0.85rem; color: var(--text-muted);
  margin-top: 4px;
}

/* ═══════════════════════════════════════
   SPECIALIZED TABLES
   ═���═════════════════════════════════════ */
.vocab-table { margin: 16px 0; }
.vocab-table th { background: var(--unit-color); }
.vocab-word { font-weight: 700; color: var(--heading-color); }
.data-table { margin: 16px 0; }
.data-table th { background: var(--unit-accent); }
.calendar-table td { text-align: center; padding: 8px; min-width: 40px; }
.calendar-table .today { background: var(--unit-accent); color: white; border-radius: 50%; }
.calendar-table .holiday { background: #fef2f2; }
.hundred-chart td { text-align: center; padding: 6px; font-size: 0.9rem; width: 10%; }
.place-value-chart th { text-align: center; }
.place-value-chart td { text-align: center; font-size: 1.1rem; font-weight: 600; }
.tally-table td { vertical-align: middle; }
.tally-marks { font-size: 1.1rem; letter-spacing: 2px; }
.sharing-table, .sorting-table, .pattern-table { margin: 16px 0; }
.pattern-row td { text-align: center; }
.pictograph-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; }
.pictograph-label { min-width: 80px; font-weight: 600; }
.pictograph-icons { font-size: 1.2rem; letter-spacing: 4px; }

/* ═══════════════════════════════════════
   CODE BLOCKS (Coding Lessons)
   ═══════════════════════════════════════ */
.code-block, .pseudo-block {
  background: #1e293b; color: #e2e8f0;
  padding: 20px 24px; border-radius: 10px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.92rem; line-height: 1.8;
  margin: 16px 0; overflow-x: auto;
}
.code-keyword, .keyword { color: #818cf8; font-weight: 700; }
.code-string { color: #34d399; }
.code-comment, .comment { color: #64748b; font-style: italic; }
.line-num {
  display: inline-block; width: 28px;
  color: #475569; text-align: right;
  margin-right: 16px; user-select: none;
}

/* --- Flowchart Steps --- */
.step-arrow {
  display: flex; flex-direction: column;
  align-items: center; gap: 0; margin: 20px auto;
  max-width: 300px;
}
.step-box {
  background: white; border: 2px solid var(--unit-color);
  border-radius: 8px; padding: 10px 20px;
  text-align: center; font-family: 'Open Sans', sans-serif;
  font-weight: 600; width: 100%;
}
.start-box { background: #dcfce7; border-color: #16a34a; color: #15803d; }
.end-box { background: #fee2e2; border-color: #dc2626; color: #b91c1c; }
.arrow-down, .arrow-icon {
  font-size: 1.4rem; color: var(--unit-color);
  text-align: center; padding: 4px 0;
}
.arrow-down::after { content: '▼'; }

/* ═══════════════════════════════════════
   COMING UP NEXT / EXIT TICKET
   ═══════════════════════════════════════ */
.coming-up-next {
  display: flex; align-items: center; gap: 16px;
  background: linear-gradient(135deg, var(--unit-color), var(--unit-accent));
  color: white; padding: 20px 24px; border-radius: 12px;
  margin: 32px 0;
}
.coming-up-next__icon { font-size: 1.6rem; flex-shrink: 0; }
.coming-up-next__content { flex: 1; }
.coming-up-next__label {
  font-family: 'Open Sans', sans-serif;
  font-size: 0.8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 1px;
  opacity: 0.85;
}
.coming-up-next__title {
  font-family: 'Open Sans', sans-serif;
  font-size: 1.1rem; font-weight: 700;
  margin-top: 4px;
}
.coming-up-next__arrow { font-size: 1.5rem; opacity: 0.7; }

.exit-ticket {
  background: #fef3c7; border: 2px solid #f59e0b;
  border-radius: 12px; padding: 20px 24px;
  margin: 24px 0;
}
.exit-ticket h3, .exit-ticket .section-title {
  color: #92400e; margin-top: 0;
}

/* ═══════════════════════════════════════
   GLOSSARY (Back Matter)
   ═══════════════════════════════════════ */
.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px; margin: 20px 0;
}
.glossary-entry {
  background: white; border: 1px solid #e2e8f0;
  border-radius: 10px; padding: 16px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.04);
}
.glossary-svg { text-align: center; margin-bottom: 8px; }
.glossary-word, .glossary-term {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; color: var(--heading-color);
  font-size: 1rem; margin-bottom: 4px;
}
.glossary-def, .glossary-text {
  font-size: 0.9rem; color: var(--text-muted);
  line-height: 1.5;
}
.term-title {
  font-family: 'Open Sans', sans-serif;
  color: var(--heading-color); margin: 0 0 4px;
}

/* ═══════════════════════════════════════
   JOURNAL & REVIEW (Back Matter)
   ═══════════════════════════════════════ */
.journal-prompt {
  background: var(--bg-journal); border-left: 5px solid var(--border-journal);
  border-radius: 0 10px 10px 0; padding: 18px 22px;
  margin-bottom: 20px;
}
.journal-unit {
  font-family: 'Open Sans', sans-serif;
  font-size: 0.8rem; font-weight: 700;
  color: var(--border-journal);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.journal-q { font-style: italic; margin-bottom: 12px; }
.journal-lines, .journal-draw, .journal-write, .journal-entry {
  border: 2px dashed #d8b4fe; border-radius: 8px;
  min-height: 80px; padding: 12px; margin-top: 8px;
  background: white;
}

.review-q {
  padding: 14px 0; border-bottom: 1px solid #e2e8f0;
}
.review-q-num {
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; color: var(--unit-color);
  margin-right: 8px;
}
.review-q-body { display: inline; }
.review-choices { list-style: upper-alpha; margin-top: 8px; }
.review-strand {
  display: inline-block; font-size: 0.75rem;
  font-family: 'Open Sans', sans-serif;
  font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-left: 8px;
}
.review-img-row { text-align: center; margin: 12px 0; }

/* ═══════════════════════════════════════
   SEL CARDS
   ═══════════════════════════════════════ */
.sel-card {
  border-top: 4px solid var(--unit-color);
  background: white; border-radius: 0 0 10px 10px;
  padding: 20px 24px; margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  border: 1px solid #e2e8f0; border-top-width: 4px;
}
.sel-scenario { font-style: italic; margin-bottom: 12px; }
.sel-tip { color: var(--text-muted); font-size: 0.95rem; }

/* ═══════════════════════════════════════
   NAVIGATION VARIANTS (Back Matter)
   ═══════════════════════════════════════ */
.nav-bar, .book-nav {
  display: flex; align-items: center;
  justify-content: center; gap: 12px;
  padding: 12px 0; font-family: 'Open Sans', sans-serif;
  font-size: 0.9rem;
}
.nav-sep { color: #cbd5e1; }
.nav-center { font-weight: 700; }
.nav-arrow { font-size: 1.2rem; color: var(--unit-color); }

/* --- Section Title Page --- */
.section-title-page, .back-section-header {
  text-align: center; padding: 48px 24px;
  margin: 32px 0;
}
.section-title-page h2, .back-section-header h2 {
  font-size: 2rem; margin-bottom: 8px;
}

/* --- Page Dividers & Decorations --- */
.page-divider {
  border: none; border-top: 3px solid var(--unit-color);
  margin: 32px 0; opacity: 0.3;
}
.page-footer-grass {
  height: 40px;
  background: linear-gradient(to top, #dcfce7, transparent);
  margin-top: 32px; border-radius: 0 0 12px 12px;
}

/* ═══════════════════════════════════════
   MISCELLANEOUS COMPONENTS
   ═══════════════════════════════════════ */
.math-display {
  text-align: center; font-size: 1.3rem;
  margin: 20px 0; padding: 16px;
}
.two-col {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 16px; margin: 16px 0;
}
.compare-row {
  display: flex; align-items: center;
  justify-content: center; gap: 16px; margin: 12px 0;
}
.compare-item {
  background: white; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 12px 16px;
  text-align: center; min-width: 80px;
}
.pair-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px; margin: 16px 0;
}
.pair-box {
  background: white; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 12px; text-align: center;
}
.pair-label { font-weight: 600; margin-bottom: 4px; }
.visual-row {
  display: flex; align-items: center;
  gap: 12px; flex-wrap: wrap; margin: 12px 0;
}
.highlight-blue, .hl-blue { background: #dbeafe; padding: 1px 6px; border-radius: 4px; }
.hl-green { background: #dcfce7; padding: 1px 6px; border-radius: 4px; }
.divider { border: none; border-top: 1px solid #e2e8f0; margin: 24px 0; }

/* --- Shape & Season Cards --- */
.shape-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px; margin: 16px 0;
}
.shape-card {
  background: white; border: 1px solid #e2e8f0;
  border-radius: 10px; padding: 14px; text-align: center;
}
.shape-name { font-weight: 700; color: var(--heading-color); margin-bottom: 4px; }
.shape-desc { font-size: 0.85rem; color: var(--text-muted); }

.season-cards {
  display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: center; margin: 16px 0;
}
.season-card {
  border-radius: 10px; padding: 14px 18px;
  min-width: 120px; text-align: center;
  font-family: 'Open Sans', sans-serif; font-weight: 600;
}
.season-spring { background: #dcfce7; color: #15803d; }
.season-summer { background: #fef9c3; color: #854d0e; }
.season-fall { background: #ffedd5; color: #9a3412; }
.season-winter { background: #dbeafe; color: #1e40af; }

/* --- Data Visualization Containers --- */
.spinner-container, .bar-graph-container {
  text-align: center; margin: 20px 0;
}
.fact-family-box {
  background: white; border: 2px solid var(--unit-color);
  border-radius: 10px; padding: 16px 20px;
  margin: 16px auto; max-width: 300px;
  text-align: center;
}

/* --- Lesson wrapper --- */
.lesson { margin-bottom: 32px; }
.warmup { background: var(--bg-warmup); border-left: 7px solid var(--border-warmup); }
.unit-subtitle {
  font-size: 1.1rem; opacity: 0.9;
  font-family: 'Source Serif 4', serif;
}

/* ═══════════════════════════════════════
   LESSON PAGER BAR
   ═══════════════════════════════════════ */
body.has-pager { padding-bottom: 72px; }

.lesson-pager-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 300;
  background: linear-gradient(135deg, var(--unit-color, #2563eb), var(--unit-accent, #06b6d4));
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; gap: 12px;
  box-shadow: 0 -3px 14px rgba(0,0,0,0.18);
  font-family: 'Open Sans', sans-serif;
}
.pager-btn {
  background: rgba(255,255,255,0.22); border: 1.5px solid rgba(255,255,255,0.45);
  color: white; padding: 8px 18px; border-radius: 999px;
  font-size: 0.88rem; font-weight: 700; cursor: pointer;
  font-family: 'Open Sans', sans-serif; white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
  min-width: 110px;
}
.pager-btn:hover  { background: rgba(255,255,255,0.38); transform: scale(1.03); }
.pager-btn:active { transform: scale(0.97); }
.pager-center {
  flex: 1; text-align: center; color: white; min-width: 0;
}
.pager-fraction {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.5px; opacity: 0.85; margin-bottom: 2px;
}
.pager-title {
  font-size: 0.9rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@media (max-width: 640px) {
  .pager-btn { padding: 7px 10px; font-size: 0.78rem; min-width: 80px; }
  .pager-title { font-size: 0.78rem; }
}
@media print { .lesson-pager-bar { display: none !important; } }

/* ═══════════════════════════════════════
   WRITING LINES — Student Workbook Areas
   Lines appear BELOW the question text via
   ::after — never behind the text itself.
   Question writing lines are PRINT ONLY.
   ═══════════════════════════════════════ */

/* ── Shared line mixin ─────────────────── */
/* Reset any background-image on prompt itself — lines go in ::after */
.prompt,
.warm-up .prompt,
.try-it .prompt, .try-this .prompt,
.math-journal .prompt, .math-journal blockquote, .journal-prompt,
.design-challenge .prompt {
  background-image: none;
  min-height: auto;
}

/* Base prompt writing lines — 3 lines below text */
.prompt::after {
  content: '';
  display: block;
  height: 84px;   /* 3 lines × 28px */
  margin-top: 10px;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    rgba(30, 64, 175, 0.22) 27px,
    rgba(30, 64, 175, 0.22) 28px
  );
  border-radius: 0 0 4px 4px;
}

/* Warm Up — green lines */
.warm-up .prompt::after {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    rgba(34, 197, 94, 0.5) 27px,
    rgba(34, 197, 94, 0.5) 28px
  );
}

/* Try It — teal lines */
.try-it .prompt::after,
.try-this .prompt::after {
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    rgba(20, 184, 166, 0.42) 27px,
    rgba(20, 184, 166, 0.42) 28px
  );
}

/* Math Journal — purple lines, 6 lines of reflection space */
.math-journal .prompt::after,
.math-journal blockquote::after,
.journal-prompt::after {
  height: 168px;  /* 6 lines */
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    rgba(147, 51, 234, 0.38) 27px,
    rgba(147, 51, 234, 0.38) 28px
  );
}

/* Design Challenge — deep purple, 4 lines */
.design-challenge .prompt::after {
  height: 112px;  /* 4 lines */
  background: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 27px,
    rgba(109, 40, 217, 0.32) 27px,
    rgba(109, 40, 217, 0.32) 28px
  );
}

/* ═══════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════ */
.unit-footer {
  margin-top: 48px; padding: 24px 20px;
  border-top: 3px solid #e2e8f0;
  text-align: center;
  font-family: 'Open Sans', sans-serif;
  color: var(--text-muted); font-size: 0.9rem;
}

/* ═══════════════════════════════════════
   PRINT STYLES — PROFESSIONAL TEXTBOOK
   ═══════════════════════════════════════ */
@media print {

  /* ── PAGE SETUP ────────────────────────────────────────── */
  @page {
    size: letter portrait;
    margin: 0.75in 0.75in 0.75in 0.75in;
  }

  /* ── FORCE ALL COLOURS TO PRINT ────────────────────────── */
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
    box-shadow: none !important;
    text-shadow: none !important;
    transition: none !important;
    animation: none !important;
  }

  /* ── BODY ───────────────────────────────────────────────── */
  body {
    background: white !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 10pt !important;
    line-height: 1.45 !important;
    color: #1e1e2e !important;
  }

  /* ── ONLY PRINT THE ACTIVE LESSON ──────────────────────── */
  .lesson-page-wrap { display: none !important; }
  .lesson-page-wrap.is-printing {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* ── HIDE SCREEN UI ─────────────────────────────────────── */
  .unit-nav, .lesson-pager-bar { display: none !important; }
  /* page-break divs forced new pages in the old whole-unit print view —
     with the pager we print one lesson at a time so they must be hidden */
  .page-break { display: none !important; }

  /* ── LESSON HEADER ──────────────────────────────────────── */
  .lesson-header, .unit-header {
    break-before: avoid !important;
    page-break-before: avoid !important;
    break-after: avoid;
    page-break-after: avoid;
    margin: 0 0 8px 0 !important;
    padding: 14px 20px !important;
    border-radius: 5px !important;
  }
  .lesson-header h2, .lesson-title {
    font-size: 1.35rem !important;
    margin: 3px 0 2px !important;
    line-height: 1.2 !important;
  }
  .lesson-pill, .lesson-code, .lesson-badge { font-size: 0.75rem !important; }
  .lesson-subtitle { font-size: 0.82rem !important; margin: 0 !important; opacity: 0.9; }

  /* ── TYPOGRAPHY — tight, professional ───────────────────── */
  h1 { font-size: 1.25rem !important; margin: 6px 0 3px !important; }
  h2 { font-size: 1.1rem !important;  margin: 7px 0 3px !important; }
  h3 { font-size: 0.97rem !important; margin: 5px 0 2px !important; }
  h4, h5 { font-size: 0.88rem !important; margin: 4px 0 2px !important; }
  p  { margin: 0 0 4px 0 !important; }
  ul, ol { padding-left: 16px !important; margin: 1px 0 4px !important; }
  li { margin-bottom: 1px !important; }

  /* Headings stay with next content, never orphaned */
  h1, h2, h3, h4, h5, .section-title, .lesson-title {
    break-after: avoid; page-break-after: avoid;
  }
  p, li { orphans: 3; widows: 3; }

  /* ── SECTION BOXES — flow freely across pages ────────────── */
  /* CRITICAL: screen CSS has break-inside:avoid on .section-box / .section-card
     which makes the browser bump large sections to the next page → huge white gap.
     Must explicitly override to auto so content flows naturally. */
  .section-box, .section-card, .learn-section {
    padding: 7px 11px !important;
    margin-bottom: 5px !important;
    border-radius: 4px !important;
    break-inside: auto !important;
    page-break-inside: auto !important;
  }
  .section-title {
    font-size: 0.88rem !important;
    margin: 0 0 5px 0 !important;
    break-after: avoid;
  }

  /* ── COLOURED SECTIONS ──────────────────────────────────── */
  .learning-goal  { padding: 7px 11px !important; margin-bottom: 5px !important; }
  .success-criteria { padding: 7px 11px !important; margin-bottom: 5px !important; }
  .success-criteria li { font-size: 0.85rem !important; padding: 1px 0 1px 20px !important; }
  .warm-up, .try-it { padding: 7px 11px !important; margin-bottom: 5px !important; }
  .key-idea { padding: 7px 11px !important; margin: 4px 0 5px !important; }
  .design-challenge, .math-journal { padding: 7px 11px !important; margin-bottom: 5px !important; }
  .example-box, .worked-example { padding: 6px 10px !important; margin: 3px 0 !important; }
  .worked-example__label { font-size: 0.78rem !important; margin-bottom: 3px !important; }

  /* ── CALLOUTS — small, keep together ───────────────────── */
  .callout, .callout-tip, .callout-warning,
  .math-tip, .try-this, .did-you-know,
  .callout__icon, .callout-icon { break-inside: avoid; page-break-inside: avoid; }
  .callout, .callout-tip, .callout-warning,
  .math-tip, .try-this, .did-you-know {
    padding: 5px 9px !important;
    margin: 3px 0 !important;
    gap: 8px !important;
    border-radius: 3px !important;
  }
  .callout-icon, .callout__icon { font-size: 1rem !important; }
  .callout-text, .callout__text { font-size: 0.85rem !important; }
  .callout-label, .callout__label { font-size: 0.82rem !important; }

  /* ── PRACTICE — most important section ─────────────────── */
  .practice-section {
    padding: 7px 11px !important;
    margin-bottom: 5px !important;
    break-inside: auto; page-break-inside: auto; /* allow multi-page */
  }
  .practice-section .section-title { border-bottom: 1px solid #bae6fd !important; padding-bottom: 4px !important; }
  .practice-level { margin: 5px 0 !important; break-inside: auto; }
  .badge, .level-badge {
    font-size: 0.68rem !important;
    padding: 2px 8px !important;
    margin-bottom: 4px !important;
  }
  /* Individual questions stay together — they're atomic */
  .question {
    padding: 3px 0 !important;
    gap: 6px !important;
    break-inside: avoid; page-break-inside: avoid;
  }
  .question__number {
    min-width: 20px !important; height: 20px !important; font-size: 0.7rem !important;
  }
  .question__body { font-size: 0.9rem !important; padding-top: 1px !important; }
  /* question-set flows freely — individual .question keeps break-inside: avoid */
  .question-set {
    margin-bottom: 4px !important;
    break-inside: auto !important; page-break-inside: auto !important;
  }
  /* Level badge header glues to first question below it */
  .question-set__label { break-after: avoid; page-break-after: avoid; margin-bottom: 3px !important; }
  /* Also cover .practice-block (sci/lang variant class) */
  .practice-block {
    padding: 7px 11px !important;
    margin-bottom: 5px !important;
    break-inside: auto; page-break-inside: auto;
  }

  /* ── CPA CARDS ──────────────────────────────────────────── */
  .cpa-row { grid-template-columns: repeat(3,1fr) !important; gap: 5px !important; margin: 5px 0 !important; }
  .concrete-model, .pictorial-model, .abstract-model { padding: 7px !important; }
  .cpa-label { font-size: 0.68rem !important; padding: 1px 6px !important; margin-bottom: 5px !important; }
  .cpa-content { font-size: 0.85rem !important; }

  /* ── STEP FLOW ──────────────────────────────────────────── */
  .step-flow { gap: 4px !important; margin: 5px 0 !important; }
  .step-flow__step { padding: 7px 10px !important; min-width: 90px !important; }
  .step-flow__step-text { font-size: 0.8rem !important; }
  .step-flow__arrow { font-size: 1rem !important; padding-top: 6px !important; }

  /* ── SVGs — keep each diagram together ─────────────────── */
  .svg-container, .svg-diagram, .svg-center,
  .svg-figure, .diagram-container {
    break-inside: avoid; page-break-inside: avoid;
    padding: 6px !important; margin: 4px 0 !important;
  }
  img, svg { max-width: 100% !important; height: auto !important; }

  /* ── TABLES ─────────────────────────────────────────────── */
  table { display: table !important; width: 100% !important; overflow: visible !important; font-size: 0.85rem !important; }
  th, td { padding: 4px 7px !important; }
  tr  { break-inside: avoid; page-break-inside: avoid; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }

  /* ── CODE BLOCKS ────────────────────────────────────────── */
  .code-block, .pseudo-block {
    white-space: pre-wrap !important; word-break: break-word !important;
    overflow: visible !important; font-size: 7.5pt !important;
    padding: 7px 10px !important; line-height: 1.4 !important;
  }

  /* ── SPEECH BUBBLES ─────────────────────────────────────── */
  .speech-bubble-wrapper { break-inside: avoid; page-break-inside: avoid; gap: 8px !important; margin: 4px 0 !important; }
  .speech-bubble { padding: 8px 12px !important; }

  /* ── SELF-ASSESSMENT & PEER FEEDBACK ────────────────────── */
  .self-assessment, .peer-feedback { break-inside: avoid; page-break-inside: avoid; padding: 7px 11px !important; margin-bottom: 5px !important; }

  /* ── EXIT TICKET / SEL ──────────────────────────────────── */
  .exit-ticket, .sel-card { break-inside: avoid; page-break-inside: avoid; padding: 7px 11px !important; margin: 4px 0 !important; }

  /* ── WRITING LINES — crisp in print, sized to NEVER overflow ── */
  /* Keep prompt + its lines together on the same page */
  .prompt {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  /* Smaller line blocks in print — enough to write, not enough to push a new page */
  .prompt::after,
  .warm-up .prompt::after,
  .try-it .prompt::after, .try-this .prompt::after,
  .math-journal .prompt::after, .math-journal blockquote::after, .journal-prompt::after,
  .design-challenge .prompt::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    display: block !important;
  }
  .math-journal .prompt::after,
  .math-journal blockquote::after,
  .journal-prompt::after { height: 84px !important; }   /* 3 lines — fits cleanly */
  .design-challenge .prompt::after { height: 56px !important; } /* 2 lines */
  .prompt::after { height: 56px !important; }           /* 2 lines for other prompts */

  /* Questions — add writing lines ONLY in print (would destroy screen layout otherwise) */
  .question {
    flex-wrap: wrap !important;   /* lets ::after drop to its own row */
    break-inside: avoid; page-break-inside: avoid;
  }
  .question::after {
    content: '' !important;
    display: block !important;
    width: 100% !important;
    height: 56px !important;      /* 2 writing lines per question — won't overflow */
    margin-top: 4px !important;
    background: repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 27px,
      rgba(14, 165, 233, 0.3) 27px,
      rgba(14, 165, 233, 0.3) 28px
    ) !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ── DIVIDERS & FOOTER ──────────────────────────────────── */
  /* Lesson divider separates lessons in scroll view — useless when printing 1 lesson */
  .lesson-divider { display: none !important; }
  .page-divider   { margin: 4px 0 !important; }
  .unit-footer    { font-size: 7pt !important; margin-top: 6px !important; padding: 4px 0 !important; }
  /* Kill trailing margin on last element — prevents phantom blank last page */
  .lesson-page-wrap.is-printing > *:last-child {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  /* ── LINKS ──────────────────────────────────────────────── */
  a { color: var(--unit-accent) !important; text-decoration: none !important; }
  a[href]::after { content: none !important; }

  /* ── INDEX ──────────────────────────────────────────────── */
  .unit-grid { grid-template-columns: 1fr 1fr !important; }
  .unit-card { break-inside: avoid; page-break-inside: avoid; padding: 12px !important; }
}

/* ═══════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════ */

/* --- Tablet (≤ 900px) --- */
@media (max-width: 900px) {
  body { font-size: 15px; padding: 0 14px; }
  .cover-unit-num { font-size: 4rem; }
  .cover-title, .unit-title { font-size: 2rem; }
  .cover-banner, .unit-header { padding: 60px 28px; }
  .lesson-header { padding: 28px 28px; }
  .lesson-header h2, .lesson-title { font-size: 1.75rem; }
  .section-box { padding: 20px 22px; }
  .index-hero { padding: 48px 28px; }
  .index-hero h1 { font-size: 2.4rem; }
}

/* --- Mobile (≤ 640px) --- */
@media (max-width: 640px) {
  body { font-size: 15px; padding: 0 10px; }

  /* Cover */
  .cover-banner, .unit-header { padding: 36px 16px; border-radius: 8px; margin-top: 10px; }
  .cover-unit-num { font-size: 2.8rem; }
  .cover-title, .unit-title { font-size: 1.5rem; margin: 10px 0 14px; }
  .cover-subtitle { font-size: 0.9rem; letter-spacing: 1px; }

  /* Index */
  .index-hero { padding: 32px 14px; border-radius: 10px; margin: 10px 0 24px; }
  .index-hero h1 { font-size: 1.8rem; }
  .index-hero .tagline { font-size: 0.95rem; }
  .unit-grid { grid-template-columns: 1fr; }

  /* Nav bar */
  .unit-nav { padding: 8px 10px; flex-wrap: wrap; gap: 4px; border-radius: 0 0 8px 8px; }
  .unit-nav .nav-title { font-size: 0.78rem; width: 100%; text-align: center; order: -1; }
  .unit-nav a { padding: 4px 8px; font-size: 0.78rem; }

  /* Lesson header */
  .lesson-header { padding: 18px 14px; border-radius: 8px; margin: 18px 0 16px; }
  .lesson-header h2, .lesson-title { font-size: 1.35rem; }
  .lesson-subtitle { font-size: 0.88rem; }

  /* Section boxes */
  .section-box { padding: 14px 12px; border-radius: 8px; margin-bottom: 14px; }
  .section-title { font-size: 1rem; }

  /* Cards */
  .cover-desc-card, .toc-card { padding: 16px 14px; border-radius: 8px; }

  /* TOC items */
  .toc-item { padding: 8px 10px; }
  .toc-num { width: 28px; height: 28px; font-size: 0.8rem; margin-right: 10px; }
  .toc-code { display: none; }

  /* CPA row → single column */
  .cpa-row { grid-template-columns: 1fr; }

  /* Two-column → single column */
  .two-col { grid-template-columns: 1fr; }

  /* Step flow → vertical */
  .step-flow { flex-direction: column; align-items: stretch; }
  .step-flow__arrow { display: none; }
  .step-flow__step { min-width: unset; }

  /* Callouts */
  .callout, .callout-tip, .callout-warning,
  .math-tip, .try-this, .did-you-know { padding: 10px 12px; gap: 8px; }
  .callout-icon, .callout__icon { font-size: 1.1rem; }

  /* Glossary → single column */
  .glossary-grid { grid-template-columns: 1fr; }

  /* Coming-up-next → stack */
  .coming-up-next { flex-direction: column; gap: 6px; padding: 14px; }
  .coming-up-next__arrow { display: none; }

  /* Tables: horizontal scroll */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }

  /* Code blocks */
  .code-block, .pseudo-block { font-size: 0.78rem; padding: 12px; }

  /* Practice */
  .question { gap: 8px; }
  .question__number { min-width: 28px; height: 28px; font-size: 0.78rem; }
}
