)) {
                    clearInterval(checkConnection);
                }
            }, 100);

            // Stop trying after 5 seconds
            setTimeout(() => {
                clearInterval(checkConnection);
                if (!window.canvasGame.ws) {
                    console.error('Failed to connect canvas game to WebSocket');
                }
            }, 5000);
        }
    });

    // Global functions for UI
    function startNewGame() {
        if (window.canvasGame) {
            wi