<script>
    import { push, querystring } from 'svelte-spa-router';
    import { resetLevel } from '../stores/colorStore.js';
    import { getLevel } from '../game/levelData.js';

    $: levelNum = $querystring
        ? parseInt(new URLSearchParams($querystring).get('level')) || 1
        : 1;

    function retry() {
        const level = getLevel(levelNum);
        resetLevel(levelNum, level.color);
        push(`/game?level=${levelNum}`);
    }
</script>

<div class="screen">
    <h1>the light faded...</h1>
    <p>the world stays gray a little longer</p>
    <div class="buttons">
        <button on:click={retry}>try again</button>
        <button on:click={() => push('/levelselect')}>level select</button>
    </div>
</div>

<style>
    .screen {
        width: 800px;
        height: 450px;
        margin: 0 auto;
        background: #0a0a0a;
        color: #ccc;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 16px;
    }
    h1 {
        font-family: 'Courier New', Courier, monospace;
        font-size: 48px;
        font-weight: 400;
        color: white;
    }
    p {
        font-family: 'Courier New', Courier, monospace;
        font-size: 20px;
        opacity: 0.6;
    }
    .buttons {
        display: flex;
        gap: 16px;
        margin-top: 8px;
    }
    button {
        padding: 10px 32px;
        border-radius: 24px;
        cursor: pointer;
        font-family: 'Courier New', Courier, monospace;
        font-size: 20px;
        background: rgba(255,255,255,0.08);
        border: 1px solid rgba(255,255,255,0.2);
        color: white;
    }
    button:hover { background: rgba(255,255,255,0.18); }
</style>