"""python -B span_witness_333.py EVIDENCE OUTPUT.svg; no characters or byte values read."""
import gzip,json,sys
from pathlib import Path
from collections import defaultdict
d=Path(sys.argv[1]);a=defaultdict(list)
for v in json.loads(gzip.decompress((d/'grid_geometry_245.json.gz').read_bytes())):
 a[v['page'],v['row']].append((v['bbox'][0],v['bbox'][2]))
p=a[50,3];q=a[51,2]
gap=max(v[i+1][0]-v[i][1] for (pg,r),v in a.items() if pg!=51 for i in range(7))
ww=a[51,3][0][1]-a[51,3][0][0];extra=q[-1][1]+gap
end=extra+ww;PS=p[-1][1]-p[0][0];QS=end-q[0][0];assert (PS,QS,gap,ww)==(1144,1072,54,88)
scale=.45;left=21
def boxes(row,y,ghost=False):
 s=row[0][0];o=''
 for i,(x1,x2) in enumerate(row):
  ninth=ghost and i==8
  o+=f'<rect x="{left+(x1-s)*scale:.2f}" y="{y}" width="{(x2-x1)*scale:.2f}" height="23" rx="2" fill="'+('#feebbb' if ninth else '#76cbc5')+'" stroke="'+('#f8bd61' if ninth else '#95d9d4')+'"'+(' stroke-dasharray="3 2"' if ninth else '')+'/>'
 return o
out=f"""<svg xmlns="http://www.w3.org/2000/svg" width="566" height="205" viewBox="0 0 566 205" role="img" aria-labelledby="t d"><title id="t">A printed row of eight is wider than a candidate row of nine</title><desc id="d">Eight measured cells on page 50 row 3 span 1,144 pixels. Eight on page 51 row 2 span 930; allow the widest comparison gap of 54, then add the 88-pixel next cell, for 1,072. Rows drawn from a common left edge for scale, not original page position.</desc><rect width="566" height="205" fill="#10272b" rx="10"/><g fill="#eff7f6" font-family="system-ui, sans-serif" font-size="16"><text x="21" y="32" font-weight="600">Eight printed cells · page 50, row 3</text>{boxes(p,46)}<text x="21" y="90" fill="#b6d7d4">1,144 px</text><text x="21" y="122" font-weight="600">Page 51, row 2 + its next printed cell</text>{boxes(q+[(extra,end)],136,True)}<text x="21" y="183" fill="#b6d7d4">930 + 54 gap + 88 next cell = 1,072 px</text><path d="M{left+scale*PS:.2f} 72 V160" stroke="#909f9e" stroke-dasharray="2 4"/></g></svg>"""
Path(sys.argv[2]).write_text(out+'\n')
