#!/usr/bin/env python3
"""Build five original, accessible A4 vector aids for the fictional inquiry."""
import subprocess
from html import escape
from pathlib import Path

HERE = Path(__file__).resolve().parent
BG, INK, BLUE, TEAL, ORANGE, LIGHT = '#fbfaf5', '#172932', '#194f72', '#0e645d', '#9c4d22', '#e9f2f1'


def txt(x, y, value, size=19, weight=400, fill=INK):
    return f'<text x="{x}" y="{y}" font-family="DejaVu Sans" font-size="{size}" font-weight="{weight}" fill="{fill}">{escape(value)}</text>'


def rect(x, y, w, h, fill='white', stroke=BLUE, radius=12):
    return f'<rect x="{x}" y="{y}" width="{w}" height="{h}" rx="{radius}" fill="{fill}" stroke="{stroke}" stroke-width="2"/>'


def line(x1, y1, x2, y2, color=BLUE, width=2):
    return f'<line x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}" stroke="{color}" stroke-width="{width}"/>'


def base(title, subtitle, body, desc):
    return '\n'.join([
        '<svg xmlns="http://www.w3.org/2000/svg" width="210mm" height="297mm" viewBox="0 0 794 1123" role="img" aria-labelledby="title desc">',
        f'<title id="title">{escape(title)}</title><desc id="desc">{escape(desc)}</desc>',
        rect(0, 0, 794, 1123, BG, BG, 0),
        rect(34, 32, 726, 10, TEAL, TEAL, 0),
        txt(44, 91, title, 30, 700, BLUE), txt(44, 124, subtitle, 15, 400),
        body,
        line(44, 1060, 750, 1060, '#bdcac6', 1),
        txt(44, 1087, 'SubjectNest  •  Year 9  •  fictional inquiry  •  A4', 13, 400, BLUE),
        '</svg>'
    ])


def card(x, y, w, h, title, lines, accent=BLUE):
    items = [rect(x,y,w,h,'white',accent), txt(x+20,y+34,title,19,700,accent)]
    for i, value in enumerate(lines):
        items.append(txt(x+20,y+69+i*31,value,16))
    return '\n'.join(items)


def write(name, title, subtitle, body, desc):
    svg = HERE / f'{name}.svg'
    svg.write_text(base(title,subtitle,body,desc), encoding='utf-8')
    subprocess.run(['rsvg-convert','-f','pdf','-o',str(HERE/f'{name}.pdf'),str(svg)], check=True)


write('claim-poster','EACH EXTRA LAYER HALVES','Fictional Paper Screen team  •  draft poster  •  18 September 2026', '\n'.join([
    rect(45,170,704,258,BLUE,BLUE),
    txt(73,228,'THE SENSOR VALUE!',34,700,'white'),
    txt(73,291,'160 × 2⁻⁴ = 10',43,700,'white'),
    txt(73,338,'at four layers, IF exact halving holds',20,400,'white'),
    rect(45,462,704,253,LIGHT,TEAL),
    txt(72,512,'BUT OUR FIRST RECORD SAID 20',26,700,TEAL),
    txt(72,560,'That is 10 units above the model prediction.',18),
    txt(72,597,'We want a controlled retest before calling it',18),
    txt(72,627,'dependable. These are invented arbitrary units.',18),
    card(45,750,704,228,'LOOK AGAIN',[
        'Who made this poster, and who is its audience?',
        'Which number is a model prediction? Which is a record?',
        'What does the small-print limit change?'],ORANGE)
]),'Large exact-halving headline, dark prediction panel, contrasting qualification panel showing 20 recorded versus 10 model, then three claim-audit questions.')

write('claim-audit','CLAIM AUDIT','Read the bold claim and its quiet limits with equal care.', '\n'.join([
    card(45,165,704,154,'1  MAKER + PURPOSE',['Who created this source? For whom? To do what?']),
    card(45,337,704,154,'2  EXACT CLAIM',['Write the words or numbers it asks us to accept.'],TEAL),
    card(45,509,704,154,'3  SOURCE DETAIL',['Quote a value and say prediction OR recorded.']),
    card(45,681,704,154,'4  ASSUMPTION + LIMIT',['What must hold? What method detail is missing?'],ORANGE),
    card(45,853,704,154,'5  REVISED SENTENCE',['Name the source; keep uncertainty visible.'],TEAL)
]),'Five numbered high-contrast boxes for maker, claim, source detail, assumption and limit, and revised sentence.')

head = [rect(45,165,704,674,'white',BLUE), txt(64,203,'n',17,700),txt(146,203,'160 × 2⁻ⁿ',17,700),txt(365,203,'B: invented record',17,700),txt(617,203,'gap',17,700)]
for i, val in enumerate((160,80,44,26,20)):
    y=244+i*91
    head.extend([line(65,y+18,727,y+18,'#bdcac6',1),txt(68,y,str(i),20,700,BLUE),txt(382,y,str(val),20,700,TEAL),txt(145,y,'________',18),txt(623,y,'____',18)])
head.extend([card(45,864,704,145,'BOUNDARY',['n = 5 is unobserved. A prediction is not a new reading.'],ORANGE)])
write('model-and-data','MODEL / DATA / GAP','A conditional exact-half rule beside one invented record. Units: arbitrary.', '\n'.join(head),'Five-row table for n 0 through 4, blank model and gap cells, fictional record 160, 80, 44, 26, 20, and unobserved-boundary note.')

write('retest-method','RETEST METHOD MAT','A good written plan is not evidence that a test was performed.', '\n'.join([
    card(45,165,704,155,'QUESTION + VARIABLES',['Change: number of layers. Read: sensor value.'],TEAL),
    card(45,337,704,160,'HOLD / RECORD',['Paper batch and size • lamp setting • geometry', 'Background light • sensor calibration or zero'],BLUE),
    card(45,516,704,144,'RUNS + ROLES',['How many? What order? Who records? Who checks?'],ORANGE),
    card(45,678,704,145,'SAFETY + PERMISSION',['Teacher-approved low-voltage equipment only.', 'No eyes, mains wiring or public installation.'],TEAL),
    card(45,841,704,169,'OBSERVATION STATUS',['If no approved test took place, write:', 'NOT OBSERVED'],BLUE)
]),'Five separated fields for variables, held controls, runs/roles, permission and conspicuous NOT OBSERVED status.')

write('recommendation-canvas','TWO-PANEL DECISION BRIEF','For a fictional manager deciding only about a small supervised retest.', '\n'.join([
    rect(45,166,704,366,'white',BLUE),txt(67,207,'PANEL 1  •  WHAT THE SOURCES SHOW',21,700,BLUE),
    txt(67,252,'Source + exact numerical contrast + model assumption',17),
    line(68,285,727,285,'#bdcac6',1),line(68,337,727,337,'#bdcac6',1),line(68,389,727,389,'#bdcac6',1),line(68,441,727,441,'#bdcac6',1),
    rect(45,550,704,372,'white',TEAL),txt(67,591,'PANEL 2  •  DECISION + NEXT CHECK',21,700,TEAL),
    txt(67,636,'Limit + operational retest step + who may act',17),
    line(68,669,727,669,'#bdcac6',1),line(68,721,727,721,'#bdcac6',1),line(68,773,727,773,'#bdcac6',1),line(68,825,727,825,'#bdcac6',1),
    txt(48,970,'First-glance check: could either panel be mistaken for approval?',17,700,ORANGE)
]),'Two high-contrast large blank panels for evidence and decision, with ruled writing space and an overclaim check.')
