"""Generate solid-color PNG icons for PWA manifest using stdlib only (no Pillow)."""
import zlib, struct, os

def make_png(size, rgb=(0x25, 0x63, 0xEB)):
    """Create a minimal valid RGB PNG of the given size filled with one color."""
    w = h = size
    raw = b''
    for _ in range(h):
        raw += b'\x00' + bytes(rgb) * w  # filter byte 0 (None) + RGB pixels

    compressed = zlib.compress(raw, 9)

    def chunk(name, data):
        c = name + data
        return struct.pack('>I', len(data)) + c + struct.pack('>I', zlib.crc32(c) & 0xffffffff)

    sig  = b'\x89PNG\r\n\x1a\n'
    ihdr = chunk(b'IHDR', struct.pack('>IIBBBBB', w, h, 8, 2, 0, 0, 0))
    idat = chunk(b'IDAT', compressed)
    iend = chunk(b'IEND', b'')
    return sig + ihdr + idat + iend


if __name__ == '__main__':
    out_dir = os.path.join(os.path.dirname(__file__), '..', 'static')
    os.makedirs(out_dir, exist_ok=True)
    for size in [192, 512]:
        path = os.path.join(out_dir, f'icon-{size}.png')
        with open(path, 'wb') as f:
            f.write(make_png(size))
        print(f'Wrote {path}')
