<script>
    import { onMount } from 'svelte';
    import { push } from 'svelte-spa-router';

    const COLORS = [
        '#970505', '#CF8917', '#E3D214', '#39BD1C',
        '#12B6C8', '#170CB7', '#6613BA', '#C71287',
        '#753F16', '#FFD700',
    ];

    let sparks = [];

    onMount(() => {
        sparks = Array.from({ length: 140 }, () => ({
            x:        Math.random() * 100,
            y:        Math.random() * 100,
            size:     Math.random() * 3 + 1,
            color:    COLORS[Math.floor(Math.random() * COLORS.length)],
            delay:    -(Math.random() * 4),
            duration: Math.random() * 2 + 1,
        }));

        const timer = setTimeout(() => push('/'), 5000);
        return () => clearTimeout(timer);
    });
</script>

<div class="screen">
    <div class="sparkfield" aria-hidden="true">
        {#each sparks as s}
            <span
                class="spark"
                style="
                    left: {s.x}%;
                    top: {s.y}%;
                    width: {s.size}px;
                    height: {s.size}px;
                    background: {s.color};
                    box-shadow: 0 0 {s.size * 2}px {s.color};
                    animation-duration: {s.duration}s;
                    animation-delay: {s.delay}s;
                "
            ></span>
        {/each}
    </div>

    <h1 class="title">color restored</h1>
    <p class="line1">every fragment found. every hue returned</p>
    <p class="line2">Go forth and experience the world in all its colors.</p>
</div>

<style>
    .screen {
        width: 800px;
        height: 450px;
        margin: 0 auto;
        background: #0a0a0a;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 14px;
        position: relative;
        overflow: hidden;
    }

    .sparkfield {
        position: absolute;
        inset: 0;
        pointer-events: none;
    }

    .spark {
        position: absolute;
        border-radius: 50%;
        animation: sparkle linear infinite;
    }

    @keyframes sparkle {
        0%, 100% { opacity: 1;    transform: scale(1);   }
        50%       { opacity: 0.05; transform: scale(0.4); }
    }

    .title {
        font-family: 'Courier New', Courier, monospace;
        font-size: 52px;
        font-weight: 400;
        background: linear-gradient(
            90deg,
            #FF4136, #FF851B, #FFDC00, #2ECC40,
            #0074D9, #B10DC9, #FF69B4, #FF4136
        );
        background-size: 200% auto;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        animation: shimmer 4s linear infinite;
        position: relative;
        z-index: 1;
    }

    @keyframes shimmer {
        from { background-position: 0% center; }
        to   { background-position: 200% center; }
    }

    .line1 {
        font-family: 'Courier New', Courier, monospace;
        font-size: 18px;
        color: #ccc;
        text-align: center;
        position: relative;
        z-index: 1;
    }

    .line2 {
        font-family: 'Courier New', Courier, monospace;
        font-size: 15px;
        color: #666;
        text-align: center;
        margin-top: -4px;
        position: relative;
        z-index: 1;
    }
</style>
