Details describe the mechanism of respiration for MBBS students

Reading File
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
I now have comprehensive information to write a detailed, well-organized answer on the mechanism of respiration for MBBS students. Let me compile it all.

Mechanism of Respiration

For MBBS Students - Comprehensive Coverage

1. Definition and Overview

Respiration refers to the series of processes by which oxygen (O₂) is supplied to tissues and carbon dioxide (CO₂) is eliminated. It has two major components:
  • External (Pulmonary) Respiration - gas exchange between the atmosphere and the blood at the alveoli
  • Internal (Tissue) Respiration - gas exchange between blood and tissue cells at the mitochondrial level

2. Anatomy of the Respiratory System

The respiratory system is divided into two functional zones:

Conducting Zone (Anatomical Dead Space)

Trachea → Primary bronchi → Secondary/Tertiary bronchi → Bronchioles → Terminal bronchioles
  • This zone does not participate in gas exchange
  • It filters, warms, and humidifies incoming air
  • Volume = ~150 mL (anatomical dead space)

Respiratory Zone (Gas Exchange Zone)

Respiratory bronchioles → Alveolar ducts → Alveolar sacs → Alveoli
  • Each lung contains ~300 million alveoli, each ~200 μm in diameter
  • Total alveolar surface area = ~70 m² (size of a tennis court)
  • Lined by:
    • Type I pneumocytes - thin, flat cells ideal for gas diffusion (~95% of surface)
    • Type II pneumocytes - secrete surfactant to reduce surface tension; also regenerate Type I cells
    • Alveolar macrophages - phagocytose dust and debris (the "scavengers" of the lung)

3. Mechanics of Breathing (Ventilation)

Breathing depends on pressure gradients generated by changes in lung volume, governed by Boyle's Law (P₁V₁ = P₂V₂ - at constant temperature, pressure and volume are inversely related).

Key Pressures

PressureLocationNormal Value
Atmospheric pressure (Patm)Outside760 mmHg
Alveolar pressure (Palv)Inside alveoli760 mmHg at rest
Intrapleural pressure (Pip)Pleural space~756 mmHg (-4 mmHg)
Transpulmonary pressurePalv - Pip+4 mmHg
The intrapleural pressure is always subatmospheric (negative). This negative pressure keeps the lungs inflated against their natural tendency to recoil inward.

A. INSPIRATION (Active Process)

Step-by-step:
  1. Inspiratory muscles contract:
    • Diaphragm (primary muscle) - contracts and descends ~1.5 cm (during quiet breathing), increasing the vertical dimension of the thoracic cavity
    • External intercostal muscles - contract, elevating the ribs ("bucket handle" movement) and sternum ("pump handle" movement), increasing AP and transverse diameters
    • During forced/deep inspiration, accessory muscles are recruited: sternocleidomastoid (elevates sternum), scalenes (elevate first 2 ribs), pectoralis minor
  2. Thoracic volume increases → intrathoracic and intrapleural pressure falls further (from -4 to ~-8 mmHg)
  3. Lungs expand (held to chest wall by negative intrapleural pressure) → lung volume increases
  4. Alveolar pressure falls below atmospheric (from 760 to ~758 mmHg)
  5. Air flows in from atmosphere into alveoli (down the pressure gradient) until Palv = Patm
Summary: Muscle contraction → ↑ thoracic volume → ↓ Pip → ↑ lung volume → ↓ Palv < Patm → air flows IN

B. EXPIRATION (Passive at Rest)

  1. Inspiratory muscles relax - no active muscle contraction required during quiet breathing
  2. Elastic recoil of the lungs (due to elastic fibers and surface tension) drives the lungs back to their resting position
  3. Thoracic volume decreases → intrapleural pressure rises back to -4 mmHg
  4. Alveolar pressure rises above atmospheric (760 → ~762 mmHg)
  5. Air flows out from alveoli to atmosphere
Forced expiration (during exercise, coughing, sneezing) is active and involves:
  • Internal intercostal muscles - depress ribs
  • Abdominal muscles (rectus abdominis, obliques) - increase intraabdominal pressure, force diaphragm upward
Summary: Muscle relaxation + elastic recoil → ↓ thoracic volume → ↑ Pip → ↓ lung volume → ↑ Palv > Patm → air flows OUT

4. Lung Compliance

Compliance = ΔVolume / ΔPressure
Compliance is a measure of how easily the lung distends (stretches).
  • Normal compliance = ~200 mL/cmH₂O
  • Decreased compliance (stiff lungs) - pulmonary fibrosis, pulmonary edema, ARDS (more effort needed to breathe)
  • Increased compliance - emphysema (lung tissue destroyed, elastic recoil lost; lungs overinflate but cannot expel air)

Surface Tension and Surfactant

The alveolar surface tension (air-water interface at the alveolar wall) is the largest contributor to lung recoil. Surfactant, produced by Type II pneumocytes, reduces surface tension by ~5-fold.
  • Composition: Dipalmitoylphosphatidylcholine (DPPC) - the main active component
  • Function: Reduces surface tension, especially at low lung volumes; prevents alveolar collapse (atelectasis)
  • Clinical: Deficiency in premature neonates causes Infant Respiratory Distress Syndrome (IRDS/RDS) - treated with exogenous surfactant

5. Lung Volumes and Capacities

Volume/CapacityDefinitionNormal Value
Tidal Volume (TV)Volume per normal breath~500 mL
Inspiratory Reserve Volume (IRV)Extra volume above TV on max inspiration~3000 mL
Expiratory Reserve Volume (ERV)Extra volume expelled after normal expiration~1200 mL
Residual Volume (RV)Volume remaining after max expiration (can't be expelled)~1200 mL
Inspiratory Capacity (IC)TV + IRV~3500 mL
Functional Residual Capacity (FRC)ERV + RV~2400 mL
Vital Capacity (VC)IRV + TV + ERV (max in + max out)~4700 mL
Total Lung Capacity (TLC)All volumes combined~5900 mL
RV cannot be measured by spirometry - requires gas dilution or body plethysmography
FRC is the resting lung volume where elastic recoil of the lung inward equals the chest wall recoil outward. At FRC, Palv = Patm and there is no airflow.

6. Dead Space and Alveolar Ventilation

  • Minute ventilation (VE) = Tidal volume × Respiratory rate = 500 mL × 14 = 7000 mL/min
  • Anatomical dead space = ~150 mL (conducting airways that don't exchange gas)
  • Physiological dead space = Anatomical dead space + Alveolar dead space (perfused but not ventilated alveoli)
  • Alveolar ventilation (VA) = (TV - Dead space) × Rate = (500 - 150) × 14 = 4900 mL/min
Only alveolar ventilation participates in gas exchange.

Bohr Equation (Dead Space Calculation)

VD/VT = (PaCO₂ - PECO₂) / PaCO₂

Alveolar Ventilation Equation

PA CO₂ = (VCO₂ × 863) / VA
This shows: if alveolar ventilation halves, alveolar PCO₂ doubles. This is the basis of hypercapnia in hypoventilation.

7. Diffusion of Gases (Alveolar-Capillary Exchange)

Gas exchange at the alveolus occurs by simple diffusion governed by Fick's Law:
Rate of diffusion ∝ (Surface area × Partial pressure gradient × Solubility) / (Thickness × √Molecular weight)
Key determinants:
  • Partial pressure gradient (driving force): O₂ moves from alveolus (PAO₂ ~100 mmHg) → capillary blood (PaO₂ ~40 mmHg); CO₂ moves from blood (~46 mmHg) → alveolus (~40 mmHg)
  • Surface area - ~70 m² for both lungs
  • Membrane thickness - ~0.5 μm (alveolar epithelium + basement membranes + capillary endothelium)
  • Solubility - CO₂ is 20× more soluble than O₂, hence CO₂ diffuses much more readily despite a smaller gradient
Alveolar-arterial (A-a) gradient: Normal PAO₂ - PaO₂ = ~5-15 mmHg. A widened A-a gradient suggests diffusion impairment, V/Q mismatch, or shunt.

8. Transport of Gases in Blood

Oxygen Transport

FormAmount
Dissolved in plasma~1.5% (0.3 mL/dL)
Bound to hemoglobin (oxyhemoglobin)~98.5% (20 mL/dL)
Each hemoglobin molecule carries 4 O₂ molecules (cooperative binding). The O₂-Hemoglobin Dissociation Curve (sigmoid shape) describes the relationship between PO₂ and Hb saturation.
Shifts of the curve:
  • Right shift (reduced O₂ affinity, easier O₂ unloading at tissues): ↑ CO₂, ↑ H⁺ (Bohr effect), ↑ temperature, ↑ 2,3-DPG
  • Left shift (increased O₂ affinity, reduced O₂ delivery): ↓ CO₂, ↓ H⁺, ↓ temperature, ↓ 2,3-DPG, fetal Hb (HbF)

Carbon Dioxide Transport

FormAmount
Dissolved in plasma~7%
As bicarbonate (HCO₃⁻)~70%
Bound to Hb as carbaminohemoglobin~23%
The most important form is bicarbonate (HCO₃⁻), formed inside RBCs via carbonic anhydrase:
CO₂ + H₂O ⇌ H₂CO₃ ⇌ H⁺ + HCO₃⁻
HCO₃⁻ exchanges with Cl⁻ across the RBC membrane (Chloride shift / Hamburger phenomenon). At the lungs, this reaction reverses and CO₂ is expelled.

9. Ventilation-Perfusion (V/Q) Matching

For optimal gas exchange, alveolar ventilation (V) must be matched with pulmonary capillary perfusion (Q).
  • Normal V/Q ratio = ~0.8 (VA ~4.2 L/min, Q ~5 L/min)
  • V/Q = 0 (Shunt): Alveolus perfused but not ventilated (e.g., collapsed alveolus, pneumonia) - causes hypoxemia not correctable by supplemental O₂
  • V/Q = ∞ (Dead space): Alveolus ventilated but not perfused (e.g., pulmonary embolism)
  • V/Q mismatch is the most common cause of hypoxemia in clinical practice
In the upright lung, V/Q is highest at the apex (least gravity-dependent, less blood flow relative to ventilation) and lowest at the base (greatest perfusion but relatively less ventilation).

10. Control of Respiration

Breathing is controlled by neural centers in the brainstem:

Central Respiratory Centers

CenterLocationFunction
Pre-Bötzinger complexMedullaPrimary rhythm generator - "pacemaker"
Dorsal Respiratory Group (DRG)MedullaInspiratory neurons
Ventral Respiratory Group (VRG)MedullaBoth inspiration and forced expiration
Pneumotaxic centerUpper ponsLimits inspiration; adjusts rate and depth
Apneustic centerLower ponsPromotes prolonged inspiration

Chemoreceptors (Chemical Control)

Central Chemoreceptors (medullary surface):
  • Respond to CO₂ (via changes in CSF H⁺ concentration)
  • Most important in minute-to-minute regulation
  • Equation: CO₂ + H₂O → H₂CO₃ → H⁺ + HCO₃⁻ (CO₂ crosses blood-brain barrier freely; H⁺ does not)
  • ↑ PCO₂ → ↑ CSF [H⁺] → ↑ ventilation
Peripheral Chemoreceptors (carotid and aortic bodies):
  • Carotid bodies (cranial nerve IX) and aortic bodies (cranial nerve X)
  • Respond primarily to: ↓ PaO₂ (<60 mmHg), also ↑ PaCO₂, ↓ pH
  • Important during hypoxemia (e.g., high altitude, chronic lung disease)
  • In COPD with CO₂ retention, the hypoxic drive via peripheral chemoreceptors becomes the primary driver of breathing (basis of the "O₂ toxicity" concern)

Other Reflexes

  • Hering-Breuer reflex: Pulmonary stretch receptors (in airway smooth muscle) activated on inflation → inhibit further inspiration (via vagus nerve) - prevents overinflation
  • Irritant receptors: Triggered by noxious stimuli → bronchoconstriction, cough, hyperpnea
  • J-receptors (juxtacapillary): In alveolar walls, stimulated by pulmonary congestion/edema → rapid shallow breathing, dyspnea
  • Exercise: Increases ventilation via joint/muscle proprioceptors, CO₂ production, and lactic acidosis

11. Summary Flow Chart

Inspiratory muscle contraction (diaphragm + external intercostals)
        ↓
Thoracic cavity enlarges
        ↓
Intrapleural pressure falls (more negative)
        ↓
Lung expands → Alveolar pressure falls below atmospheric
        ↓
Air flows in (inspiration)
        ↓
O₂ diffuses across alveolar-capillary membrane into blood
CO₂ diffuses from blood into alveoli
        ↓
Inspiratory muscles relax → Elastic recoil expels air (expiration)
        ↓
CO₂ expelled; O₂-loaded blood returns to systemic circulation

12. Clinical Correlations (High-Yield for MBBS)

ConditionDefectMechanism
PneumothoraxAir in pleural spaceIntrapleural pressure = atmospheric → lung collapses
Emphysema↓ Elastic recoil↑ Compliance; air trapping; ↑ RV
Pulmonary fibrosis↓ Compliance↑ Work of breathing; ↓ TLC
RDS (neonates)↓ SurfactantAlveolar collapse; ↑ surface tension
Pulmonary embolismV/Q mismatch (dead space)↑ Physiological dead space; hypoxemia
COPDAirflow obstructionDynamic airway compression during expiration; auto-PEEP

Sources: Costanzo Physiology 7th Edition; Medical Physiology (Boron & Boulpaep); Tintinalli's Emergency Medicine; Murray & Nadel's Textbook of Respiratory Medicine

Make a presentation on respiratory anatomy, mechanics, and physiology for exams

Reading File
Reading File
Reading File
Reading File
Running Command

mkdir -p /home/daytona/workspace/respiratory-pptx && ls /home/daytona/workspace/respiratory-pptx

Writing File

~/respiratory-pptx/build.js

"use strict";
const pptxgen = require("pptxgenjs");

const pres = new pptxgen();
pres.layout = "LAYOUT_16x9";
pres.title = "Respiratory Anatomy, Mechanics & Physiology";
pres.author = "Orris Medical Education";

// ─── COLOUR PALETTE ───────────────────────────────────────────────────────────
const DEEP_TEAL   = "0B4F6C";   // dominant dark
const MID_TEAL    = "1A7FA0";   // secondary
const LIGHT_TEAL  = "D6EEF7";   // panel bg / accent
const WHITE       = "FFFFFF";
const GOLD        = "E8A020";   // accent highlight
const DARK_TEXT   = "1A2E35";
const MUTED       = "5C7D8A";
const PALE_BG     = "EEF7FC";
const RED_ACCENT  = "C0392B";
const GREEN_ACCENT= "1E7E48";

// ─── HELPER FUNCTIONS ─────────────────────────────────────────────────────────

// Draws a top header bar with title and subtitle
function addHeader(slide, title, subtitle = "") {
  // Dark teal header bar
  slide.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 0, w: 10, h: 1.1,
    fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL }
  });
  // Gold left accent stripe
  slide.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 0, w: 0.08, h: 1.1,
    fill: { color: GOLD }, line: { color: GOLD }
  });
  slide.addText(title, {
    x: 0.2, y: 0.1, w: 9.6, h: 0.55,
    fontSize: 22, bold: true, color: WHITE, fontFace: "Calibri", margin: 0
  });
  if (subtitle) {
    slide.addText(subtitle, {
      x: 0.2, y: 0.65, w: 9.6, h: 0.35,
      fontSize: 13, color: GOLD, fontFace: "Calibri", italic: true, margin: 0
    });
  }
  // Bottom border of header
  slide.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 1.1, w: 10, h: 0.04,
    fill: { color: GOLD }, line: { color: GOLD }
  });
}

// Section divider card
function addSectionCard(slide, num, title, sub) {
  slide.background = { color: DEEP_TEAL };
  // Decorative circle
  slide.addShape(pres.shapes.OVAL, {
    x: 0.4, y: 0.9, w: 2.0, h: 2.0,
    fill: { color: MID_TEAL, transparency: 60 }, line: { color: GOLD, pt: 2 }
  });
  slide.addText(num, {
    x: 0.4, y: 0.9, w: 2.0, h: 2.0,
    fontSize: 48, bold: true, color: GOLD, align: "center", valign: "middle", fontFace: "Calibri"
  });
  slide.addText(title, {
    x: 2.8, y: 1.4, w: 7.0, h: 1.2,
    fontSize: 34, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle"
  });
  slide.addText(sub, {
    x: 2.8, y: 2.65, w: 7.0, h: 0.7,
    fontSize: 16, color: LIGHT_TEAL, fontFace: "Calibri", italic: true
  });
  slide.addShape(pres.shapes.RECTANGLE, {
    x: 2.8, y: 2.55, w: 5.0, h: 0.06,
    fill: { color: GOLD }, line: { color: GOLD }
  });
}

// Small labelled info box
function infoBox(slide, x, y, w, h, heading, lines, headingColor = DEEP_TEAL) {
  slide.addShape(pres.shapes.RECTANGLE, {
    x, y, w, h,
    fill: { color: WHITE },
    line: { color: headingColor, pt: 1.5 },
    shadow: { type: "outer", color: "000000", blur: 4, offset: 2, angle: 135, opacity: 0.10 }
  });
  // Heading bar
  slide.addShape(pres.shapes.RECTANGLE, {
    x, y, w, h: 0.32,
    fill: { color: headingColor }, line: { color: headingColor }
  });
  slide.addText(heading, {
    x: x + 0.08, y, w: w - 0.1, h: 0.32,
    fontSize: 11, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0
  });
  const bulletItems = lines.map((l, i) => ({
    text: l, options: { bullet: true, breakLine: i < lines.length - 1, fontSize: 10.5, color: DARK_TEXT, fontFace: "Calibri" }
  }));
  slide.addText(bulletItems, {
    x: x + 0.08, y: y + 0.38, w: w - 0.16, h: h - 0.44,
    fontFace: "Calibri", valign: "top"
  });
}

// Key-value row table (two columns)
function kvTable(slide, x, y, w, rows, headerRow = null) {
  const tableData = [];
  if (headerRow) {
    tableData.push([
      { text: headerRow[0], options: { bold: true, color: WHITE, fill: { color: DEEP_TEAL }, fontSize: 11 } },
      { text: headerRow[1], options: { bold: true, color: WHITE, fill: { color: DEEP_TEAL }, fontSize: 11 } }
    ]);
  }
  rows.forEach(([k, v], i) => {
    const bg = i % 2 === 0 ? LIGHT_TEAL : WHITE;
    tableData.push([
      { text: k, options: { bold: true, color: DARK_TEXT, fill: { color: bg }, fontSize: 10.5 } },
      { text: v, options: { color: DARK_TEXT, fill: { color: bg }, fontSize: 10.5 } }
    ]);
  });
  slide.addTable(tableData, {
    x, y, w,
    border: { pt: 0.5, color: "C8DCE5" },
    rowH: 0.31
  });
}

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 1 — TITLE SLIDE
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: DEEP_TEAL };

  // Large decorative circle background
  s.addShape(pres.shapes.OVAL, {
    x: 6.5, y: -1.5, w: 5.5, h: 5.5,
    fill: { color: MID_TEAL, transparency: 70 }, line: { color: MID_TEAL }
  });
  s.addShape(pres.shapes.OVAL, {
    x: -1.5, y: 2.5, w: 3.8, h: 3.8,
    fill: { color: MID_TEAL, transparency: 75 }, line: { color: MID_TEAL }
  });

  // Gold accent bar left
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0, y: 0, w: 0.12, h: 5.625,
    fill: { color: GOLD }, line: { color: GOLD }
  });

  s.addText("Respiratory System", {
    x: 0.4, y: 0.7, w: 9.4, h: 0.75,
    fontSize: 40, bold: true, color: WHITE, fontFace: "Calibri", charSpacing: 1
  });
  s.addText("Anatomy · Mechanics · Physiology", {
    x: 0.4, y: 1.45, w: 9.4, h: 0.55,
    fontSize: 22, color: GOLD, fontFace: "Calibri", italic: true
  });
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.4, y: 2.1, w: 4.5, h: 0.06,
    fill: { color: GOLD }, line: { color: GOLD }
  });
  s.addText("A complete guide for MBBS examination preparation", {
    x: 0.4, y: 2.25, w: 9.4, h: 0.45,
    fontSize: 14, color: LIGHT_TEAL, fontFace: "Calibri"
  });

  // Topic pills
  const topics = ["Anatomy", "Lung Volumes", "Mechanics", "Gas Exchange", "Gas Transport", "Ventilation Control"];
  topics.forEach((t, i) => {
    const col = i % 3;
    const row = Math.floor(i / 3);
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, {
      x: 0.4 + col * 3.1, y: 3.2 + row * 0.62, w: 2.9, h: 0.48,
      fill: { color: MID_TEAL, transparency: 40 }, line: { color: GOLD, pt: 1 }, rectRadius: 0.1
    });
    s.addText(t, {
      x: 0.4 + col * 3.1, y: 3.2 + row * 0.62, w: 2.9, h: 0.48,
      fontSize: 13, color: WHITE, fontFace: "Calibri", align: "center", valign: "middle"
    });
  });

  s.addText("Sources: Costanzo Physiology 7e · Boron & Boulpaep Medical Physiology · Murray & Nadel · Tintinalli", {
    x: 0.4, y: 5.25, w: 9.4, h: 0.3,
    fontSize: 8.5, color: MUTED, fontFace: "Calibri"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 2 — SECTION DIVIDER: Anatomy
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  addSectionCard(s, "01", "Respiratory Anatomy", "Conducting Zone · Respiratory Zone · Alveoli · Blood Supply");
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 3 — CONDUCTING VS RESPIRATORY ZONE
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Two Functional Zones of the Lung", "Conducting Zone (Dead Space) vs. Respiratory Zone (Gas Exchange)");

  infoBox(s, 0.25, 1.3, 4.5, 3.9,
    "Conducting Zone (Anatomical Dead Space)",
    [
      "Trachea → Primary bronchi → Secondary/Tertiary bronchi",
      "Bronchioles → Terminal bronchioles",
      "NO gas exchange occurs here",
      "Functions: filters, warms, humidifies air",
      "Volume ≈ 150 mL (dead space)",
      "Lined with ciliated pseudostratified epithelium",
      "Cilia beat upward (mucociliary escalator)"
    ],
    DEEP_TEAL
  );

  infoBox(s, 5.25, 1.3, 4.5, 3.9,
    "Respiratory Zone (Gas Exchange Zone)",
    [
      "Respiratory bronchioles → Alveolar ducts",
      "Alveolar sacs → Alveoli",
      "~300 million alveoli per lung",
      "Each alveolus ≈ 200 μm diameter",
      "Total surface area ≈ 70 m²",
      "Wall thickness ≈ 0.5 μm (ideal for diffusion)",
      "Type I & Type II pneumocytes line the wall"
    ],
    MID_TEAL
  );

  // Arrow between boxes
  s.addShape(pres.shapes.RECTANGLE, {
    x: 4.78, y: 3.0, w: 0.45, h: 0.08,
    fill: { color: GOLD }, line: { color: GOLD }
  });
  s.addText("→", { x: 4.72, y: 2.8, w: 0.55, h: 0.45, fontSize: 20, color: GOLD, align: "center" });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 4 — ALVEOLAR WALL: CELL TYPES
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Alveolar Cell Types", "Structure and function of the alveolar wall");

  // Three cell-type boxes
  const cells = [
    { title: "Type I Pneumocyte", color: DEEP_TEAL, lines: [
      "Large, flat squamous cells",
      "Cover ~95% of alveolar surface",
      "Thin — ideal for rapid gas diffusion",
      "Cannot divide (no regeneration)",
      "Forms the blood-gas barrier"
    ]},
    { title: "Type II Pneumocyte", color: MID_TEAL, lines: [
      "Cuboidal cells, ~5% of surface",
      "Produce pulmonary SURFACTANT",
      "Surfactant = reduces surface tension",
      "Main component: DPPC",
      "Can regenerate both Type I and II cells"
    ]},
    { title: "Alveolar Macrophage", color: GOLD, lines: [
      "Phagocytic — 'dustcells'",
      "Engulf inhaled particles & pathogens",
      "No cilia in alveoli — macrophages take over",
      "Migrate to bronchioles → mucociliary clearance",
      "Key: 1st line immune defence in lungs"
    ]}
  ];

  cells.forEach((c, i) => {
    const x = 0.25 + i * 3.2;
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, {
      x, y: 1.3, w: 3.0, h: 3.9,
      fill: { color: WHITE }, line: { color: c.color, pt: 2 }, rectRadius: 0.12,
      shadow: { type: "outer", color: "000000", blur: 5, offset: 2, angle: 135, opacity: 0.12 }
    });
    s.addShape(pres.shapes.ROUNDED_RECTANGLE, {
      x, y: 1.3, w: 3.0, h: 0.42,
      fill: { color: c.color }, line: { color: c.color }, rectRadius: 0.12
    });
    s.addShape(pres.shapes.RECTANGLE, {
      x, y: 1.58, w: 3.0, h: 0.14,
      fill: { color: c.color }, line: { color: c.color }
    });
    s.addText(c.title, {
      x: x + 0.1, y: 1.3, w: 2.8, h: 0.42,
      fontSize: 12, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0
    });
    const bulletItems = c.lines.map((l, j) => ({
      text: l, options: { bullet: true, breakLine: j < c.lines.length - 1, fontSize: 11, color: DARK_TEXT, fontFace: "Calibri" }
    }));
    s.addText(bulletItems, { x: x + 0.1, y: 1.82, w: 2.8, h: 3.2, valign: "top" });
  });

  // Key note at bottom
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.25, y: 5.12, w: 9.5, h: 0.38,
    fill: { color: LIGHT_TEAL }, line: { color: MID_TEAL }
  });
  s.addText("★  EXAM TIP:  Type II pneumocytes → surfactant production. Deficiency in premature neonates → RDS (Infant Respiratory Distress Syndrome)", {
    x: 0.35, y: 5.12, w: 9.3, h: 0.38,
    fontSize: 10.5, color: DEEP_TEAL, fontFace: "Calibri", bold: false, valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 5 — SECTION DIVIDER: Lung Volumes
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  addSectionCard(s, "02", "Lung Volumes & Capacities", "Spirometry · FRC · Dead Space · Alveolar Ventilation");
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 6 — LUNG VOLUMES TABLE
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Lung Volumes & Capacities", "Measured by spirometry (RV cannot be measured by spirometry alone)");

  // Volumes
  infoBox(s, 0.25, 1.25, 4.5, 1.95, "Four Basic Volumes", [
    "Tidal Volume (TV)  =  ~500 mL",
    "Inspiratory Reserve (IRV)  =  ~3000 mL",
    "Expiratory Reserve (ERV)  =  ~1200 mL",
    "Residual Volume (RV)  =  ~1200 mL  ← cannot spirometry"
  ], DEEP_TEAL);

  // Capacities
  infoBox(s, 0.25, 3.3, 4.5, 2.0, "Four Capacities (Sum of volumes)", [
    "Total Lung Capacity (TLC)  =  ~5900 mL  (all four)",
    "Vital Capacity (VC)  =  ~4700 mL  (TV+IRV+ERV)",
    "Inspiratory Capacity (IC)  =  ~3500 mL  (TV+IRV)",
    "Functional Residual Capacity (FRC)  =  ~2400 mL  (ERV+RV)"
  ], MID_TEAL);

  // Spirogram diagram (drawn with shapes)
  // Base line
  s.addShape(pres.shapes.RECTANGLE, { x: 5.2, y: 4.7, w: 4.55, h: 0.04, fill: { color: MUTED }, line: { color: MUTED } });

  // Labels on spirogram panel
  s.addShape(pres.shapes.RECTANGLE, { x: 5.1, y: 1.25, w: 4.7, h: 3.95, fill: { color: WHITE }, line: { color: MID_TEAL, pt: 1.5 } });
  s.addShape(pres.shapes.RECTANGLE, { x: 5.1, y: 1.25, w: 4.7, h: 0.32, fill: { color: MID_TEAL }, line: { color: MID_TEAL } });
  s.addText("Spirogram — Lung Volume Diagram", { x: 5.18, y: 1.25, w: 4.55, h: 0.32, fontSize: 10.5, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0 });

  // Volume bars (vertical position guide — illustrative)
  const barX = 5.35;
  const baseY = 4.62;
  const scale = 0.00052; // 1 mL = this many inches

  const vols = [
    { label: "RV", mL: 1200, color: RED_ACCENT },
    { label: "ERV", mL: 1200, color: GOLD },
    { label: "TV", mL: 500, color: MID_TEAL },
    { label: "IRV", mL: 3000, color: DEEP_TEAL },
  ];

  let cumY = baseY;
  vols.forEach(v => {
    const h = v.mL * scale;
    cumY -= h;
    s.addShape(pres.shapes.RECTANGLE, {
      x: barX, y: cumY, w: 1.5, h: h - 0.03,
      fill: { color: v.color, transparency: 20 }, line: { color: v.color }
    });
    s.addText(`${v.label}\n${v.mL} mL`, {
      x: barX + 1.55, y: cumY, w: 1.2, h: h,
      fontSize: 9.5, color: v.color, bold: true, fontFace: "Calibri", valign: "middle"
    });
  });

  // TLC brace label
  s.addShape(pres.shapes.RECTANGLE, { x: 5.25, y: cumY, w: 0.05, h: baseY - cumY, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("TLC\n5900 mL", { x: 5.26, y: 1.7, w: 0.9, h: 0.6, fontSize: 9, color: DEEP_TEAL, bold: true, fontFace: "Calibri" });

  // FRC brace
  const frcH = (1200 + 1200) * scale;
  s.addShape(pres.shapes.RECTANGLE, { x: 7.08, y: baseY - frcH, w: 0.05, h: frcH, fill: { color: GOLD }, line: { color: GOLD } });
  s.addText("FRC\n2400", { x: 7.15, y: baseY - frcH + 0.1, w: 0.75, h: 0.5, fontSize: 9, color: GOLD, bold: true, fontFace: "Calibri" });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 7 — DEAD SPACE & ALVEOLAR VENTILATION
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Dead Space & Alveolar Ventilation", "Only alveolar ventilation participates in gas exchange");

  infoBox(s, 0.25, 1.25, 4.5, 2.0, "Types of Dead Space", [
    "Anatomical dead space: conducting airways  ≈ 150 mL",
    "Alveolar dead space: ventilated but NOT perfused",
    "Physiological dead space = anatomical + alveolar",
    "Normal: ~150 mL (≈ 30% of tidal volume)"
  ], DEEP_TEAL);

  infoBox(s, 0.25, 3.35, 4.5, 1.95, "Calculations", [
    "Minute ventilation (VE) = TV × RR = 500 × 14 = 7000 mL/min",
    "Alveolar ventilation (VA) = (TV − VD) × RR",
    "= (500 − 150) × 14 = 4900 mL/min",
    "Bohr equation: VD/VT = (PaCO₂ − PECO₂) / PaCO₂"
  ], MID_TEAL);

  // Alveolar ventilation equation box
  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.1, y: 1.25, w: 4.7, h: 2.2,
    fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL },
    shadow: { type: "outer", color: "000000", blur: 6, offset: 2, angle: 135, opacity: 0.15 }
  });
  s.addText("Alveolar Ventilation Equation", {
    x: 5.2, y: 1.3, w: 4.5, h: 0.4,
    fontSize: 13, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle"
  });
  s.addText("PACO₂  =  VCO₂ × 863 / VA", {
    x: 5.2, y: 1.75, w: 4.5, h: 0.55,
    fontSize: 18, bold: true, color: WHITE, fontFace: "Calibri", align: "center"
  });
  s.addText([
    { text: "KEY: ", options: { bold: true, color: GOLD } },
    { text: "If VA halves → PACO₂ doubles (hypoventilation)\nIf VA doubles → PACO₂ halves (hyperventilation)", options: { color: LIGHT_TEAL } }
  ], { x: 5.2, y: 2.35, w: 4.5, h: 1.0, fontSize: 11.5, fontFace: "Calibri" });

  // Clinical box
  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.1, y: 3.55, w: 4.7, h: 1.7,
    fill: { color: LIGHT_TEAL }, line: { color: MID_TEAL }
  });
  s.addText("Clinical Correlations", {
    x: 5.2, y: 3.6, w: 4.5, h: 0.35,
    fontSize: 12, bold: true, color: DEEP_TEAL, fontFace: "Calibri"
  });
  const clinLines = [
    { text: "Pulmonary embolism", options: { bold: true, color: RED_ACCENT } },
    { text: " → ↑ alveolar dead space (V̇/Q̇ = ∞)", options: { color: DARK_TEXT } },
    { text: "\nPneumonia/ARDS", options: { bold: true, color: RED_ACCENT, breakLine: false } },
    { text: " → ↓ alveolar ventilation", options: { color: DARK_TEXT } },
    { text: "\nCOPD", options: { bold: true, color: RED_ACCENT, breakLine: false } },
    { text: " → air trapping → ↑ FRC, ↑ RV", options: { color: DARK_TEXT } }
  ];
  s.addText(clinLines, { x: 5.2, y: 4.0, w: 4.5, h: 1.15, fontSize: 11, fontFace: "Calibri" });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 8 — SECTION DIVIDER: Mechanics
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  addSectionCard(s, "03", "Mechanics of Breathing", "Inspiration · Expiration · Pressures · Boyle's Law");
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 9 — KEY PRESSURES
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Respiratory Pressures", "Understanding pressure gradients that drive breathing");

  kvTable(s, 0.25, 1.28, 5.5,
    [
      ["Atmospheric (Patm)", "760 mmHg — reference pressure"],
      ["Alveolar (Palv) — at rest", "760 mmHg (equal to Patm, no airflow)"],
      ["Alveolar — inspiration", "< 760 mmHg (~ 758) → air flows IN"],
      ["Alveolar — expiration", "> 760 mmHg (~ 762) → air flows OUT"],
      ["Intrapleural (Pip) — resting", "~ 756 mmHg (−4 cmH₂O below Patm)"],
      ["Pip — peak inspiration", "~ 752 mmHg (−8 cmH₂O below Patm)"],
      ["Transpulmonary (Ptp)", "Palv − Pip = +4 mmHg; keeps lungs inflated"],
    ],
    ["Pressure", "Value & Significance"]
  );

  // Key concept box
  s.addShape(pres.shapes.RECTANGLE, {
    x: 5.95, y: 1.28, w: 3.8, h: 3.5,
    fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL }
  });
  s.addText("Why is Intrapleural\nPressure Negative?", {
    x: 6.05, y: 1.35, w: 3.6, h: 0.7,
    fontSize: 13, bold: true, color: GOLD, fontFace: "Calibri", align: "center"
  });
  s.addText([
    { text: "The lung and chest wall pull in OPPOSITE directions:\n\n", options: { color: WHITE } },
    { text: "• Lung elastic recoil", options: { color: GOLD, bold: true } },
    { text: " → tends to collapse inward\n\n", options: { color: WHITE } },
    { text: "• Chest wall recoil", options: { color: GOLD, bold: true } },
    { text: " → tends to spring outward\n\n", options: { color: WHITE } },
    { text: "The pleural space stretches between them → subatmospheric (negative) pressure\n\n", options: { color: LIGHT_TEAL } },
    { text: "Clinical: Pneumothorax\n", options: { color: RED_ACCENT, bold: true } },
    { text: "Air enters pleural space → Pip = Patm → lung collapses", options: { color: WHITE } }
  ], { x: 6.05, y: 2.1, w: 3.6, h: 2.55, fontSize: 10.5, fontFace: "Calibri" });

  // Boyle's law note
  s.addShape(pres.shapes.RECTANGLE, {
    x: 0.25, y: 4.87, w: 5.5, h: 0.55,
    fill: { color: LIGHT_TEAL }, line: { color: MID_TEAL }
  });
  s.addText("Boyle's Law: P₁V₁ = P₂V₂  →  ↑ volume causes ↓ pressure, which drives air into the lungs during inspiration", {
    x: 0.35, y: 4.87, w: 5.3, h: 0.55,
    fontSize: 10.5, color: DEEP_TEAL, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 10 — INSPIRATION MECHANISM
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Mechanism of Inspiration", "Active process — requires muscular contraction");

  // Step-by-step flow (vertical numbered steps)
  const steps = [
    { n: "1", title: "Inspiratory muscles contract", body: "Diaphragm descends 1.5 cm (quiet), up to 10 cm (deep)\nExternal intercostals: elevate ribs (bucket-handle) and sternum (pump-handle)" },
    { n: "2", title: "Thoracic volume increases", body: "AP, transverse & vertical diameters all increase\nIntrapleural pressure falls: −4 → −8 cmH₂O" },
    { n: "3", title: "Alveolar pressure drops below atmospheric", body: "Palv falls from 760 → ~758 mmHg\nPressure gradient: atmosphere > alveoli" },
    { n: "4", title: "Air flows into the lungs", body: "Air moves from high → low pressure until Palv = Patm\nApproximately 500 mL enters per breath (tidal volume)" },
  ];

  steps.forEach((st, i) => {
    const y = 1.28 + i * 1.02;
    // Number circle
    s.addShape(pres.shapes.OVAL, { x: 0.22, y: y + 0.07, w: 0.52, h: 0.52, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
    s.addText(st.n, { x: 0.22, y: y + 0.07, w: 0.52, h: 0.52, fontSize: 15, bold: true, color: WHITE, fontFace: "Calibri", align: "center", valign: "middle" });
    // Content box
    s.addShape(pres.shapes.RECTANGLE, {
      x: 0.85, y, w: 4.25, h: 0.9,
      fill: { color: WHITE }, line: { color: DEEP_TEAL, pt: 1 },
      shadow: { type: "outer", color: "000000", blur: 3, offset: 1, angle: 135, opacity: 0.10 }
    });
    s.addText(st.title, { x: 0.95, y: y + 0.04, w: 4.1, h: 0.28, fontSize: 12, bold: true, color: DEEP_TEAL, fontFace: "Calibri", margin: 0 });
    s.addText(st.body, { x: 0.95, y: y + 0.3, w: 4.1, h: 0.57, fontSize: 10, color: DARK_TEXT, fontFace: "Calibri", margin: 0 });
  });

  // Muscles panel
  s.addShape(pres.shapes.RECTANGLE, { x: 5.4, y: 1.28, w: 4.35, h: 3.95, fill: { color: WHITE }, line: { color: MID_TEAL, pt: 1.5 } });
  s.addShape(pres.shapes.RECTANGLE, { x: 5.4, y: 1.28, w: 4.35, h: 0.35, fill: { color: MID_TEAL }, line: { color: MID_TEAL } });
  s.addText("Muscles of Inspiration", { x: 5.5, y: 1.28, w: 4.15, h: 0.35, fontSize: 12, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0 });

  const muscleRows = [
    ["PRIMARY MUSCLES", ""],
    ["Diaphragm", "Most important. Dome-shaped. Phrenic nerve (C3,4,5)"],
    ["External intercostals", "Elevate ribs. Intercostal nerves"],
    ["ACCESSORY (forced inspiration)", ""],
    ["Scalene muscles", "Elevate 1st & 2nd ribs"],
    ["Sternocleidomastoid (SCM)", "Elevates sternum and clavicles"],
    ["Pectoralis minor", "Elevates ribs 3–5 when arms fixed"],
    ["Serratus anterior", "Elevates upper ribs"],
  ];
  muscleRows.forEach(([k, v], i) => {
    const bg = i === 0 || i === 3 ? LIGHT_TEAL : (i % 2 === 0 ? "F8FBFD" : WHITE);
    const isCat = i === 0 || i === 3;
    s.addShape(pres.shapes.RECTANGLE, { x: 5.4, y: 1.63 + i * 0.37, w: 4.35, h: 0.37, fill: { color: bg }, line: { color: "D0E8F0", pt: 0.5 } });
    s.addText(k, { x: 5.48, y: 1.63 + i * 0.37, w: 1.7, h: 0.37, fontSize: isCat ? 10 : 9.5, bold: isCat, color: isCat ? DEEP_TEAL : DARK_TEXT, fontFace: "Calibri", valign: "middle", margin: 0 });
    s.addText(v, { x: 7.2, y: 1.63 + i * 0.37, w: 2.45, h: 0.37, fontSize: 9, color: MUTED, fontFace: "Calibri", valign: "middle", margin: 0 });
  });

  // Summary arrow
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 5.15, w: 9.5, h: 0.35, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("Inspiration = ACTIVE process  |  Muscles contract → ↑ volume → ↓ pressure → air flows in", {
    x: 0.35, y: 5.15, w: 9.3, h: 0.35, fontSize: 11, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 11 — EXPIRATION MECHANISM
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Mechanism of Expiration", "Passive at rest — active during forced breathing");

  // Quiet expiration
  infoBox(s, 0.25, 1.28, 4.5, 2.8,
    "Quiet (Passive) Expiration",
    [
      "Inspiratory muscles RELAX — no active effort",
      "Elastic recoil of lungs drives recoil",
      "Thoracic volume decreases",
      "Intrapleural pressure returns: −8 → −4 cmH₂O",
      "Alveolar pressure rises: 760 → ~762 mmHg",
      "Palv > Patm → air flows OUT",
      "Air exits until Palv = Patm again"
    ], DEEP_TEAL);

  // Forced expiration
  infoBox(s, 0.25, 4.18, 4.5, 1.22,
    "Forced (Active) Expiration",
    [
      "Internal intercostals: depress ribs",
      "Abdominal muscles (rectus, obliques): push diaphragm up",
      "Activated during exercise, coughing, sneezing, Valsalva"
    ], RED_ACCENT);

  // Elastic recoil concept
  s.addShape(pres.shapes.RECTANGLE, { x: 5.1, y: 1.28, w: 4.7, h: 2.3, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("What Provides Elastic Recoil?", { x: 5.2, y: 1.32, w: 4.5, h: 0.4, fontSize: 13, bold: true, color: GOLD, fontFace: "Calibri" });
  s.addText([
    { text: "1. Elastic fibres ", options: { bold: true, color: GOLD } },
    { text: "in alveolar walls (collagen + elastin)\n\n", options: { color: WHITE } },
    { text: "2. Surface tension ", options: { bold: true, color: GOLD } },
    { text: "at the air-water interface inside alveoli\n(This is the LARGER component — ~⅔ of recoil)\n\n", options: { color: LIGHT_TEAL } },
    { text: "Reduced by SURFACTANT ", options: { bold: true, color: GOLD } },
    { text: "(Type II pneumocytes)\nSurfactant prevents alveolar collapse at low volumes", options: { color: WHITE } }
  ], { x: 5.2, y: 1.77, w: 4.5, h: 1.7, fontSize: 11, fontFace: "Calibri" });

  // Dynamic airway compression
  s.addShape(pres.shapes.RECTANGLE, { x: 5.1, y: 3.68, w: 4.7, h: 1.7, fill: { color: LIGHT_TEAL }, line: { color: MID_TEAL } });
  s.addText("Dynamic Airway Compression (Clinical)", { x: 5.2, y: 3.72, w: 4.5, h: 0.38, fontSize: 12, bold: true, color: DEEP_TEAL, fontFace: "Calibri" });
  s.addText("In asthma / COPD / bronchiolitis:\n• Expiration becomes ACTIVE to overcome resistance\n• Positive intrapleural pressure → compresses airways\n• Results in: air trapping, ↑ FRC, auto-PEEP, wheeze", {
    x: 5.2, y: 4.12, w: 4.5, h: 1.2, fontSize: 10.5, color: DARK_TEXT, fontFace: "Calibri"
  });

  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 5.15, w: 9.5, h: 0.35, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("Expiration = PASSIVE at rest (elastic recoil)  |  ACTIVE during forced breathing (internal intercostals + abdominals)", {
    x: 0.35, y: 5.15, w: 9.3, h: 0.35, fontSize: 11, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 12 — COMPLIANCE & SURFACTANT
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Lung Compliance & Surfactant", "Compliance = ΔV / ΔP  ·  Normal ≈ 200 mL / cmH₂O");

  infoBox(s, 0.25, 1.28, 4.5, 2.2, "Lung Compliance", [
    "Compliance = ΔVolume / ΔPressure",
    "Normal: ~200 mL/cmH₂O",
    "HIGH compliance → easy to inflate (emphysema)",
    "LOW compliance → stiff lungs, hard to inflate",
    "Low compliance diseases: pulmonary fibrosis, ARDS, pulmonary oedema, RDS"
  ], DEEP_TEAL);

  infoBox(s, 0.25, 3.58, 4.5, 1.73, "Surfactant (DPPC)", [
    "Produced by Type II pneumocytes",
    "Reduces surface tension of alveolar fluid lining",
    "Especially at LOW lung volumes (end-expiration)",
    "Prevents alveolar collapse (atelectasis)",
    "Composition: Dipalmitoylphosphatidylcholine (DPPC)"
  ], MID_TEAL);

  // Compliance comparison
  s.addShape(pres.shapes.RECTANGLE, { x: 5.1, y: 1.28, w: 4.7, h: 4.05, fill: { color: WHITE }, line: { color: MID_TEAL, pt: 1.5 } });
  s.addShape(pres.shapes.RECTANGLE, { x: 5.1, y: 1.28, w: 4.7, h: 0.35, fill: { color: MID_TEAL }, line: { color: MID_TEAL } });
  s.addText("Compliance: High vs Low", { x: 5.2, y: 1.28, w: 4.5, h: 0.35, fontSize: 12, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0 });

  const compRows = [
    ["Condition", "Compliance", "Mechanism"],
    ["Normal", "200 mL/cmH₂O", "Baseline"],
    ["Emphysema", "↑ Increased", "Elastin destruction → ↓ recoil"],
    ["Pulmonary Fibrosis", "↓ Decreased", "Scar tissue → stiff lungs"],
    ["Pulmonary Oedema", "↓ Decreased", "Fluid in alveoli"],
    ["ARDS", "↓ Decreased", "Diffuse alveolar damage"],
    ["Neonatal RDS", "↓ Decreased", "Surfactant deficiency (<28 wk)"],
  ];
  compRows.forEach(([a, b, c], i) => {
    const bg = i === 0 ? DEEP_TEAL : (i % 2 === 0 ? WHITE : LIGHT_TEAL);
    const textColor = i === 0 ? WHITE : DARK_TEXT;
    const isBold = i === 0;
    s.addShape(pres.shapes.RECTANGLE, { x: 5.1, y: 1.63 + i * 0.39, w: 4.7, h: 0.39, fill: { color: bg }, line: { color: "C8DCE5", pt: 0.5 } });
    s.addText(a, { x: 5.18, y: 1.63 + i * 0.39, w: 1.4, h: 0.39, fontSize: 9.5, bold: isBold, color: textColor, fontFace: "Calibri", valign: "middle", margin: 0 });
    const bColor = b.includes("↑") ? GREEN_ACCENT : b.includes("↓") ? RED_ACCENT : textColor;
    s.addText(b, { x: 6.6, y: 1.63 + i * 0.39, w: 1.05, h: 0.39, fontSize: 9.5, bold: isBold || b !== "Baseline", color: bColor, fontFace: "Calibri", valign: "middle", align: "center", margin: 0 });
    s.addText(c, { x: 7.67, y: 1.63 + i * 0.39, w: 2.0, h: 0.39, fontSize: 9, color: textColor, fontFace: "Calibri", valign: "middle", margin: 0 });
  });

  // RDS exam tip
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 5.12, w: 9.5, h: 0.38, fill: { color: "FFF3CD" }, line: { color: GOLD } });
  s.addText("★  RDS (Respiratory Distress Syndrome): Premature neonates (<28–32 weeks) lack surfactant → alveolar collapse → hypoxia. Tx: Exogenous surfactant + CPAP/mechanical ventilation", {
    x: 0.35, y: 5.12, w: 9.3, h: 0.38, fontSize: 10.5, color: DARK_TEXT, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 13 — SECTION DIVIDER: Gas Exchange
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  addSectionCard(s, "04", "Gas Exchange & Transport", "Diffusion · Fick's Law · O₂-Hb Dissociation · CO₂ Transport");
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 14 — GAS EXCHANGE: FICK'S LAW & PARTIAL PRESSURES
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Alveolar Gas Exchange", "Diffusion driven by partial pressure gradients — Fick's Law");

  // Fick's Law box
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 1.28, w: 4.9, h: 1.5, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("Fick's Law of Diffusion", { x: 0.35, y: 1.3, w: 4.7, h: 0.4, fontSize: 13, bold: true, color: GOLD, fontFace: "Calibri" });
  s.addText("Rate ∝ (Area × Solubility × ΔP)\n             (Thickness × √MW)", {
    x: 0.35, y: 1.72, w: 4.7, h: 0.9, fontSize: 14, color: WHITE, fontFace: "Calibri", align: "center"
  });

  // Partial pressures table
  kvTable(s, 0.25, 2.88, 4.9,
    [
      ["Atmospheric O₂ (PiO₂)", "~150 mmHg"],
      ["Alveolar O₂ (PAO₂)", "~100 mmHg"],
      ["Venous blood PO₂", "~40 mmHg  (O₂ flows IN)"],
      ["Alveolar CO₂ (PACO₂)", "~40 mmHg"],
      ["Venous blood PCO₂", "~46 mmHg  (CO₂ flows OUT)"],
    ],
    ["Gas / Location", "Partial Pressure"]
  );

  // Diffusion factors
  infoBox(s, 5.35, 1.28, 4.4, 2.7, "Factors Facilitating O₂ & CO₂ Diffusion", [
    "Large surface area: ~70 m² (both lungs)",
    "Ultra-thin membrane: ~0.5 μm",
    "High partial pressure gradients (see table)",
    "CO₂: 20× more soluble than O₂ → diffuses rapidly despite smaller gradient",
    "Short diffusion distance (RBC in capillary ~0.3 s — equilibration takes ~0.25 s)",
    "A-a gradient (PAO₂ − PaO₂) = 5–15 mmHg normally"
  ], DEEP_TEAL);

  // Widened A-a gradient causes
  infoBox(s, 5.35, 4.07, 4.4, 1.22, "Widened A-a Gradient (>15 mmHg) — Causes", [
    "V/Q mismatch (most common: PE, pneumonia, ARDS)",
    "Diffusion impairment (fibrosis, emphysema)",
    "Right-to-left shunt (ASD/VSD with Eisenmenger, AVMS)"
  ], RED_ACCENT);

  // Alveolar air equation
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 4.95, w: 4.9, h: 0.52, fill: { color: LIGHT_TEAL }, line: { color: MID_TEAL } });
  s.addText("Alveolar Air Equation: PAO₂ = PiO₂ − (PACO₂ / R)   where R = respiratory quotient (~0.8)", {
    x: 0.35, y: 4.95, w: 4.7, h: 0.52, fontSize: 10, color: DEEP_TEAL, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 15 — O₂ TRANSPORT & Hb DISSOCIATION CURVE
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Oxygen Transport & Hb–O₂ Dissociation Curve", "Sigmoid curve due to cooperative binding of O₂ to haemoglobin");

  // Oxygen transport forms
  infoBox(s, 0.25, 1.28, 4.5, 1.6, "Forms of O₂ Transport in Blood", [
    "Dissolved in plasma: ~1.5%  (0.3 mL/dL) — clinically negligible",
    "Bound to haemoglobin (OxyHb): ~98.5%  (20 mL/dL)",
    "O₂ capacity of Hb: 1.34 mL O₂ per gram Hb",
    "Hb = 4 subunits, each binds 1 O₂ (cooperative binding)"
  ], DEEP_TEAL);

  // Curve shifts
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 2.98, w: 4.5, h: 2.3, fill: { color: WHITE }, line: { color: MID_TEAL, pt: 1.5 } });
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 2.98, w: 4.5, h: 0.34, fill: { color: MID_TEAL }, line: { color: MID_TEAL } });
  s.addText("Shifts of the O₂-Hb Dissociation Curve", { x: 0.35, y: 2.98, w: 4.3, h: 0.34, fontSize: 11.5, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0 });

  s.addText([
    { text: "RIGHT SHIFT ", options: { bold: true, color: RED_ACCENT } },
    { text: "(↓ O₂ affinity → easier tissue O₂ delivery):\n", options: { color: DARK_TEXT } },
    { text: "↑ PCO₂, ↑ H⁺/↓ pH (Bohr effect), ↑ Temp, ↑ 2,3-DPG\n\n", options: { color: DARK_TEXT, italic: true } },
    { text: "LEFT SHIFT ", options: { bold: true, color: MID_TEAL } },
    { text: "(↑ O₂ affinity → less O₂ released to tissues):\n", options: { color: DARK_TEXT } },
    { text: "↓ PCO₂, ↓ H⁺/↑ pH, ↓ Temp, ↓ 2,3-DPG, HbF (fetal Hb), COHb", options: { color: DARK_TEXT, italic: true } }
  ], { x: 0.35, y: 3.38, w: 4.3, h: 1.82, fontSize: 10.5, fontFace: "Calibri" });

  // Dissociation curve (drawn with shapes — schematic sigmoid)
  const cX = 5.1, cY = 1.28, cW = 4.7, cH = 3.95;
  s.addShape(pres.shapes.RECTANGLE, { x: cX, y: cY, w: cW, h: cH, fill: { color: WHITE }, line: { color: MID_TEAL, pt: 1 } });
  s.addShape(pres.shapes.RECTANGLE, { x: cX, y: cY, w: cW, h: 0.34, fill: { color: MID_TEAL }, line: { color: MID_TEAL } });
  s.addText("O₂–Hb Dissociation Curve (Schematic)", { x: cX + 0.1, y: cY, w: cW - 0.2, h: 0.34, fontSize: 11, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0 });

  // Axes
  s.addShape(pres.shapes.RECTANGLE, { x: cX + 0.55, y: cY + 0.5, w: 0.04, h: 3.0, fill: { color: DARK_TEXT }, line: { color: DARK_TEXT } });
  s.addShape(pres.shapes.RECTANGLE, { x: cX + 0.55, y: cY + 3.5, w: 3.8, h: 0.04, fill: { color: DARK_TEXT }, line: { color: DARK_TEXT } });
  s.addText("SaO₂ (%)", { x: cX + 0.05, y: cY + 1.3, w: 0.55, h: 1.0, fontSize: 9, color: DARK_TEXT, fontFace: "Calibri", align: "center" });
  s.addText("PO₂ (mmHg)", { x: cX + 2.2, y: cY + 3.55, w: 1.5, h: 0.3, fontSize: 9, color: DARK_TEXT, fontFace: "Calibri", align: "center" });

  // Y-axis tick labels
  ["100", "75", "50", "25", "0"].forEach((v, i) => {
    s.addText(v, { x: cX + 0.06, y: cY + 0.45 + i * 0.62, w: 0.42, h: 0.3, fontSize: 8.5, color: DARK_TEXT, fontFace: "Calibri", align: "right" });
  });
  // X-axis tick labels
  ["0", "27", "40", "60", "100"].forEach((v, i) => {
    const xPos = [0, 0.68, 1.09, 1.63, 2.72];
    s.addText(v, { x: cX + 0.55 + xPos[i], y: cY + 3.55, w: 0.45, h: 0.28, fontSize: 8.5, color: DARK_TEXT, fontFace: "Calibri", align: "center" });
  });

  // Normal sigmoid curve (approximated with line segments)
  const pts = [
    [0.55, 3.5], [0.88, 3.34], [1.09, 3.0], [1.3, 2.55], [1.55, 2.1], [1.85, 1.73], [2.2, 1.52], [2.6, 1.4], [3.1, 1.35], [4.35, 1.33]
  ];
  for (let i = 0; i < pts.length - 1; i++) {
    const [x1, y1] = pts[i], [x2, y2] = pts[i + 1];
    s.addShape(pres.shapes.RECTANGLE, {
      x: cX + x1, y: cY + Math.min(y1, y2),
      w: x2 - x1, h: Math.abs(y2 - y1) + 0.035,
      fill: { color: MID_TEAL }, line: { color: MID_TEAL }
    });
  }

  // P50 label
  s.addShape(pres.shapes.RECTANGLE, { x: cX + 1.09, y: cY + 0.5, w: 0.03, h: 3.0, fill: { color: "DDDDDD" }, line: { color: "DDDDDD" } });
  s.addText("P50 = 27 mmHg", { x: cX + 1.12, y: cY + 0.52, w: 1.3, h: 0.28, fontSize: 8.5, color: RED_ACCENT, bold: true, fontFace: "Calibri" });

  // Key points
  s.addText("Key values:\n• PO₂ 100 mmHg → SaO₂ ~98% (lungs)\n• PO₂ 40 mmHg → SaO₂ ~75% (tissues)\n• P50 = 27 mmHg (50% saturation)", {
    x: cX + 0.6, y: cY + 3.22, w: 3.9, h: 0.65,
    fontSize: 9.5, color: DARK_TEXT, fontFace: "Calibri"
  });

  // Clinical note
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 5.15, w: 9.5, h: 0.35, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("Bohr Effect: ↑ CO₂ / ↑ H⁺ → Right shift → ↑ O₂ unloading at tissues (physiologically beneficial)", {
    x: 0.35, y: 5.15, w: 9.3, h: 0.35, fontSize: 11, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 16 — CO₂ TRANSPORT
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Carbon Dioxide Transport", "Three forms — bicarbonate is most important");

  // Three forms
  const forms = [
    { pct: "70%", label: "Bicarbonate\n(HCO₃⁻)", color: DEEP_TEAL, detail: "Formed in RBCs via carbonic anhydrase\nCO₂ + H₂O → H₂CO₃ → H⁺ + HCO₃⁻\nHCO₃⁻ exits RBC via Chloride Shift\n(Hamburger Phenomenon)" },
    { pct: "23%", label: "Carbamino-\nhaemoglobin", color: MID_TEAL, detail: "CO₂ binds to NH₂ groups of Hb\nUnloaded at lungs\nDeoxyHb binds more CO₂ than OxyHb\n(Haldane Effect)" },
    { pct: "7%", label: "Dissolved\nin Plasma", color: GOLD, detail: "Small amount dissolved directly\nContributes to PaCO₂\nDrives diffusion into alveoli" },
  ];

  forms.forEach((f, i) => {
    const x = 0.25 + i * 3.25;
    s.addShape(pres.shapes.OVAL, {
      x: x + 0.5, y: 1.28, w: 2.0, h: 2.0,
      fill: { color: f.color }, line: { color: f.color }
    });
    s.addText(f.pct, { x: x + 0.5, y: 1.28, w: 2.0, h: 1.15, fontSize: 28, bold: true, color: WHITE, fontFace: "Calibri", align: "center", valign: "bottom" });
    s.addText(f.label, { x: x + 0.5, y: 2.1, w: 2.0, h: 1.1, fontSize: 11, color: WHITE, fontFace: "Calibri", align: "center", valign: "top" });
    s.addShape(pres.shapes.RECTANGLE, {
      x, y: 3.38, w: 3.0, h: 1.72,
      fill: { color: WHITE }, line: { color: f.color, pt: 1.5 }
    });
    s.addText(f.detail, { x: x + 0.1, y: 3.42, w: 2.8, h: 1.64, fontSize: 10.5, color: DARK_TEXT, fontFace: "Calibri" });
  });

  // Carbonic anhydrase reaction
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 5.12, w: 9.5, h: 0.4, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("CO₂ + H₂O  ⇌  H₂CO₃  ⇌  H⁺ + HCO₃⁻     [Carbonic Anhydrase — forward in tissues, reverse in lungs]", {
    x: 0.35, y: 5.12, w: 9.3, h: 0.4, fontSize: 12, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle", align: "center"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 17 — SECTION DIVIDER: V/Q & Control
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  addSectionCard(s, "05", "V/Q Matching & Control of Breathing", "Ventilation-Perfusion Ratio · Chemoreceptors · Neural Control");
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 18 — V/Q MATCHING
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Ventilation–Perfusion (V̇/Q̇) Matching", "Most common cause of hypoxaemia in clinical practice");

  kvTable(s, 0.25, 1.28, 5.5,
    [
      ["Normal V̇/Q̇ ratio", "~0.8  (V̇A = 4.2 L/min,  Q̇ = 5.25 L/min)"],
      ["V̇/Q̇ = 0  (Shunt)", "Alveolus perfused but NOT ventilated → venous admixture"],
      ["V̇/Q̇ = ∞  (Dead Space)", "Alveolus ventilated but NOT perfused (e.g. PE)"],
      ["Shunt response to 100% O₂", "NO improvement (shunted blood bypasses alveoli)"],
      ["V/Q mismatch response", "Partial improvement with supplemental O₂"],
      ["Hypoxic vasoconstriction", "Low PAO₂ → local vasoconstriction → redirects blood flow"],
    ],
    ["Concept", "Description"]
  );

  // Regional V/Q
  s.addShape(pres.shapes.RECTANGLE, { x: 5.95, y: 1.28, w: 3.8, h: 4.1, fill: { color: WHITE }, line: { color: MID_TEAL, pt: 1.5 } });
  s.addShape(pres.shapes.RECTANGLE, { x: 5.95, y: 1.28, w: 3.8, h: 0.34, fill: { color: MID_TEAL }, line: { color: MID_TEAL } });
  s.addText("Regional V̇/Q̇ in Upright Lung", { x: 6.03, y: 1.28, w: 3.63, h: 0.34, fontSize: 11.5, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0 });

  const zones = [
    { z: "APEX", vq: "V̇/Q̇ = ~3.3", detail: "High V/Q\nLeast perfusion (gravity)\nHighest PAO₂\nTB reactivation site", color: DEEP_TEAL },
    { z: "MID", vq: "V̇/Q̇ = ~1.0", detail: "Near normal\nModerate perfusion\nNormal gas exchange", color: MID_TEAL },
    { z: "BASE", vq: "V̇/Q̇ = ~0.6", detail: "Low V/Q\nGreatest perfusion\nLowest PAO₂\nMost gas exchange occurs here", color: MUTED },
  ];
  zones.forEach((z, i) => {
    s.addShape(pres.shapes.RECTANGLE, { x: 5.95, y: 1.65 + i * 1.18, w: 3.8, h: 1.12, fill: { color: PALE_BG }, line: { color: z.color, pt: 1 } });
    s.addShape(pres.shapes.RECTANGLE, { x: 5.95, y: 1.65 + i * 1.18, w: 0.7, h: 1.12, fill: { color: z.color }, line: { color: z.color } });
    s.addText(z.z, { x: 5.95, y: 1.65 + i * 1.18, w: 0.7, h: 1.12, fontSize: 10, bold: true, color: WHITE, fontFace: "Calibri", align: "center", valign: "middle" });
    s.addText(z.vq, { x: 6.7, y: 1.68 + i * 1.18, w: 2.9, h: 0.3, fontSize: 11, bold: true, color: z.color, fontFace: "Calibri" });
    s.addText(z.detail, { x: 6.7, y: 1.98 + i * 1.18, w: 2.9, h: 0.75, fontSize: 9.5, color: DARK_TEXT, fontFace: "Calibri" });
  });

  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 5.17, w: 9.5, h: 0.33, fill: { color: DEEP_TEAL }, line: { color: DEEP_TEAL } });
  s.addText("TB reactivates at apex (high V/Q, high O₂) · PE raises dead space · Pneumonia creates shunt", {
    x: 0.35, y: 5.17, w: 9.3, h: 0.33, fontSize: 10.5, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 19 — CONTROL OF BREATHING
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "Neural & Chemical Control of Breathing", "Brainstem centres + Chemoreceptors + Reflexes");

  // Brainstem centres
  infoBox(s, 0.25, 1.28, 4.55, 2.65, "Brainstem Respiratory Centres", [
    "Pre-Bötzinger complex (medulla) → PRIMARY rhythm generator",
    "Dorsal Respiratory Group (DRG, medulla) → inspiration",
    "Ventral Respiratory Group (VRG, medulla) → inspiration + forced expiration",
    "Pneumotaxic centre (upper pons) → limits inspiration, ↑ rate",
    "Apneustic centre (lower pons) → promotes prolonged inspiration"
  ], DEEP_TEAL);

  // Reflexes
  infoBox(s, 0.25, 4.03, 4.55, 1.35, "Pulmonary Reflexes", [
    "Hering-Breuer reflex: stretch receptors → vagus → stop inspiration (anti-over-inflation)",
    "Irritant receptors: noxious stimuli → bronchospasm, cough, hyperpnea",
    "J-receptors (alveolar wall): oedema/congestion → rapid shallow breathing, dyspnoea"
  ], MID_TEAL);

  // Chemoreceptors
  s.addShape(pres.shapes.RECTANGLE, { x: 5.05, y: 1.28, w: 4.7, h: 4.1, fill: { color: WHITE }, line: { color: MID_TEAL, pt: 1.5 } });
  s.addShape(pres.shapes.RECTANGLE, { x: 5.05, y: 1.28, w: 4.7, h: 0.34, fill: { color: MID_TEAL }, line: { color: MID_TEAL } });
  s.addText("Chemoreceptors", { x: 5.15, y: 1.28, w: 4.5, h: 0.34, fontSize: 12, bold: true, color: WHITE, fontFace: "Calibri", valign: "middle", margin: 0 });

  // Central chemoreceptors
  s.addShape(pres.shapes.RECTANGLE, { x: 5.05, y: 1.62, w: 4.7, h: 1.7, fill: { color: LIGHT_TEAL }, line: { color: DEEP_TEAL, pt: 1 } });
  s.addText("Central Chemoreceptors", { x: 5.15, y: 1.65, w: 4.5, h: 0.32, fontSize: 11, bold: true, color: DEEP_TEAL, fontFace: "Calibri" });
  s.addText([
    { text: "Location: ", options: { bold: true, color: DEEP_TEAL } },
    { text: "Medullary surface (ventral)\n", options: { color: DARK_TEXT } },
    { text: "Stimulus: ", options: { bold: true, color: DEEP_TEAL } },
    { text: "↑ CO₂ → ↑ CSF H⁺ concentration\n", options: { color: DARK_TEXT } },
    { text: "Note: ", options: { bold: true, color: DEEP_TEAL } },
    { text: "CO₂ crosses blood-brain barrier freely; H⁺ does NOT\n", options: { color: DARK_TEXT } },
    { text: "Role: ", options: { bold: true, color: DEEP_TEAL } },
    { text: "Most important for minute-to-minute ventilation control", options: { color: DARK_TEXT } }
  ], { x: 5.15, y: 2.0, w: 4.5, h: 1.25, fontSize: 10.5, fontFace: "Calibri" });

  // Peripheral chemoreceptors
  s.addShape(pres.shapes.RECTANGLE, { x: 5.05, y: 3.35, w: 4.7, h: 2.0, fill: { color: "FFF3F3" }, line: { color: RED_ACCENT, pt: 1 } });
  s.addText("Peripheral Chemoreceptors", { x: 5.15, y: 3.38, w: 4.5, h: 0.32, fontSize: 11, bold: true, color: RED_ACCENT, fontFace: "Calibri" });
  s.addText([
    { text: "Location: ", options: { bold: true, color: RED_ACCENT } },
    { text: "Carotid bodies (CN IX) + Aortic bodies (CN X)\n", options: { color: DARK_TEXT } },
    { text: "Stimulus: ", options: { bold: true, color: RED_ACCENT } },
    { text: "↓ PaO₂ (<60 mmHg) >> ↑ PaCO₂ >> ↓ pH\n", options: { color: DARK_TEXT } },
    { text: "Clinical: ", options: { bold: true, color: RED_ACCENT } },
    { text: "In COPD with chronic CO₂ retention, central receptors are blunted → peripheral hypoxic drive becomes primary stimulus\n", options: { color: DARK_TEXT } },
    { text: "Altitude sickness: ", options: { bold: true, color: RED_ACCENT } },
    { text: "↓ PaO₂ → ↑ peripheral drive → hyperventilation → ↓ PCO₂ → respiratory alkalosis", options: { color: DARK_TEXT } }
  ], { x: 5.15, y: 3.73, w: 4.5, h: 1.55, fontSize: 10, fontFace: "Calibri" });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 20 — CLINICAL CORRELATIONS (EXAM HIGH-YIELD)
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: PALE_BG };
  addHeader(s, "High-Yield Clinical Correlations", "Exam focus: linking physiology to pathology");

  s.addTable([
    [
      { text: "Condition", options: { bold: true, color: WHITE, fill: { color: DEEP_TEAL }, fontSize: 11 } },
      { text: "Pathophysiology", options: { bold: true, color: WHITE, fill: { color: DEEP_TEAL }, fontSize: 11 } },
      { text: "Key Changes", options: { bold: true, color: WHITE, fill: { color: DEEP_TEAL }, fontSize: 11 } },
    ],
    [
      { text: "Emphysema", options: { bold: true, color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
      { text: "Elastin destruction → ↑ compliance, ↓ recoil", options: { color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
      { text: "↑ TLC, ↑ RV, ↓ FEV1/FVC, barrel chest, air trapping", options: { color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
    ],
    [
      { text: "Pulmonary Fibrosis", options: { bold: true, color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
      { text: "Scar tissue → ↓ compliance, stiff lungs", options: { color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
      { text: "↓ TLC, ↓ VC, ↓ compliance, widened A-a gradient", options: { color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
    ],
    [
      { text: "Pneumothorax", options: { bold: true, color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
      { text: "Air in pleural space → Pip = Patm → lung collapse", options: { color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
      { text: "↓ breath sounds, tracheal deviation (tension), hypoxia", options: { color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
    ],
    [
      { text: "Pulmonary Embolism", options: { bold: true, color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
      { text: "Blocked artery → V̇/Q̇ = ∞ (dead space)", options: { color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
      { text: "↑ dead space, hypoxia, tachycardia, pleuritic chest pain", options: { color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
    ],
    [
      { text: "RDS (Neonatal)", options: { bold: true, color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
      { text: "Surfactant deficiency → ↑ surface tension → alveolar collapse", options: { color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
      { text: "Premature neonate, grunting, nasal flaring; Rx: surfactant + CPAP", options: { color: DARK_TEXT, fill: { color: LIGHT_TEAL }, fontSize: 10 } },
    ],
    [
      { text: "COPD Exacerbation", options: { bold: true, color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
      { text: "Airway obstruction → dynamic compression → air trapping", options: { color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
      { text: "Auto-PEEP, ↑ WOB, V̇/Q̇ mismatch, hypercapnia", options: { color: DARK_TEXT, fill: { color: WHITE }, fontSize: 10 } },
    ],
  ], {
    x: 0.25, y: 1.28, w: 9.5,
    border: { pt: 0.5, color: "C8DCE5" },
    rowH: 0.58,
    colW: [1.7, 3.9, 3.9]
  });

  // Exam tip bar
  s.addShape(pres.shapes.RECTANGLE, { x: 0.25, y: 5.18, w: 9.5, h: 0.33, fill: { color: GOLD }, line: { color: GOLD } });
  s.addText("★  EXAM TIP: FEV1/FVC ratio — <0.7 = OBSTRUCTIVE (asthma, COPD)  |  >0.7 with ↓ FVC = RESTRICTIVE (fibrosis, RDS)", {
    x: 0.35, y: 5.18, w: 9.3, h: 0.33, fontSize: 10.5, bold: true, color: DARK_TEXT, fontFace: "Calibri", valign: "middle"
  });
})();

// ═══════════════════════════════════════════════════════════════════════════════
// SLIDE 21 — SUMMARY / REVISION SLIDE
// ═══════════════════════════════════════════════════════════════════════════════
(function() {
  const s = pres.addSlide();
  s.background = { color: DEEP_TEAL };

  s.addShape(pres.shapes.OVAL, { x: 7.5, y: -1.2, w: 4.5, h: 4.5, fill: { color: MID_TEAL, transparency: 75 }, line: { color: MID_TEAL } });
  s.addShape(pres.shapes.OVAL, { x: -1.5, y: 3.0, w: 3.5, h: 3.5, fill: { color: MID_TEAL, transparency: 78 }, line: { color: MID_TEAL } });
  s.addShape(pres.shapes.RECTANGLE, { x: 0, y: 0, w: 0.12, h: 5.625, fill: { color: GOLD }, line: { color: GOLD } });

  s.addText("Key Takeaways", { x: 0.3, y: 0.2, w: 9.4, h: 0.6, fontSize: 30, bold: true, color: WHITE, fontFace: "Calibri" });
  s.addShape(pres.shapes.RECTANGLE, { x: 0.3, y: 0.85, w: 5.0, h: 0.06, fill: { color: GOLD }, line: { color: GOLD } });

  const points = [
    ["Conducting zone", "≈ 150 mL dead space | filters, warms, humidifies"],
    ["Type II pneumocytes", "Produce surfactant (DPPC) | regenerate alveolar epithelium"],
    ["Inspiration", "ACTIVE (diaphragm + external intercostals) | ↑ volume → ↓ Palv → air in"],
    ["Expiration", "PASSIVE at rest (elastic recoil) | ACTIVE with forced breathing"],
    ["FRC", "Resting lung volume = ERV + RV | point of balance between lung + chest wall recoil"],
    ["Alveolar ventilation eq.", "PACO₂ = VCO₂ × 863 / VA | hypoventilation → ↑ PCO₂"],
    ["Fick's Law", "Diffusion ∝ Area × Solubility × ΔP / (Thickness × √MW)"],
    ["Bohr Effect", "↑ CO₂/H⁺ → right shift of Hb-O₂ curve → more O₂ to tissues"],
    ["CO₂ transport", "70% as HCO₃⁻ (most) | 23% carbaminoHb | 7% dissolved"],
    ["V̇/Q̇ mismatch", "Most common cause of hypoxaemia | shunt vs. dead space"],
    ["Central chemoreceptors", "Respond to CO₂ (via CSF H⁺) | main day-to-day controller"],
    ["Peripheral chemoreceptors", "Respond to ↓ PaO₂ (<60 mmHg) | critical in COPD"],
  ];

  const col1 = points.slice(0, 6);
  const col2 = points.slice(6);

  col1.forEach(([k, v], i) => {
    s.addShape(pres.shapes.OVAL, { x: 0.3, y: 1.05 + i * 0.73, w: 0.28, h: 0.28, fill: { color: GOLD }, line: { color: GOLD } });
    s.addText(k, { x: 0.65, y: 1.04 + i * 0.73, w: 1.6, h: 0.28, fontSize: 9.5, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle", margin: 0 });
    s.addText(v, { x: 2.28, y: 1.04 + i * 0.73, w: 2.5, h: 0.28, fontSize: 9.5, color: LIGHT_TEAL, fontFace: "Calibri", valign: "middle", margin: 0 });
  });

  col2.forEach(([k, v], i) => {
    s.addShape(pres.shapes.OVAL, { x: 5.1, y: 1.05 + i * 0.73, w: 0.28, h: 0.28, fill: { color: GOLD }, line: { color: GOLD } });
    s.addText(k, { x: 5.45, y: 1.04 + i * 0.73, w: 1.6, h: 0.28, fontSize: 9.5, bold: true, color: GOLD, fontFace: "Calibri", valign: "middle", margin: 0 });
    s.addText(v, { x: 7.08, y: 1.04 + i * 0.73, w: 2.75, h: 0.28, fontSize: 9.5, color: LIGHT_TEAL, fontFace: "Calibri", valign: "middle", margin: 0 });
  });

  s.addText("Sources: Costanzo Physiology 7e · Boron & Boulpaep Medical Physiology · Murray & Nadel · Tintinalli's Emergency Medicine", {
    x: 0.3, y: 5.28, w: 9.4, h: 0.28, fontSize: 8.5, color: MUTED, fontFace: "Calibri"
  });
})();

// ─── WRITE FILE ───────────────────────────────────────────────────────────────
pres.writeFile({ fileName: "/home/daytona/workspace/respiratory-pptx/Respiratory_System_MBBS.pptx" })
  .then(() => console.log("DONE: Respiratory_System_MBBS.pptx written successfully"))
  .catch(err => { console.error("ERROR:", err); process.exit(1); });
Running Command

cd /home/daytona/workspace/respiratory-pptx && node build.js 2>&1

Running Command

ls -lh /home/daytona/workspace/respiratory-pptx/Respiratory_System_MBBS.pptx

Your presentation is ready!

Respiratory System MBBS

Presentation · PPTX


What's inside (21 slides)

The deck uses a deep teal + gold colour scheme designed specifically for medical/academic presentations. Here's the full structure:
#SlideContent
1Title SlideTopic pills, author, sources
2Section dividerRespiratory Anatomy
3Conducting vs Respiratory ZoneSide-by-side info boxes with key facts
4Alveolar Cell TypesType I & II pneumocytes + macrophages with exam tip on RDS
5Section dividerLung Volumes & Capacities
6Lung Volumes & CapacitiesTable + colour-coded spirogram diagram
7Dead Space & Alveolar VentilationBohr equation, alveolar ventilation equation, clinical correlations
8Section dividerMechanics of Breathing
9Respiratory PressuresFull table + why intrapleural pressure is negative + Boyle's law
10Inspiration MechanismStep-by-step numbered flow + muscles table (primary + accessory)
11Expiration MechanismPassive vs active + dynamic airway compression (asthma/COPD)
12Lung Compliance & SurfactantCompliance comparison table (emphysema, fibrosis, ARDS, RDS)
13Section dividerGas Exchange & Transport
14Alveolar Gas ExchangeFick's Law, partial pressures, A-a gradient
15O₂ Transport & Hb CurveDissociation curve diagram, left/right shifts, Bohr effect
16CO₂ TransportThree forms (70/23/7%), carbonic anhydrase reaction, Haldane effect
17Section dividerV/Q Matching & Control
18V/Q MatchingShunt vs dead space + regional V/Q (apex to base)
19Control of BreathingBrainstem centres + central/peripheral chemoreceptors + reflexes
20High-Yield Clinical Correlations7-condition table: emphysema, fibrosis, pneumothorax, PE, RDS, COPD + FEV1/FVC exam tip
21Summary / Key Takeaways12 bullet revision points on dark background
This is a shared conversation. Sign in to Orris to start your own chat.