from pathlib import Path
import csv,json
OUT=Path(__file__).parent
studies=json.loads((OUT/'deep-studies.json').read_text(encoding='utf-8'))
by={s['study_id']:s for s in studies}
# Each comparison was selected for an actual compositional disagreement, not a colour swap.
PAIRS=[
('DS01','DS02','Centered ceremony versus left editorial','Continuous middle axis versus fixed left edge','Formal joined script versus Roman/script name mixture','Quiet main card versus one-sided botanical mass','Retain a centered contender and a truly left-aligned contender; use blank-area art only.','Sleeve above/below opening; invitation central axis versus left edge; programme rows versus left labels.'),
('DS03','DS04','Roman grandeur versus flourished calligraphy','Large Roman stack versus ornate script stack','Roman display versus high-loop script','Art-free versus lettering-as-ornament','Large expressive type alone can be the signature; schedule body must remain upright.','Two art-free sleeve concepts; page one tests genuine long-name width; page two preserves a readable body floor.'),
('DS05','DS15','Art-free invitation versus pocket suite','Name-filled single card versus distinct card roles','Inscriptional type versus script','No image art versus shaped system','Coherence does not require identical grids; reject new stock construction.','Use the existing three pieces; repeat fonts/ink while changing page-two grid.'),
('DS06','DS16','Classical blocks versus tracked inscription','Distinct centered copy islands versus measured capital rows','Mixed classical type roles versus spaced capitals','Fine rules versus decorative border','Use whitespace to define blocks; the existing gold is already the rule system.','No new insert frame; name/family/date/venue gaps become the hierarchy.'),
('DS07','DS08','Portrait stack versus landscape spread','Tall stacked names versus wide name lines','Narrow Roman display versus bold informal lower case','Art-free versus quiet pale texture','Landscape should use width intelligently and never stretch the font.','Sleeve names keep horizontal rhythm; landscape inserts use wide text field with shorter prose lines.'),
('DS09','DS02','Small lower-left art versus large right edge','Offset art/detail pair versus asymmetric main field','Condensed capitals versus mixed script/Roman','Compact art mass versus oversized botanical edge','The better transfer is art that occupies genuinely spare area.','Original tiny sprig can balance a detail column; no full-height botanical border.'),
('DS10','DS12','Quiet formal script versus extreme swash','Separated script lines versus extravagant lettering crossing thread','Light script versus dark highly flourished script','Perimeter texture versus physical thread','Script must be optically spaced with safe swashes; no overlap with the aperture.','Cover names on solid ivory only; upright details on both inserts.'),
('DS11','DS17','Central connector versus editorial initial','Centered name pair with single connector versus left-aligned information','Roman names plus one connector versus initial identity','Perimeter ornament versus art-free main field','Do not add a second emblem to the bought medallion; a connector can be enough.','Original name treatment with factual blocks; no unapproved initials required.'),
('DS13','DS14','Physical seal pause versus typographic pause','Material divider in middle versus empty middle pause','Script versus Roman names','Seal versus quiet blind art','Protect the physical opening; typography can create ceremony without adding an object.','Sleeve exclusion remains empty; insert pauses shrink sensibly for density.'),
('DS18','DS38','Rich liner versus warm original accent','Broad formal central field versus name blocks separated by sprigs','Roman names versus Roman names with tiny art pauses','Big proprietary liner flowers versus tiny front accents','Keep the reading face calm and develop only original tiny marks.','Stock already provides richness; warm floral contender uses only permitted blank zones.'),
('DS19','DS29','Greenery as context versus small top mark','Long central invitation field versus compact top-accent field','Roman names versus Roman names','Liner plants versus one small front sprig','Botanical identity can be subordinate; green itself is optional.','One original bud/sprig on cover or invitation, not every blank margin.'),
('DS20','DS32','Square calm versus landscape calm','Compact centered paragraph islands versus wide centered islands','Quiet classical names versus stronger Roman name rows','Art-free versus one perimeter rule','Typography and gaps adapt better than borrowed borders.','A wider invitation block still needs usable prose measure; omit extra frame.'),
('DS21','DS30','Branch under names versus opposing corners','High-left names plus descending branch versus centered names and diagonal accents','Script title versus quiet script','One branch versus two tiny marks','Choose art placement after stock clearance, never before copy fitting.','Protect side flourishes; adjust original corner art to text instead of squeezing text around art.'),
('DS22','DS37','All-script warning versus divided type roles','Continuous script stack versus clearly separated Roman utility','Script throughout versus script display/Roman facts','None versus none','Elegant names do not justify script timings and long event titles.','Both sleeve contenders may use script; practical page always uses readable companion type.'),
('DS23','DS33','Loose name alignment versus weighted Roman names','High-left display crossing width versus bold central display block','Flowing script versus bold serif/soft connector','Art-free front versus art-free front','These are meaningful name-treatment alternatives, not colour variations.','Test actual short and full names at identical view scale; hold programme text size constant.'),
('DS24','DS43','Date anchor versus split event columns','Large date marker beneath names versus two practical columns','Loose script versus modest mixed title/body','No main art versus stock decoration','Date and venue should create findable landmarks on page two.','Keep six event groups discrete; day/date headers and aligned venues follow the real chronology.'),
('DS25','DS26','Information compartments versus ceremonial blocks','Labelled horizontal compartments versus central prose islands','Narrow Roman versus Roman names','No front art in both','A dense programme needs stronger grouping than an invitation paragraph.','Programme row hierarchy: event title, date/time, venue and separate meal-start; no vague merged facts.'),
('DS27','DS28','Botanical between people versus botanical between sections','Separated name stacks versus central blocks with divider marks','Stacked Roman versus quieter Roman','Midpoint leaf versus small section separator','An ornament must have one clear editorial purpose.','Sleeve divider separates names; page-two divider marks event group boundaries only when needed.'),
('DS31','DS45','Art-free modern field versus warm preprinted texture','Calm neutral invitation versus stock-driven coloured sleeve','Roman names versus warm smaller name role','No main art versus dense existing red pattern','Ordinary dark warm ink can succeed without printing another background.','Keep purchased ivory/gold pixel layer; add only dark text and optional original modest warm marks.'),
('DS34','DS38','Green sprigs versus warm simple romance','Two sprigs around identity versus two small section accents','Classical Roman versus spaced Roman','Botanical identity versus botanical punctuation','Colour is not a religious gate; restrained art/approved copy matter more.','Warm contender can use russet/garnet essentials and amber accents with dark fallback.'),
('DS39','DS40','Nikah title versus independent reception card','Clear Nikah title over invitation versus distinct event surfaces','Event title with modest names versus independent heading/name roles','Botanical stock versus floral stock','Use the chosen family titles; never relabel Dawat-e-Aam as a vendor example.','Invitation establishes the couple/Nikah; programme preserves all six groups and the separate meal start.'),
('DS41','DS42','Blue cover hierarchy versus ivory/gold floral stock','Rich cover/quiet insert versus ivory decorative field/insert','Modest name role versus modest name role','Cover pattern versus golden floral masses','Existing gold can carry ceremonial richness while dark type carries utility.','No religious-symbol copying; dark text baseline remains independent of gold decoration.'),
('DS44','DS47','Warm ordinary text versus multi-insert brown system','Landscape pale field versus portrait-looking suite blocks','Warm dark name role versus small name role','Gold stock edge versus rich floral cover','Dark brown/russet is credible beside gold, but process feasibility remains untested.','One dark-ink fallback per suite; physical printer proof before adhesion/feed claims.'),
('DS48','DS44','Warm copper accent versus warm dark essentials','Expressive copper names/darker body versus uniformly dark warm role','Formal expressive names versus smaller warm name role','Botanical liner versus existing gold stock','Copper/amber earns use as a controlled accent while facts keep dark contrast.','Warm suite text stays dark; any extra foil remains a conditional experiment, not final printing plan.')
]
rows=[]
for n,(a,b,title,grid,type_,art,result,adapt) in enumerate(PAIRS,1):
    s,t=by[a],by[b]
    rows.append(dict(study_id=f'CS{n:02}',source_a_id=a,source_a=s['title'],source_a_url=s['url'],source_b_id=b,source_b=t['title'],source_b_url=t['url'],question=title,composition_comparison=grid,type_comparison=type_,art_comparison=art,editorial_result=result,three_face_adaptation=adapt,status='comparative source study; adaptation proposal, not rendered proof'))
(OUT/'24-comparative-studies.json').write_text(json.dumps(rows,ensure_ascii=False,indent=2),encoding='utf-8')
with (OUT/'24-comparative-studies.csv').open('w',encoding='utf-8-sig',newline='') as f:
    w=csv.DictWriter(f,fieldnames=list(rows[0]));w.writeheader();w.writerows(rows)
lines=['# 24 comparative layout, type and art studies','', 'Each comparison links two designs actually visually screened this run and source-opened individually. The resulting adaptation is a proposal for the purchased three faces. It is not a claim that a source grid was copied or that all proposed variants have been typeset and physically printed. Fonts identified from metadata remain separate from visual style labels.','']
for r in rows:
    lines.extend([f"## {r['study_id']} · {r['question']}",'',f"[A · {r['source_a']}]({r['source_a_url']}) / [B · {r['source_b']}]({r['source_b_url']})",'',f"**Composition:** {r['composition_comparison']}. **Type:** {r['type_comparison']}. **Art:** {r['art_comparison']}.",'',f"**Judgement:** {r['editorial_result']}",'',f"**Three-face study:** {r['three_face_adaptation']}",''])
(OUT/'24-comparative-studies.md').write_text('\n'.join(lines),encoding='utf-8')
print('Saved',len(rows),'paired studies')
