"""Landing v4 + Codex merge (19 Nov 2026): 0 console errors, 0 JS errors, 0 horizontal overflow at 390 / 820 / 1440,
both themes, with motion on and with reduced motion. Serve this folder on 8931 first: python3 -m http.server 8931"""
import json, sys
from playwright.sync_api import sync_playwright
BASE = "http://127.0.0.1:8931/index.html?skin="
CHROME = "/home/box/.cache/ms-playwright/chromium-1243/chrome-linux64/chrome"
bad = n = 0
with sync_playwright() as p:
    b = p.chromium.launch(executable_path=CHROME)
    for w, h in [(390, 844), (820, 1180), (1440, 900)]:
        for t in ["pearl", "midnight"]:
            for rm in ["no-preference", "reduce"]:
                ctx = b.new_context(viewport={"width": w, "height": h}, reduced_motion=rm); pg = ctx.new_page(); errs = []
                pg.on("console", lambda m: errs.append(m.text) if m.type == "error" else None)
                pg.on("pageerror", lambda e: errs.append("js: " + str(e)))
                pg.goto(BASE + t, wait_until="networkidle")
                H = pg.evaluate("document.documentElement.scrollHeight"); ov = 0
                for y in range(0, H, h // 2):
                    pg.evaluate(f"scrollTo(0,{y})"); pg.wait_for_timeout(60)
                    ov = max(ov, pg.evaluate("document.documentElement.scrollWidth - document.documentElement.clientWidth"))
                n += 1
                if errs or ov > 0: bad += 1; print("FAIL", w, t, rm, json.dumps(errs), "overflow", ov)
                ctx.close()
    b.close()
print("%d runs, %d failed" % (n, bad)); sys.exit(1 if bad else 0)
