        // 3. Variant fallback — resize master on-the-fly via Cloudflare Image Resizing
        if (CONFIG.ENABLE_VARIANT_FALLBACK) {
            const variantMatch = path.match(/^(.+)-(\d+)x(\d+)\.(jpe?g|png|webp|gif|avif)$/i);
            if (variantMatch) {
                const basePath = variantMatch[1];
                const width = parseInt(variantMatch[2], 10);
                const height = parseInt(variantMatch[3], 10);
                const ext = variantMatch[4].toLowerCase().replace('jpeg', 'jpg');
                const isWebP = (ext === 'webp');

                // For WebP variants the master is a jpg/png; otherwise same extension
                const masterExts = isWebP ? ['jpg', 'jpeg', 'png'] : [ext];

                for (const masterExt of masterExts) {
                    const masterUrl = new URL(url);
                    masterUrl.pathname = basePath + '.' + masterExt;

                    try {
                        const imageOpts = {
                            width: width,
                            height: height,
                            fit: 'cover'
                        };
                        if (isWebP) {
                            imageOpts.format = 'webp';
                        }

                        const resized = await fetch(masterUrl.toString(), {
                            cf: { image: imageOpts }
                        });

                        if (resized.ok) {
                            const headers = new Headers(resized.headers);
                            headers.set('cache-control', 'public, max-age=3600');
                            headers.set('cdn-cache-control', 'max-age=' + CONFIG.VARIANT_FALLBACK_CDN_TTL);
                            headers.set('x-staticq-source', 'resize-fallback');
                            headers.set('x-staticq-cache', 'MISS');

                            const response = new Response(resized.body, {
                                status: 200,
                                headers: headers
                            });

                            ctx.waitUntil(cache.put(cacheKey, response.clone()));
                            return response;
                        }
                    } catch (e) {
                        console.error('StaticQ resize fallback error:', e.message);
                    }
                }
            }
        }
