attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment
attachment

using this notes on pulmonary respiration according to its topic and subtopics create notes and add diagrams to it for easier understanding along with a revision diagram and flowchart.

analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
analyse_media
Running Command

mkdir -p /tmp/workspace/pulmonary-notes && echo "Directory created"

Writing File

~/pulmonary-notes/pulmonary_notes.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pulmonary Respiration - Comprehensive Notes</title>
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { font-family: 'Segoe UI', Arial, sans-serif; background: #f0f4f8; color: #1a202c; font-size: 14px; }
  
  .cover { background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #0ea5e9 100%); color: white; padding: 60px 40px; text-align: center; min-height: 200px; display: flex; flex-direction: column; justify-content: center; }
  .cover h1 { font-size: 42px; font-weight: 800; letter-spacing: 2px; margin-bottom: 10px; text-shadow: 2px 2px 6px rgba(0,0,0,0.3); }
  .cover p { font-size: 18px; opacity: 0.9; margin-top: 10px; }
  .cover .subtitle { font-size: 14px; opacity: 0.7; margin-top: 8px; letter-spacing: 1px; }

  .toc { background: white; margin: 30px 40px; border-radius: 16px; padding: 30px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); }
  .toc h2 { font-size: 22px; color: #1e3a5f; margin-bottom: 20px; border-bottom: 3px solid #2563eb; padding-bottom: 10px; }
  .toc ul { list-style: none; }
  .toc li { padding: 6px 0; border-bottom: 1px dashed #e2e8f0; }
  .toc a { color: #2563eb; text-decoration: none; font-weight: 500; }
  .toc .sub { margin-left: 20px; color: #64748b; font-size: 13px; }

  .section { background: white; margin: 20px 40px; border-radius: 16px; padding: 30px; box-shadow: 0 4px 20px rgba(0,0,0,0.08); page-break-inside: avoid; }
  .section-header { display: flex; align-items: center; margin-bottom: 24px; }
  .section-num { background: #2563eb; color: white; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; margin-right: 16px; flex-shrink: 0; }
  .section h2 { font-size: 26px; color: #1e3a5f; font-weight: 700; }
  .section h3 { font-size: 18px; color: #2563eb; font-weight: 700; margin: 20px 0 12px; padding-left: 12px; border-left: 4px solid #2563eb; }
  .section h4 { font-size: 15px; color: #0ea5e9; font-weight: 600; margin: 14px 0 8px; }
  .section p { line-height: 1.8; color: #374151; margin-bottom: 10px; }
  .section ul { margin: 8px 0 12px 20px; }
  .section ul li { line-height: 1.8; color: #374151; margin-bottom: 4px; }
  .section table { width: 100%; border-collapse: collapse; margin: 16px 0; }
  .section table th { background: #1e3a5f; color: white; padding: 10px 14px; text-align: left; }
  .section table td { padding: 9px 14px; border-bottom: 1px solid #e2e8f0; }
  .section table tr:nth-child(even) td { background: #f8fafc; }

  /* Callout boxes */
  .callout { border-radius: 10px; padding: 14px 18px; margin: 14px 0; font-size: 13.5px; }
  .callout-blue { background: #eff6ff; border-left: 5px solid #2563eb; }
  .callout-green { background: #f0fdf4; border-left: 5px solid #16a34a; }
  .callout-orange { background: #fff7ed; border-left: 5px solid #ea580c; }
  .callout-red { background: #fef2f2; border-left: 5px solid #dc2626; }
  .callout-purple { background: #faf5ff; border-left: 5px solid #7c3aed; }
  .callout strong { display: block; margin-bottom: 4px; }

  /* Key value pairs */
  .kv { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
  .kv-item { background: #f1f5f9; border-radius: 8px; padding: 8px 14px; flex: 1; min-width: 140px; }
  .kv-item .k { font-size: 11px; color: #64748b; text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }
  .kv-item .v { font-size: 15px; font-weight: 700; color: #1e3a5f; margin-top: 2px; }

  /* SVG diagrams */
  .diagram-wrap { background: #f8fafc; border-radius: 14px; padding: 20px; margin: 20px 0; text-align: center; overflow: hidden; }
  .diagram-wrap svg { max-width: 100%; height: auto; }
  .diagram-title { font-size: 14px; font-weight: 600; color: #64748b; margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.8px; }

  /* Formula */
  .formula { background: #1e3a5f; color: white; border-radius: 10px; padding: 14px 20px; font-size: 16px; font-weight: 700; text-align: center; margin: 16px 0; font-family: 'Courier New', monospace; letter-spacing: 1px; }

  /* Badge */
  .badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-left: 8px; vertical-align: middle; }
  .badge-blue { background: #dbeafe; color: #1d4ed8; }
  .badge-red { background: #fee2e2; color: #b91c1c; }
  .badge-green { background: #dcfce7; color: #15803d; }

  /* Two column */
  .two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 14px 0; }
  .col-box { background: #f8fafc; border-radius: 10px; padding: 16px; border: 1px solid #e2e8f0; }
  .col-box h5 { font-size: 14px; font-weight: 700; color: #1e3a5f; margin-bottom: 10px; border-bottom: 2px solid #2563eb; padding-bottom: 6px; }

  /* Revision card */
  .revision-section { background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%); color: white; margin: 20px 40px; border-radius: 16px; padding: 30px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); }
  .revision-section h2 { font-size: 26px; margin-bottom: 24px; text-align: center; }
  .revision-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
  .revision-card { background: rgba(255,255,255,0.12); border-radius: 10px; padding: 14px; border: 1px solid rgba(255,255,255,0.2); }
  .revision-card h4 { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: #bfdbfe; margin-bottom: 8px; }
  .revision-card ul { list-style: none; }
  .revision-card ul li { font-size: 12.5px; padding: 2px 0; opacity: 0.9; }
  .revision-card ul li::before { content: "→ "; color: #93c5fd; }

  @media print {
    body { background: white; }
    .section, .toc, .revision-section { margin: 10px; }
  }
</style>
</head>
<body>

<!-- COVER -->
<div class="cover">
  <h1>🫁 Pulmonary Respiration</h1>
  <p>Comprehensive Study Notes with Diagrams</p>
  <div class="subtitle">Pulmonary Circulation · Gas Exchange · Transport · Ventilation</div>
</div>

<!-- TABLE OF CONTENTS -->
<div class="toc">
  <h2>📋 Table of Contents</h2>
  <ul>
    <li><a href="#s1">1. Pulmonary Circulation</a></li>
    <li class="sub">Functions · Systemic vs Pulmonary Vessels · HPV · Shunts</li>
    <li><a href="#s2">2. West's Zones of the Lung</a></li>
    <li class="sub">Zone 1, 2, 3 · Blood Flow Distribution</li>
    <li><a href="#s3">3. Ventilation & Dead Space</a></li>
    <li class="sub">Minute Ventilation · Alveolar Ventilation · Dead Space Types · V/Q Ratio</li>
    <li><a href="#s4">4. Deep Vein Thrombosis & Pulmonary Embolism</a></li>
    <li class="sub">DVT · PE · Treatment</li>
    <li><a href="#s5">5. Partial Pressures of Gases</a></li>
    <li class="sub">Dalton's Law · Gas Pressures at Key Sites</li>
    <li><a href="#s6">6. Diffusion Across the Respiratory Membrane</a></li>
    <li class="sub">Fick's Law · Factors Affecting Diffusion · Diffusion Coefficient</li>
    <li><a href="#s7">7. Oxygen Transport in Blood</a></li>
    <li class="sub">Haemoglobin Structure · O₂ Content · Anaemia · Hb-O₂ Dissociation Curve</li>
    <li><a href="#s8">8. CO₂ Transport in Blood</a></li>
    <li class="sub">Forms of Transport · Chloride Shift · Bohr Effect · Haldane Effect</li>
    <li><a href="#s9">Revision Summary & Flowchart</a></li>
  </ul>
</div>

<!-- SECTION 1: PULMONARY CIRCULATION -->
<div class="section" id="s1">
  <div class="section-header">
    <div class="section-num">1</div>
    <h2>Pulmonary Circulation</h2>
  </div>

  <div class="callout callout-blue">
    <strong>Key Fact</strong>
    Pulmonary circulation contains approximately <strong>5–6 L of blood</strong> at any time. It is a <em>low-pressure, high-compliance</em> circuit.
  </div>

  <h3>Functions of the Pulmonary Circulation</h3>
  <ul>
    <li><strong>Regulation of blood pressure</strong> - acts as a buffer</li>
    <li><strong>Gas exchange</strong> - O₂ uptake, CO₂ removal</li>
    <li><strong>Converts inactive plasminogen → plasmin</strong> (via tPA - tissue Plasminogen Activator)</li>
    <li><strong>Reservoir for blood</strong> - stores extra volume</li>
    <li><strong>Filters and breaks down small emboli</strong> - has tPA activity</li>
  </ul>

  <div class="callout callout-orange">
    <strong>Emboli Types</strong>
    Emboli = anything that travels in blood vessels. Types include:
    <ul style="margin-top:6px;">
      <li>Thromboembolus (blood clot)</li>
      <li>Fat embolus</li>
      <li>Air bubble (can block pulmonary circulation)</li>
    </ul>
    tPA converts inactive plasminogen → plasmin to dissolve these.
  </div>

  <h3>Systemic vs Pulmonary Vessels - Key Differences</h3>
  
  <!-- SVG Vessel Comparison Diagram -->
  <div class="diagram-wrap">
    <div class="diagram-title">Vessel Wall Comparison: Systemic (Left) vs Pulmonary (Right)</div>
    <svg width="520" height="180" viewBox="0 0 520 180" xmlns="http://www.w3.org/2000/svg">
      <!-- Systemic vessel -->
      <g transform="translate(80,90)">
        <!-- Outer wall - thick -->
        <circle cx="0" cy="0" r="70" fill="#fde8e8" stroke="#dc2626" stroke-width="3"/>
        <!-- Inner lumen - small -->
        <circle cx="0" cy="0" r="32" fill="#fee2e2" stroke="#ef4444" stroke-width="2"/>
        <circle cx="0" cy="0" r="20" fill="#fca5a5"/>
        <text x="0" y="5" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">Lumen</text>
        <text x="0" y="18" text-anchor="middle" fill="#7f1d1d" font-size="9">(small)</text>
      </g>
      <text x="80" y="168" text-anchor="middle" fill="#1e3a5f" font-size="13" font-weight="bold">SYSTEMIC</text>
      <text x="80" y="18" text-anchor="middle" fill="#dc2626" font-size="11" font-weight="600">Thick Wall</text>
      <text x="80" y="32" text-anchor="middle" fill="#dc2626" font-size="10">High Resistance → ↑BP</text>
      <text x="80" y="44" text-anchor="middle" fill="#dc2626" font-size="10">Non-compliant</text>
      <text x="80" y="56" text-anchor="middle" fill="#dc2626" font-size="10">Longer circuit</text>

      <!-- Arrow between -->
      <text x="260" y="96" text-anchor="middle" fill="#64748b" font-size="22" font-weight="bold">VS</text>

      <!-- Pulmonary vessel -->
      <g transform="translate(440,90)">
        <!-- Thin wall -->
        <circle cx="0" cy="0" r="70" fill="#e0f2fe" stroke="#0284c7" stroke-width="1.5"/>
        <!-- Thick lumen region -->
        <circle cx="0" cy="0" r="52" fill="#bae6fd" stroke="#0ea5e9" stroke-width="1.5"/>
        <circle cx="0" cy="0" r="38" fill="#7dd3fc"/>
        <text x="0" y="5" text-anchor="middle" fill="#0c4a6e" font-size="11" font-weight="bold">Lumen</text>
        <text x="0" y="18" text-anchor="middle" fill="#0c4a6e" font-size="9">(large)</text>
      </g>
      <text x="440" y="168" text-anchor="middle" fill="#1e3a5f" font-size="13" font-weight="bold">PULMONARY</text>
      <text x="440" y="18" text-anchor="middle" fill="#0284c7" font-size="11" font-weight="600">Thin Wall, Thin-coated</text>
      <text x="440" y="32" text-anchor="middle" fill="#0284c7" font-size="10">Low Resistance → ↓BP</text>
      <text x="440" y="44" text-anchor="middle" fill="#0284c7" font-size="10">Distensible (Compliant)</text>
      <text x="440" y="56" text-anchor="middle" fill="#0284c7" font-size="10">Shorter circuit, less elastic tissue</text>
    </svg>
  </div>

  <div class="two-col">
    <div class="col-box">
      <h5>SYSTEMIC Vessels</h5>
      <ul>
        <li>Thick wall → small lumen</li>
        <li>↑Resistance → higher BP</li>
        <li>Non-compliant (elastic = hard to stretch)</li>
        <li>Longer circuit</li>
        <li>High pressure (systemic R ↑)</li>
      </ul>
    </div>
    <div class="col-box">
      <h5>PULMONARY Vessels</h5>
      <ul>
        <li>Thin wall, thin-coated → large lumen</li>
        <li>↓Pressure, ↓elastic tissue</li>
        <li>Distensible = compliant (stretch easily)</li>
        <li>Shorter circuit</li>
        <li>Low resistance (pulm. R ↓)</li>
      </ul>
    </div>
  </div>

  <div class="kv">
    <div class="kv-item"><div class="k">Both pumps output</div><div class="v">5 L/min</div></div>
    <div class="kv-item"><div class="k">Systemic BP</div><div class="v">↑ (high pressure)</div></div>
    <div class="kv-item"><div class="k">Pulmonary BP</div><div class="v">↓ (low pressure)</div></div>
    <div class="kv-item"><div class="k">Pulmonary compliance</div><div class="v">High (distensible)</div></div>
  </div>

  <div class="callout callout-blue">
    <strong>Elastic vs Compliance</strong>
    <ul style="margin-top:4px;">
      <li><strong>Elastic</strong> = hard to stretch (systemic arteries)</li>
      <li><strong>Compliance</strong> = ability to stretch easily (pulmonary vessels)</li>
    </ul>
    Thick wall → ↑resistance (than VP). Systemic: ↑R; Pulmonary: ↓R.
  </div>

  <h3>Hypoxic Pulmonary Vasoconstriction (HPV)</h3>
  <p>HPV is a local reflex unique to the pulmonary circulation:</p>
  <div class="callout callout-purple">
    <strong>HPV Mechanism</strong>
    When alveolar PO₂ is low → local vasoconstriction of pulmonary vessels → blood is diverted <em>away</em> from poorly ventilated areas → redirected to well-ventilated areas. This optimises V/Q matching.
  </div>
  <p>Blood is pumped from ↑P → ↓P (high to low pressure).</p>

  <h3>Shunts</h3>
  <h4>Physiological Shunt</h4>
  <div class="callout callout-green">
    <strong>Definition</strong> Diversion of venous blood directly into the systemic arterial circulation without passing through functional alveoli.
  </div>
  <ul>
    <li><strong>1st shunt:</strong> Thebesian veins (drain into left heart directly) and bronchial veins</li>
    <li><strong>2nd shunt:</strong> Sebaceous veins (minor contribution)</li>
    <li><strong>Shunt in liver</strong> → ductus innosus (in foetal circulation)</li>
  </ul>

  <h4>Pathological Shunts</h4>
  <ul>
    <li><strong>VSD</strong> - Ventricular Septal Defect</li>
    <li><strong>ASD</strong> - Atrial Septal Defect</li>
    <li><strong>PDA</strong> - Patent Ductus Arteriosus</li>
  </ul>

  <div class="callout callout-orange">
    <strong>Shunt Effects</strong>
    <ul style="margin-top:4px;">
      <li>Ventilation defect → shunt → bypass of alveoli</li>
      <li>Perfusion defect → bypasses capillary bed</li>
    </ul>
    Results in: ↓Ventilation, ↓Diffusion (V/Q mismatch), ↓minute ventilation
  </div>
</div>

<!-- SECTION 2: WEST'S ZONES -->
<div class="section" id="s2">
  <div class="section-header">
    <div class="section-num">2</div>
    <h2>West's Zones of the Lung</h2>
  </div>

  <p>Due to gravity, blood flow and alveolar pressure vary from apex to base of the lung. West's model describes three zones:</p>

  <!-- SVG West's Zones Diagram -->
  <div class="diagram-wrap">
    <div class="diagram-title">West's Zones: Lung Blood Flow Distribution (Upright Position)</div>
    <svg width="500" height="340" viewBox="0 0 500 340" xmlns="http://www.w3.org/2000/svg">
      <!-- Lung outline -->
      <ellipse cx="180" cy="170" rx="100" ry="145" fill="#e0f2fe" stroke="#0284c7" stroke-width="2"/>
      
      <!-- Zone 1 (apex) - red/orange -->
      <ellipse cx="180" cy="65" rx="75" ry="50" fill="#fde8e8" stroke="#dc2626" stroke-width="1.5" opacity="0.8"/>
      <text x="180" y="58" text-anchor="middle" fill="#dc2626" font-size="13" font-weight="bold">Zone 1</text>
      <text x="180" y="72" text-anchor="middle" fill="#7f1d1d" font-size="11">Palv &gt; Part &gt; Pven</text>
      <text x="180" y="86" text-anchor="middle" fill="#7f1d1d" font-size="10">NO blood flow</text>

      <!-- Zone 2 (middle) - yellow -->
      <ellipse cx="180" cy="170" rx="90" ry="50" fill="#fefce8" stroke="#ca8a04" stroke-width="1.5" opacity="0.85"/>
      <text x="180" y="163" text-anchor="middle" fill="#92400e" font-size="13" font-weight="bold">Zone 2</text>
      <text x="180" y="177" text-anchor="middle" fill="#92400e" font-size="11">Part &gt; Palv &gt; Pven</text>
      <text x="180" y="191" text-anchor="middle" fill="#92400e" font-size="10">Blood flow present</text>

      <!-- Zone 3 (base) - green -->
      <ellipse cx="180" cy="272" rx="80" ry="50" fill="#f0fdf4" stroke="#16a34a" stroke-width="1.5" opacity="0.9"/>
      <text x="180" y="265" text-anchor="middle" fill="#14532d" font-size="13" font-weight="bold">Zone 3</text>
      <text x="180" y="279" text-anchor="middle" fill="#14532d" font-size="11">Part &gt; Pven &gt; Palv</text>
      <text x="180" y="293" text-anchor="middle" fill="#14532d" font-size="10">Max blood flow</text>

      <!-- Gravity arrow -->
      <defs>
        <marker id="arrowDown" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">
          <polygon points="0 0, 10 3.5, 0 7" fill="#64748b"/>
        </marker>
      </defs>
      <line x1="340" y1="40" x2="340" y2="300" stroke="#64748b" stroke-width="2" marker-end="url(#arrowDown)"/>
      <text x="368" y="175" fill="#64748b" font-size="12" font-weight="600" transform="rotate(90,368,175)">GRAVITY</text>

      <!-- Apex / Base labels -->
      <text x="340" y="35" text-anchor="middle" fill="#64748b" font-size="12">APEX</text>
      <text x="340" y="320" text-anchor="middle" fill="#64748b" font-size="12">BASE</text>

      <!-- Blood flow arrow -->
      <line x1="430" y1="80" x2="430" y2="300" stroke="#2563eb" stroke-width="2.5" marker-end="url(#arrowDown)"/>
      <text x="450" y="180" fill="#2563eb" font-size="11" font-weight="600" transform="rotate(90,450,180)">Blood Flow ↑</text>
    </svg>
  </div>

  <table>
    <thead>
      <tr><th>Zone</th><th>Location</th><th>Pressure Relationship</th><th>Blood Flow</th><th>V/Q Ratio</th></tr>
    </thead>
    <tbody>
      <tr>
        <td><strong>Zone 1</strong> <span class="badge badge-red">Apex</span></td>
        <td>Top of lung</td>
        <td>P<sub>alv</sub> &gt; P<sub>art</sub> = no blood flow</td>
        <td>None (dead space)</td>
        <td>High V/Q</td>
      </tr>
      <tr>
        <td><strong>Zone 2</strong></td>
        <td>Middle</td>
        <td>P<sub>art</sub> &gt; P<sub>alv</sub> = blood flow present</td>
        <td>Moderate (V/Q = 4.2/5L = 0.8)</td>
        <td>Normal ~0.8</td>
      </tr>
      <tr>
        <td><strong>Zone 3</strong> <span class="badge badge-green">Base</span></td>
        <td>Bottom</td>
        <td>P<sub>art</sub> &gt; P<sub>ven</sub> &gt; P<sub>alv</sub></td>
        <td>Maximum (V/Q = 4.2/5.5 = ~0.7)</td>
        <td>Low V/Q</td>
      </tr>
    </tbody>
  </table>

  <div class="callout callout-blue">
    <strong>Key Gradients (Gravity Effect)</strong>
    <ul style="margin-top:4px;">
      <li>Perfusion (blood flow) ↑ from apex → base (gravity pulls blood down)</li>
      <li>Ventilation ↑ at apex, ↓ while ↑ at base (more airway opening at base)</li>
    </ul>
    Normal V/Q at Zone 2 ≈ <strong>0.8</strong> (ideal)
  </div>
</div>

<!-- SECTION 3: VENTILATION & DEAD SPACE -->
<div class="section" id="s3">
  <div class="section-header">
    <div class="section-num">3</div>
    <h2>Ventilation, Dead Space & V/Q Ratio</h2>
  </div>

  <h3>Minute Ventilation</h3>
  <p>Total amount of air entering the respiratory tract each minute:</p>
  <div class="formula">Minute Ventilation = RR × TV = 15 × 500 = 7,500 mL/min = 7–7.5 L/min</div>

  <h3>Dead Space</h3>
  <div class="callout callout-blue">
    <strong>Dead Space</strong> = area that doesn't take part in gas exchange
  </div>

  <div class="two-col">
    <div class="col-box">
      <h5>Anatomical Dead Space</h5>
      <ul>
        <li>Conducting airways (trachea, bronchi, bronchioles)</li>
        <li>~150 mL</li>
        <li>No gas exchange occurs here</li>
      </ul>
    </div>
    <div class="col-box">
      <h5>Alveolar Dead Space</h5>
      <ul>
        <li>Alveoli not perfused with blood flow</li>
        <li>Zone 1 at apex is alveolar dead space</li>
        <li>Any alveolus not perfused = alveolar dead space</li>
      </ul>
    </div>
  </div>

  <div class="kv">
    <div class="kv-item"><div class="k">Total air inhaled (per breath)</div><div class="v">500 mL</div></div>
    <div class="kv-item"><div class="k">Gas exchange volume</div><div class="v">350 mL</div></div>
    <div class="kv-item"><div class="k">Anatomical dead space</div><div class="v">150 mL</div></div>
    <div class="kv-item"><div class="k">Total physiological dead space</div><div class="v">~150 mL</div></div>
  </div>

  <h3>Alveolar Ventilation</h3>
  <p>Volume of new air reaching respiratory zone per minute (where gas exchange happens):</p>
  <div class="formula">Alveolar Ventilation = (Tidal Volume − Dead Space) × RR = (500 − 150) × 12 = 4,200 mL/min = 4.2 L/min</div>

  <div class="callout callout-green">
    <strong>Alveolar Ventilation Rate = 4.2 L/min</strong>
    Note: Take lower limit value. This is the air actually available for gas exchange.
  </div>

  <!-- Ventilation diagram SVG -->
  <div class="diagram-wrap">
    <div class="diagram-title">Ventilation & Dead Space Breakdown per Breath</div>
    <svg width="480" height="200" viewBox="0 0 480 200" xmlns="http://www.w3.org/2000/svg">
      <!-- Total tidal volume bar -->
      <rect x="30" y="50" width="420" height="60" rx="8" fill="#dbeafe" stroke="#2563eb" stroke-width="2"/>
      <text x="240" y="38" text-anchor="middle" fill="#1e3a5f" font-size="13" font-weight="bold">Tidal Volume = 500 mL per breath</text>

      <!-- Dead space portion -->
      <rect x="30" y="50" width="126" height="60" rx="8" fill="#fde8e8" stroke="#dc2626" stroke-width="2"/>
      <text x="93" y="75" text-anchor="middle" fill="#7f1d1d" font-size="12" font-weight="bold">150 mL</text>
      <text x="93" y="92" text-anchor="middle" fill="#7f1d1d" font-size="10">Dead Space</text>

      <!-- Gas exchange portion -->
      <rect x="162" y="50" width="288" height="60" rx="0" fill="#dcfce7" stroke="#16a34a" stroke-width="2"/>
      <text x="306" y="75" text-anchor="middle" fill="#14532d" font-size="12" font-weight="bold">350 mL</text>
      <text x="306" y="92" text-anchor="middle" fill="#14532d" font-size="10">Gas Exchange</text>

      <!-- Labels below -->
      <text x="93" y="135" text-anchor="middle" fill="#dc2626" font-size="11">Conducting airways</text>
      <text x="93" y="150" text-anchor="middle" fill="#dc2626" font-size="11">No gas exchange</text>
      <text x="306" y="135" text-anchor="middle" fill="#16a34a" font-size="11">Alveoli</text>
      <text x="306" y="150" text-anchor="middle" fill="#16a34a" font-size="11">Gas exchange occurs here</text>

      <text x="240" y="185" text-anchor="middle" fill="#64748b" font-size="11">× 15 breaths/min → Alveolar Ventilation = 4.2 L/min | Total Minute Vent = 7.5 L/min</text>
    </svg>
  </div>

  <h3>Ventilation/Perfusion (V/Q) Ratio</h3>
  <p>The ratio of alveolar ventilation to pulmonary blood flow. Critical for gas exchange efficiency.</p>

  <div class="formula">V/Q = Ventilation (V) / Perfusion (Q) = 4.2 / 5 = 0.8 (normal/ideal)</div>

  <div class="callout callout-blue">
    <strong>Intrapleural Pressure</strong>
    <ul style="margin-top:4px;">
      <li>Intrapleural pressure prevents lungs from collapsing</li>
      <li>↑(−) intrapleural pressure → more widening/opening of airways</li>
      <li>Surfactant (Zone 1): ↑V → ↓V (counteracts collapse)</li>
    </ul>
  </div>

  <table>
    <thead>
      <tr><th>Zone</th><th>V/Q Calculation</th><th>Ratio</th><th>Effect</th></tr>
    </thead>
    <tbody>
      <tr><td>Zone 1 (Apex)</td><td>Ventilation only, no perfusion</td><td>∞ (high)</td><td>Dead space</td></tr>
      <tr><td>Zone 2 (Middle)</td><td>4.2/5 = 0.8</td><td>0.8</td><td>Normal gas exchange</td></tr>
      <tr><td>Zone 3 (Base)</td><td>4.2/5.5 = 0.7</td><td>~0.7</td><td>Low V/Q ratio</td></tr>
    </tbody>
  </table>

  <h3>Asthma - V/Q Effects</h3>
  <div class="callout callout-red">
    <strong>Asthma</strong>: ↓V/Q → impaired gas exchange
    <ul style="margin-top:4px;">
      <li>V/Q = 2L/6L = 0.4 (reduced)</li>
      <li>V decreases but Q (perfusion) remains the same</li>
      <li>Results in inadequate O₂ uptake and CO₂ clearance</li>
    </ul>
  </div>
</div>

<!-- SECTION 4: DVT & PE -->
<div class="section" id="s4">
  <div class="section-header">
    <div class="section-num">4</div>
    <h2>Deep Vein Thrombosis (DVT) & Pulmonary Embolism (PE)</h2>
  </div>

  <h3>Deep Vein Thrombosis (DVT)</h3>
  <div class="callout callout-blue">
    <strong>Definition</strong> DVT = abnormal blood clot that develops in deep veins (usually leg).
  </div>

  <!-- DVT flowchart SVG -->
  <div class="diagram-wrap">
    <div class="diagram-title">DVT → Pulmonary Embolism Pathway</div>
    <svg width="500" height="260" viewBox="0 0 500 260" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <marker id="arr" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">
          <polygon points="0 0, 10 3.5, 0 7" fill="#374151"/>
        </marker>
      </defs>
      <!-- Step boxes -->
      <rect x="20" y="20" width="130" height="50" rx="8" fill="#fde8e8" stroke="#dc2626" stroke-width="2"/>
      <text x="85" y="40" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">Risk Factors</text>
      <text x="85" y="56" text-anchor="middle" fill="#7f1d1d" font-size="10">Immobility, Flights</text>
      <text x="85" y="68" text-anchor="middle" fill="#7f1d1d" font-size="10">Surgery, OCP use</text>

      <line x1="150" y1="45" x2="175" y2="45" stroke="#374151" stroke-width="2" marker-end="url(#arr)"/>
      
      <rect x="175" y="20" width="130" height="50" rx="8" fill="#fef9c3" stroke="#ca8a04" stroke-width="2"/>
      <text x="240" y="42" text-anchor="middle" fill="#713f12" font-size="11" font-weight="bold">Clot Forms</text>
      <text x="240" y="58" text-anchor="middle" fill="#713f12" font-size="10">in deep vein</text>
      <text x="240" y="70" text-anchor="middle" fill="#713f12" font-size="10">Stagnant blood</text>

      <line x1="305" y1="45" x2="330" y2="45" stroke="#374151" stroke-width="2" marker-end="url(#arr)"/>
      
      <rect x="330" y="20" width="140" height="50" rx="8" fill="#fde8e8" stroke="#dc2626" stroke-width="2"/>
      <text x="400" y="42" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">Thrombus</text>
      <text x="400" y="58" text-anchor="middle" fill="#7f1d1d" font-size="10">Formed (abnormal clot)</text>
      <text x="400" y="70" text-anchor="middle" fill="#7f1d1d" font-size="10">↑ in O₂</text>

      <!-- Down arrow from Thrombus -->
      <line x1="400" y1="70" x2="400" y2="110" stroke="#374151" stroke-width="2" marker-end="url(#arr)"/>
      
      <rect x="310" y="110" width="160" height="50" rx="8" fill="#ffe4e6" stroke="#e11d48" stroke-width="2"/>
      <text x="390" y="132" text-anchor="middle" fill="#881337" font-size="11" font-weight="bold">DVT</text>
      <text x="390" y="148" text-anchor="middle" fill="#881337" font-size="10">Deep Vein Thrombosis</text>

      <line x1="310" y1="135" x2="260" y2="135" stroke="#374151" stroke-width="2" marker-end="url(#arr)"/>

      <rect x="130" y="110" width="130" height="50" rx="8" fill="#faf5ff" stroke="#7c3aed" stroke-width="2"/>
      <text x="195" y="132" text-anchor="middle" fill="#4c1d95" font-size="11" font-weight="bold">Embolus travels</text>
      <text x="195" y="148" text-anchor="middle" fill="#4c1d95" font-size="10">via venous circulation</text>

      <line x1="130" y1="135" x2="100" y2="135" stroke="#374151" stroke-width="2" marker-end="url(#arr)"/>

      <rect x="20" y="110" width="80" height="50" rx="8" fill="#f0fdf4" stroke="#16a34a" stroke-width="2"/>
      <text x="60" y="132" text-anchor="middle" fill="#14532d" font-size="10" font-weight="bold">Reaches Lung</text>
      <text x="60" y="148" text-anchor="middle" fill="#14532d" font-size="10">→ Pulm. Embolism</text>

      <!-- Bottom section - PE consequence -->
      <line x1="60" y1="160" x2="60" y2="195" stroke="#374151" stroke-width="2" marker-end="url(#arr)"/>
      
      <rect x="20" y="195" width="440" height="50" rx="8" fill="#fde8e8" stroke="#dc2626" stroke-width="3"/>
      <text x="240" y="215" text-anchor="middle" fill="#7f1d1d" font-size="12" font-weight="bold">PULMONARY EMBOLISM</text>
      <text x="240" y="232" text-anchor="middle" fill="#7f1d1d" font-size="11">Medical Emergency → Cardiac Arrest → Death if untreated</text>
    </svg>
  </div>

  <h3>Risk Factors for DVT</h3>
  <ul>
    <li>Prolonged flights / immobilisation</li>
    <li>Sitting for long periods</li>
    <li>Surgery / bedridden patients</li>
    <li>OCP (oral contraceptive pills) - due to hormonal changes</li>
    <li>Stagnant blood → blood clot → in O₂</li>
  </ul>

  <h3>Treatment of Pulmonary Embolism</h3>
  <div class="two-col">
    <div class="col-box">
      <h5>Medical Treatment</h5>
      <ul>
        <li>Thrombolytic agents (e.g., Streptokinase)</li>
        <li>Convert inactive plasminogen → plasmin</li>
        <li>Dissolves the clot</li>
      </ul>
    </div>
    <div class="col-box">
      <h5>Surgical Treatment</h5>
      <ul>
        <li>Thrombectomy = surgical removal of clot</li>
        <li>Used when medical management fails</li>
        <li>Life-saving emergency procedure</li>
      </ul>
    </div>
  </div>

  <div class="callout callout-red">
    <strong>PE → Heart Failure (HF) → Systemic consequences</strong>
    PE is a medical emergency. Block of pulmonary circulation → ↑right heart pressure → cardiac arrest.
  </div>
</div>

<!-- SECTION 5: PARTIAL PRESSURES -->
<div class="section" id="s5">
  <div class="section-header">
    <div class="section-num">5</div>
    <h2>Partial Pressures of Gases</h2>
  </div>

  <h3>Dalton's Law of Partial Pressures</h3>
  <div class="callout callout-blue">
    <strong>Dalton's Law:</strong> The total pressure of a gas mixture = sum of the partial pressures of individual gases. Each gas exerts its own pressure independently.
  </div>

  <div class="formula">Partial Pressure = pressure exerted by ONE individual gas in a mixture of gases</div>

  <!-- Gas pressures diagram SVG -->
  <div class="diagram-wrap">
    <div class="diagram-title">Gas Pressures at Key Physiological Sites</div>
    <svg width="520" height="280" viewBox="0 0 520 280" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <marker id="arrBlue" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">
          <polygon points="0 0, 10 3.5, 0 7" fill="#2563eb"/>
        </marker>
        <marker id="arrRed" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">
          <polygon points="0 0, 10 3.5, 0 7" fill="#dc2626"/>
        </marker>
      </defs>
      
      <!-- Alveolus circle -->
      <ellipse cx="260" cy="70" rx="90" ry="50" fill="#e0f2fe" stroke="#0284c7" stroke-width="2"/>
      <text x="260" y="58" text-anchor="middle" fill="#0c4a6e" font-size="13" font-weight="bold">ALVEOLUS</text>
      <text x="260" y="75" text-anchor="middle" fill="#0c4a6e" font-size="11">PO₂ = 100 mmHg</text>
      <text x="260" y="90" text-anchor="middle" fill="#0c4a6e" font-size="11">PCO₂ = 40 mmHg</text>

      <!-- Respiratory membrane label -->
      <text x="260" y="132" text-anchor="middle" fill="#64748b" font-size="11" font-style="italic">← 0.5 µm respiratory membrane →</text>

      <!-- Capillary box -->
      <rect x="100" y="150" width="320" height="70" rx="10" fill="#fef9c3" stroke="#ca8a04" stroke-width="2"/>
      <text x="170" y="175" text-anchor="middle" fill="#713f12" font-size="12" font-weight="bold">PULMONARY CAPILLARY</text>
      <text x="170" y="193" text-anchor="middle" fill="#713f12" font-size="11">PO₂ = 40 mmHg</text>
      <text x="170" y="208" text-anchor="middle" fill="#713f12" font-size="11">PCO₂ = 46 mmHg</text>
      <text x="360" y="186" text-anchor="middle" fill="#0c4a6e" font-size="11" font-weight="bold">AFTER exchange:</text>
      <text x="360" y="202" text-anchor="middle" fill="#0c4a6e" font-size="11">PO₂ = 100 mmHg</text>

      <!-- Diffusion arrows -->
      <!-- O2 from alveolus to capillary -->
      <line x1="200" y1="120" x2="170" y2="148" stroke="#2563eb" stroke-width="2.5" marker-end="url(#arrBlue)"/>
      <text x="155" y="136" fill="#2563eb" font-size="11" font-weight="600">O₂ ↓</text>
      
      <!-- CO2 from capillary to alveolus -->
      <line x1="300" y1="148" x2="300" y2="122" stroke="#dc2626" stroke-width="2.5" marker-end="url(#arrRed)"/>
      <text x="308" y="138" fill="#dc2626" font-size="11" font-weight="600">CO₂ ↑</text>

      <!-- Cell/tissue box at bottom -->
      <rect x="150" y="245" width="200" height="30" rx="8" fill="#fde8e8" stroke="#dc2626" stroke-width="1.5"/>
      <text x="250" y="265" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">TISSUE CELL: PO₂=40, PCO₂=46</text>
    </svg>
  </div>

  <table>
    <thead>
      <tr><th>Location</th><th>PO₂ (mmHg)</th><th>PCO₂ (mmHg)</th></tr>
    </thead>
    <tbody>
      <tr><td>Atmospheric air</td><td>~160</td><td>~0.3</td></tr>
      <tr><td>Alveolar air</td><td>100</td><td>40</td></tr>
      <tr><td>Pulmonary capillary blood (before exchange)</td><td>40</td><td>46</td></tr>
      <tr><td>Pulmonary capillary blood (after exchange)</td><td>100</td><td>40</td></tr>
      <tr><td>Systemic tissue</td><td>40</td><td>46</td></tr>
    </tbody>
  </table>

  <div class="callout callout-green">
    <strong>Diffusion Direction</strong>
    Gas diffuses from HIGH pressure → LOW pressure (↑P → ↓P), until equilibrium.
    O₂: Alveolus (100) → Capillary (40) = moves INTO blood<br>
    CO₂: Capillary (46) → Alveolus (40) = moves OUT of blood
  </div>
</div>

<!-- SECTION 6: DIFFUSION -->
<div class="section" id="s6">
  <div class="section-header">
    <div class="section-num">6</div>
    <h2>Diffusion Across the Respiratory Membrane</h2>
  </div>

  <h3>Respiratory Membrane</h3>
  <div class="callout callout-blue">
    <strong>Thickness = 0.5 µm</strong> (very thin for rapid diffusion)<br>
    RBCs travel through pulmonary capillaries in single file → minimises diffusion distance.
  </div>
  <ul>
    <li>Pulmonary oedema &amp; pneumonia → ↑ membrane thickness</li>
    <li>Pulmonary fibrosis → lung tissue replaced with fibrous tissue → ↑↑ membrane thickness</li>
    <li>Thicker membrane → ↓ diffusion (impairs gas exchange)</li>
  </ul>

  <h3>Fick's Law of Diffusion</h3>
  <div class="formula">Rate of Diffusion ∝ (ΔP × SA × Diffusion Coefficient) / Membrane Thickness</div>

  <!-- Fick's Law Diagram SVG -->
  <div class="diagram-wrap">
    <div class="diagram-title">Fick's Law - Factors Affecting Diffusion</div>
    <svg width="520" height="240" viewBox="0 0 520 240" xmlns="http://www.w3.org/2000/svg">
      <!-- Central circle -->
      <circle cx="260" cy="120" r="55" fill="#1e3a5f"/>
      <text x="260" y="115" text-anchor="middle" fill="white" font-size="13" font-weight="bold">DIFFUSION</text>
      <text x="260" y="132" text-anchor="middle" fill="#93c5fd" font-size="12">RATE ↑</text>

      <!-- Factor 1: ↑ Pressure difference -->
      <rect x="10" y="20" width="150" height="45" rx="8" fill="#dbeafe" stroke="#2563eb" stroke-width="1.5"/>
      <text x="85" y="38" text-anchor="middle" fill="#1e40af" font-size="11" font-weight="bold">1. ↑ Pressure Gradient</text>
      <text x="85" y="55" text-anchor="middle" fill="#1e40af" font-size="10">→ ↑ Diffusion rate</text>
      <line x1="160" y1="43" x2="210" y2="100" stroke="#2563eb" stroke-width="1.5"/>

      <!-- Factor 2: ↑ Surface area -->
      <rect x="360" y="20" width="150" height="45" rx="8" fill="#dcfce7" stroke="#16a34a" stroke-width="1.5"/>
      <text x="435" y="38" text-anchor="middle" fill="#14532d" font-size="11" font-weight="bold">2. ↑ Surface Area</text>
      <text x="435" y="55" text-anchor="middle" fill="#14532d" font-size="10">→ ↑ Diffusion rate</text>
      <line x1="360" y1="43" x2="310" y2="100" stroke="#16a34a" stroke-width="1.5"/>

      <!-- Factor 3: ↑ Solubility / diffusion coeff -->
      <rect x="360" y="160" width="150" height="55" rx="8" fill="#faf5ff" stroke="#7c3aed" stroke-width="1.5"/>
      <text x="435" y="178" text-anchor="middle" fill="#4c1d95" font-size="11" font-weight="bold">3. ↑ Solubility</text>
      <text x="435" y="194" text-anchor="middle" fill="#4c1d95" font-size="10">↓ Mol. weight</text>
      <text x="435" y="207" text-anchor="middle" fill="#4c1d95" font-size="10">→ ↑ Diffusion</text>
      <line x1="360" y1="175" x2="315" y2="145" stroke="#7c3aed" stroke-width="1.5"/>

      <!-- Factor 4: ↓ Membrane thickness -->
      <rect x="10" y="160" width="150" height="55" rx="8" fill="#fff7ed" stroke="#ea580c" stroke-width="1.5"/>
      <text x="85" y="178" text-anchor="middle" fill="#9a3412" font-size="11" font-weight="bold">4. ↓ Membrane</text>
      <text x="85" y="194" text-anchor="middle" fill="#9a3412" font-size="10">Thickness</text>
      <text x="85" y="207" text-anchor="middle" fill="#9a3412" font-size="10">→ ↑ Diffusion</text>
      <line x1="160" y1="175" x2="210" y2="145" stroke="#ea580c" stroke-width="1.5"/>
    </svg>
  </div>

  <h3>Diffusion Coefficient</h3>
  <div class="callout callout-blue">
    <strong>Diffusion Coefficient</strong> = depends on <em>gas solubility</em> and <em>molecular weight</em>
    <ul style="margin-top:6px;">
      <li>Lower molecular weight → ↑ diffusion (higher solubility)</li>
      <li>Gas more soluble → diffuses faster</li>
    </ul>
  </div>

  <div class="callout callout-orange">
    <strong>CO₂ vs O₂ Diffusion</strong>
    <ul style="margin-top:4px;">
      <li>CO₂ is 24× more soluble than O₂</li>
      <li>O₂ has lower molecular weight → diffuses 1.2× faster than CO₂ per pressure gradient</li>
      <li><strong>BUT</strong> the CO₂ pressure gradient is much smaller → CO₂ solubility compensates → CO₂ diffuses equally well</li>
      <li>Disorders impairing diffusion → hypoxaemia (low O₂) first; hypercapnia (high CO₂) develops late since CO₂ diffusion is less affected initially</li>
    </ul>
  </div>

  <h3>Henry's Law (Gas Solubility)</h3>
  <div class="callout callout-purple">
    <strong>Henry's Law:</strong> ↑ pressure → gases more soluble (dissolve more). ↓ pressure → gases less soluble.
    <ul style="margin-top:4px;">
      <li>Application: Hyperbaric chamber therapy (↑ ambient pressure → ↑ O₂ dissolved in plasma)</li>
      <li>Decompression sickness (diver comes up too fast → ↓ pressure → N₂ bubbles form)</li>
      <li>O₂ poisoning (too high PO₂)</li>
    </ul>
  </div>

  <h3>Clinical Conditions Affecting Gas Exchange</h3>
  <table>
    <thead><tr><th>Condition</th><th>Effect</th><th>Mechanism</th></tr></thead>
    <tbody>
      <tr><td>Pneumonia</td><td>↓ diffusion</td><td>Pus accumulates → alveoli not functional; ↑ membrane thickness</td></tr>
      <tr><td>Emphysema</td><td>↓ SA for diffusion</td><td>Destruction of alveolar walls → ↓ surface area</td></tr>
      <tr><td>Atelectasis</td><td>↓ SA for diffusion</td><td>Alveolar collapse → ↓ surface area</td></tr>
      <tr><td>Pulmonary fibrosis</td><td>↑↑ membrane thickness</td><td>Lung tissue replaced by fibrous tissue</td></tr>
      <tr><td>Pulmonary oedema</td><td>↑ membrane thickness</td><td>Fluid fills alveoli → longer diffusion distance</td></tr>
      <tr><td>High altitude</td><td>↓ PO₂</td><td>↓ atmospheric pressure → ↓ PO₂ → ↓ diffusion</td></tr>
    </tbody>
  </table>
</div>

<!-- SECTION 7: O2 TRANSPORT -->
<div class="section" id="s7">
  <div class="section-header">
    <div class="section-num">7</div>
    <h2>Oxygen Transport in Blood</h2>
  </div>

  <h3>Forms of O₂ Transport</h3>
  <div class="two-col">
    <div class="col-box">
      <h5>1. Dissolved in Plasma (~1.5%)</h5>
      <ul>
        <li>0.003 mL O₂ per 100 mL blood per mmHg</li>
        <li>At PO₂ = 100 mmHg → 0.3 mL/100 mL blood</li>
        <li>Small contribution</li>
        <li>Determined by partial pressure (Henry's Law)</li>
      </ul>
    </div>
    <div class="col-box">
      <h5>2. Bound to Haemoglobin (~98.5%)</h5>
      <ul>
        <li>1g Hb binds 1.34 mL O₂</li>
        <li>Normal Hb = 15 g/dL → 15 × 1.34 = 20.1 mL O₂/dL</li>
        <li>Major carrier (dominant form)</li>
        <li>Determined by O₂ saturation &amp; Hb concentration</li>
      </ul>
    </div>
  </div>

  <div class="kv">
    <div class="kv-item"><div class="k">O₂-Hb bound</div><div class="v">20.1 mL/100 mL</div></div>
    <div class="kv-item"><div class="k">O₂ dissolved</div><div class="v">0.3 mL/100 mL</div></div>
    <div class="kv-item"><div class="k">Total O₂ content</div><div class="v">20.4 mL/100 mL</div></div>
  </div>

  <h3>Haemoglobin (Hb) Structure</h3>
  
  <!-- Hb SVG diagram -->
  <div class="diagram-wrap">
    <div class="diagram-title">Haemoglobin - Tetramer with 4 O₂ Binding Sites</div>
    <svg width="400" height="200" viewBox="0 0 400 200" xmlns="http://www.w3.org/2000/svg">
      <!-- Hb molecule - 4 subunits -->
      <ellipse cx="200" cy="100" rx="80" ry="45" fill="#fee2e2" stroke="#dc2626" stroke-width="2"/>
      <!-- Alpha-beta subunits -->
      <ellipse cx="160" cy="85" rx="35" ry="28" fill="#fca5a5" stroke="#dc2626" stroke-width="1.5"/>
      <text x="160" y="90" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">α</text>
      <ellipse cx="240" cy="85" rx="35" ry="28" fill="#fca5a5" stroke="#dc2626" stroke-width="1.5"/>
      <text x="240" y="90" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">α</text>
      <ellipse cx="160" cy="120" rx="35" ry="28" fill="#fca5a5" stroke="#dc2626" stroke-width="1.5"/>
      <text x="160" y="125" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">β</text>
      <ellipse cx="240" cy="120" rx="35" ry="28" fill="#fca5a5" stroke="#dc2626" stroke-width="1.5"/>
      <text x="240" y="125" text-anchor="middle" fill="#7f1d1d" font-size="11" font-weight="bold">β</text>
      <!-- O2 labels -->
      <circle cx="128" cy="68" r="14" fill="#bfdbfe" stroke="#2563eb" stroke-width="1.5"/>
      <text x="128" y="73" text-anchor="middle" fill="#1d4ed8" font-size="10" font-weight="bold">O₂</text>
      <circle cx="272" cy="68" r="14" fill="#bfdbfe" stroke="#2563eb" stroke-width="1.5"/>
      <text x="272" y="73" text-anchor="middle" fill="#1d4ed8" font-size="10" font-weight="bold">O₂</text>
      <circle cx="128" cy="140" r="14" fill="#bfdbfe" stroke="#2563eb" stroke-width="1.5"/>
      <text x="128" y="145" text-anchor="middle" fill="#1d4ed8" font-size="10" font-weight="bold">O₂</text>
      <circle cx="272" cy="140" r="14" fill="#bfdbfe" stroke="#2563eb" stroke-width="1.5"/>
      <text x="272" y="145" text-anchor="middle" fill="#1d4ed8" font-size="10" font-weight="bold">O₂</text>
      <text x="200" y="180" text-anchor="middle" fill="#374151" font-size="12">Each Hb binds 4 O₂ molecules (one per haem group)</text>
    </svg>
  </div>

  <h3>Hb-O₂ Dissociation Curve</h3>
  <div class="callout callout-blue">
    <strong>Sigmoid (S-shaped) curve</strong>: describes relationship between PO₂ and O₂ saturation of Hb.
  </div>

  <!-- Hb Dissociation Curve SVG -->
  <div class="diagram-wrap">
    <div class="diagram-title">Hb-O₂ Dissociation Curve with Bohr Shift</div>
    <svg width="520" height="300" viewBox="0 0 520 300" xmlns="http://www.w3.org/2000/svg">
      <!-- Axes -->
      <line x1="60" y1="20" x2="60" y2="250" stroke="#374151" stroke-width="2"/>
      <line x1="60" y1="250" x2="470" y2="250" stroke="#374151" stroke-width="2"/>
      <!-- Y-axis label -->
      <text x="20" y="135" fill="#374151" font-size="12" font-weight="600" transform="rotate(-90,20,135)">O₂ Saturation (%)</text>
      <!-- X-axis label -->
      <text x="265" y="275" text-anchor="middle" fill="#374151" font-size="12" font-weight="600">Partial Pressure O₂ (mmHg)</text>
      <!-- Y-axis ticks -->
      <text x="55" y="52" text-anchor="end" fill="#64748b" font-size="10">100%</text>
      <line x1="58" y1="50" x2="62" y2="50" stroke="#374151" stroke-width="1"/>
      <text x="55" y="102" text-anchor="end" fill="#64748b" font-size="10">75%</text>
      <line x1="58" y1="100" x2="62" y2="100" stroke="#374151" stroke-width="1"/>
      <text x="55" y="152" text-anchor="end" fill="#64748b" font-size="10">50%</text>
      <line x1="58" y1="150" x2="62" y2="150" stroke="#374151" stroke-width="1"/>
      <text x="55" y="202" text-anchor="end" fill="#64748b" font-size="10">25%</text>
      <line x1="58" y1="200" x2="62" y2="200" stroke="#374151" stroke-width="1"/>
      <!-- X-axis ticks -->
      <text x="110" y="263" text-anchor="middle" fill="#64748b" font-size="10">20</text>
      <text x="185" y="263" text-anchor="middle" fill="#64748b" font-size="10">40</text>
      <text x="260" y="263" text-anchor="middle" fill="#64748b" font-size="10">60</text>
      <text x="335" y="263" text-anchor="middle" fill="#64748b" font-size="10">80</text>
      <text x="410" y="263" text-anchor="middle" fill="#64748b" font-size="10">100</text>

      <!-- NORMAL curve (sigmoid) -->
      <path d="M 60,248 C 80,245 100,240 115,225 C 130,210 150,185 175,150 C 200,115 225,80 260,62 C 295,45 330,42 410,40" stroke="#2563eb" stroke-width="3" fill="none"/>
      <text x="415" y="38" fill="#2563eb" font-size="11" font-weight="bold">Normal</text>

      <!-- RIGHT SHIFT curve -->
      <path d="M 60,248 C 85,246 110,243 130,232 C 150,218 175,195 200,162 C 225,128 255,92 290,72 C 325,52 360,45 410,43" stroke="#dc2626" stroke-width="2.5" fill="none" stroke-dasharray="6,3"/>
      <text x="415" y="45" fill="#dc2626" font-size="11" font-weight="bold">Right shift</text>

      <!-- LEFT SHIFT curve -->
      <path d="M 60,248 C 75,244 90,237 105,218 C 120,198 140,168 160,135 C 180,102 210,65 250,52 C 285,40 330,38 410,37" stroke="#16a34a" stroke-width="2.5" fill="none" stroke-dasharray="4,4"/>
      <text x="415" y="35" fill="#16a34a" font-size="11" font-weight="bold">Left shift</text>

      <!-- Key points -->
      <!-- P50 -->
      <line x1="185" y1="150" x2="185" y2="250" stroke="#64748b" stroke-width="1" stroke-dasharray="3,3"/>
      <text x="185" y="246" text-anchor="middle" fill="#64748b" font-size="9">P50=27</text>
      <!-- Lung: PO2=100 -->
      <line x1="410" y1="40" x2="410" y2="250" stroke="#2563eb" stroke-width="1" stroke-dasharray="3,3"/>
      <text x="410" y="246" text-anchor="middle" fill="#2563eb" font-size="9">PO₂=100</text>
      <!-- Tissue: PO2=40 -->
      <line x1="185" y1="100" x2="60" y2="100" stroke="#dc2626" stroke-width="1" stroke-dasharray="3,3"/>
      <text x="185" y="98" text-anchor="middle" fill="#dc2626" font-size="9">PO₂=40 → 75% sat</text>

      <!-- Annotations -->
      <text x="95" y="200" fill="#374151" font-size="10">Flat upper portion:</text>
      <text x="95" y="213" fill="#374151" font-size="10">lungs (loading zone)</text>
      <text x="250" y="185" fill="#374151" font-size="10">Steep portion:</text>
      <text x="250" y="197" fill="#374151" font-size="10">tissues (unloading)</text>

      <!-- Bohr shift causes -->
      <rect x="10" y="10" width="45" height="105" rx="4" fill="#fff7ed" stroke="#ea580c" stroke-width="1"/>
      <text x="32" y="22" text-anchor="middle" fill="#9a3412" font-size="9" font-weight="bold">Right</text>
      <text x="32" y="33" text-anchor="middle" fill="#9a3412" font-size="9" font-weight="bold">Shift</text>
      <text x="32" y="48" text-anchor="middle" fill="#9a3412" font-size="8">↑PCO₂</text>
      <text x="32" y="60" text-anchor="middle" fill="#9a3412" font-size="8">↑Temp</text>
      <text x="32" y="72" text-anchor="middle" fill="#9a3412" font-size="8">↑H⁺ / ↓pH</text>
      <text x="32" y="84" text-anchor="middle" fill="#9a3412" font-size="8">2,3-BPG</text>
      <text x="32" y="96" text-anchor="middle" fill="#9a3412" font-size="8">↓O₂</text>
      <text x="32" y="108" text-anchor="middle" fill="#9a3412" font-size="8">affinity</text>
    </svg>
  </div>

  <div class="two-col">
    <div class="col-box">
      <h5>RIGHT Shift (↓ O₂ affinity → unloads O₂ to tissues)</h5>
      <ul>
        <li>↑ PCO₂</li>
        <li>↑ Temperature</li>
        <li>↑ H⁺ (acidosis / ↓ pH)</li>
        <li>↑ 2,3-BPG (produced by RBCs - no mitochondria)</li>
        <li>BENEFICIAL: unloads O₂ to metabolically active tissues</li>
      </ul>
    </div>
    <div class="col-box">
      <h5>LEFT Shift (↑ O₂ affinity → loads O₂ in lungs)</h5>
      <ul>
        <li>↓ PCO₂</li>
        <li>↓ Temperature</li>
        <li>↓ H⁺ (alkalosis / ↑ pH)</li>
        <li>Foetal Hb (HbF)</li>
        <li>Enhances O₂ uptake in lungs</li>
      </ul>
    </div>
  </div>

  <div class="callout callout-green">
    <strong>Partial Pressure in Tissue</strong>
    <ul style="margin-top:4px;">
      <li>↑ PO₂ of O₂ → ↑ O₂ saturation</li>
      <li>↑ Pp (partial pressure) → ↑ Hb binding</li>
      <li>↓ Pp → Hb releases O₂ (doesn't bind)</li>
      <li>↑ Pp → greater O₂ binding (cooperative binding)</li>
    </ul>
  </div>

  <h3>Anaemia Effect</h3>
  <div class="callout callout-red">
    <strong>Anaemia (e.g., 9 g/dL Hb - hypothetical)</strong>
    <ul style="margin-top:4px;">
      <li>Total O₂ content = (9 × 1.34) + 0.3 = 12.6 + 0.3 = 12.9 mL/dL</li>
      <li>Normal = 20.4 mL/dL → significantly reduced</li>
      <li>Symptoms: SOB (shortness of breath), dizziness, pallor</li>
    </ul>
  </div>
</div>

<!-- SECTION 8: CO2 TRANSPORT -->
<div class="section" id="s8">
  <div class="section-header">
    <div class="section-num">8</div>
    <h2>CO₂ Transport in Blood</h2>
  </div>

  <h3>Three Forms of CO₂ Transport</h3>
  <div class="kv">
    <div class="kv-item"><div class="k">1. Dissolved in plasma</div><div class="v">~7%</div></div>
    <div class="kv-item"><div class="k">2. Carbamino-Hb (HbCO₂)</div><div class="v">~23%</div></div>
    <div class="kv-item"><div class="k">3. Bicarbonate (HCO₃⁻)</div><div class="v">~70%</div></div>
  </div>

  <!-- CO2 transport diagram SVG -->
  <div class="diagram-wrap">
    <div class="diagram-title">CO₂ Transport: Tissue Level & Lung Level</div>
    <svg width="520" height="300" viewBox="0 0 520 300" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <marker id="arr2" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto">
          <polygon points="0 0, 8 3, 0 6" fill="#374151"/>
        </marker>
      </defs>
      
      <!-- TISSUE SIDE -->
      <rect x="10" y="10" width="220" height="250" rx="12" fill="#fff7ed" stroke="#ea580c" stroke-width="2"/>
      <text x="120" y="32" text-anchor="middle" fill="#9a3412" font-size="14" font-weight="bold">TISSUE</text>
      
      <!-- CO2 enters -->
      <text x="120" y="58" text-anchor="middle" fill="#374151" font-size="11">CO₂ produced</text>
      <line x1="120" y1="62" x2="120" y2="78" stroke="#374151" stroke-width="1.5" marker-end="url(#arr2)"/>
      
      <!-- 7% dissolved -->
      <rect x="25" y="82" width="85" height="35" rx="6" fill="#dbeafe" stroke="#2563eb" stroke-width="1"/>
      <text x="67" y="97" text-anchor="middle" fill="#1d4ed8" font-size="10" font-weight="bold">7% dissolved</text>
      <text x="67" y="110" text-anchor="middle" fill="#1d4ed8" font-size="9">in plasma</text>
      
      <!-- 23% Carbamino -->
      <rect x="120" y="82" width="100" height="35" rx="6" fill="#faf5ff" stroke="#7c3aed" stroke-width="1"/>
      <text x="170" y="97" text-anchor="middle" fill="#4c1d95" font-size="10" font-weight="bold">23% HbCO₂</text>
      <text x="170" y="110" text-anchor="middle" fill="#4c1d95" font-size="9">Carbamino-Hb</text>
      
      <!-- 70% Bicarbonate reaction -->
      <rect x="25" y="132" width="195" height="70" rx="6" fill="#f0fdf4" stroke="#16a34a" stroke-width="1.5"/>
      <text x="122" y="148" text-anchor="middle" fill="#14532d" font-size="10" font-weight="bold">70% as Bicarbonate (HCO₃⁻)</text>
      <text x="122" y="162" text-anchor="middle" fill="#14532d" font-size="10">CO₂ + H₂O ⇌ H₂CO₃ ⇌ HCO₃⁻ + H⁺</text>
      <text x="122" y="176" text-anchor="middle" fill="#14532d" font-size="9">Carbonic anhydrase (CA) in RBCs</text>
      <text x="122" y="189" text-anchor="middle" fill="#14532d" font-size="9">HCO₃⁻ exits RBC; Cl⁻ enters (Chloride Shift)</text>
      
      <!-- Chloride shift -->
      <rect x="25" y="215" width="195" height="35" rx="6" fill="#fde8e8" stroke="#dc2626" stroke-width="1"/>
      <text x="122" y="232" text-anchor="middle" fill="#7f1d1d" font-size="10" font-weight="bold">Chloride Shift (Hamburger Shift)</text>
      <text x="122" y="246" text-anchor="middle" fill="#7f1d1d" font-size="9">HCO₃⁻ exits RBC; Cl⁻ enters RBC</text>

      <!-- Arrow to lung -->
      <line x1="232" y1="150" x2="275" y2="150" stroke="#374151" stroke-width="2.5" marker-end="url(#arr2)"/>
      <text x="252" y="143" text-anchor="middle" fill="#64748b" font-size="9">Blood</text>
      <text x="252" y="155" text-anchor="middle" fill="#64748b" font-size="9">to lung</text>
      
      <!-- LUNG SIDE -->
      <rect x="285" y="10" width="225" height="250" rx="12" fill="#e0f2fe" stroke="#0284c7" stroke-width="2"/>
      <text x="397" y="32" text-anchor="middle" fill="#0c4a6e" font-size="14" font-weight="bold">LUNGS</text>
      
      <text x="397" y="55" text-anchor="middle" fill="#374151" font-size="10">Reverse reactions occur:</text>
      
      <rect x="298" y="62" width="198" height="70" rx="6" fill="#f0fdf4" stroke="#16a34a" stroke-width="1.5"/>
      <text x="397" y="80" text-anchor="middle" fill="#14532d" font-size="10" font-weight="bold">HCO₃⁻ + H⁺ → H₂CO₃ → CO₂ + H₂O</text>
      <text x="397" y="96" text-anchor="middle" fill="#14532d" font-size="9">Reverse chloride shift</text>
      <text x="397" y="110" text-anchor="middle" fill="#14532d" font-size="9">Cl⁻ exits RBC; HCO₃⁻ re-enters</text>
      <text x="397" y="124" text-anchor="middle" fill="#14532d" font-size="9">HCO₃⁻ is major source → forms HCO₃⁻ blood → 70%</text>
      
      <rect x="298" y="145" width="198" height="35" rx="6" fill="#faf5ff" stroke="#7c3aed" stroke-width="1"/>
      <text x="397" y="160" text-anchor="middle" fill="#4c1d95" font-size="10" font-weight="bold">HbCO₂ → Hb + CO₂ released</text>
      <text x="397" y="174" text-anchor="middle" fill="#4c1d95" font-size="9">CO₂ diffuses to alveolus</text>
      
      <rect x="298" y="192" width="198" height="50" rx="6" fill="#fde8e8" stroke="#dc2626" stroke-width="1"/>
      <text x="397" y="212" text-anchor="middle" fill="#7f1d1d" font-size="10" font-weight="bold">CO₂ exhaled from lungs</text>
      <text x="397" y="228" text-anchor="middle" fill="#7f1d1d" font-size="9">pH → restored to normal</text>
      <text x="397" y="241" text-anchor="middle" fill="#7f1d1d" font-size="9">at lung level</text>
    </svg>
  </div>

  <h3>Bohr Effect (at Tissue Level)</h3>
  <div class="callout callout-orange">
    <strong>Bohr Effect:</strong> Occurs at tissue level. ↑ CO₂ → ↓ affinity of O₂ binding to Hb → unloads O₂ to tissues.
    <ul style="margin-top:6px;">
      <li>Tissues produce CO₂ → ↑ PCO₂</li>
      <li>↑ PCO₂ → ↑ H⁺ (Bohr effect) → ↓ O₂-Hb affinity</li>
      <li>Hb curve shifts RIGHT → O₂ released to tissue</li>
      <li><strong>Beneficial:</strong> ensures O₂ delivery to metabolically active tissues</li>
    </ul>
  </div>

  <h3>Haldane Effect</h3>
  <div class="callout callout-purple">
    <strong>Haldane Effect:</strong> Occurs at lung level (opposite of Bohr). Oxygenation of Hb promotes CO₂ release.
    <ul style="margin-top:6px;">
      <li>When O₂ binds Hb in lungs → Hb releases CO₂</li>
      <li>HbO₂ has lower affinity for CO₂</li>
      <li>Promotes CO₂ removal at lungs</li>
    </ul>
  </div>

  <h3>2,3-BPG (Bisphosphoglycerate)</h3>
  <div class="callout callout-blue">
    <strong>2,3-BPG:</strong>
    <ul style="margin-top:4px;">
      <li>Produced by RBCs (as they don't have mitochondria, use glycolysis → Glucose + O₂ → ATP → CO₂)</li>
      <li>Binds to Hb → decreases O₂ affinity → RIGHT shift of curve</li>
      <li>Important in adaptation to high altitude and anaemia</li>
    </ul>
  </div>
</div>

<!-- REVISION SUMMARY -->
<div class="revision-section" id="s9">
  <h2>⚡ RAPID REVISION SUMMARY</h2>
  <div class="revision-grid">
    <div class="revision-card">
      <h4>Pulmonary Circulation</h4>
      <ul>
        <li>5-6 L blood</li>
        <li>Low pressure, compliant</li>
        <li>Functions: gas exchange, BP regulation, filter emboli, plasminogen conversion</li>
        <li>HPV: ↓PO₂ → vasoconstriction</li>
        <li>Physiological shunt: thebesian + bronchial veins</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>West's Zones</h4>
      <ul>
        <li>Zone 1: Palv > Part = no flow (dead space)</li>
        <li>Zone 2: Part > Palv = blood flow ✓</li>
        <li>Zone 3: Part > Pven > Palv = max flow</li>
        <li>Blood flow ↑ from apex→base (gravity)</li>
        <li>Ventilation ↑ apex, ↑ at base</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>Ventilation</h4>
      <ul>
        <li>Minute vent = RR × TV = 7.5 L/min</li>
        <li>Dead space = 150 mL</li>
        <li>Alveolar vent = 4.2 L/min</li>
        <li>V/Q normal = 0.8</li>
        <li>Asthma V/Q = 0.4</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>DVT & PE</h4>
      <ul>
        <li>DVT = clot in deep veins</li>
        <li>Risks: flights, surgery, OCP, immobility</li>
        <li>PE = medical emergency</li>
        <li>Treat: thrombolytics (streptokinase)</li>
        <li>Surgery: thrombectomy</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>Gas Pressures</h4>
      <ul>
        <li>Alveolus: PO₂=100, PCO₂=40</li>
        <li>Capillary (before): PO₂=40, PCO₂=46</li>
        <li>Dalton's Law: PP = individual pressures sum</li>
        <li>Diffusion: ↑P → ↑P (high to low)</li>
        <li>Resp. membrane = 0.5 µm</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>Fick's Law</h4>
      <ul>
        <li>↑ΔP gradient → ↑diffusion</li>
        <li>↑SA → ↑diffusion</li>
        <li>↑solubility → ↑diffusion</li>
        <li>↓mol. weight → ↑diffusion</li>
        <li>↓membrane thickness → ↑diffusion</li>
        <li>CO₂: 24× more soluble than O₂</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>O₂ Transport</h4>
      <ul>
        <li>98.5% bound to Hb, 1.5% dissolved</li>
        <li>1g Hb = 1.34 mL O₂</li>
        <li>Total O₂ = 20.4 mL/dL</li>
        <li>Sigmoid Hb-O₂ curve</li>
        <li>Right shift: ↑CO₂, ↑T, ↓pH, BPG</li>
        <li>Left shift: opposite factors</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>CO₂ Transport</h4>
      <ul>
        <li>70% as HCO₃⁻ (bicarbonate)</li>
        <li>23% as HbCO₂ (carbamino)</li>
        <li>7% dissolved</li>
        <li>Chloride shift in RBCs</li>
        <li>Bohr effect: tissue level, ↑CO₂ → unload O₂</li>
        <li>Haldane: lungs, O₂ binding → CO₂ release</li>
      </ul>
    </div>
    <div class="revision-card">
      <h4>Key Clinical</h4>
      <ul>
        <li>Pneumonia → ↑membrane thickness</li>
        <li>Emphysema → ↓SA</li>
        <li>Atelectasis → ↓SA</li>
        <li>Fibrosis → ↑↑membrane</li>
        <li>High altitude → ↓PO₂</li>
        <li>Hypoxia → hypercapnia late</li>
      </ul>
    </div>
  </div>
</div>

<!-- MASTER FLOWCHART -->
<div class="section">
  <div class="section-header">
    <div class="section-num" style="background:#16a34a;">↓</div>
    <h2>Master Flowchart: O₂ Journey from Air to Cell</h2>
  </div>

  <div class="diagram-wrap">
    <div class="diagram-title">Complete O₂ & CO₂ Transport Pathway</div>
    <svg width="540" height="480" viewBox="0 0 540 480" xmlns="http://www.w3.org/2000/svg">
      <defs>
        <marker id="fArr" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">
          <polygon points="0 0, 10 3.5, 0 7" fill="#374151"/>
        </marker>
        <marker id="fArrB" markerWidth="10" markerHeight="7" refX="10" refY="3.5" orient="auto">
          <polygon points="0 0, 10 3.5, 0 7" fill="#dc2626"/>
        </marker>
      </defs>
      
      <!-- Step 1: Atmosphere -->
      <rect x="170" y="10" width="200" height="40" rx="8" fill="#f0f9ff" stroke="#0284c7" stroke-width="2"/>
      <text x="270" y="28" text-anchor="middle" fill="#0c4a6e" font-size="12" font-weight="bold">ATMOSPHERE</text>
      <text x="270" y="43" text-anchor="middle" fill="#0c4a6e" font-size="10">PO₂ = 160 mmHg</text>
      
      <line x1="270" y1="50" x2="270" y2="75" stroke="#374151" stroke-width="2" marker-end="url(#fArr)"/>
      <text x="290" y="67" fill="#374151" font-size="9">Inhalation</text>
      
      <!-- Step 2: Alveolus -->
      <rect x="170" y="75" width="200" height="40" rx="8" fill="#e0f2fe" stroke="#0284c7" stroke-width="2"/>
      <text x="270" y="93" text-anchor="middle" fill="#0c4a6e" font-size="12" font-weight="bold">ALVEOLUS</text>
      <text x="270" y="108" text-anchor="middle" fill="#0c4a6e" font-size="10">PO₂ = 100 | PCO₂ = 40 mmHg</text>
      
      <line x1="270" y1="115" x2="270" y2="140" stroke="#374151" stroke-width="2" marker-end="url(#fArr)"/>
      <text x="290" y="132" fill="#374151" font-size="9">Diffusion (Fick's Law)</text>
      <text x="290" y="142" fill="#374151" font-size="9">0.5µm membrane</text>
      
      <!-- Step 3: Pulmonary capillary -->
      <rect x="140" y="148" width="260" height="50" rx="8" fill="#fefce8" stroke="#ca8a04" stroke-width="2"/>
      <text x="270" y="168" text-anchor="middle" fill="#713f12" font-size="12" font-weight="bold">PULMONARY CAPILLARY</text>
      <text x="270" y="183" text-anchor="middle" fill="#713f12" font-size="10">PO₂: 40 → 100 | PCO₂: 46 → 40 mmHg</text>
      <text x="270" y="195" text-anchor="middle" fill="#713f12" font-size="9">O₂ loaded; CO₂ unloaded</text>
      
      <line x1="270" y1="198" x2="270" y2="220" stroke="#374151" stroke-width="2" marker-end="url(#fArr)"/>
      <text x="290" y="213" fill="#374151" font-size="9">via pulmonary veins</text>
      
      <!-- Step 4: Left Heart -->
      <rect x="185" y="222" width="170" height="35" rx="8" fill="#fde8e8" stroke="#dc2626" stroke-width="2"/>
      <text x="270" y="242" text-anchor="middle" fill="#7f1d1d" font-size="12" font-weight="bold">LEFT HEART → AORTA</text>
      
      <line x1="270" y1="257" x2="270" y2="278" stroke="#374151" stroke-width="2" marker-end="url(#fArr)"/>
      
      <!-- Step 5: Systemic capillary -->
      <rect x="130" y="280" width="280" height="50" rx="8" fill="#dcfce7" stroke="#16a34a" stroke-width="2"/>
      <text x="270" y="300" text-anchor="middle" fill="#14532d" font-size="12" font-weight="bold">SYSTEMIC CAPILLARY</text>
      <text x="270" y="315" text-anchor="middle" fill="#14532d" font-size="10">O₂ unloaded to tissues (Bohr effect helps)</text>
      <text x="270" y="328" text-anchor="middle" fill="#14532d" font-size="9">PO₂ drops from 100 → 40 mmHg</text>
      
      <line x1="270" y1="330" x2="270" y2="352" stroke="#374151" stroke-width="2" marker-end="url(#fArr)"/>
      
      <!-- Step 6: Cell -->
      <rect x="160" y="354" width="220" height="50" rx="8" fill="#f3e8ff" stroke="#7c3aed" stroke-width="2"/>
      <text x="270" y="374" text-anchor="middle" fill="#4c1d95" font-size="12" font-weight="bold">CELL (Mitochondria)</text>
      <text x="270" y="390" text-anchor="middle" fill="#4c1d95" font-size="10">O₂ + Glucose → ATP + CO₂ + H₂O</text>
      <text x="270" y="403" text-anchor="middle" fill="#4c1d95" font-size="9">PO₂ = 40 mmHg inside cell</text>
      
      <!-- CO2 return arrow (red dashed) -->
      <line x1="380" y1="380" x2="440" y2="380" stroke="#dc2626" stroke-width="2"/>
      <line x1="440" y1="380" x2="440" y2="95" stroke="#dc2626" stroke-width="2"/>
      <line x1="440" y1="95" x2="375" y2="95" stroke="#dc2626" stroke-width="2" marker-end="url(#fArrB)"/>
      <rect x="443" y="180" width="75" height="60" rx="6" fill="#fde8e8" stroke="#dc2626" stroke-width="1"/>
      <text x="480" y="200" text-anchor="middle" fill="#7f1d1d" font-size="10" font-weight="bold">CO₂</text>
      <text x="480" y="215" text-anchor="middle" fill="#7f1d1d" font-size="9">return:</text>
      <text x="480" y="228" text-anchor="middle" fill="#7f1d1d" font-size="9">70% HCO₃⁻</text>
      <text x="480" y="240" text-anchor="middle" fill="#7f1d1d" font-size="9">23% HbCO₂</text>
      
      <!-- Venous return labels -->
      <text x="155" y="340" fill="#64748b" font-size="9">via systemic veins</text>
      <text x="155" y="352" fill="#64748b" font-size="9">→ Right Heart → Pulm. art</text>
    </svg>
  </div>
</div>

<div style="text-align:center; padding: 20px; color: #64748b; font-size: 12px;">
  Pulmonary Respiration Notes · All content from student lecture notes · For revision use only
</div>

</body>
</html>
Running Command

cd /tmp/workspace/pulmonary-notes && python3 -c " import subprocess # Try weasyprint first try: import weasyprint weasyprint.HTML(filename='pulmonary_notes.html').write_pdf('pulmonary_notes.pdf') print('WeasyPrint: PDF created') except Exception as e: print(f'WeasyPrint error: {e}') # Try pdfkit try: import pdfkit pdfkit.from_file('pulmonary_notes.html', 'pulmonary_notes.pdf') print('pdfkit: PDF created') except Exception as e2: print(f'pdfkit error: {e2}') "

Running Command

cd /tmp/workspace/pulmonary-notes && python3 -c " from reportlab.lib.pagesizes import A4 from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle from reportlab.lib.units import mm, cm from reportlab.lib import colors from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, HRFlowable, KeepTogether from reportlab.graphics.shapes import Drawing, Rect, Circle, String, Line, Ellipse, Polygon from reportlab.graphics.charts.lineplots import LinePlot from reportlab.graphics import renderPDF from reportlab.lib.colors import HexColor, white, black import math doc = SimpleDocTemplate('pulmonary_notes.pdf', pagesize=A4, leftMargin=18*mm, rightMargin=18*mm, topMargin=15*mm, bottomMargin=15*mm) styles = getSampleStyleSheet() story = [] # Colors DARK_BLUE = HexColor('#1e3a5f') BLUE = HexColor('#2563eb') LIGHT_BLUE = HexColor('#e0f2fe') TEAL = HexColor('#0ea5e9') GREEN = HexColor('#16a34a') LIGHT_GREEN = HexColor('#f0fdf4') ORANGE = HexColor('#ea580c') LIGHT_ORANGE = HexColor('#fff7ed') RED = HexColor('#dc2626') LIGHT_RED = HexColor('#fde8e8') PURPLE = HexColor('#7c3aed') LIGHT_PURPLE = HexColor('#faf5ff') GREY = HexColor('#64748b') LIGHT_GREY = HexColor('#f8fafc') YELLOW_BG = HexColor('#fefce8') YELLOW = HexColor('#ca8a04') # Custom styles def heading1(text, color=DARK_BLUE): p = ParagraphStyle('h1', fontSize=22, textColor=color, fontName='Helvetica-Bold', spaceAfter=6, spaceBefore=16, leading=28) return Paragraph(text, p) def heading2(text, color=BLUE): p = ParagraphStyle('h2', fontSize=16, textColor=color, fontName='Helvetica-Bold', spaceAfter=4, spaceBefore=12, leading=20, borderPadding=(0,0,0,8), leftIndent=10, borderColor=BLUE, borderWidth=0) return Paragraph(f'<font color=\"#{color.hexval()[1:]}\">■ {text}</font>', p) def heading3(text): p = ParagraphStyle('h3', fontSize=13, textColor=TEAL, fontName='Helvetica-Bold', spaceAfter=3, spaceBefore=8, leading=16) return Paragraph(f'◆ {text}', p) def body(text, color=HexColor('#374151')): p = ParagraphStyle('body', fontSize=10, textColor=color, fontName='Helvetica', spaceAfter=4, leading=15, leftIndent=8) return Paragraph(text, p) def bullet(text, color=HexColor('#374151'), indent=16): p = ParagraphStyle('bullet', fontSize=10, textColor=color, fontName='Helvetica', spaceAfter=3, leading=14, leftIndent=indent, bulletIndent=indent-10) return Paragraph(f'• {text}', p) def formula_text(text): p = ParagraphStyle('formula', fontSize=11, textColor=white, fontName='Helvetica-Bold', spaceAfter=6, spaceBefore=6, leading=16, backColor=DARK_BLUE, borderPadding=10, borderRadius=8, alignment=1) return Paragraph(text, p) def callout(text, title=None, bg=LIGHT_BLUE, border=BLUE): content = f'<b>{title}</b><br/>' if title else '' content += text p = ParagraphStyle('callout', fontSize=10, textColor=HexColor('#1e3a5f'), fontName='Helvetica', spaceAfter=6, spaceBefore=6, leading=15, backColor=bg, borderPadding=10, leftIndent=10, rightIndent=10, borderColor=border, borderWidth=0, borderRadius=6) return Paragraph(content, p) def spacer(h=6): return Spacer(1, h) # ===================== COVER ===================== cover_drawing = Drawing(500, 120) cover_drawing.add(Rect(0, 0, 500, 120, fillColor=DARK_BLUE, strokeColor=None, rx=12)) cover_drawing.add(Rect(0, 0, 500, 60, fillColor=BLUE, strokeColor=None)) cover_drawing.add(String(250, 88, '🫁 PULMONARY RESPIRATION', fontSize=24, fontName='Helvetica-Bold', fillColor=white, textAnchor='middle')) cover_drawing.add(String(250, 68, 'Comprehensive Study Notes with Diagrams', fontSize=13, fontName='Helvetica', fillColor=HexColor('#bfdbfe'), textAnchor='middle')) cover_drawing.add(String(250, 50, 'Circulation · Gas Exchange · Ventilation · Transport', fontSize=10, fontName='Helvetica', fillColor=HexColor('#93c5fd'), textAnchor='middle')) cover_drawing.add(String(250, 32, 'Based on Lecture Notes · Medical Physiology', fontSize=9, fontName='Helvetica', fillColor=HexColor('#7dd3fc'), textAnchor='middle')) story.append(cover_drawing) story.append(spacer(14)) # ===================== SECTION 1 ===================== story.append(heading1('1. Pulmonary Circulation')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) story.append(callout('<b>Contains ~5–6 L of blood.</b> Low-pressure, high-compliance circuit dedicated to gas exchange and several metabolic functions.', bg=LIGHT_BLUE, border=BLUE)) story.append(spacer(6)) story.append(heading2('Functions')) funcs = [ ('Regulation of blood pressure', 'Acts as a buffer/reservoir'), ('Gas exchange', 'O₂ uptake, CO₂ removal across alveoli'), ('Converts plasminogen → plasmin', 'Via tPA (tissue Plasminogen Activator)'), ('Blood reservoir', 'Stores extra volume that can be mobilised'), ('Filters small emboli', 'Breaks down via tPA activity'), ] for f, d in funcs: story.append(bullet(f'<b>{f}</b>: {d}')) story.append(spacer(6)) story.append(heading2('Systemic vs Pulmonary Vessels')) # Vessel comparison SVG-like drawing vessel_d = Drawing(460, 150) # Systemic - left circle vessel_d.add(Circle(100, 75, 65, fillColor=HexColor('#fde8e8'), strokeColor=RED, strokeWidth=2)) vessel_d.add(Circle(100, 75, 30, fillColor=HexColor('#fca5a5'), strokeColor=HexColor('#ef4444'), strokeWidth=1.5)) vessel_d.add(Circle(100, 75, 18, fillColor=HexColor('#f87171'), strokeColor=None)) vessel_d.add(String(100, 78, 'LUMEN', fontSize=9, fontName='Helvetica-Bold', fillColor=HexColor('#7f1d1d'), textAnchor='middle')) vessel_d.add(String(100, 68, 'small', fontSize=8, fillColor=HexColor('#7f1d1d'), textAnchor='middle')) vessel_d.add(String(100, 148, 'SYSTEMIC', fontSize=12, fontName='Helvetica-Bold', fillColor=DARK_BLUE, textAnchor='middle')) vessel_d.add(String(100, 135, 'Thick wall | Small lumen', fontSize=8, fillColor=RED, textAnchor='middle')) vessel_d.add(String(100, 124, 'High BP | Non-compliant', fontSize=8, fillColor=RED, textAnchor='middle')) vessel_d.add(String(230, 78, 'VS', fontSize=20, fontName='Helvetica-Bold', fillColor=GREY, textAnchor='middle')) # Pulmonary - right circle vessel_d.add(Circle(360, 75, 65, fillColor=HexColor('#e0f2fe'), strokeColor=TEAL, strokeWidth=1.5)) vessel_d.add(Circle(360, 75, 50, fillColor=HexColor('#bae6fd'), strokeColor=HexColor('#0ea5e9'), strokeWidth=1.5)) vessel_d.add(Circle(360, 75, 38, fillColor=HexColor('#7dd3fc'), strokeColor=None)) vessel_d.add(String(360, 78, 'LUMEN', fontSize=9, fontName='Helvetica-Bold', fillColor=HexColor('#0c4a6e'), textAnchor='middle')) vessel_d.add(String(360, 68, 'large', fontSize=8, fillColor=HexColor('#0c4a6e'), textAnchor='middle')) vessel_d.add(String(360, 148, 'PULMONARY', fontSize=12, fontName='Helvetica-Bold', fillColor=DARK_BLUE, textAnchor='middle')) vessel_d.add(String(360, 135, 'Thin wall | Large lumen', fontSize=8, fillColor=TEAL, textAnchor='middle')) vessel_d.add(String(360, 124, 'Low BP | Compliant', fontSize=8, fillColor=TEAL, textAnchor='middle')) story.append(vessel_d) tbl_data = [ ['Feature', 'Systemic', 'Pulmonary'], ['Wall', 'Thick', 'Thin, thin-coated'], ['Lumen', 'Small', 'Large'], ['Pressure', '↑ BP (high)', '↓ BP (low)'], ['Compliance', 'Non-compliant (elastic)', 'Distensible (compliant)'], ['Circuit', 'Longer', 'Shorter'], ['Resistance', '↑ (high)', '↓ (low)'], ] tbl = Table(tbl_data, colWidths=[120, 165, 165]) tbl.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ALIGN', (0,0), (-1,-1), 'CENTER'), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ('FONTNAME', (0,1), (0,-1), 'Helvetica-Bold'), ])) story.append(tbl) story.append(spacer(8)) story.append(heading2('Hypoxic Pulmonary Vasoconstriction (HPV)')) story.append(callout('When alveolar PO₂ ↓ → local vasoconstriction of pulmonary vessels → blood diverted to well-ventilated areas → optimises V/Q matching.', bg=LIGHT_PURPLE, border=PURPLE)) story.append(heading2('Shunts')) story.append(heading3('Physiological Shunt')) story.append(callout('Diversion of venous blood into systemic arterial circulation without passing through functional alveoli.\n• 1st: Thebesian veins and bronchial veins\n• 2nd: Sebaceous veins (minor)', bg=LIGHT_GREEN, border=GREEN)) story.append(heading3('Pathological Shunts')) for s in ['VSD - Ventricular Septal Defect', 'ASD - Atrial Septal Defect', 'PDA - Patent Ductus Arteriosus']: story.append(bullet(s)) # ===================== SECTION 2 ===================== story.append(spacer(10)) story.append(heading1('2. West\'s Zones of the Lung')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) story.append(body('Due to gravity, blood flow varies from apex (top) to base (bottom) of the lung.')) # Zones diagram zones_d = Drawing(460, 200) # Lung outline zones_d.add(Ellipse(160, 100, 100, 90, fillColor=HexColor('#e0f2fe'), strokeColor=BLUE, strokeWidth=1.5)) # Zone 1 zones_d.add(Ellipse(160, 170, 75, 32, fillColor=HexColor('#fde8e8'), strokeColor=RED, strokeWidth=1.5)) zones_d.add(String(160, 173, 'Zone 1 - APEX', fontSize=10, fontName='Helvetica-Bold', fillColor=HexColor('#7f1d1d'), textAnchor='middle')) zones_d.add(String(160, 162, 'Palv > Part = NO blood flow', fontSize=8, fillColor=HexColor('#7f1d1d'), textAnchor='middle')) # Zone 2 zones_d.add(Ellipse(160, 100, 75, 25, fillColor=HexColor('#fefce8'), strokeColor=YELLOW, strokeWidth=1.5)) zones_d.add(String(160, 103, 'Zone 2 - MIDDLE', fontSize=10, fontName='Helvetica-Bold', fillColor=HexColor('#713f12'), textAnchor='middle')) zones_d.add(String(160, 92, 'Part > Palv = Blood flows (V/Q=0.8)', fontSize=8, fillColor=HexColor('#713f12'), textAnchor='middle')) # Zone 3 zones_d.add(Ellipse(160, 30, 70, 28, fillColor=HexColor('#f0fdf4'), strokeColor=GREEN, strokeWidth=1.5)) zones_d.add(String(160, 33, 'Zone 3 - BASE', fontSize=10, fontName='Helvetica-Bold', fillColor=HexColor('#14532d'), textAnchor='middle')) zones_d.add(String(160, 22, 'Part > Pven > Palv = MAX flow', fontSize=8, fillColor=HexColor('#14532d'), textAnchor='middle')) # Gravity arrow zones_d.add(Line(330, 180, 330, 20, strokeColor=GREY, strokeWidth=2)) zones_d.add(String(360, 100, 'GRAVITY', fontSize=10, fontName='Helvetica-Bold', fillColor=GREY, textAnchor='middle')) zones_d.add(String(345, 15, 'BASE', fontSize=9, fillColor=GREY, textAnchor='middle')) zones_d.add(String(345, 185, 'APEX', fontSize=9, fillColor=GREY, textAnchor='middle')) # Blood flow zones_d.add(Line(410, 180, 410, 20, strokeColor=BLUE, strokeWidth=2.5)) zones_d.add(String(430, 100, 'Blood', fontSize=8, fillColor=BLUE, textAnchor='middle')) zones_d.add(String(430, 90, 'Flow ↑', fontSize=8, fillColor=BLUE, textAnchor='middle')) story.append(zones_d) zones_tbl = [ ['Zone', 'Location', 'Pressure Relation', 'Blood Flow', 'V/Q'], ['Zone 1', 'Apex', 'Palv > Part', 'None (dead space)', 'High/∞'], ['Zone 2', 'Middle', 'Part > Palv', 'Moderate', '~0.8'], ['Zone 3', 'Base', 'Part > Pven > Palv', 'Maximum', '~0.7'], ] zt = Table(zones_tbl, colWidths=[55, 65, 120, 110, 60]) zt.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ALIGN', (0,0), (-1,-1), 'CENTER'), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(zt) # ===================== SECTION 3 ===================== story.append(spacer(10)) story.append(heading1('3. Ventilation, Dead Space & V/Q Ratio')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) story.append(heading2('Minute Ventilation')) story.append(formula_text('Minute Ventilation = RR × TV = 15 × 500 = 7,500 mL/min = 7–7.5 L/min')) story.append(heading2('Alveolar Ventilation')) story.append(formula_text('Alveolar Ventilation = (TV − Dead Space) × RR = (500 − 150) × 12 = 4,200 mL/min = 4.2 L/min')) kv_tbl = [ ['Total Inhaled/breath', 'Dead Space', 'For Gas Exchange', 'Alv. Ventilation', 'Minute Vent'], ['500 mL', '150 mL', '350 mL', '4.2 L/min', '7.5 L/min'], ] kvt = Table(kv_tbl, colWidths=[90,90,90,90,90]) kvt.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTNAME', (0,1), (-1,1), 'Helvetica-Bold'), ('TEXTCOLOR', (0,1), (-1,1), BLUE), ('FONTSIZE', (0,0), (-1,-1), 9), ('ALIGN', (0,0), (-1,-1), 'CENTER'), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 7), ('BOTTOMPADDING', (0,0), (-1,-1), 7), ])) story.append(kvt) story.append(spacer(6)) story.append(heading2('V/Q Ratio')) story.append(formula_text('V/Q = Ventilation / Perfusion = 4.2 / 5 = 0.8 (Normal)')) story.append(callout('<b>Asthma:</b> V decreases while Q remains same → V/Q = 2L/6L = 0.4 → impaired gas exchange.', bg=LIGHT_RED, border=RED)) # ===================== SECTION 4 ===================== story.append(spacer(10)) story.append(heading1('4. DVT & Pulmonary Embolism')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) story.append(callout('<b>DVT</b> = Deep Vein Thrombosis = abnormal blood clot that develops in deep veins (usually legs).', bg=LIGHT_BLUE, border=BLUE)) story.append(heading2('DVT Risk Factors')) for r in ['Prolonged flights / immobilisation', 'Surgery / bedridden', 'OCP (oral contraceptive pills) – hormonal', 'Prolonged sitting, immobility']: story.append(bullet(r)) # DVT flowchart dvt_d = Drawing(460, 80) boxes = [('DVT\n(deep vein clot)', 0), ('→ Embolus\ntravels', 100), ('→ Reaches\nLung', 200), ('→ PE\n(emergency)', 310), ('→ Cardiac\nArrest/Death', 400)] cols = [LIGHT_RED, YELLOW_BG, LIGHT_PURPLE, LIGHT_RED, LIGHT_RED] borders = [RED, YELLOW, PURPLE, RED, RED] for i, ((txt, x), bg, bc) in enumerate(zip(boxes, cols, borders)): dvt_d.add(Rect(x, 10, 90, 55, fillColor=bg, strokeColor=bc, strokeWidth=1.5, rx=6)) lines = txt.split('\n') dvt_d.add(String(x+45, 38, lines[0], fontSize=9, fontName='Helvetica-Bold', fillColor=HexColor('#1e3a5f'), textAnchor='middle')) if len(lines) > 1: dvt_d.add(String(x+45, 25, lines[1], fontSize=8, fillColor=HexColor('#374151'), textAnchor='middle')) story.append(dvt_d) story.append(heading2('Treatment')) trt_tbl = [ ['Medical', 'Surgical'], ['Thrombolytics (Streptokinase)', 'Thrombectomy (surgical removal)'], ['Converts plasminogen → plasmin', 'Emergency procedure'], ['Dissolves the clot', 'When medical treatment fails'], ] trt = Table(trt_tbl, colWidths=[230, 220]) trt.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ALIGN', (0,0), (-1,-1), 'CENTER'), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(trt) # ===================== SECTION 5 ===================== story.append(spacer(10)) story.append(heading1('5. Partial Pressures of Gases')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) story.append(callout(\"<b>Dalton's Law:</b> Total pressure = sum of individual partial pressures. Each gas exerts its own pressure independently in a mixture.\", bg=LIGHT_BLUE, border=BLUE)) gas_tbl = [ ['Location', 'PO₂ (mmHg)', 'PCO₂ (mmHg)', 'Comment'], ['Atmosphere', '~160', '~0.3', 'Ambient air'], ['Alveolar air', '100', '40', 'After mixing with dead space air'], ['Pulmonary cap (BEFORE exchange)', '40', '46', 'Deoxygenated blood arriving'], ['Pulmonary cap (AFTER exchange)', '100', '40', 'After gas exchange'], ['Systemic tissue', '40', '46', 'O₂ consumed, CO₂ produced'], ] gt = Table(gas_tbl, colWidths=[140, 70, 80, 160]) gt.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ALIGN', (1,0), (2,-1), 'CENTER'), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(gt) story.append(callout('<b>Diffusion direction:</b> O₂ moves from alveolus (100) → capillary (40) — high to low pressure. CO₂ moves capillary (46) → alveolus (40). Gas diffuses ↑P → ↓P.', bg=LIGHT_GREEN, border=GREEN)) # ===================== SECTION 6 ===================== story.append(spacer(10)) story.append(heading1('6. Diffusion Across the Respiratory Membrane')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) story.append(callout('<b>Respiratory Membrane Thickness = 0.5 µm</b> (very thin for rapid diffusion). RBCs travel in single file through pulmonary capillaries → minimal diffusion distance.', bg=LIGHT_BLUE, border=BLUE)) story.append(formula_text(\"Fick's Law: Rate ∝ (ΔP × Surface Area × Diffusion Coefficient) / Membrane Thickness\")) ficks = [ ('↑ Pressure gradient (ΔP)', 'Faster diffusion', GREEN, LIGHT_GREEN), ('↑ Surface area (# alveoli)', 'Faster diffusion', GREEN, LIGHT_GREEN), ('↑ Solubility / ↓ mol weight', 'Faster diffusion (diffusion coeff ↑)', PURPLE, LIGHT_PURPLE), ('↓ Membrane thickness', 'Faster diffusion', ORANGE, LIGHT_ORANGE), ('Slow ventilation → ↓PO₂', 'Slower diffusion', RED, LIGHT_RED), ('↑ Altitude → ↓ atm pressure', 'Slower diffusion', RED, LIGHT_RED), ] ficks_tbl = [[f, e] for f, e, _, _ in ficks] ficks_tbl.insert(0, ['Factor (↑)', 'Effect on Diffusion']) ft = Table(ficks_tbl, colWidths=[250, 200]) ft.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(ft) story.append(spacer(6)) story.append(callout('<b>CO₂ vs O₂:</b> CO₂ is 24× more soluble than O₂. O₂ diffuses 1.2× faster per pressure gradient unit. Disorders → hypoxaemia first; hypercapnia develops late (CO₂ diffusion less initially affected).', bg=LIGHT_ORANGE, border=ORANGE)) clin_tbl = [ ['Condition', 'Effect', 'Mechanism'], ['Pneumonia', '↓ Diffusion', 'Pus → alveoli non-functional, ↑ membrane thickness'], ['Emphysema', '↓ Surface area', 'Destruction of alveolar walls → ↓ SA'], ['Atelectasis', '↓ Surface area', 'Alveolar collapse → ↓ SA'], ['Pulmonary fibrosis', '↑↑ Membrane thickness', 'Fibrous tissue replaces normal lung tissue'], ] ct = Table(clin_tbl, colWidths=[100, 110, 240]) ct.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(ct) # ===================== SECTION 7 ===================== story.append(spacer(10)) story.append(heading1('7. Oxygen Transport in Blood')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) o2_tbl = [ ['Form', '% of Total', 'Detail'], ['Dissolved in plasma', '~1.5%', '0.003 mL × PO₂ = 0.3 mL at PO₂=100 mmHg'], ['Bound to Haemoglobin (HbO₂)', '~98.5%', '1g Hb × 1.34 mL = 20.1 mL at 15g/dL Hb'], ['TOTAL O₂ content', '100%', '20.1 + 0.3 = 20.4 mL/100 mL blood'], ] o2t = Table(o2_tbl, colWidths=[150, 80, 220]) o2t.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(o2t) story.append(spacer(6)) story.append(heading2('Hb-O₂ Dissociation Curve')) story.append(callout('<b>Sigmoid (S-shaped) curve.</b> Flat upper part (lung: O₂ loading at high PO₂). Steep lower part (tissue: O₂ unloading at low PO₂).', bg=LIGHT_BLUE, border=BLUE)) # Hb curve hb_d = Drawing(460, 200) hb_d.add(Rect(40, 20, 390, 165, fillColor=white, strokeColor=GREY, strokeWidth=1)) # Axes hb_d.add(Line(40, 20, 40, 185, strokeColor=black, strokeWidth=1.5)) hb_d.add(Line(40, 20, 430, 20, strokeColor=black, strokeWidth=1.5)) # Labels hb_d.add(String(15, 100, 'O₂ Sat%', fontSize=8, fontName='Helvetica-Bold', fillColor=DARK_BLUE)) hb_d.add(String(230, 5, 'PO₂ (mmHg)', fontSize=8, fontName='Helvetica-Bold', fillColor=DARK_BLUE, textAnchor='middle')) # Y ticks for pct, y in [(100, 183), (75, 140), (50, 100), (25, 60)]: hb_d.add(String(38, y, str(pct), fontSize=7, fillColor=GREY, textAnchor='end')) hb_d.add(Line(38, y+3, 42, y+3, strokeColor=GREY, strokeWidth=0.8)) # X ticks for mmhg, x in [(20, 100), (40, 175), (60, 250), (80, 325), (100, 395)]: hb_d.add(String(x, 11, str(mmhg), fontSize=7, fillColor=GREY, textAnchor='middle')) hb_d.add(Line(x, 18, x, 22, strokeColor=GREY, strokeWidth=0.8)) # Normal sigmoid curve (approximate) # Points: (PO2, sat%) -> scaled to drawing coords # x = 40 + (PO2/100)*375, y = 20 + (sat/100)*163 def px(po2): return 40 + (po2/100)*375 def py(sat): return 20 + (sat/100)*163 # Normal curve points pts_normal = [(0,0),(10,13),(20,35),(27,50),(40,75),(60,89),(80,95),(100,97.5)] pts_right = [(0,0),(10,8),(20,25),(35,50),(50,75),(70,89),(90,94),(100,96)] # Draw normal curve from reportlab.graphics.shapes import PolyLine npts = [] for po2, sat in pts_normal: npts.extend([px(po2), py(sat)]) hb_d.add(PolyLine(npts, strokeColor=BLUE, strokeWidth=2.5, strokeLineJoin=1)) # Draw right shift rpts = [] for po2, sat in pts_right: rpts.extend([px(po2), py(sat)]) hb_d.add(PolyLine(rpts, strokeColor=RED, strokeWidth=2, strokeDashArray=[6,3])) # Key lines hb_d.add(Line(px(40), py(0), px(40), py(75), strokeColor=ORANGE, strokeWidth=1, strokeDashArray=[3,3])) hb_d.add(Line(px(0), py(75), px(40), py(75), strokeColor=ORANGE, strokeWidth=1, strokeDashArray=[3,3])) hb_d.add(String(px(40)+4, py(72), 'PO₂=40: 75% sat', fontSize=7, fillColor=ORANGE)) hb_d.add(String(px(100)+5, py(97), 'Normal', fontSize=8, fontName='Helvetica-Bold', fillColor=BLUE)) hb_d.add(String(px(100)+5, py(94), 'Right shift', fontSize=8, fontName='Helvetica-Bold', fillColor=RED)) # Annotations hb_d.add(String(130, 175, 'Flat: lungs (loading)', fontSize=7, fillColor=GREY)) hb_d.add(String(200, 130, 'Steep: tissues (unloading)', fontSize=7, fillColor=GREY)) story.append(hb_d) story.append(heading2('Shifts of the Hb-O₂ Curve')) shift_tbl = [ ['RIGHT SHIFT (↓ O₂ affinity – good for tissues)', 'LEFT SHIFT (↑ O₂ affinity – good for lungs)'], ['↑ PCO₂ (Bohr effect)', '↓ PCO₂'], ['↑ Temperature', '↓ Temperature'], ['↑ H⁺ (↓ pH / acidosis)', '↓ H⁺ (↑ pH / alkalosis)'], ['↑ 2,3-BPG (produced by RBCs)', 'Foetal Hb (HbF)'], ['→ O₂ unloaded to active tissues', '→ O₂ loaded in lungs'], ] st_t = Table(shift_tbl, colWidths=[230, 220]) st_t.setStyle(TableStyle([ ('BACKGROUND', (0,0), (0,0), HexColor('#fde8e8')), ('BACKGROUND', (1,0), (1,0), HexColor('#f0fdf4')), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('TEXTCOLOR', (0,0), (0,0), RED), ('TEXTCOLOR', (1,0), (1,0), GREEN), ('FONTSIZE', (0,0), (-1,-1), 9), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(st_t) story.append(callout('<b>Anaemia example (9g/dL Hb):</b> O₂ content = (9 × 1.34) + 0.3 = 12.9 mL/dL vs normal 20.4 mL/dL → ↓O₂ delivery → SOB, dizziness, pallor.', bg=LIGHT_RED, border=RED)) # ===================== SECTION 8 ===================== story.append(spacer(10)) story.append(heading1('8. CO₂ Transport in Blood')) story.append(HRFlowable(width='100%', thickness=2, color=BLUE, spaceAfter=8)) co2_tbl = [ ['Form', '%', 'Mechanism'], ['Dissolved in plasma', '7%', 'Simple dissolution, depends on partial pressure'], ['Carbamino-Hb (HbCO₂)', '23%', 'CO₂ binds to amino groups of Hb'], ['Bicarbonate (HCO₃⁻)', '70%', 'CO₂ + H₂O ⇌ H₂CO₃ ⇌ HCO₃⁻ + H⁺ (via Carbonic Anhydrase in RBCs)'], ] co2t = Table(co2_tbl, colWidths=[130, 40, 280]) co2t.setStyle(TableStyle([ ('BACKGROUND', (0,0), (-1,0), DARK_BLUE), ('TEXTCOLOR', (0,0), (-1,0), white), ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'), ('FONTSIZE', (0,0), (-1,-1), 9), ('ROWBACKGROUNDS', (0,1), (-1,-1), [white, LIGHT_GREY]), ('GRID', (0,0), (-1,-1), 0.5, HexColor('#e2e8f0')), ('TOPPADDING', (0,0), (-1,-1), 5), ('BOTTOMPADDING', (0,0), (-1,-1), 5), ])) story.append(co2t) story.append(spacer(6)) story.append(callout('<b>Chloride Shift (Hamburger Shift):</b> At tissues → HCO₃⁻ exits RBC → Cl⁻ enters RBC (maintains electrical neutrality). Reversed at lungs.', bg=LIGHT_GREEN, border=GREEN)) story.append(spacer(4)) story.append(callout('<b>Bohr Effect (tissue level):</b> ↑CO₂ → ↑H⁺ → ↓O₂ affinity of Hb → O₂ unloaded to tissues. BENEFICIAL.', bg=LIGHT_ORANGE, border=ORANGE)) story.append(spacer(4)) story.append(callout('<b>Haldane Effect (lung level):</b> O₂ binding to Hb → Hb releases CO₂ → promotes CO₂ removal at lungs.', bg=LIGHT_PURPLE, border=PURPLE)) story.append(spacer(4)) story.append(callout('<b>2,3-BPG:</b> Produced by RBCs (glycolysis, no mitochondria). Binds Hb → ↓O₂ affinity → right shift. Important in anaemia and high altitude adaptation.', bg=LIGHT_BLUE, border=BLUE)) # ===================== REVISION SUMMARY ===================== story.append(spacer(14)) rev_d = Drawing(460, 40) rev_d.add(Rect(0, 0, 460, 40, fillColor=DARK_BLUE, rx=10, strokeColor=None)) rev_d.add(String(230, 15, '⚡ RAPID REVISION SUMMARY', fontSize=18, fontName='Helvetica-Bold', fillColor=white, textAnchor='middle')) story.append(rev_d) story.append(spacer(8)) rev_cards = [ ('Pulmonary Circulation', ['5-6 L blood, low pressure, compliant', 'Functions: gas exchange, BP reg, filter emboli', 'HPV: ↓PO₂ → vasoconstriction', 'Phys shunt: thebesian + bronchial veins', 'Pathol: VSD, ASD, PDA']), ("West's Zones", ['Zone 1 (apex): Palv > Part = no flow', 'Zone 2 (mid): Part > Palv = normal flow', 'Zone 3 (base): max blood flow', 'V/Q: 0.8 (normal), 0.7 (base)', 'Blood flow ↑ apex → base (gravity)']), ('Ventilation & Dead Space', ['Min vent = RR×TV = 7.5 L/min', 'Dead space = 150 mL', 'Alveolar vent = 4.2 L/min', 'V/Q normal = 0.8; Asthma = 0.4', 'Alv dead space = unperfused alveoli']), ('DVT & PE', ['DVT = clot in deep veins', 'Risks: flights, surgery, OCP', 'PE = medical emergency', 'Treat: thrombolytics (streptokinase)', 'Surgery: thrombectomy']), ('Partial Pressures', ['Alveolus: PO₂=100, PCO₂=40 mmHg', 'Cap before: PO₂=40, PCO₂=46', "Dalton's Law: sum of partial pressures", 'Diffusion: ↑P → ↓P direction', 'Resp membrane = 0.5 µm']), ("Fick's Law", ['↑ΔP gradient → ↑diffusion', '↑SA → ↑diffusion', '↑solubility / ↓mol wt → ↑diffusion', '↓membrane thickness → ↑diffusion', 'CO₂: 24× more soluble than O₂']), ('O₂ Transport', ['98.5% Hb-bound; 1.5% dissolved', '1g Hb = 1.34 mL O₂', 'Total O₂ = 20.4 mL/dL', 'Sigmoid Hb-O₂ curve', 'Right shift: ↑CO₂,↑T,↓pH,2,3-BPG']), ('CO₂ Transport', ['70% as HCO₃⁻', '23% as HbCO₂', '7% dissolved', 'Chloride shift in RBCs', 'Bohr effect (tissue); Haldane (lung)']), ] for i in range(0, len(rev_cards), 2): row = rev_cards[i:i+2] row_tables = [] for title, points in row: inner = [[Paragraph(f'<b><font color=\"#ffffff\">{title}</font></b>', ParagraphStyle('rt', fontSize=10, fontName='Helvetica-Bold', textColor=white, leading=14))]] for pt in points: inner.append([Paragraph(f'→ {pt}', ParagraphStyle('rp', fontSize=8.5, textColor=HexColor('#dbeafe'), leading=12, leftIndent=4))]) t = Table(inner, colWidths=[210]) t.setStyle(TableStyle([ ('BACKGROUND', (0,0), (0,0), DARK_BLUE), ('BACKGROUND', (0,1), (0,-1), BLUE), ('TOPPADDING', (0,0), (0,-1), 4), ('BOTTOMPADDING', (0,0), (0,-1), 4), ('LEFTPADDING', (0,0), (0,-1), 8), ('RIGHTPADDING', (0,0), (0,-1), 4), ])) row_tables.append(t) if len(row_tables) == 2: combined = Table([[row_tables[0], row_tables[1]]], colWidths=[225, 225]) combined.setStyle(TableStyle([ ('LEFTPADDING', (0,0), (-1,-1), 4), ('RIGHTPADDING', (0,0), (-1,-1), 4), ('TOPPADDING', (0,0), (-1,-1), 4), ('BOTTOMPADDING', (0,0), (-1,-1), 4), ])) else: combined = Table([[row_tables[0]]], colWidths=[225]) combined.setStyle(TableStyle([('LEFTPADDING', (0,0), (0,0), 4)])) story.append(combined) story.append(spacer(6)) # ===================== MASTER FLOWCHART ===================== story.append(spacer(14)) fc_d = Drawing(460, 60) fc_d.add(Rect(0, 0, 460, 60, fillColor=GREEN, rx=10, strokeColor=None)) fc_d.add(String(230, 25, 'MASTER FLOWCHART: O₂ Journey from Air to Cell', fontSize=15, fontName='Helvetica-Bold', fillColor=white, textAnchor='middle')) story.append(fc_d) story.append(spacer(10)) # Flowchart as table flow_steps = [ ('1', 'ATMOSPHERE', 'PO₂ = 160 mmHg | PCO₂ ≈ 0', HexColor('#f0f9ff'), TEAL), ('↓', 'Inhalation', '', white, GREY), ('2', 'ALVEOLUS', 'PO₂ = 100 mmHg | PCO₂ = 40 mmHg | Surfactant keeps alveoli open', LIGHT_BLUE, BLUE), ('↓', 'Diffusion (Fick\'s Law)', '0.5 µm respiratory membrane | ↑PO₂ → O₂ enters blood | ↑PCO₂ → CO₂ exits blood', white, GREY), ('3', 'PULMONARY CAPILLARY', 'PO₂: 40 → 100 mmHg | PCO₂: 46 → 40 mmHg | O₂ loaded onto Hb | CO₂ released to alveolus', YELLOW_BG, YELLOW), ('↓', 'Via Pulmonary Veins', 'Oxygenated blood returns to left heart', white, GREY), ('4', 'LEFT HEART → AORTA', 'Oxygenated blood pumped to systemic circulation', LIGHT_RED, RED), ('↓', 'Systemic arteries', 'O₂-rich blood to all organs', white, GREY), ('5', 'SYSTEMIC CAPILLARY', 'PO₂: 100 → 40 mmHg | O₂ unloaded (Bohr effect) | CO₂ enters blood from tissues', LIGHT_GREEN, GREEN), ('↓', 'CO₂ transport', '70% HCO₃⁻ | 23% HbCO₂ | 7% dissolved | Chloride shift in RBCs', white, GREY), ('6', 'CELL (Mitochondria)', 'PO₂ = 40 mmHg | O₂ + Glucose → ATP + CO₂ + H₂O | Cellular respiration', LIGHT_PURPLE, PURPLE), ('↓', 'Venous return', 'Via systemic veins → right heart → pulmonary artery → cycle repeats', white, GREY), ] for num, title, detail, bg, border in flow_steps: if num == '↓': arr_tbl = Table([[Paragraph(f'<font color=\"#64748b\">↓ {title}</font>', ParagraphStyle('a', fontSize=9, fontName='Helvetica', textColor=GREY, leading=12)), Paragraph(f'<font color=\"#94a3b8\">{detail}</font>', ParagraphStyle('ad', fontSize=8, fontName='Helvetica', textColor=GREY, leading=12))]], colWidths=[150, 300]) arr_tbl.setStyle(TableStyle([ ('TOPPADDING', (0,0), (-1,-1), 2), ('BOTTOMPADDING', (0,0), (-1,-1), 2), ('LEFTPADDING', (0,0), (-1,-1), 20), ])) story.append(arr_tbl) else: step_inner = [[ Paragraph(f'<b><font size=\"14\">{num}</font></b>', ParagraphStyle('sn', fontSize=14, fontName='Helvetica-Bold', textColor=white, leading=18, alignment=1)), Paragraph(f'<b>{title}</b>', ParagraphStyle('st', fontSize=11, fontName='Helvetica-Bold', textColor=DARK_BLUE, leading=14)), Paragraph(detail, ParagraphStyle('sd', fontSize=8.5, fontName='Helvetica', textColor=HexColor('#374151'), leading=13)), ]] step_t = Table(step_inner, colWidths=[30, 140, 270]) step_t.setStyle(TableStyle([ ('BACKGROUND', (0,0), (0,0), border), ('BACKGROUND', (1,0), (-1,0), bg), ('LINEBELOW', (0,0), (-1,0), 1, border), ('TOPPADDING', (0,0), (-1,-1), 7), ('BOTTOMPADDING', (0,0), (-1,-1), 7), ('LEFTPADDING', (0,0), (-1,-1), 8), ('RIGHTPADDING', (0,0), (-1,-1), 8), ('VALIGN', (0,0), (-1,-1), 'MIDDLE'), ])) story.append(step_t) story.append(spacer(16)) footer_d = Drawing(460, 25) footer_d.add(Rect(0, 0, 460, 25, fillColor=LIGHT_GREY, rx=8, strokeColor=None)) footer_d.add(String(230, 8, 'Pulmonary Respiration Study Notes · Medical Physiology · For Revision Use', fontSize=8, fillColor=GREY, textAnchor='middle')) story.append(footer_d) doc.build(story) print('PDF successfully created!') import os size = os.path.getsize('pulmonary_notes.pdf') print(f'File size: {size/1024:.1f} KB') "

This is a shared conversation. Sign in to Orris to start your own chat.