"""Assemble the offline classroom in the Open Science notebook data directory."""
from pathlib import Path
import base64, csv, json, sys
R=Path(__file__).resolve().parents[1]; S=R/'scene'
def encoded(p):return base64.b64encode(p.read_bytes()).decode('ascii')
def read(p):return (R/p).read_text()
def create(reader):
    figs=json.loads(read('figures/index.json'))
    for f in figs:f['image']='data:image/png;base64,'+encoded(R/'figures'/(f['id']+'.png'))
    refs=[
        ('Author’s announcement · 20 November','https://alpo.ge/remark.pdf'),
        ('Lean and Mathlib joint statement · 21 November','https://leanprover-community.github.io/blog/posts/riemann-hypothesis/'),
        ('Sutherland · independent verification logs','https://math.mit.edu/~drew/grh/'),
        ('Rubinstein · working guide, version 2','https://www.math.uwaterloo.ca/~mrubinst/alpoge_claude_grh/'),
        ('Clay Mathematics Institute · problem status','https://www.claymath.org/millennium/riemann-hypothesis/'),
        ('LMFDB · zero reference table','https://www.lmfdb.org/zeros/zeta/'),
        ('NIST DLMF · zeros','https://dlmf.nist.gov/25.10')]
    zeros=list(csv.DictReader((R/'results/zeros.csv').open()));primes=list(csv.DictReader((R/'results/primes.csv').open()))
    conclusions=[
        'External formal verification. The Lean and Mathlib communities certified the standard RH statement and its proof. The five exported endpoints also cover nonvanishing and critical-strip zero locations for Dirichlet L-functions. Extension to general L-functions is outside these statements.',
        'Local audit. All five theorem names matched the external statement-comparison log and exactly three used axioms. Four archived MIT log hashes matched the published manifest. The complete 61.57 GB proof export was not replayed locally.',
        'Numerical replication. One hundred computed ordinates agree with the published LMFDB decimals to within 2.22 × 10⁻³¹ in height. The largest of the eleven bracketed-crossing differences was 4.84 × 10⁻¹³ or less. The finite list carries no independent zero-completeness certificate.',
        'Prime distribution. Both counting methods yield 78,498 primes through 10⁶. The grid, sums and finite products illustrate analytic relationships. The formal universal claim rests on the external proof checks.',
        'Status on 23 November 2026. Clay’s problem page still lists RH as unsolved. Rubinstein’s second working draft separates the weighted inequality (M) from the hypotheses needed to derive it. The mathematical exposition continues.']
    records={k:read(v) for k,v in [('Main.lean','sources/Main.lean'),('Statements.lean','sources/Statements.lean'),('Axiom audit','sources/audit.log'),('Statement comparison','sources/con-leche-compare.log'),('Numerical results','results/summary.json'),('Verification checks','results/audit.json'),('Run timeline','results/numerical_timeline.json'),('Calculation code','calculations/analyze.py'),('Independent check code','calculations/verify.py')]}
    data=dict(glb=encoded(S/'classroom.glb'),figures=figs,zeros=[[int(i['index']),i['height']] for i in zeros],primes=[[int(i['x']),int(i['pi'])] for i in primes],reader=reader,refs=[dict(name=k,url=v) for k,v in refs],conclusions=conclusions,records=records)
    template=(S/'classroom.html.in').read_text()
    return template.replace('/*LIBRARY*/',(S/'three-gltf.min.js').read_text()).replace('/*APP*/',(S/'classroom.js').read_text()).replace('/*DATA*/',json.dumps(data,ensure_ascii=False).replace('<','\\u003c'))
if __name__=='__main__':
    (R/'Proof Classroom.html').write_text(create((S/'proof_reading.html').read_text()))

