#!/usr/bin/env python3
"""
Week 10: Subtraction with Regrouping — REWRITTEN
Phase 2: Addition & Subtraction to 100

New Standard:
- Reduced drill (40% fewer problems)
- Estimation before calculating
- Multiple strategies encouraged (take-away, counting up, decomposition)
- Better word problems (reasoning over keywords)
- Real challenges (open-ended thinking)
- Number talks (compare without calculating)
- Friday self-check with reflection
- Mental math ±10 woven throughout (2.NBT.B.8)
- Unknowns in equations
- Word problems every day
- Fact fluency warmup daily
"""

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, tg_page_multi, tg_sec, tg_note, tg_section_title,
    col_sub, col_sub_inline,
)
from activity_builders import (
    build_column_subtraction,
    build_regrouping_visual,
    build_two_step_problems,
)

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


# ═══════════════════════════════════════════════════
# MONDAY — Introduction to Subtraction Regrouping
# ═══════════════════════════════════════════════════
def monday():
    # 1: Fluency warmup — Mental math ±10 (2.NBT.B.8)
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Subtract 10 in your head.</p>'\
         '<div class="mgrid c3">'
    for n in [35, 68, 92, 54]:
        s1 += f'<div class="abox"><p>{n} − 10 = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Visual regrouping — "Break a ten" concept
    s2 = '<p class="note">When you can\'t subtract the ones, break a ten: trade 1 ten for 10 ones.</p>'
    s2 += build_regrouping_visual({
        "problems": [(53, 17, "subtract"), (72, 28, "subtract")],
        "note": "Draw base-10 blocks. Show how you break a ten to subtract the ones."
    })

    # 3: Simple subtraction with regrouping (reduced from 6 to 4)
    s3 = '<p class="note">Can you subtract the ones? If not, break a ten!</p>'
    s3 += '<div class="mgrid c3">'
    for a, c in [(53, 17), (72, 28), (61, 24), (85, 37)]:
        s3 += f'<div class="abox"><p>{a} − {c} = {b("5em")}</p></div>'
    s3 += '</div>'

    # 4: NEW — Number Talk: Which is larger? Explain WITHOUT calculating
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT calculating.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>Which difference is bigger?</p><p>53 − 17  or  53 − 27</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>Which difference is bigger?</p><p>72 − 28  or  82 − 28</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Challenge — Show two ways to decompose
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Challenge</b> — Show two different ways to solve each problem.</p>'\
         '<p style="font-size:11px; color:#666;">Try: (1) breaking a ten with blocks, (2) counting up from the smaller number.</p>'\
         '<div class="mgrid c2">'
    for a, c in [(61, 24), (85, 37)]:
        s5 += f'<div class="abox"><p><b>{a} − {c} = </b>{b("5em")}</p>'\
              '<p style="font-size:11px; color:#666;">Strategy 1: ' + bw() + '</p>'\
              '<p style="font-size:11px; color:#666;">Strategy 2: ' + bw() + '</p></div>'
    s5 += '</div></div>'

    return page(10, "Monday", "Introduction to Subtraction Regrouping",
        f'''{sec(1, "Warm-up: Subtract 10 (Mental Math)", s1)}
{sec(2, "Visual: Break a Ten", s2)}
{sec(3, "Simple Regrouping", s3)}
{sec(4, "Number Talk: Which Difference is Bigger?", s4)}
{sec(5, "Challenge: Show Two Different Ways", s5)}''')


# ═══════════════════════════════════════════════════
# TUESDAY — Column Subtraction with Borrowing
# ═══════════════════════════════════════════════════
def tuesday():
    # 1: Fluency warmup — Add or subtract 10 (2.NBT.B.8)
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Mental math: add or subtract 10.</p>'\
         '<div class="mgrid c3">'
    for expr in [("43 + 10", 53), ("76 − 10", 66), ("52 + 10", 62), ("89 − 10", 79)]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Column subtraction with borrowing (reduced from 6 to 4)
    s2 = '<p class="note">If the ones aren\'t enough, borrow from the tens. Cross out the ten and write the new number above.</p>'
    s2 += build_column_subtraction({
        "problems": [(53, 17), (72, 28), (61, 24), (85, 37)],
        "digits": 2,
        "note": "Remember: crossing out the ten means it becomes one less!"
    })

    # 3: NEW — Estimation before calculating
    s3 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Round to tens, estimate the difference, then calculate.</p>'\
         '<div class="mgrid c2">'
    for a, c in [(53, 17), (72, 28), (61, 24), (85, 37)]:
        at = (a + 5) // 10 * 10
        ct = (c + 5) // 10 * 10
        s3 += f'<div class="abox"><p><b>{a} − {c}</b></p>'\
              f'<p>Round: {at} − {ct} = {at - ct}</p>'\
              f'<p>Estimate: {b("4em")}</p>'\
              f'<p>Actual: {b("4em")}</p></div>'
    s3 += '</div></div>'

    # 4: Unknowns in equations
    s4 = '<div class="abox">' \
         '<p class="note">Find the missing number. Think: what goes in the blank?</p>' \
         '<div class="mgrid c3">'
    for left, sub, res in [(60, None, 25), (None, 42, 32), (83, None, 56), (None, 31, 52)]:
        if left is None:
            s4 += f'<div class="abox"><p>{b("4em")} − {sub} = {res}</p></div>'
        else:
            s4 += f'<div class="abox"><p>{left} − {b("4em")} = {res}</p></div>'
    s4 += '</div></div>'

    # 5: Step-by-step regrouping explanation (reduced from 3 to 2)
    s5 = '<p class="note">Write each step. Show where you borrow.</p>'\
         '<div class="mgrid c2">'
    for a, c in [(53, 17), (72, 28)]:
        ao, at = a % 10, a // 10
        co, ct = c % 10, c // 10
        new_tens = at - 1
        new_ones = ao + 10
        s5 += f'<div class="abox"><p><b>{a} − {c}</b></p>'\
              f'<p>Ones: {ao} − {co}? Can\'t do it!</p>'\
              f'<p>Borrow: {a} = {new_tens} tens + {new_ones} ones</p>'\
              f'<p>Ones: {new_ones} − {co} = ' + b("3em") + '</p>'\
              f'<p>Tens: {new_tens} − {ct} = ' + b("3em") + '</p>'\
              '<p><b>Answer: </b>' + b("5em") + '</p></div>'
    s5 += '</div>'

    return page(10, "Tuesday", "Column Subtraction with Borrowing",
        f'''{sec(1, "Warm-up: ±10 Mental Math", s1)}
{sec(2, "Borrow from Tens", s2)}
{sec(3, "Estimate First!", s3)}
{sec(4, "Find the Missing Number", s4)}
{sec(5, "Step-by-Step Borrowing", s5)}''')


# ═══════════════════════════════════════════════════
# WEDNESDAY — Mixed Subtraction Regrouping
# ═══════════════════════════════════════════════════
def wednesday():
    # 1: Fluency warmup — ±10 and ±100 (2.NBT.B.8)
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Mental math.</p>'\
         '<div class="mgrid c3">'
    for expr in [("45 − 10", 35), ("63 + 10", 73), ("300 + 100", 400), ("500 − 100", 400)]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Mixed — some regroup, some don't (reduced from 6 to 4)
    s2 = '<p class="note">Look at the ones first. Will you need to regroup? Write <b>yes</b> or <b>no</b>.</p>'\
         '<div class="mgrid c3">'
    for a, c in [(68, 14), (63, 27), (85, 30), (91, 46)]:
        s2 += f'<div class="abox"><p>{a} − {c}: Regroup? <span class="bw">____</span></p>'\
              f'<p>{a} − {c} = {b("5em")}</p></div>'
    s2 += '</div>'

    # 3: Word problem — reasoning about situations
    s3 = '<div class="wp">'\
         '<p class="note">Think about what is happening. Draw a picture or write your thinking.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("A farmer had 72 apples in his orchard. A storm knocked down some branches, and 28 apples fell to the ground and were lost. How many good apples does the farmer still have?", "apples"),
        ("The school had 85 library books checked out. By Friday, 37 books had been returned. How many books are still checked out?", "books"),
    ]
    for text, unit in problems:
        s3 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
              '<p>' + b("6em") + f' {unit}</p></div>'
    s3 += '</div></div>'

    # 4: Find the error — regrouping mistakes (reduced from 3 to 2)
    s4 = '<div class="abox">' \
         '<p class="note">One of these has a borrowing error. Find it, explain the error, and fix it.</p>' \
         '<div class="mgrid c2">'
    # Wrong: 53-17 should be 36, not 44 (forgot to borrow)
    s4 += '<div class="abox"><p style="text-align:center;">  53</p><p style="text-align:center;">- 17</p><hr><p style="text-align:center;">  44</p><p>✓ or ✗?</p><p style="font-size:11px;">Explain the error: ' + bw() + '</p><p style="font-size:11px;">Correct answer: ' + b("4em") + '</p></div>'
    # Wrong: 82-35 should be 47, not 53
    s4 += '<div class="abox"><p style="text-align:center;">  82</p><p style="text-align:center;">- 35</p><hr><p style="text-align:center;">  53</p><p>✓ or ✗?</p><p style="font-size:11px;">Explain the error: ' + bw() + '</p><p style="font-size:11px;">Correct answer: ' + b("4em") + '</p></div>'
    s4 += '</div></div>'

    # 5: Challenge — Create your own subtraction with regrouping
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own</b></p>'\
         '<p>Make a subtraction problem that <b>needs regrouping</b>. Write it and solve it.</p>'\
         '<p style="text-align:center; font-size:1.3em; letter-spacing:3px;">  ' + b("3em") + '</p>'\
         '<p style="text-align:center; font-size:1.3em; letter-spacing:3px;">- ' + b("3em") + '</p>'\
         '<hr style="border:2px solid #333;">'\
         '<p style="text-align:center; font-size:1.3em; letter-spacing:3px;">  ' + b("4em") + '</p>'\
         '<p style="font-size:11px; color:#666;">Strategy I used: ' + bw() + '</p>'\
         '</div>'

    return page(10, "Wednesday", "Mixed Subtraction Regrouping",
        f'''{sec(1, "Warm-up: ±10 and ±100", s1)}
{sec(2, "Mixed: Does It Need Regrouping?", s2)}
{sec(3, "Word Problems", s3)}
{sec(4, "Find the Error", s4)}
{sec(5, "Challenge: Create Your Own", s5)}''')


# ═══════════════════════════════════════════════════
# THURSDAY — Word Problems with Subtraction Regrouping
# ═══════════════════════════════════════════════════
def thursday():
    # 1: Fluency warmup — Mental math ±10 (2.NBT.B.8)
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Solve in your head.</p>'\
         '<div class="mgrid c3">'
    for expr in [("56 − 10", 46), ("29 + 10", 39), ("74 − 10", 64), ("41 + 10", 51)]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Better word problems — reasoning, not keywords (reduced from 4 to 3)
    s2 = '<div class="wp">'\
         '<p class="note">Read carefully. Think about what is happening in the situation. Draw if it helps!</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("Lily started with 83 stickers in her collection book. She gave some to her best friend at recess. Now she has 56 stickers left. How many stickers did Lily give to her friend?", 83, 56, "stickers"),
        ("The playground had 74 children at lunch time. After lunch, some went back to class. Now there are 29 children on the playground. How many children went back to class?", 74, 29, "children"),
        ("A baker made 95 cupcakes for the school fair. By noon, 38 cupcakes were sold. How many cupcakes were left for the afternoon?", 95, 38, "cupcakes"),
    ]
    for text, a, c, unit in problems:
        s2 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
              '<p>' + b("6em") + f' {unit}</p></div>'
    s2 += '</div></div>'

    # 3: Two-step word problem (reduced from 3 to 1)
    s3 = '<div class="abox">' \
          '<p class="note">Solve step by step. Write each answer as you go.</p>' \
          + build_two_step_problems({
              "problems": [
                  {
                      "text": "Marcus had 68 marbles. He lost 27 marbles at the park. Then his dad gave him 15 more for his birthday. How many marbles does Marcus have now?",
                      "blanks": 2
                  }
              ],
              "note": "Solve each step carefully."
          }) + '</div>'

    # 4: NEW — Number Talk: Compare differences WITHOUT calculating
    s4 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT calculating.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p>A: 72 − 28</p><p>B: 82 − 38</p><p>Which difference is bigger, or are they the same?</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '<div class="abox"><p>A: 65 − 17</p><p>B: 65 − 27</p><p>Which difference is bigger, or are they the same?</p><p style="font-size:11px;">My thinking: ' + bw() + '</p></div>'
    s4 += '</div></div>'

    # 5: Create your own word problem (open-ended challenge)
    s5 = '<div class="abox" style="background:#f3e5f5;">'\
         '<p><b>Create Your Own Word Problem</b></p>'\
         '<p>Write a subtraction word problem about something you like (sports, animals, food, games, etc.). Make sure it needs regrouping. Then solve it.</p>'\
         '<p style="min-height:60px; border-bottom:1px solid #333;"></p>'\
         '<p style="min-height:30px; border-bottom:1px solid #333;"></p>'\
         '<p style="font-size:11px;">My thinking: ' + bw() + '</p>'\
         '<p>Answer: ' + bl() + '</p>'\
         '</div>'

    return page(10, "Thursday", "Word Problems with Subtraction Regrouping",
        f'''{sec(1, "Warm-up: ±10 Mental Math", s1)}
{sec(2, "Word Problems: Think About What Is Happening", s2)}
{sec(3, "Two-Step Problem", s3)}
{sec(4, "Number Talk: Compare Differences", s4)}
{sec(5, "Challenge: Create Your Own", s5)}''')


# ═══════════════════════════════════════════════════
# FRIDAY — Review & Self-Check
# ═══════════════════════════════════════════════════
def friday():
    # 1: Fluency warmup — ±10 and ±100 (2.NBT.B.8)
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Mental math. Go fast!</p>'\
         '<div class="mgrid c3">'
    for expr in [("83 − 10", 73), ("47 + 10", 57), ("200 + 100", 300), ("600 − 100", 500)]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Estimation warm-up (NEW — replaced timed quiz)
    s2 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Round to tens, estimate the difference, then solve.</p>'\
         '<div class="mgrid c2">'
    for a, c in [(63, 28), (91, 45), (74, 38), (82, 19)]:
        at = (a + 5) // 10 * 10
        ct = (c + 5) // 10 * 10
        s2 += f'<div class="abox"><p><b>{a} − {c}</b></p>'\
              f'<p>Estimate ({at} − {ct}): {b("4em")}</p>'\
              f'<p>Actual: {b("4em")}</p></div>'
    s2 += '</div></div>'

    # 3: Mixed column subtraction review (reduced from 6 to 4)
    s3 = '<p class="note">Use any strategy you prefer.</p>'
    s3 += build_column_subtraction({
        "problems": [(63, 28), (91, 45), (74, 38), (82, 19)],
        "digits": 2,
        "note": "Review: Column subtraction with regrouping."
    })

    # 4: Word problem review (reduced from 3 to 2)
    s4 = '<div class="wp">'\
         '<p class="note">Read carefully. Show your work.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("A garden had 68 flowers. After a big wind, 35 flowers fell over. How many flowers are still standing?", 68, 35, "flowers"),
        ("Mom had 93 cookies in the jar. The family ate 47 cookies for snacks. How many cookies are left in the jar?", 93, 47, "cookies"),
    ]
    for text, a, c, unit in problems:
        s4 += f'<div class="abox"><p style="font-size:0.95em;">{text}</p>'\
              '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
              '<p>' + b("6em") + f' {unit}</p></div>'
    s4 += '</div></div>'

    # 5: Even/odd concept + unknown equation
    s5a = '<div class="abox">' \
          '<p class="note">Is each answer <b>even</b> or <b>odd</b>? Write it.</p>' \
          '<div class="mgrid c3">'
    for a, c in [(63, 28), (91, 45), (74, 38)]:
        s5a += f'<div class="abox"><p>{a} − {c} = {b("3em")}</p><p>even or odd? <span class="bw">____</span></p></div>'
    s5a += '</div></div>'

    # 6: NEW — Self-check with emoji reflection
    s5b = '<div class="selfcheck">'\
          '<p><b>Self-Check: How do you feel about subtracting with regrouping?</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>Breaking a Ten (Visual)</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>Column Subtraction (Borrow)</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>Word Problems with Subtraction</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 favorite strategy for subtracting:</b> ' + bl() + '</p>'\
          '</div>'

    return page(10, "Friday", "Week 10 Review & Self-Check",
        f'''{sec(1, "Warm-up: ±10 and ±100", s1)}
{sec(2, "Estimate First!", s2)}
{sec(3, "Column Subtraction Review", s3)}
{sec(4, "Word Problems", s4)}
{sec(5, "Even or Odd?", 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 10", "Subtraction with Regrouping — Teacher Guide",

        # Monday
        tg_section_title("Monday: Introduction to Subtraction Regrouping") +
        tg_sec(1, "Warm-up ±10", ["25, 58, 82, 44"]) +
        tg_sec(2, "Visual Regrouping", ["53−17=36, 72−28=44"]) +
        tg_sec(3, "Simple Regrouping", ["36, 44, 37, 48"]) +
        tg_sec(4, "Number Talk", ["53−17 is bigger (subtracting less)", "82−28 is bigger (starting with more)"]) +
        tg_sec(5, "Challenge", ["61−24=37, 85−37=48"]) +
        tg_note("Page break"),

        # Tuesday
        tg_section_title("Tuesday: Column Subtraction with Borrowing") +
        tg_sec(1, "Warm-up ±10", ["53, 66, 62, 79"]) +
        tg_sec(2, "Borrow from Tens", ["36, 44, 37, 48"]) +
        tg_sec(3, "Estimation", ["Est 50−20=30, actual 36 / Est 70−30=40, actual 44 / Est 60−20=40, actual 37 / Est 90−40=50, actual 48"]) +
        tg_sec(4, "Missing Numbers", ["35, 74, 27, 83"]) +
        tg_sec(5, "Step-by-Step", ["36, 44"]) +
        tg_note("Page break"),

        # Wednesday
        tg_section_title("Wednesday: Mixed Subtraction Regrouping") +
        tg_sec(1, "Warm-up ±10/±100", ["35, 73, 400, 400"]) +
        tg_sec(2, "Mixed Regrouping", ["68−14=no(54), 63−27=yes(36), 85−30=no(55), 91−46=yes(45)"]) +
        tg_sec(3, "Word Problems", ["44 apples, 48 books"]) +
        tg_sec(4, "Find Error", ["53−17=36 not 44 (forgot to borrow, 13−7=6)", "82−35=47 not 53 (forgot to borrow, 12−5=7)"]) +
        tg_sec(5, "Create Own", ["Various — any subtraction needing regrouping"]) +
        tg_note("Page break"),

        # Thursday
        tg_section_title("Thursday: Word Problems with Subtraction Regrouping") +
        tg_sec(1, "Warm-up ±10", ["46, 39, 64, 51"]) +
        tg_sec(2, "Word Problems", ["27 stickers (83−56), 45 children (74−29), 57 cupcakes (95−38)"]) +
        tg_sec(3, "Two-Step", ["Step 1: 68−27=41, Step 2: 41+15=56 marbles"]) +
        tg_sec(4, "Number Talk", ["Same difference (72−28=44, 82−38=44)", "65−17 is bigger (subtracting less)"]) +
        tg_sec(5, "Create Own", ["Accept student-created problems with regrouping"]) +
        tg_note("Page break"),

        # Friday
        tg_section_title("Friday: Review & Self-Check") +
        tg_sec(1, "Warm-up", ["73, 57, 300, 500"]) +
        tg_sec(2, "Estimation", ["Est 60−30=30, actual 35 / Est 90−50=40, actual 46 / Est 70−40=30, actual 36 / Est 80−20=60, actual 63"]) +
        tg_sec(3, "Column Review", ["35, 46, 36, 63"]) +
        tg_sec(4, "Word Problems", ["33 flowers, 46 cookies"]) +
        tg_sec(5, "Even/Odd", ["35(odd), 46(even), 36(even)"]) +
        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", "Introduction to Subtraction Regrouping"),
        (tuesday, "Tuesday", "Column Subtraction with Borrowing"),
        (wednesday, "Wednesday", "Mixed Subtraction Regrouping"),
        (thursday, "Thursday", "Word Problems with Subtraction Regrouping"),
        (friday, "Friday", "Week 10 Review & Self-Check"),
    ]

    for lesson_func, day, title in days:
        html = lesson_func()
        fname = f"Week_10_{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_10_Teacher_Guide.html")
    with open(path, "w") as f:
        f.write(html)
    pdf_path = os.path.join(WEEK, "Week_10_Teacher_Guide.pdf")
    HTML(filename=path).write_pdf(pdf_path)
    print(f"Generated: {pdf_path}")

    print("\nWeek 10 (rewritten to new standard) complete!")
