why wont this work

function bossPhase5() {
    // Configuration
    const blockWidth = 80;
    const blockHeight = 20;
    const lavaRiseSpeed = 1; // pixels per interval
    const lavaRiseInterval = 100; // ms
    const totalPhases = 3;

    // State variables
    let currentPhase = 0;
    let lavaHeight = 0;
    let lavaInterval = null;

    // Keep track of spawned obstacles and blocks for cleanup
    const obstacles = [];
    const blocks = [];

    // Cleanup previous lava, blocks, and obstacles if any
    const existingLava = gameWorld.querySelector('.lava');
    if (existingLava) existingLava.remove();

    gameWorld.querySelectorAll('.block').forEach(el => el.remove());
    gameWorld.querySelectorAll('.obstacle').forEach(el => el.remove());

    // Create lava element once
    const lavaElement = document.createElement('div');
    lavaElement.className = 'lava';
    lavaElement.style.position = 'absolute';
    lavaElement.style.backgroundColor = 'red';
    lavaElement.style.width = '100%';
    lavaElement.style.bottom = '0';
    lavaElement.style.height = '0';
    lavaElement.style.zIndex = '5';
    gameWorld.appendChild(lavaElement);

    function spawnBlock(x) {
        const block = document.createElement('div');
        block.className = 'block';
        block.style.position = 'absolute';
        block.style.width = blockWidth + 'px';
        block.style.height = blockHeight + 'px';
        block.style.backgroundColor = 'blue';
        block.style.left = x + 'px';
        block.style.bottom = '0';
        block.style.zIndex = '10';
        gameWorld.appendChild(block);
        blocks.push(block);
        return block;
    }

    function spawnObstacle(x) {
        const obstacle = document.createElement('div');
        obstacle.className = 'obstacle';
        obstacle.style.position = 'absolute';
        obstacle.style.width = '40px';
        obstacle.style.height = '20px';
        obstacle.style.backgroundColor = 'orange';
        obstacle.style.left = x + 'px';
        obstacle.style.bottom = '0';
        obstacle.style.zIndex = '10';
        gameWorld.appendChild(obstacle);
        obstacles.push(obstacle);
        return obstacle;
    }

    function spawnInitialBlocks() {
        spawnBlock(100);
        spawnBlock(300);
        spawnBlock(500);
    }

    function spawnPhaseObstacles() {
        spawnObstacle(150);
        spawnObstacle(350);
        spawnObstacle(550);
    }

    // You need a reliable collision method:
    // This assumes both elements are positioned similarly relative to gameWorld and have boundingClientRects

    // Function to get player's bottom relative to gameWorld bottom
    function getPlayerBottomOffset() {
        const playerRect = player.getBoundingClientRect();
        const worldRect = gameWorld.getBoundingClientRect();
        // Distance from bottom of player to bottom of game world (positive means above bottom)
        return worldRect.bottom - playerRect.bottom;
    }

    function onLavaRise() {
        lavaHeight += lavaRiseSpeed;
        lavaElement.style.height = lavaHeight + 'px';

        // Collision check: Is player touching lava?
        if (checkCollision(player, lavaElement)) {
            // Slight buffer check if player bottom inside lava height, reduce lives once per collision
            const distanceToBottom = getPlayerBottomOffset();
            if (distanceToBottom < lavaHeight) {
                reduceLives();
            }
        }

        // Check if current phase lava fully raised
        if (lavaHeight >= (currentPhase + 1) * 100) {
            clearInterval(lavaInterval);
            lavaInterval = null;

            currentPhase++;

            if (currentPhase < totalPhases) {
                // Spawn new phase obstacles
                spawnPhaseObstacles();
                // Reset lava for next phase after short delay for player to reposition maybe
                setTimeout(() => {
                    lavaHeight = 0;
                    lavaElement.style.height = '0px';
                    lavaInterval = setInterval(onLavaRise, lavaRiseInterval);
                }, 1000);
            } else {
                // Final phase complete, proceed to boss attacks cycle or further logic
                cycleBossAttacks();
            }
        }
    }

    // Initialize phase by clearing old obstacles, resetting lava and spawning items
    function startPhase() {
        // Remove old obstacles
        obstacles.forEach(ob => ob.remove());
        obstacles.length = 0;

        // Initialize blocks and obstacles for phase 1
        spawnInitialBlocks();
        spawnPhaseObstacles();

        // Reset lava state
        lavaHeight = 0;
        lavaElement.style.height = '0px';

        // Start lava rising interval
        lavaInterval = setInterval(onLavaRise, lavaRiseInterval);
    }

    // Start the entire boss phase 5
    startPhase();
}