#!/usr/bin/env python3
"""
Week 13: 3-Digit Addition & Subtraction — REWRITTEN
Phase 2: Addition & Subtraction to 100
Key skills: Hundreds place, regrouping across hundreds, working to 1,000

New Standard:
- Reduced drill (40% fewer problems)
- Estimation before calculating
- Multiple strategies encouraged
- Better word problems (reasoning over keywords)
- Real challenges (open-ended thinking)
- Number talks (compare without calculating)
- Friday self-check with reflection
- Mental math ±10, ±100 woven throughout
- Unknowns in equations
- Word problems every day
"""

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_add, col_sub, col_add_inline, col_sub_inline,
)

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


# ═══════════════════════════════════════════════════
# MONDAY — 3-Digit Addition (No Regrouping)
# ═══════════════════════════════════════════════════
def monday():
    # 1: Fluency warmup — ±100 (2.NBT.B.8)
    s1 = '<div class="abox" style="background:#e8f5e9;">'\
         '<p><b>2-min Fluency Warm-up</b> — Mental math: add/subtract 100.</p>'\
         '<div class="mgrid c3">'
    for expr in [("200 + 100", ""), ("500 − 100", ""), ("300 + 100", ""), ("700 − 100", "")]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Concept — 3-digit addition is like 2-digit, just another column
    s2 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>New Skill: 3-Digit Addition</b></p>'\
         '<p>Adding 3-digit numbers is just like adding 2-digit numbers — you add ones, then tens, then hundreds.</p>'\
         '<div class="mgrid c2" style="gap:12px;">'\
         '<div class="abox" style="text-align:center; padding:12px;">'\
         '<p style="font-weight:bold; font-size:14px;">245 + 132</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Ones: 5 + 2 = 7</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Tens: 40 + 30 = 70</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Hundreds: 200 + 100 = 300</p>'\
         '<p style="font-weight:bold; font-size:14px;">Answer: 377</p></div>'\
         '<div class="abox" style="text-align:center; padding:12px;">'\
         '<p style="font-weight:bold; font-size:14px;">314 + 253</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Ones: 4 + 3 = 7</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Tens: 10 + 50 = 60</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Hundreds: 300 + 200 = 500</p>'\
         '<p style="font-weight:bold; font-size:14px;">Answer: 567</p></div>'\
         '</div></div>'

    # 3: Guided practice — no regrouping
    s3 = '<p class="note">Add using columns. No regrouping needed yet!</p>'\
         '<div class="mgrid c2">'
    problems = [(125, 234), (412, 325), (231, 146), (324, 153)]
    for a, c in problems:
        s3 += f'<div class="abox" style="text-align:center;">{col_add(a, c, digits=3)}</div>'
    s3 += '</div>'

    # 4: Number Talk — estimate 3-digit sums
    s4 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Number Talk</b> — Estimate each sum by rounding to hundreds.</p>'\
         '<div class="mgrid c2">'
    problems = [
        (342, 218, "About 300 + 200 = 500"),
        (615, 281, "About 600 + 300 = 900"),
    ]
    for a, c, est in problems:
        s4 += f'<div class="abox"><p><b>{a} + {c}</b></p>'\
              f'<p>Estimate ({est}): {b("4em")}</p>'\
              f'<p>Actual: {b("4em")}</p></div>'
    s4 += '</div></div>'

    # 5: Word problem — 3-digit
    s5 = '<div class="wp"><p class="note">Read carefully. These are big numbers!</p>'\
         '<div class="abox"><p style="font-size:0.95em;">The library has 342 books about animals and 218 books about space. '\
         'How many books are there altogether?</p>'\
         '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
         '<p>' + b("6em") + ' books</p></div></div>'

    return page(13, "Monday", "3-Digit Addition (No Regrouping)",
        f'''{sec(1, "Warm-up: ±100 Mental Math", s1)}
{sec(2, "Learn: 3-Digit Addition", s2)}
{sec(3, "Guided Practice", s3)}
{sec(4, "Estimate First", s4)}
{sec(5, "Word Problem", s5)}''')


# ═══════════════════════════════════════════════════
# TUESDAY — 3-Digit Addition WITH Regrouping
# ═══════════════════════════════════════════════════
def tuesday():
    # 1: Fluency warmup — ±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 [("400 + 100", ""), ("600 − 100", ""), ("100 + 100", ""), ("900 − 100", "")]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Concept — regrouping in 3-digit addition
    s2 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Regrouping in 3-Digit Addition</b></p>'\
         '<p>When adding ones or tens reaches 10 or more, carry the 1 — just like before!</p>'\
         '<div class="mgrid c2" style="gap:12px;">'\
         '<div class="abox" style="text-align:center; padding:12px;">'\
         '<p style="font-weight:bold; font-size:14px;">248 + 135</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Ones: 8 + 5 = 13 → write 3, carry 1</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Tens: 40 + 30 + 10 = 80</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Hundreds: 200 + 100 = 300</p>'\
         '<p style="font-weight:bold; font-size:14px;">Answer: 383</p></div>'\
         '<div class="abox" style="text-align:center; padding:12px;">'\
         '<p style="font-weight:bold; font-size:14px;">376 + 245</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Ones: 6 + 5 = 11 → write 1, carry 1</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Tens: 70 + 40 + 10 = 120 → write 20, carry 100</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Hundreds: 300 + 200 + 100 = 600</p>'\
         '<p style="font-weight:bold; font-size:14px;">Answer: 621</p></div>'\
         '</div></div>'

    # 3: Practice with regrouping
    s3 = '<p class="note">Use columns. Don\'t forget to carry!</p>'\
         '<div class="mgrid c2">'
    problems = [(248, 135), (376, 245), (168, 327), (459, 263)]
    for a, c in problems:
        s3 += f'<div class="abox" style="text-align:center;">{col_add(a, c, digits=3)}</div>'
    s3 += '</div>'

    # 4: Estimate first, then solve
    s4 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Round to hundreds, estimate, then find the actual answer.</p>'\
         '<div class="mgrid c2">'
    problems = [(248, 135), (376, 245)]
    for a, c in problems:
        at = round(a / 100) * 100
        ct = round(c / 100) * 100
        s4 += 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>'
    s4 += '</div></div>'

    # 5: Word problem
    s5 = '<div class="wp"><p class="note">Read carefully. Big numbers need careful adding.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("The stadium had 348 people at the start of the game. 267 more people arrived during the game. How many people are at the stadium?", "people"),
        ("The school ordered 425 books for elementary students and 318 books for middle school students. How many books were ordered in all?", "books"),
    ]
    for text, unit in problems:
        s5 += 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>'
    s5 += '</div></div>'

    # 5a: Two Ways — solve one problem two different ways
    s5 += '<div class="abox" style="background:#fff8e1; margin-top:6px;">'\
          '<p><b>Two Ways!</b> Solve 253 + 128 <b>two different ways</b>.</p>'\
          '<div class="mgrid c2">'\
          '<div class="abox"><p style="font-size:11px;">Way 1 — columns:</p><p>' + bw() + '</p><p>Answer: ' + b("5em") + '</p></div>'\
          '<div class="abox"><p style="font-size:11px;">Way 2 (another way) — add hundreds, then tens, then ones:</p><p>' + bw() + '</p><p>Answer: ' + b("5em") + '</p></div>'\
          '</div><p style="font-size:11px; color:#666;">Which way felt easier? Why? ' + bw() + '</p></div>'

    return page(13, "Tuesday", "3-Digit Addition with Regrouping",
        f'''{sec(1, "Warm-up: ±100 Mental Math", s1)}
{sec(2, "Regrouping in 3-Digit Addition", s2)}
{sec(3, "Practice with Regrouping", s3)}
{sec(4, "Estimate First", s4)}
{sec(5, "Word Problems", s5)}''')


# ═══════════════════════════════════════════════════
# WEDNESDAY — 3-Digit Subtraction
# ═══════════════════════════════════════════════════
def wednesday():
    # 1: Fluency warmup — ±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 [("500 − 100", ""), ("200 + 100", ""), ("800 − 100", ""), ("300 + 100", "")]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Concept — 3-digit subtraction
    s2 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>3-Digit Subtraction</b></p>'\
         '<p>Subtracting 3-digit numbers: start with ones, then tens, then hundreds. Borrow if you need to.</p>'\
         '<div class="mgrid c2" style="gap:12px;">'\
         '<div class="abox" style="text-align:center; padding:12px;">'\
         '<p style="font-weight:bold; font-size:14px;">573 − 241</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Ones: 3 − 1 = 2</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Tens: 70 − 40 = 30</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Hundreds: 500 − 200 = 300</p>'\
         '<p style="font-weight:bold; font-size:14px;">Answer: 332</p></div>'\
         '<div class="abox" style="text-align:center; padding:12px;">'\
         '<p style="font-weight:bold; font-size:14px;">604 − 237</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Ones: 4 < 7, borrow → 14 − 7 = 7</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Tens: 0 became 9 (borrowed) → 9 − 3 = 6</p>'\
         '<p style="color:#3f51b5; font-size:11px;">Hundreds: 6 became 5 → 5 − 2 = 3</p>'\
         '<p style="font-weight:bold; font-size:14px;">Answer: 367</p></div>'\
         '</div></div>'

    # 3: Practice — subtraction with and without regrouping
    s3 = '<p class="note">Use columns. Borrow when needed!</p>'\
         '<div class="mgrid c2">'
    problems = [(573, 241), (604, 237), (812, 365), (725, 418)]
    for a, c in problems:
        s3 += f'<div class="abox" style="text-align:center;">{col_sub(a, c, digits=3)}</div>'
    s3 += '</div>'

    # 4: Find the error
    s4 = '<div class="abox"><p class="note">One of these has an error. Find it, explain, and fix it.</p>'\
         '<div class="mgrid c2">'
    s4 += '<div class="abox"><p style="text-align:center;">  542</p><p style="text-align:center;">- 278</p><hr><p style="text-align:center;">  264</p>'\
          '<p>✓ or ✗?</p><p style="font-size:11px;">Explain: ' + bw() + '</p><p style="font-size:11px;">Correct: ' + b("4em") + '</p></div>'
    s4 += '<div class="abox"><p style="text-align:center;">  705</p><p style="text-align:center;">- 348</p><hr><p style="text-align:center;">  357</p>'\
          '<p>✓ or ✗?</p><p style="font-size:11px;">Explain: ' + bw() + '</p><p style="font-size:11px;">Correct: ' + b("4em") + '</p></div>'
    s4 += '</div></div>'

    # 5: Word problem
    s5 = '<div class="wp"><p class="note">Think about the situation. What happens to the total?</p>'\
         '<div class="abox"><p style="font-size:0.95em;">The school had 648 pencils in the supply closet. '\
         'During the year, 275 pencils were given to students. How many pencils are left?</p>'\
         '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
         '<p>' + b("6em") + ' pencils</p></div></div>'

    return page(13, "Wednesday", "3-Digit Subtraction",
        f'''{sec(1, "Warm-up: ±100 Mental Math", s1)}
{sec(2, "3-Digit Subtraction", s2)}
{sec(3, "Practice", s3)}
{sec(4, "Find the Error", s4)}
{sec(5, "Word Problem", s5)}''')


# ═══════════════════════════════════════════════════
# THURSDAY — Mixed 3-Digit Add & Subtract
# ═══════════════════════════════════════════════════
def thursday():
    # 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 [("150 − 100", ""), ("320 + 100", ""), ("400 − 100", ""), ("60 + 10", "")]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Mixed practice — add or subtract
    s2 = '<p class="note">Solve each using columns.</p>'\
         '<div class="mgrid c3">'
    # 2 additions, 2 subtractions
    for a, c in [(248, 135), (376, 245)]:
        s2 += f'<div class="abox" style="text-align:center;">{col_add(a, c, digits=3)}</div>'
    for a, c in [(573, 241), (604, 237)]:
        s2 += f'<div class="abox" style="text-align:center;">{col_sub(a, c, digits=3)}</div>'
    s2 += '</div>'

    # 3: Number Talk — compare WITHOUT calculating
    s3 = '<div class="abox" style="background:#e3f2fd;">'\
         '<p><b>Number Talk</b> — Explain WITHOUT calculating.</p>'\
         '<div class="mgrid c2">'
    s3 += '<div class="abox"><p>A: 456 + 234</p><p>B: 456 + 244</p>'\
          '<p>Which is bigger? ' + bw() + '</p></div>'
    s3 += '<div class="abox"><p>A: 700 − 300</p><p>B: 700 − 200</p>'\
          '<p>Which is bigger? ' + bw() + '</p></div>'
    s3 += '</div></div>'

    # 4: Word problems — mixed
    s4 = '<div class="wp"><p class="note">Decide if you add or subtract.</p>'\
         '<div class="mgrid c2">'
    problems = [
        ("The farmer grew 425 carrots and 318 tomatoes. How many vegetables did the farmer grow?", "vegetables"),
        ("The warehouse had 832 boxes. They shipped 367 boxes today. How many boxes are left?", "boxes"),
    ]
    for text, 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: Unknown in equation
    s5 = '<div class="abox"><p class="note">Find the missing number.</p>'\
         '<div class="mgrid c2">'
    s5 += f'<div class="abox"><p>{b("5em")} + 234 = 578</p>'\
          '<p style="font-size:11px;">How did you figure it out? ' + bw() + '</p></div>'
    s5 += f'<div class="abox"><p>645 − {b("5em")} = 312</p>'\
          '<p style="font-size:11px;">How did you figure it out? ' + bw() + '</p></div>'
    s5 += '</div></div>'

    # 5a: Create Your Own — open-ended
    s5 += '<div class="abox" style="background:#f3e5f5; margin-top:6px;">'\
          '<p><b>Create Your Own!</b> Write a word problem that uses <b>3-digit subtraction</b>. '\
          'Then solve it.</p>'\
          '<p style="font-size:11px;">My problem: ' + bl() + '</p>'\
          '<p style="font-size:11px;">' + bl() + '</p>'\
          '<p>My answer: ' + b("6em") + '</p></div>'

    return page(13, "Thursday", "Mixed 3-Digit Add & Subtract",
        f'''{sec(1, "Warm-up: ±10 and ±100", s1)}
{sec(2, "Mixed Column Practice", s2)}
{sec(3, "Number Talk: Compare Without Calculating", s3)}
{sec(4, "Word Problems", s4)}
{sec(5, "Find the Missing Number", s5)}''')


# ═══════════════════════════════════════════════════
# FRIDAY — Review & Self-Check
# ═══════════════════════════════════════════════════
def friday():
    # 1: Fluency warmup — ±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 [("400 + 100", ""), ("700 − 100", ""), ("100 + 100", ""), ("900 − 100", "")]:
        s1 += f'<div class="abox"><p>{expr[0]} = {b("4em")}</p></div>'
    s1 += '</div></div>'

    # 2: Estimate and solve
    s2 = '<div class="abox" style="background:#fff3e0;">'\
         '<p><b>Estimate First!</b> Round to hundreds, estimate, then solve.</p>'\
         '<div class="mgrid c2">'
    problems = [(248, "+", 135), (604, "−", 237)]
    for a, op, c in problems:
        at = round(a / 100) * 100
        ct = round(c / 100) * 100
        s2 += f'<div class="abox"><p><b>{a} {op} {c}</b></p>'\
              f'<p>Estimate ({at} {op} {ct}): {b("4em")}</p>'\
              f'<p>Actual: {b("4em")}</p></div>'
    s2 += '</div></div>'

    # 3: Mixed review
    s3 = '<p class="note">Solve each using your best strategy.</p>'\
         '<div class="mgrid c3">'
    problems = [
        "156 + 234 = ", "487 − 215 = ", "368 + 145 = ", "620 − 378 = "
    ]
    for prob in problems:
        s3 += f'<div class="abox"><p style="font-size:1.1em; text-align:center;">{prob}{b("5em")}</p></div>'
    s3 += '</div>'

    # 4: Word problem review
    s4 = '<div class="wp"><p class="note">Read carefully. Show your work.</p>'\
         '<div class="abox"><p style="font-size:0.95em;">The bookstore had 524 books. They sold 186 books on Saturday '\
         'and 97 books on Sunday. How many books are left?</p>'\
         '<p style="font-size:11px;">Draw or write your thinking: ' + bw() + '</p>'\
         '<p>' + b("6em") + ' books</p></div></div>'

    # 5: Self-check with reflection
    s5 = '<div class="selfcheck">' \
         '<p><b>Self-Check: How do you feel about 3-digit addition and subtraction?</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>Adding 3-Digit Numbers</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>Subtracting 3-Digit Numbers</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>Estimating 3-Digit Sums/Diffs</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>' \
         '</div>'

    return page(13, "Friday", "Week 13 Review & Self-Check",
        f'''{sec(1, "Warm-up: ±100 Mental Math", s1)}
{sec(2, "Estimate First!", s2)}
{sec(3, "Mixed Review", s3)}
{sec(4, "Word Problem", s4)}
{sec(5, "Self-Check & Reflection", s5)}''')


# ═══════════════════════════════════════════════════
# TEACHER GUIDE
# ═══════════════════════════════════════════════════
def teacher_guide():
    return tg_page_multi(
        "Week 13", "3-Digit Addition & Subtraction — Teacher Guide",

        tg_section_title("Monday: 3-Digit Addition (No Regrouping)") +
        tg_sec(1, "Warm-up ±100", ["300, 400, 400, 600"]) +
        tg_sec(2, "Examples", ["245+132=377, 314+253=567"]) +
        tg_sec(3, "Guided Practice", ["359, 737, 377, 477"]) +
        tg_sec(4, "Estimation", ["Est 300+200=500, actual 560 | Est 600+300=900, actual 896"]) +
        tg_sec(5, "Word Problem", ["342+218=560 books"]) +
        tg_note("Page break"),

        tg_section_title("Tuesday: 3-Digit Addition with Regrouping") +
        tg_sec(1, "Warm-up", ["500, 500, 200, 800"]) +
        tg_sec(2, "Strategy", ["248+135=383, 376+245=621"]) +
        tg_sec(3, "Practice", ["383, 621, 495, 722"]) +
        tg_sec(4, "Estimation", ["Est 200+100=300, actual 383 | Est 400+200=600, actual 621"]) +
        tg_sec(5, "Word Problems", ["348+267=615 people, 425+318=743 books", "Two Ways: 253+128=381 both ways (columns; or 200+100=300, 50+20=70, 3+8=11 → 381)"]) +
        tg_note("Page break"),

        tg_section_title("Wednesday: 3-Digit Subtraction") +
        tg_sec(1, "Warm-up", ["400, 300, 700, 400"]) +
        tg_sec(2, "Concept", ["573-241=332, 604-237=367"]) +
        tg_sec(3, "Practice", ["332, 367, 447, 307"]) +
        tg_sec(4, "Find Error", ["542-278=264 ✓ correct | 705-348=357 ✓ correct"]) +
        tg_sec(5, "Word Problem", ["648-275=373 pencils"]) +
        tg_note("Page break"),

        tg_section_title("Thursday: Mixed 3-Digit Add & Subtract") +
        tg_sec(1, "Warm-up", ["50, 420, 300, 70"]) +
        tg_sec(2, "Mixed Practice", ["383, 621, 332, 367"]) +
        tg_sec(3, "Number Talk", ["B bigger (adding more) | B bigger (subtracting less)"]) +
        tg_sec(4, "Word Problems", ["425+318=743 vegetables, 832-367=465 boxes"]) +
        tg_sec(5, "Unknown", ["344+234=578 | 645-333=312", "Create Your Own: accept any valid 3-digit subtraction problem with correct answer"]) +
        tg_note("Page break"),

        tg_section_title("Friday: Review & Self-Check") +
        tg_sec(1, "Warm-up", ["500, 600, 200, 800"]) +
        tg_sec(2, "Estimation", ["Est 200+100=300, actual 383 | Est 600-200=400, actual 367"]) +
        tg_sec(3, "Mixed Review", ["390, 272, 513, 242"]) +
        tg_sec(4, "Word Problem", ["524-186-97=241 books"]) +
        tg_sec(5, "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)

    days = [
        (monday, "Monday", "3-Digit Addition (No Regrouping)"),
        (tuesday, "Tuesday", "3-Digit Addition with Regrouping"),
        (wednesday, "Wednesday", "3-Digit Subtraction"),
        (thursday, "Thursday", "Mixed 3-Digit Add & Subtract"),
        (friday, "Friday", "Week 13 Review & Self-Check"),
    ]

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