#!/usr/bin/env python3
"""Before/after comparison clips (Designer, 12 Nov 2026).
iPhone 390x844 screens at deviceScaleFactor 3, 5s at 30fps, same simulated timeline in both halves.
Out: out/rollout-before-after-{pearl,midnight}.mp4 (+ a still at 2.0s). libx264 crf 14 preset slow yuv420p."""
import asyncio, shutil, subprocess
from pathlib import Path
from playwright.async_api import async_playwright
D=Path('/workspace/reload-new'); OUT=D/'out'; FPS=30; SEC=5.0
def ff(*a): subprocess.run(['ffmpeg','-y','-loglevel','error',*a],check=True)
async def main():
    async with async_playwright() as p:
        b=await p.chromium.launch(args=['--font-render-hinting=none','--disable-lcd-text'])
        for th in ['pearl','midnight']:
            tmp=Path(f'/tmp/rl-ba-{th}'); shutil.rmtree(tmp,ignore_errors=True); tmp.mkdir()
            pg=await b.new_page(viewport={'width':900,'height':958},device_scale_factor=3)
            await pg.emulate_media(reduced_motion='no-preference')
            await pg.goto((D/'demo-before-after.html').as_uri()+f'?render=1&theme={th}')
            await pg.evaluate('document.fonts.ready')
            for i in range(int(SEC*FPS)):
                await pg.evaluate('t=>seek(t)',i/FPS); await pg.screenshot(path=str(tmp/f'f{i:04d}.png'))
            await pg.close()
            out=OUT/f'rollout-before-after-{th}.mp4'
            ff('-framerate',str(FPS),'-i',str(tmp/'f%04d.png'),'-c:v','libx264','-pix_fmt','yuv420p','-crf','14','-preset','slow','-movflags','+faststart',str(out))
            shutil.copy(tmp/'f0060.png',OUT/f'rollout-before-after-{th}.png')
            print('WROTE',out,out.stat().st_size)
        await b.close()
asyncio.run(main())
