meId = requestAnimationFrame(animate);
    }

    let resizeTimeout;
    function onResize() {
        clearTimeout(resizeTimeout);
        resizeTimeout = setTimeout(() => {
            if (animationFrameId) cancelAnimationFrame(animationFrameId);
            init();
            // animate(0); // Restart animation loop
        }, 250);
    }

    init();
    animate(0); // Start animation loop
    window.addEventListener('resize', onResize);
    canvas.cleanup = function() { if (animationFrameId) cancelAni