"""One summary picture for MT: tick verdict, jet badge options, badge rules. Renders summary.html next to index.html."""
import os, sys
HERE = os.path.dirname(os.path.abspath(__file__)); sys.path.insert(0, HERE)
import build, marks, data, base64, io
REF = os.environ.get('SF50_REF', '/workspace/badges-20nov/ref')
def photo(name, box, w=760):
    from PIL import Image
    im = Image.open(os.path.join(REF, name)).convert('RGB').crop(box); im = im.resize((w, round(im.height * w / im.width)))
    b = io.BytesIO(); im.save(b, 'JPEG', quality=80); return 'data:image/jpeg;base64,' + base64.b64encode(b.getvalue()).decode()
from build import inline, LOCK, pass_card, name_row
css = open(os.path.join(HERE, 'page.css')).read().replace('/*TOKENS*/', build.tokens_css())
def tk(t): return f'<i class="tn">{data.THEME_NAME[t]}</i>' + ''.join(f'<div class="c"><div class="big">{inline(marks.tick(k,t))}</div><div class="smr"><span class="s24">{inline(marks.tick(k,t))}</span><span class="s16">{inline(marks.tick(k,t))}</span></div><b>{"Today" if k=="current" else k.upper()+" · "+marks.TICK[k]["name"]}</b></div>' for k in ['current','a','b','c'])
jets = ''.join(f'<div class="jo"><div class="jm">{inline(marks.medallion(k))}</div><div class="jsm"><span class="s48">{inline(marks.medallion(k))}</span><span class="s24">{inline(marks.medallion(k))}</span></div><b>{k.upper()} · {marks.COMP[k]["name"]}</b></div>' for k in 'abc')
ato = inline(LOCK['ato-tick-locked'], 'mk15'); dfe = inline(LOCK['dfe-tick-locked'], 'mk15'); fc = inline(LOCK['founding-compass-gold'], 'mk15')
rows = lambda: (f'<div class="r">{name_row(dfe,"Sipho Ndlovu","ATPL",".dfe")}</div><div class="r">{name_row(fc,"Thandi Mokoena","CPL")}</div>'
                f'<div class="r"><span class="nrow"><span class="nm">capeflight<span class="sfx">.official</span></span>{ato}</span></div><div class="r"><span class="nrow"><span class="tag warn">Expired</span><span class="tag">DTO</span><span class="tag">Drone</span></span></div>')
html = f'''<!doctype html><html data-t="pearl"><head><meta charset="utf-8"><style>{css}
body{{width:1600px;margin:0;padding:36px 40px;background:var(--bg)}}
.g{{display:grid;grid-template-columns:1fr 1.25fr 1fr;gap:22px}}
.p{{border-radius:24px;padding:22px;background:var(--card);box-shadow:inset 0 0 0 .5px var(--ln);min-width:0}}
.k{{font:600 11px/1 'General Sans',sans-serif;letter-spacing:.1em;text-transform:uppercase;color:var(--tx2);margin:0 0 8px}}
.t{{font:500 26px/1.1 'Clash Display',sans-serif;margin:0 0 6px;letter-spacing:-.01em}} .d{{font-size:14px;color:var(--tx2);margin:0 0 14px}}
.tr{{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;padding:12px 10px;border-radius:16px;margin-top:8px}}
.tn{{grid-column:1/-1;font:600 10px/1 "General Sans",sans-serif;letter-spacing:.1em;text-transform:uppercase;color:var(--tx2);font-style:normal}} .c{{display:grid;justify-items:center;gap:6px;text-align:center}} .c b{{font:600 11px/1.2 'General Sans',sans-serif;color:var(--tx2)}}
.big svg{{width:64px;height:64px}} .smr{{display:flex;gap:8px;align-items:center}} .s24 svg{{width:24px;height:24px}} .s16 svg{{width:16px;height:16px}} .s48 svg{{width:48px;height:48px}}
.pick{{margin-top:12px;font:600 13px/1.4 'General Sans',sans-serif}} .pick span{{color:var(--ok)}}
.jr{{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}} .jo{{display:grid;justify-items:center;gap:8px}} .jm svg{{width:150px;height:150px}} .jsm{{display:flex;gap:8px;align-items:center}}
.jo b{{font:600 12px/1 'General Sans',sans-serif}}
.pc{{margin-top:18px;display:grid;grid-template-columns:1fr;gap:12px}} .pc .pass{{padding:14px}} .pc .pname{{font-size:17px}} .pc .lbl{{font-size:9.5px}} .pc .av{{width:44px;height:44px;font-size:16px}} .pc .seal{{width:46px;height:46px;right:12px;top:12px}} .pc .seal-c{{width:24px;height:24px}} .pc .who{{padding-right:40px}}
.pc figcaption{{font:600 11px/1 'General Sans',sans-serif;color:var(--tx2);margin-bottom:6px}} .pc figure{{margin:0}}
.r{{padding:8px 0;border-top:.5px solid var(--ln)}} .r:first-of-type{{border-top:0}}
.tl{{border-radius:16px;padding:10px 14px;margin-top:8px}}
.ru{{margin:12px 0 0;padding:0;list-style:none;display:grid;gap:7px;font-size:13px;color:var(--tx2)}} .ru b{{color:var(--tx);font:600 13px/1.3 'General Sans',sans-serif}}
.cmp{{margin-top:22px}} .cg{{display:grid;grid-template-columns:1fr 1fr;gap:22px}} .cg figure{{margin:0;display:grid;gap:8px;align-content:start}} .cg img{{width:100%;border-radius:14px;display:block}}
.gs{{background:#120A04;border-radius:14px;padding:6px 0}} .gsv{{display:block;width:100%;height:auto;transform:scaleX(-1)}} .cg figcaption{{font-size:13px;color:var(--tx2)}} .cg figcaption b{{color:var(--tx)}}
.c2{{grid-template-columns:1.45fr 1fr;align-items:center}} .c2 figcaption{{grid-column:1/-1}} .csv{{display:block;width:100%;height:auto}}
.hd{{display:flex;justify-content:space-between;align-items:flex-end;margin-bottom:20px}} .hd h1{{font-size:34px;max-width:none}} .hd p{{margin:0;color:var(--tx2);font:500 13px/1.4 'General Sans',sans-serif;text-align:right}}
</style></head><body>
<div class="hd"><div><p class="eyebrow" style="justify-content:flex-start"><span class="draft">Draft</span> for MT · 20 Nov 2026</p><h1>Badges: green tick, Founding jet, one set of rules</h1></div><p>badges-20nov.go-around-design-previews.pages.dev<br>go-around-design · brand/badges</p></div>
<div class="g">
<section class="p"><p class="k">1 · Green tick</p><p class="t">Good, not fancy yet.</p><p class="d">Clean shape and lovely draw-in, but the bright mint, the blurred glow and the green page wash read like a payment app. Three refined versions, same meaning:</p>
<div class="tr" data-t="pearl" style="background:var(--bg)">{tk("pearl")}</div><div class="tr" data-t="midnight" style="background:var(--bg)">{tk("midnight")}</div>
<div class="tr" data-t="amethyst" style="background:var(--bg)">{tk("amethyst")}</div><div class="tr" data-t="champagne" style="background:var(--bg)">{tk("champagne")}</div>
<p class="pick">My pick: <span>B · Enamel</span>. Made like the verified seals, clear at 16 px.</p></section>
<section class="p"><p class="k">2 · Founding Member</p><p class="t">Half a Vision Jet instead of the runway</p><p class="d">Round 2: an original 3D model of the SF50, traced on a grid from photos (9.4 m long, 11.8 m span), shaded in our gold. V-tail at 40°, engine on the back running into the tail, wraparound windscreen, 3 big cabin windows. Shown at 150, 48 and 24 px.</p>
<div class="jr">{jets}</div>
<div class="pc"><figure><figcaption>Today: the runway</figcaption>{pass_card("current")}</figure><figure><figcaption>A · Climb-out replaces the runway (the locked compass stays)</figcaption>{pass_card("a")}</figure></div></section>
<section class="p"><p class="k">3 · Badge rules</p><p class="t">One mark per name</p><p class="d">Name, then .official or .dfe, then one mark, then the licence pill, then stars. Locked colours in every theme.</p>
<div class="tl" data-t="pearl" style="background:var(--bg)">{rows()}</div><div class="tl" data-t="amethyst" style="background:var(--bg)">{rows()}</div>
<ul class="ru"><li><b>Priority.</b> Schools: gold tick only while paying. Pilots: DFE blue tick wins over Founding. Pro, Trial, Free: no mark.</li>
<li><b>How many.</b> 1 mark per name, 1 licence pill on reviews, up to 3 on the pass, 1 school tag.</li>
<li><b>Never.</b> Badges on anonymous posts, two marks together, or green as "verified".</li>
<li><b>Ask MT.</b> 5 open questions on the page.</li></ul></section>
</div>
<section class="p cmp"><p class="k">Checked against photos</p>
<div class="cg"><figure><img src="{photo('Cirrus_Vision_SF50_N124MW_cn_0009__28664083278_.jpg', (0, 55, 1280, 600))}" alt=""><div class="gs">{inline(marks.jet_gold_side(), 'gsv')}</div>
<figcaption><b>Side.</b> Top: N124MW in flight, photo Markus Eigenheer, CC BY-SA 2.0 (Wikimedia Commons). Bottom: our model, same scale. Nose, windscreen, three windows, engine and V-tail line up.</figcaption></figure>
<figure class="c2"><img src="{photo('Cirrus_Vision_SF50_Jet__EAA_AirVenture_Oshkosh__July_2016.jpg', (180, 40, 1280, 640), 560)}" alt=""><div class="cs">{inline(marks.medallion('c'), 'csv')}</div>
<figcaption><b>Three-quarter.</b> Left: SF50 at Oshkosh 2016, photo Joey1niner, CC BY-SA 4.0 (Wikimedia Commons). Right: seal C. Gear is up in flight, so no nose gear; the CAPS hatch is flush and too fine for a seal.</figcaption></figure></div></section>
</body></html>'''
open(os.path.join(build.ROOT, 'summary.html'), 'w').write(html)
