<script>
    let { game } = $props();

    function formatDate(dateStr) {
        return new Date(dateStr).toLocaleDateString("en-US", {
            month: "short", day: "numeric", year: "numeric"
        });
    }
</script>

<a href={`/game/${game.id}`} class="game-card">
    <div class="game-icon">
        <svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
            <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
            <path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
            <path d="M8 7h8M8 11h5"/>
        </svg>
    </div>

    <div class="game-info">
        <h2>{game.title}</h2>
        <p class="context">{game.world_context}</p>
        <p class="date">Started {formatDate(game.created_at)}</p>
    </div>

    <div class="game-arrow">
        <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M5 12h14M12 5l7 7-7 7"/>
        </svg>
    </div>
</a>

<style>
    .game-card {
        display: flex;
        align-items: center;
        gap: 1.25rem;
        padding: 1.25rem 1.5rem;
        background: #0f0f18;
        border: 1px solid #1e1e28;
        border-radius: 12px;
        text-decoration: none;
        color: inherit;
        transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
        position: relative;
        overflow: hidden;
    }

    .game-card::before {
        content: "";
        position: absolute;
        inset: 0;
        background: radial-gradient(ellipse at left, rgba(192, 132, 252, 0.06) 0%, transparent 70%);
        opacity: 0;
        transition: opacity 0.2s;
    }

    .game-card:hover {
        border-color: #c084fc;
        transform: translateX(4px);
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    }

    .game-card:hover::before {
        opacity: 1;
    }

    .game-icon {
        width: 44px;
        height: 44px;
        border-radius: 10px;
        background: rgba(192, 132, 252, 0.1);
        color: #c084fc;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }

    .game-info {
        flex: 1;
        min-width: 0;
    }

    .game-info h2 {
        font-size: 1rem;
        font-weight: 600;
        color: #e5e5ea;
        letter-spacing: -0.2px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .context {
        font-size: 0.85rem;
        color: #6b6b7a;
        margin-top: 0.25rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .date {
        font-size: 0.75rem;
        color: #44445a;
        margin-top: 0.2rem;
    }

    .game-arrow {
        color: #3a3a50;
        flex-shrink: 0;
        transition: color 0.2s, transform 0.2s;
    }

    .game-card:hover .game-arrow {
        color: #c084fc;
        transform: translateX(3px);
    }
</style>
