"""Go Around badge marks, 20 Nov 2026 (DRAFT for MT).
Founding Member: half a Cirrus SF50 Vision Jet (three compositions). Success tick: current + three refined alternatives.
The jet is an original 3D model (jet3d/sf50.py, traced on a grid from public photos of N124MW), projected and shaded
by jet3d/make_geo.py into jet3d/geo.json. Everything else is drawn here as plain SVG."""
import json, os
GEO = json.load(open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'jet3d', 'geo.json')))

GOLD = ('#F6E3A6', '#D4AE52', '#9C7424')          # --gold1/2/3 (auth kit tokens)
ONYX = ('#37260C', '#120A04', '#080502')          # founding medallion fill (badge-founding-medallion.svg)

COMP = {
  'a': dict(name='Climb-out', note='Front three-quarter, climbing right. V-tail, engine on the back, cabin windows and the big windscreen; the nose leaves through the rim.'),
  'b': dict(name='Split plan', note='Seen from above, split down the centreline: one half shaded gold, the other half a fine engraved line. The wingtips touch the rim.'),
  'c': dict(name='Nose-in', note='Front three-quarter, close: the wraparound windscreen, three cabin windows and the engine intake come at you; the tail is cut by the rim.'),
}
def _rot(key):
    v = GEO['views'][key]
    return f' transform="rotate({v["rot"]} {v["cx"]} {v["cy"]})"' if v.get('rot') else ''

def _mono_mask(key, sw):
    """Mask content: body parts white, glass/intake black, and a black hairline between parts so they read."""
    out = []
    for kind, d in GEO[f'parts_{key}']:
        out.append(f'<path d="{d}" fill="#000" stroke="#fff" stroke-width="{sw * 1.6:.2f}" stroke-linejoin="round"/>' if kind == 'dark' else f'<path d="{d}" fill="#fff" stroke="#000" stroke-width="{sw}" stroke-linejoin="round"/>')
    return f'<g{_rot(key)}>' + ''.join(out) + '</g>'

def _defs(uid):
    return (f'<radialGradient id="{uid}o" cx=".5" cy=".36" r=".7"><stop offset="0" stop-color="{ONYX[0]}"/><stop offset=".58" stop-color="{ONYX[1]}"/><stop offset="1" stop-color="{ONYX[2]}"/></radialGradient>'
            f'<linearGradient id="{uid}g" x1="96" y1="40" x2="420" y2="480" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="{GOLD[0]}"/><stop offset=".45" stop-color="{GOLD[1]}"/><stop offset="1" stop-color="{GOLD[2]}"/></linearGradient>'
            f'<linearGradient id="{uid}r" x1="60" y1="20" x2="452" y2="492" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#FBEFC6"/><stop offset=".35" stop-color="{GOLD[1]}"/><stop offset=".6" stop-color="#F3DB93"/><stop offset="1" stop-color="{GOLD[2]}"/></linearGradient>'
            f'<clipPath id="{uid}c"><circle cx="256" cy="256" r="224"/></clipPath>')

def medallion(key, uid=None, mono=None, title=None):
    """512 x 512 Founding Member seal with half a Vision Jet. mono: None | 'dark' | 'light'."""
    uid = uid or f'fj{key}'
    t = title or f'Founding Member, {COMP[key]["name"]}'
    svg = f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512" role="img" aria-label="{t}"><title>{t}</title>'
    if mono:
        ink, ground = ('#111114', '#FFFFFF') if mono == 'light' else ('#FFFFFF', '#111114')
        if key == 'b':
            m = (f'<g clip-path="url(#{uid}L)">{_mono_mask(key, 2.2)}</g>'
                 f'<g clip-path="url(#{uid}R)"><path d="{GEO["sil_b"]}" fill="none" stroke="#fff" stroke-width="2.6" stroke-linejoin="round"/></g>')
            extra = f'<clipPath id="{uid}L"><rect x="0" y="0" width="256" height="512"/></clipPath><clipPath id="{uid}R"><rect x="256" y="0" width="256" height="512"/></clipPath>'
        else:
            m, extra = _mono_mask(key, 2.2), ''
        return (svg + f'<defs>{extra}<clipPath id="{uid}c"><circle cx="256" cy="256" r="224"/></clipPath>'
                f'<mask id="{uid}m" maskUnits="userSpaceOnUse" x="0" y="0" width="512" height="512">{m}</mask></defs>'
                f'<circle cx="256" cy="256" r="250" fill="{ground}" stroke="{ink}" stroke-width="8"/>'
                f'<circle cx="256" cy="256" r="224" fill="none" stroke="{ink}" stroke-width="3" opacity=".6"/>'
                f'<g clip-path="url(#{uid}c)"><rect width="512" height="512" fill="{ink}" mask="url(#{uid}m)"/></g></svg>')
    jet = f'<g{_rot(key)}>' + GEO[f'gold_{key}'].replace('__U__', uid) + '</g>'
    extra = ''
    if key == 'b':
        extra = f'<clipPath id="{uid}L"><rect x="0" y="0" width="256" height="512"/></clipPath><clipPath id="{uid}R"><rect x="256" y="0" width="256" height="512"/></clipPath>'
        jet = (f'<g clip-path="url(#{uid}L)">{jet}</g>'
               f'<g clip-path="url(#{uid}R)"><path d="{GEO["sil_b"]}" fill="none" stroke="url(#{uid}g)" stroke-width="2.2" stroke-linejoin="round"/></g>'
               f'<line x1="256" y1="36" x2="256" y2="476" stroke="url(#{uid}g)" stroke-width="1" opacity=".35"/>')
    return (svg + f'<defs>{_defs(uid)}{extra}</defs>'
            f'<circle cx="256" cy="256" r="252" fill="url(#{uid}r)"/>'
            f'<circle cx="256" cy="256" r="236" fill="url(#{uid}o)"/>'
            f'<circle cx="256" cy="256" r="224" fill="none" stroke="url(#{uid}g)" stroke-width="2.5" opacity=".55"/>'
            f'<g clip-path="url(#{uid}c)">{jet}</g>'
            f'<circle cx="256" cy="256" r="251" fill="none" stroke="#5A3F0A" stroke-opacity=".35" stroke-width="2"/></svg>')

# ---------- watermark for the gold Founding pass (replaces .runway) ----------
def watermark(key, colour='currentColor', uid=None):
    """Jet alone in a 300 x 180 box, anchored bottom-right of the card and cropped by its edges.
    A left-to-right fade keeps it off the name and chips; the card shows it at low opacity."""
    uid = uid or f'wm{key}'
    return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 180" preserveAspectRatio="xMaxYMax meet" aria-hidden="true">'
            f'<defs><linearGradient id="{uid}f" x1="0" y1="0" x2="300" y2="0" gradientUnits="userSpaceOnUse"><stop offset=".1" stop-color="#000"/><stop offset=".55" stop-color="#fff"/></linearGradient>'
            f'<mask id="{uid}j" maskUnits="userSpaceOnUse" x="0" y="0" width="300" height="180">{_mono_mask("w" + key, 1.1)}</mask>'
            f'<mask id="{uid}" maskUnits="userSpaceOnUse" x="0" y="0" width="300" height="180"><rect width="300" height="180" fill="url(#{uid}f)"/></mask></defs>'
            f'<g mask="url(#{uid})"><rect width="300" height="180" fill="{colour}" mask="url(#{uid}j)"/></g></svg>')

def jet_gold_side(uid='gs'):
    """The side view in the seal gold, for checking against photos (1000 x 340, transparent)."""
    return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 340" width="1000" height="340" role="img" aria-label="Cirrus SF50 Vision Jet, side view in gold">'
            f'<title>Cirrus SF50 Vision Jet, side view in gold (Go Around original drawing)</title>' + GEO['gold_side'].replace('__U__', uid) + '</svg>')

def jet_master(view, fill='#111114'):
    """Plain-ink master drawings from the same 3D model (side 1000 x 340, plan 1200 x 1040)."""
    vb, lab = ('0 0 1000 340', 'side view') if view == 'side' else ('0 0 1200 1040', 'plan view')
    w, h = vb.split()[2:]
    return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="{vb}" width="{w}" height="{h}" role="img" aria-label="Cirrus SF50 Vision Jet, {lab}">'
            f'<title>Cirrus SF50 Vision Jet, {lab} (Go Around original drawing)</title>'
            f'<defs><mask id="ms{view}" maskUnits="userSpaceOnUse" x="0" y="0" width="{w}" height="{h}">{_mono_mask(view, 3)}</mask></defs>'
            f'<rect width="{w}" height="{h}" fill="{fill}" mask="url(#ms{view})"/></svg>')

# ---------- success tick ----------
CHECK_CUR = 'M30 63 L50 83 L92 37'           # site/signup ptick (v3.css), unchanged
CHECK_NEW = 'M37.5 61.5 L52.5 76 L83 44.5'    # optically centred in a 120 circle (centroid 60,60)
TICK = {
  'current': dict(name='Current', note='Today: a thick bright-green stroke with a blurred green glow and a green wash over the whole page.'),
  'a': dict(name='Hairline seal', note='A fine ring and a thinner check in deep green. Quiet and editorial, like a stamp in a logbook.'),
  'b': dict(name='Enamel', note='A deep emerald enamel disc with a white check and a fine light rim, made like the gold and blue verified seals.'),
  'c': dict(name='Liquid glass', note='A frosted glass disc with a lit rim, and the check in the theme green inside it. Matches the glass pills of sign-in v12.'),
}
# per theme: (ok-deep, ok-bright, enamel top, enamel bottom, glass fill, glass rim)
TT = {
  'pearl':     ('#0A8F47', '#22C470', '#23B26A', '#0A7A3E', 'rgba(255,255,255,.62)', 'rgba(255,255,255,.95)'),
  'champagne': ('#0A7F40', '#22C470', '#23A866', '#09703A', 'rgba(255,252,246,.62)', 'rgba(255,253,248,.95)'),
  'midnight':  ('#3DDC97', '#4BEA94', '#1FA35B', '#0B6B39', 'rgba(255,255,255,.08)', 'rgba(255,255,255,.55)'),
  'amethyst':  ('#5EE6A8', '#4BEA94', '#1FA35B', '#0B6B39', 'rgba(220,200,255,.10)', 'rgba(236,228,255,.55)'),
}
def tick(key, theme, uid=None, size=120):
    uid = uid or f'tk{key}{theme[:2]}'
    deep, bright, e1, e2, gf, gr = TT[theme]
    dark = theme in ('midnight', 'amethyst')
    head = f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120" width="{size}" height="{size}" role="img" aria-label="Done"><title>Done</title>'
    if key == 'current':
        a, b = (('#4BEA94', '#0FB45C') if dark else ('#22C470', '#0A8F47'))
        return (head + f'<defs><linearGradient id="{uid}g" x1="0" y1="1" x2="1" y2="0"><stop offset="0" stop-color="{a}"/><stop offset="1" stop-color="{b}"/></linearGradient>'
                f'<filter id="{uid}f" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation="5"/></filter></defs>'
                f'<path d="{CHECK_CUR}" fill="none" stroke="{b}" stroke-width="10.5" stroke-linecap="round" stroke-linejoin="round" opacity=".22" transform="translate(0 5)" filter="url(#{uid}f)"/>'
                f'<path d="{CHECK_CUR}" fill="none" stroke="url(#{uid}g)" stroke-width="10.5" stroke-linecap="round" stroke-linejoin="round"/></svg>')
    if key == 'a':
        return (head + f'<circle cx="60" cy="60" r="51" fill="none" stroke="{deep}" stroke-width="2.4"/>'
                f'<path d="{CHECK_NEW}" fill="none" stroke="{deep}" stroke-width="6.5" stroke-linecap="round" stroke-linejoin="round"/></svg>')
    if key == 'b':
        return (head + f'<defs><linearGradient id="{uid}e" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="{e1}"/><stop offset="1" stop-color="{e2}"/></linearGradient>'
                f'<linearGradient id="{uid}r" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#fff" stop-opacity=".55"/><stop offset=".5" stop-color="#fff" stop-opacity="0"/><stop offset="1" stop-color="#fff" stop-opacity=".18"/></linearGradient>'
                f'<radialGradient id="{uid}h" cx=".5" cy="0" r=".75"><stop offset="0" stop-color="#fff" stop-opacity=".28"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></radialGradient>'
                f'<filter id="{uid}s" x="-30%" y="-30%" width="160%" height="160%"><feGaussianBlur stdDeviation="2.6"/></filter></defs>'
                f'<ellipse cx="60" cy="108" rx="36" ry="5" fill="{e2}" opacity="{".45" if dark else ".28"}" filter="url(#{uid}s)"/>'
                f'<circle cx="60" cy="58" r="50" fill="url(#{uid}e)"/>'
                f'<circle cx="60" cy="58" r="50" fill="url(#{uid}h)"/>'
                f'<circle cx="60" cy="58" r="48.6" fill="none" stroke="url(#{uid}r)" stroke-width="1.6"/>'
                f'<circle cx="60" cy="58" r="50" fill="none" stroke="#04331A" stroke-opacity=".35" stroke-width=".8"/>'
                f'<path d="{CHECK_NEW}" transform="translate(0 -2)" fill="none" stroke="#fff" stroke-width="8.5" stroke-linecap="round" stroke-linejoin="round"/></svg>')
    if key == 'c':
        shadow = '' if dark else f'<circle cx="60" cy="62" r="52" fill="#1C2A20" opacity=".10" filter="url(#{uid}s)"/>'
        edge = '' if dark else '<circle cx="60" cy="60" r="52.2" fill="none" stroke="#141413" stroke-opacity=".09" stroke-width=".8"/>'
        return (head + f'<defs><linearGradient id="{uid}r" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="{gr}"/><stop offset=".45" stop-color="{gr}" stop-opacity=".15"/><stop offset="1" stop-color="{gr}" stop-opacity=".6"/></linearGradient>'
                f'<radialGradient id="{uid}i" cx=".5" cy=".55" r=".55"><stop offset="0" stop-color="{bright}" stop-opacity="{".22" if dark else ".16"}"/><stop offset="1" stop-color="{bright}" stop-opacity="0"/></radialGradient>'
                f'<linearGradient id="{uid}k" x1="0" y1="1" x2="1" y2="0"><stop offset="0" stop-color="{bright}"/><stop offset="1" stop-color="{deep}"/></linearGradient>'
                f'<filter id="{uid}s" x="-30%" y="-30%" width="160%" height="160%"><feGaussianBlur stdDeviation="3"/></filter>'
                f'<linearGradient id="{uid}t" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#fff" stop-opacity="{".22" if dark else ".7"}"/><stop offset="1" stop-color="#fff" stop-opacity="0"/></linearGradient></defs>'
                + shadow + f'<circle cx="60" cy="60" r="52" fill="{gf}"/>'
                f'<circle cx="60" cy="60" r="52" fill="url(#{uid}i)"/>'
                f'<path d="M20 44 A44 44 0 0 1 100 44 A60 30 0 0 0 20 44 Z" fill="url(#{uid}t)"/>'
                f'<circle cx="60" cy="60" r="51.3" fill="none" stroke="url(#{uid}r)" stroke-width="1.5"/>' + edge +
                f'<path d="{CHECK_NEW}" fill="none" stroke="url(#{uid}k)" stroke-width="7.5" stroke-linecap="round" stroke-linejoin="round"/></svg>')

def small_mark(fill=None, uid='fjs'):
    """For 14-24 px next to a name: the whole jet from above in gold, no disc (a half jet does not read that small)."""
    f = fill or f'url(#{uid}g)'
    g = '' if fill else (f'<defs><linearGradient id="{uid}g" x1="0" y1="0" x2="1200" y2="1200" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="{GOLD[0]}"/><stop offset=".5" stop-color="{GOLD[1]}"/><stop offset="1" stop-color="{GOLD[2]}"/></linearGradient></defs>')
    return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 1200" width="24" height="24" role="img" aria-label="Founding Member"><title>Founding Member</title>{g}'
            f'<path d="{GEO["sil_small"]}" fill="{f}"/></svg>')
