server {
    listen 80;
    server_name _;

    root /usr/share/nginx/html;
    index index.html;

    include /etc/nginx/mime.types;
    types {
        application/wasm wasm;
    }

    # SharedArrayBuffer requires these headers (used by audio/video workers)
    add_header Cross-Origin-Opener-Policy "same-origin" always;
    add_header Cross-Origin-Embedder-Policy "require-corp" always;

    # SPA fallback
    location / {
        try_files $uri $uri/ /index.html;
    }

    # Cache static assets aggressively (content-hashed filenames)
    location ~* \.(js|css|wasm|woff2|woff|ttf|png|jpg|webp|svg|ico)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
        add_header Cross-Origin-Opener-Policy "same-origin" always;
        add_header Cross-Origin-Embedder-Policy "require-corp" always;
    }

    gzip on;
    gzip_types text/plain text/css application/javascript application/json application/wasm;
    gzip_min_length 1024;
}
