#!/usr/bin/env python3
"""
Week 3: Comparing & Ordering Numbers
Phase 1: Number Sense & Operations

Curriculum: Comparing numbers using >, <, =; ordering numbers; number line position
Standard: 2.NBT.A.4 — Compare two three-digit numbers based on meanings of the hundreds, tens, and ones digits.

New Standard (7 principles):
1. Reduced drill (4-6 problems per section, "reduced from" noted)
2. Estimation before calculating (more/less than benchmark — Tue, Fri)
3. Multiple strategies (show two ways to compare — Mon, Wed)
4. Better word problems (reasoning over keywords — Wed, Thu, Fri)
5. Create Your Own open-ended challenge (Wed, Thu)
6. Number Talks — explain WITHOUT calculating (Mon, Thu)
7. Friday self-check with emoji + "One thing I learned"
"""

import os
import glob
from weasyprint import HTML

from math_helpers import (
    CSS, TEACHER_CSS,
    page, page_multi, hdr, sec, b, bw, bl,
    tg_page_multi, tg_sec, tg_note, tg_section_title,
)

BASE = os.path.expanduser("~/Home_School/2nd_Grade/Math")
WEEK = os.path.join(BASE, "Week_3")


# ═══════════════════════════════════════════════════
# MONDAY — Comparing Numbers with <, >, =
# ═══════════════════════════════════════════════════
def monday():
    # 1: Fluency warmup — which is bigger?
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Which number is bigger?</p>'\
         '<div class="mgrid c4">'
    for a, c in [(14, 19), (27, 23), (8, 31), (45, 45)]:
        s1 += f'<div class="abox"><p>{a}  __  {c}</p><p style="font-size:11px;">Write &gt; &lt; or =</p></div>'
    s1 += '</div></div>'

    # 2: Comparing with place value reasoning
    s2 = '<p class="note">Look at the tens first. If tens are the same, look at the ones.</p>'\
         '<div class="mgrid c2">'
    comparisons = [
        (34, 43, "4 tens &gt; 3 tens, so 43 is bigger"),
        (56, 52, "Same tens (5), 6 ones &gt; 2 ones, so 56 is bigger"),
        (71, 17, "7 tens &gt; 1 ten, so 71 is bigger"),
        (89, 98, "9 tens &gt; 8 tens, so 98 is bigger"),
    ]
    for a, c, _ in comparisons:
        s2 += f'<div class="abox"><p style="font-size:1.2em; text-align:center;"><b>{a}  {b("2em")}  {c}</b></p>'\
              f'<p style="font-size:11px; color:#666;">Why: {bw()}</p></div>'
    s2 += '</div>'

    # 3: Alligator mouth — visual comparison (reduced from 8 to 4)
    s3 = '<p class="note">The alligator always eats the bigger number! Draw &gt; or &lt; between each pair.</p>'\
         '<div class="mgrid c2">'
    for a, c in [(62, 26), (48, 51), (33, 33), (90, 9)]:
        s3 += f'<div class="abox"><p style="text-align:center; font-size:1.3em;"><b>{a}  🐊  {c}</b></p>'\
              f'<p style="text-align:center; font-size:11px; color:#666;">{a} {b("2em")} {c}</p></div>'
    s3 += '</div>'

    # 4: Number Talk — explain WITHOUT calculating
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT writing the answer.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>Is 57 bigger than 52?</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>Is 4 tens and 8 ones bigger than 5 tens?</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Challenge — show two ways to compare
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Challenge</b> — Show two different ways to prove which is bigger.</p>'\
         '<p style="font-size:11px; color:#666;">Try: (1) look at place value, (2) use a number line, or (3) count on.</p>'\
         '<div class="abox"><p style="text-align:center; font-size:1.3em;"><b>68  vs  72</b></p>'\
         '<p style="font-size:11px; color:#666;">Way 1 (place value): ' + bw() + '</p>'\
         '<p style="font-size:11px; color:#666;">Way 2 (number line): ' + bw() + '</p></div>'\
         '</div>'

    return page(3, "Monday", "Comparing Numbers",
        f'''{sec(1, "Warm-up: Which is Bigger?", s1)}
{sec(2, "Compare with Place Value", s2)}
{sec(3, "Alligator Mouth!", s3)}
{sec(4, "Number Talk: Explain Without Writing", s4)}
{sec(5, "Challenge: Show Two Ways", s5)}''')


# ═══════════════════════════════════════════════════
# TUESDAY — Ordering Numbers (Least to Greatest)
# ═══════════════════════════════════════════════════
def tuesday():
    # 1: Fluency warmup — number order
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Put in order from LEAST to GREATEST.</p>'\
         '<div class="mgrid c2">'
    sets = [
        [12, 25, 8],
        [43, 34, 53],
    ]
    for i, nums in enumerate(sets):
        s1 += f'<div class="abox"><p style="font-size:1.2em; text-align:center;">{", ".join(map(str, nums))}</p>'\
              f'<p style="text-align:center;">{b("6em")}, {b("6em")}, {b("6em")}</p></div>'
    s1 += '</div></div>'

    # 2: Ordering sets of 4 (reduced from 6 to 4)
    s2 = '<p class="note">Look at the tens first! Then the ones. Order from LEAST to GREATEST.</p>'\
         '<div class="mgrid c2">'
    sets = [
        [34, 43, 33, 44],
        [57, 75, 56, 65],
        [29, 92, 22, 20],
        [81, 18, 80, 10],
    ]
    for nums in sets:
        boxes = ', '.join([b('4em') for _ in nums])
        s2 += f'<div class="abox"><p style="text-align:center;">{", ".join(map(str, nums))}</p>'\
              f'<p style="text-align:center;">{boxes}</p></div>'
    s2 += '</div>'

    # 3: Estimate First — bigger or smaller than 50?
    s3 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> BEFORE ordering, circle each number: is it MORE or LESS than 50?</p>'\
         '<p style="font-size:11px;">Now put them in order: {", ".join(map(str, [38, 62, 47, 55, 71]))}</p>'\
         '<p style="text-align:center; margin-top:4px;">' + ', '.join([b('4em') for _ in range(5)]) + '</p></div>'

    # 4: Number line ordering
    s4 = '<p class="note">Draw a number line from 0 to 100. Plot each number, then write them in order.</p>'\
         '<div class="abox"><p>Numbers: 23, 67, 45, 12, 89</p>'\
         '<div class="draw-box" style="min-height:60px;"></div>'\
         '<p style="text-align:center; margin-top:6px;">' + ', '.join([b('4em') for _ in range(5)]) + '</p></div>'

    # 5: Missing numbers in a sequence
    s5 = '<p class="note">Fill in the missing numbers to complete the sequence.</p>'\
         '<div class="mgrid c2">'
    sequences = [
        ["10", "15", b("3em"), "25", "30"],
        ["50", b("3em"), "55", b("3em"), "60"],
        ["22", "24", b("3em"), "28", "30"],
        [b("3em"), "41", "43", b("3em"), "47"],
    ]
    for seq in sequences:
        s5 += f'<div class="abox"><p style="font-size:1.2em; text-align:center;">{", ".join(seq)}</p></div>'
    s5 += '</div>'

    return page(3, "Tuesday", "Ordering Numbers",
        f'''{sec(1, "Warm-up: Put in Order", s1)}
{sec(2, "Order Sets of 4", s2)}
{sec(3, "Estimate First: More or Less Than 50?", s3)}
{sec(4, "Number Line Ordering", s4)}
{sec(5, "Fill in the Missing Numbers", s5)}''')


# ═══════════════════════════════════════════════════
# WEDNESDAY — Comparing Word Problems
# ═══════════════════════════════════════════════════
def wednesday():
    # 1: Fluency warmup — quick compare
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Write &gt;, &lt;, or =</p>'\
         '<div class="mgrid c4">'
    for a, c in [(15, 51), (72, 72), (39, 93), (86, 68)]:
        s1 += f'<div class="abox"><p>{a} {b("2em")} {c}</p></div>'
    s1 += '</div></div>'

    # 2: Comparison word problems — reasoning about situations
    s2 = '<div class="wp">'\
         '<p class="note">Read carefully. Think about what is happening. Who or what has more? Explain why.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("Tom has 43 marbles. Sara has 34 marbles. Who has more? How many more?", ""),
        ("The blue ribbon is 68 cm long. The red ribbon is 86 cm long. Which ribbon is longer? By how much?", ""),
    ]
    for text, _ in problems:
        s2 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p style="font-size:11px;">My thinking: ' + bw() + '</p>'\
              '<p>' + bl() + '</p></div>'
    s2 += '</div></div>'

    # 3: Three-way comparison
    s3 = '<p class="note">Compare all three numbers. Circle the greatest, put a box around the least, and put a star by the one in the middle.</p>'\
         '<div class="mgrid c2">'
    groups = [
        [54, 45, 55],
        [73, 37, 73],
    ]
    for nums in groups:
        s3 += f'<div class="abox"><p style="font-size:1.3em; text-align:center;"><b>{nums[0]}  |  {nums[1]}  |  {nums[2]}</b></p>'\
              '<p style="text-align:center;">Greatest: {b("4em")}  |  Middle: {b("4em")}  |  Least: {b("4em")}</p></div>'
    s3 += '</div>'

    # 4: Find the error
    s4 = '<div class="abox">'\
         '<p class="note">Someone says "29 is bigger than 31 because 9 is bigger than 1." Is that person right? Explain.</p>'\
         '<p>Right or Wrong? {b("4em")}</p>'\
         '<p style="font-size:11px;">My explanation: ' + bw() + '</p>'\
         '<p style="font-size:11px;">The correct comparison: ' + b('8em') + '</p></div>'

    # 5: Challenge — Create your own comparison problem
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own</b></p>'\
         '<p>Write a word problem that compares two numbers. Include a trick that might confuse someone (like the 29 vs 31 example). Then solve it.</p>'\
         '<p style="min-height:50px; border-bottom:1px solid #333;"></p>'\
         '<p style="font-size:11px;">My solution: ' + bw() + '</p>'\
         '</div>'

    return page(3, "Wednesday", "Comparing Word Problems",
        f'''{sec(1, "Warm-up: Quick Compare", s1)}
{sec(2, "Word Problems: Who Has More?", s2)}
{sec(3, "Three-Way Comparison", s3)}
{sec(4, "Find the Error", s4)}
{sec(5, "Challenge: Create Your Own", s5)}''')


# ═══════════════════════════════════════════════════
# THURSDAY — Place Value & Comparing
# ═══════════════════════════════════════════════════
def thursday():
    # 1: Fluency warmup — compare using place value
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Compare: &gt;, &lt;, or =</p>'\
         '<div class="mgrid c4">'
    for a, c in [(63, 36), (47, 57), (90, 9), (82, 82)]:
        s1 += f'<div class="abox"><p>{a} {b("2em")} {c}</p></div>'
    s1 += '</div></div>'

    # 2: Build the biggest/smallest number
    s2 = '<p class="note">Use these digits to make the biggest and smallest two-digit numbers. You can use each digit only once per number.</p>'\
         '<div class="mgrid c2">'
    digit_sets = [
        [3, 7],
        [5, 1, 8],
        [4, 9, 2],
        [6, 0],
    ]
    for digits in digit_sets:
        s2 += f'<div class="abox"><p>Digits: <b>{", ".join(map(str, digits))}</b></p>'\
              '<p>Biggest: ' + b("4em") + '</p>'\
              '<p>Smallest: ' + b("4em") + '</p></div>'
    s2 += '</div>'

    # 3: Mystery number — ordering clues
    s3 = '<p class="note">Read the clues. What number am I thinking of?</p>'\
         '<div class="abox">'\
         '<p>Clue 1: I am between 40 and 50.</p>'\
         '<p>Clue 2: My tens digit is 4.</p>'\
         '<p>Clue 3: My ones digit is bigger than 6.</p>'\
         '<p>Clue 4: I am an even number.</p>'\
         '<p style="font-size:11px;">My thinking: ' + bw() + '</p>'\
         '<p>My number is: ' + b("4em") + '</p></div>'

    # 4: Number Talk — compare WITHOUT calculating
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT writing the numbers.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>Is "6 tens and 3 ones" bigger than "3 tens and 6 ones"?</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>Is 59 closer to 50 or 60? How do you know?</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Create your own mystery number
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own Mystery Number</b></p>'\
         '<p>Think of a number. Write 3 clues about it (use comparison words like "bigger than," "less than," "between"). A classmate tries to guess!</p>'\
         '<p style="font-size:11px;">My secret number: _____ (don\'t show anyone!)</p>'\
         '<p>Clue 1: ' + bl() + '</p>'\
         '<p>Clue 2: ' + bl() + '</p>'\
         '<p>Clue 3: ' + bl() + '</p>'\
         '</div>'

    return page(3, "Thursday", "Place Value & Comparing",
        f'''{sec(1, "Warm-up: Compare with Place Value", s1)}
{sec(2, "Build the Biggest and Smallest", s2)}
{sec(3, "Mystery Number Clues", s3)}
{sec(4, "Number Talk: Compare Without Writing", s4)}
{sec(5, "Challenge: Create Your Own Mystery", s5)}''')


# ═══════════════════════════════════════════════════
# FRIDAY — Review & Self-Check
# ═══════════════════════════════════════════════════
def friday():
    # 1: Fluency warmup — rapid compare
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Go fast! Write &gt;, &lt;, or =</p>'\
         '<div class="mgrid c4">'
    for a, c in [(38, 83), (71, 17), (44, 44), (95, 59)]:
        s1 += f'<div class="abox"><p>{a} {b("2em")} {c}</p></div>'
    s1 += '</div></div>'

    # 2: Estimate First — bigger or smaller than 50?
    s2 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Circle: is it MORE or LESS than 50? Then compare the pair.</p>'\
         '<div class="mgrid c2">'
    for a, c in [(47, 53), (61, 39), (50, 50), (48, 52)]:
        s2 += f'<div class="abox"><p><b>{a}  vs  {c}</b></p>'\
              f'<p>{a}: more than 50 / less than 50</p>'\
              f'<p>{c}: more than 50 / less than 50</p>'\
              f'<p>{a} {b("2em")} {c}</p></div>'
    s2 += '</div></div>'

    # 3: Ordering review (reduced from 10 to 6 problems total)
    s3 = '<p class="note">Order from LEAST to GREATEST.</p>'\
         '<div class="mgrid c2">'
    sets = [
        [18, 81, 10, 80],
        [56, 65, 55, 66],
    ]
    for nums in sets:
        boxes = ', '.join([b('4em') for _ in nums])
        s3 += f'<div class="abox"><p style="text-align:center;">{", ".join(map(str, nums))}</p>'\
              f'<p style="text-align:center;">{boxes}</p></div>'
    s3 += '</div>'

    # 4: Word problem review
    s4 = '<div class="wp">'\
         '<p class="note">Read carefully. Show your work.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("Jake scored 78 points in a game. Emma scored 87 points. Who scored more? By how many?", ""),
        ("There were 45 students on Monday and 54 students on Tuesday. Which day had more students? How many more?", ""),
    ]
    for text, _ in problems:
        s4 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p style="font-size:11px;">My thinking: ' + bw() + '</p>'\
              '<p>' + bl() + '</p></div>'
    s4 += '</div></div>'

    # 5: Mixed comparison
    s5a = '<p class="note">Fill in &gt;, &lt;, or = for each pair.</p>'\
          '<div class="mgrid c3">'
    pairs = [(32, 23), (67, 76), (50, 50), (91, 19), (48, 84), (10, 100)]
    for a, c in pairs:
        s5a += f'<div class="abox"><p style="text-align:center; font-size:1.1em;">{a} {b("2em")} {c}</p></div>'
    s5a += '</div>'

    # 6: Self-check with emoji reflection
    s5b = '<div class="selfcheck">'\
          '<p><b>Self-Check: How do you feel about comparing and ordering numbers?</b></p>'\
          '<div style="display:flex; gap:20px; flex-wrap:wrap;">'\
          '<div style="background:#fff3e0; padding:10px; border-radius:5px; flex:1; min-width:150px;">'\
          '<p><b>Comparing with &gt; &lt; =</b></p>'\
          '<p>😊 I got it!  |  😐 Getting there  |  😟 Need help</p>'\
          '</div>'\
          '<div style="background:#e3f2fd; padding:10px; border-radius:5px; flex:1; min-width:150px;">'\
          '<p><b>Ordering Least to Greatest</b></p>'\
          '<p>😊 I got it!  |  😐 Getting there  |  😟 Need help</p>'\
          '</div>'\
          '<div style="background:#f3e5f5; padding:10px; border-radius:5px; flex:1; min-width:150px;">'\
          '<p><b>Place Value Comparing</b></p>'\
          '<p>😊 I got it!  |  😐 Getting there  |  😟 Need help</p>'\
          '</div>'\
          '</div>'\
          '<p style="margin-top:10px;"><b>One thing I learned this week:</b> ' + bl() + '</p>'\
          '<p><b>One thing I want to practice more:</b> ' + bl() + '</p>'\
          '<p><b>My trick for remembering which way the alligator faces:</b> ' + bl() + '</p>'\
          '</div>'

    return page(3, "Friday", "Week 3 Review & Self-Check",
        f'''{sec(1, "Warm-up: Rapid Compare", s1)}
{sec(2, "Estimate First: More or Less Than 50?", s2)}
{sec(3, "Ordering Review", s3)}
{sec(4, "Word Problems", s4)}
{sec(5, "Mixed Comparison", s5a)}
{sec(6, "Self-Check & Reflection", s5b)}''')


# ═══════════════════════════════════════════════════
# TEACHER GUIDE — Combined for all days
# ═══════════════════════════════════════════════════
def teacher_guide():
    """Generate combined teacher guide for all 5 days."""
    return tg_page_multi(
        "Week 3", "Comparing & Ordering Numbers — Teacher Guide",

        # Monday
        tg_section_title("Monday: Comparing Numbers with <, >, =") +
        tg_sec(1, "Warm-up", ["> (19>14), < (23<27), < (8<31), = (45=45)"]) +
        tg_sec(2, "Place Value Compare", [
            "34 < 43 (4 tens > 3 tens)",
            "56 > 52 (same tens, 6 ones > 2 ones)",
            "71 > 17 (7 tens > 1 ten)",
            "89 < 98 (9 tens > 8 tens)",
        ]) +
        tg_sec(3, "Alligator", [
            "62 > 26, 48 < 51, 33 = 33, 90 > 9",
        ]) +
        tg_sec(4, "Number Talk", [
            "Yes, 57 > 52 (same tens, 7 ones > 2 ones)",
            "No, 4 tens + 8 ones = 48, which is less than 5 tens = 50",
        ]) +
        tg_sec(5, "Challenge", [
            "72 > 68 (7 tens > 6 tens; also 72 is to the right of 68 on number line)",
        ]) +
        tg_note("Page break"),

        # Tuesday
        tg_section_title("Tuesday: Ordering Numbers") +
        tg_sec(1, "Warm-up", [
            "8, 12, 25 | 34, 43, 53",
        ]) +
        tg_sec(2, "Order Sets of 4", [
            "33, 34, 43, 44 | 56, 57, 65, 75 | 20, 22, 29, 92 | 10, 18, 80, 81",
        ]) +
        tg_sec(3, "Estimate First", [
            "38<50, 62>50, 47<50, 55>50, 71>50 | Order: 38, 47, 50, 55, 62, 71",
        ]) +
        tg_sec(4, "Number Line", [
            "Order: 12, 23, 45, 67, 89",
        ]) +
        tg_sec(5, "Missing Numbers", [
            "10, 15, 20, 25, 30 | 50, 52, 55, 57, 60 | 22, 24, 26, 28, 30 | 39, 41, 43, 45, 47",
        ]) +
        tg_note("Page break"),

        # Wednesday
        tg_section_title("Wednesday: Comparing Word Problems") +
        tg_sec(1, "Warm-up", [
            "15 < 51, 72 = 72, 39 < 93, 86 > 68",
        ]) +
        tg_sec(2, "Word Problems", [
            "Tom has more (43 > 34). 43 - 34 = 9 more marbles",
            "Red ribbon is longer (86 > 68). 86 - 68 = 18 cm longer",
        ]) +
        tg_sec(3, "Three-Way", [
            "55 greatest, 54 middle, 45 least | 73 greatest (tie), 73 middle, 37 least",
        ]) +
        tg_sec(4, "Find the Error", [
            "WRONG — you look at tens first. 3 tens > 2 tens, so 31 > 29",
        ]) +
        tg_sec(5, "Create Own", [
            "Accept student-created comparison problems with tricky elements",
        ]) +
        tg_note("Page break"),

        # Thursday
        tg_section_title("Thursday: Place Value & Comparing") +
        tg_sec(1, "Warm-up", [
            "63 > 36, 47 < 57, 90 > 9, 82 = 82",
        ]) +
        tg_sec(2, "Biggest/Smallest", [
            "3,7 → biggest 73, smallest 37 | 5,1,8 → biggest 851, smallest 158",
            "4,9,2 → biggest 942, smallest 249 | 6,0 → biggest 60, smallest 06(6)",
        ]) +
        tg_sec(3, "Mystery Number", [
            "Between 40-50, tens=4, ones>6, even → 48",
        ]) +
        tg_sec(4, "Number Talk", [
            "Yes — 6 tens + 3 ones = 63 > 3 tens + 6 ones = 36 (more tens)",
            "59 is closer to 60 (only 1 away vs 9 away from 50)",
        ]) +
        tg_sec(5, "Create Mystery", [
            "Accept student-created mystery number riddles",
        ]) +
        tg_note("Page break"),

        # Friday
        tg_section_title("Friday: Review & Self-Check") +
        tg_sec(1, "Warm-up", [
            "38 < 83, 71 > 17, 44 = 44, 95 > 59",
        ]) +
        tg_sec(2, "Estimate First", [
            "47<50, 53>50, 47<53 | 61>50, 39<50, 61>39 | 50=50, 50=50 | 48<50, 52>50, 48<52",
        ]) +
        tg_sec(3, "Ordering Review", [
            "10, 18, 80, 81 | 55, 56, 65, 66",
        ]) +
        tg_sec(4, "Word Problems", [
            "Emma scored more (87 > 78). 87 - 78 = 9 more points",
            "Tuesday had more (54 > 45). 54 - 45 = 9 more students",
        ]) +
        tg_sec(5, "Mixed Comparison", [
            "32 > 23, 67 < 76, 50 = 50, 91 > 19, 48 < 84, 10 < 100",
        ]) +
        tg_sec(6, "Self-Check", [
            "Accept student self-assessment and reflection",
        ]),
    )


# ═══════════════════════════════════════════════════
# GENERATE
# ═══════════════════════════════════════════════════
if __name__ == "__main__":
    os.makedirs(WEEK, exist_ok=True)
    for f in glob.glob(os.path.join(WEEK, "*.pdf")):
        os.remove(f)
    for f in glob.glob(os.path.join(WEEK, "*.html")):
        os.remove(f)

    days = [
        (monday, "Monday", "Comparing Numbers"),
        (tuesday, "Tuesday", "Ordering Numbers"),
        (wednesday, "Wednesday", "Comparing Word Problems"),
        (thursday, "Thursday", "Place Value & Comparing"),
        (friday, "Friday", "Week 3 Review & Self-Check"),
    ]

    for lesson_func, day, title in days:
        html = lesson_func()
        fname = f"Week_3_{day}"
        path = os.path.join(WEEK, f"{fname}.html")
        with open(path, "w") as f:
            f.write(html)
        pdf_path = os.path.join(WEEK, f"{fname}.pdf")
        HTML(filename=path).write_pdf(pdf_path)
        print(f"Generated: {pdf_path}")

    html = teacher_guide()
    path = os.path.join(WEEK, "Week_3_Teacher_Guide.html")
    with open(path, "w") as f:
        f.write(html)
    pdf_path = os.path.join(WEEK, "Week_3_Teacher_Guide.pdf")
    HTML(filename=path).write_pdf(pdf_path)
    print(f"Generated: {pdf_path}")

    print("\nWeek 3 (Comparing & Ordering Numbers) complete!")
