"""Generate an accessible small-screen version of the SGL geometry sketch.

This is a concept diagram, not a scale drawing or image reconstruction.
It intentionally preserves only relationships stated in the current Site
caption: one selected target, solar deflection, a ring signal, a probe on the
focal line beginning near 548 AU, and scanning/reconstruction steps.
"""
from pathlib import Path
from xml.sax.saxutils import escape

OUT = Path(__file__).resolve().parent


def t(x, y, value, size=19, fill="#d8eaff", weight=400, anchor="start"):
    return (f'<text x="{x}" y="{y}" font-family="Arial,sans-serif" '
            f'font-size="{size}" font-weight="{weight}" fill="{fill}" '
            f'text-anchor="{anchor}">{escape(value)}</text>')


def build():
    s = ['''<svg xmlns="http://www.w3.org/2000/svg" width="320" height="1040" viewBox="0 0 320 1040" role="img" aria-labelledby="title desc">
<title id="title">One-target solar gravitational lens geometry</title>
<desc id="desc">Schematic, not to scale. Light from one selected distant planet bends around the Sun and reaches a probe on the focal line, which begins near 548 astronomical units. The probe measures a ring-shaped brightness pattern, scans it and uses a model to reconstruct an image. Distances and ray bends are not to scale; this is not an all-sky camera.</desc>
<rect width="320" height="1040" rx="20" fill="#07182e"/>
<rect x="10" y="10" width="300" height="1020" rx="16" fill="#102746"/>''']

    # Short title and plain-language introduction.
    s += [t(20, 44, "One chosen target", 23, weight=700),
          t(20, 72, "Not an all-sky camera", 23, weight=700),
          t(20, 107, "Distant planet light bends", 19),
          t(20, 132, "around the Sun toward a probe.", 19)]

    # Vertical reading order: target -> Sun -> downstream focal line/probe.
    # Rays are deliberately curved and unscaled; they show topology only.
    s += ['<path d="M150 222 L115 356 Q110 377 115 398 L154 523" fill="none" stroke="#53d3d1" stroke-width="3.5"/>',
          '<path d="M170 222 L205 356 Q210 377 205 398 L166 523" fill="none" stroke="#53d3d1" stroke-width="3.5"/>',
          '<circle cx="160" cy="202" r="25" fill="#dce7f5"/>',
          '<circle cx="160" cy="202" r="10" fill="#397da2"/>',
          t(160, 171, "Distant planet", 19, anchor="middle"),
          '<circle cx="160" cy="377" r="36" fill="#ffbd59"/>',
          t(160, 384, "Sun", 20, fill="#2b3450", weight=700, anchor="middle"),
          '<line x1="160" y1="414" x2="160" y2="535" stroke="#ffdd91" stroke-width="3" stroke-dasharray="7 6"/>',
          '<circle cx="160" cy="548" r="12" fill="#edf7ff" stroke="#7cc9ff" stroke-width="4"/>',
          '<path d="M145 548h30m-15-15v30" stroke="#fff" stroke-width="2"/>',
          t(160, 590, "Distant probe", 19, anchor="middle"),
          '<rect x="18" y="606" width="284" height="78" rx="12" fill="#172f50" stroke="#ffdd91" stroke-width="1.5"/>',
          t(160, 634, "Probe is beyond about 548 AU", 19, fill="#ffdd91", anchor="middle"),
          t(160, 662, "from the Sun on the focal line", 19, fill="#ffdd91", anchor="middle"),
          '<rect x="18" y="698" width="284" height="100" rx="12" fill="#0b1d36" stroke="#566f91" stroke-width="1.5"/>',
          '<circle cx="63" cy="748" r="24" fill="none" stroke="#ff68cb" stroke-width="4" stroke-dasharray="4 5"/>',
          '<circle cx="63" cy="748" r="8" fill="#ffbd59"/>',
          t(100, 738, "What the probe sees:", 18, fill="#ffb6e4", weight=700),
          t(100, 765, "a ring-shaped signal", 18, fill="#d8eaff"),
          t(100, 789, "to scan and reconstruct", 18, fill="#d8eaff")]

    # Explain what the future observatory does, without implying a real mission.
    s += [t(20, 839, "What the probe would do", 22, weight=700),
          t(24, 878, "1. Aim at one known planet.", 19),
          t(24, 912, "2. Measure and scan the ring.", 19),
          t(24, 946, "3. Reconstruct with a model.", 19),
          t(20, 984, "Rays and distances are not to scale.", 18, fill="#b9c9dc"),
          t(20, 1009, "No mission has flown.", 18, fill="#b9c9dc"),
          '</svg>']
    return '\n'.join(s) + '\n'


if __name__ == '__main__':
    (OUT / 'geometry-mobile.svg').write_text(build(), encoding='utf-8')
    print('Wrote geometry-mobile.svg (viewBox 320 × 1040; text 18–23 units).')
