/*
Games overview: one card per game (logo and name sticker).
Layout ranges: phone up to 600px (2 columns), tablet 601-950px (3 columns), desktop from 951px (4 columns).
*/

/* Frame: 32px side margins, at most 1200px wide, logos start 64px below the 80px header (48px on phones) */
main {
    box-sizing: border-box;
    width: min(calc(100% - 64px), 1200px);
    margin: calc(5rem + 64px) auto 0;
    isolation: isolate;
}

.games-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4rem 2rem;
    padding: 0;
    perspective: 1000px;
}

.game-card {
    --accent: white;
    --tilt: -5deg;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: calc((100% - 6rem) / 4);
    max-width: 235px;
    padding-bottom: 1rem;
    text-align: center;
    /* The logo's border and 3D edge are sized from the card width (cqi = 1% of the card width) */
    container-type: inline-size;
    transform: rotate(var(--tilt));
    transition: transform .3s;
}

/* Tilts per card: only -5deg and +5deg, alternating so that no two neighbouring logos (side by side or one above
   the other) have the same tilt. A shorter, centred last row only alternates within itself.
   Desktop: 4 columns (4 + 3). Tablet and phone below. */
.game-card:nth-child(1) {
    --tilt: -5deg;
}

.game-card:nth-child(2) {
    --tilt: 5deg;
}

.game-card:nth-child(3) {
    --tilt: -5deg;
}

.game-card:nth-child(4) {
    --tilt: 5deg;
}

.game-card:nth-child(5) {
    --tilt: -5deg;
}

.game-card:nth-child(6) {
    --tilt: 5deg;
}

.game-card:nth-child(7) {
    --tilt: -5deg;
}

.game-card::before {
    content: '';
    position: absolute;
    z-index: -1;
    inset: -12% -20% 0;
    background: radial-gradient(ellipse, color-mix(in srgb, var(--accent) 25%, transparent), transparent 65%);
    pointer-events: none;
}

.game-card img {
    display: block;
    width: 88%;
    height: auto;
    aspect-ratio: 1;
    object-fit: contain;
    border-radius: 50%;
    /* White rim 1/32 of the logo width, like the logo on the rules pages */
    border: 2.75cqi solid white;
    background: white;
    /* 3D edge like the logo on the rules pages (grey band, black band, soft shadow), in the same proportions to the logo */
    box-shadow: 0 3.44cqi 0 #ddd, 0 6.88cqi 0 black, 0 11cqi 16.5cqi #0006;
}

.game-name {
    position: relative;
    margin-top: 1.75rem;
    /* Padding, corners and shadow in em: the sticker keeps its proportions at every text size */
    padding: .37em .57em;
    border: 2px solid black;
    border-radius: .17em;
    background: var(--accent);
    color: black;
    box-shadow: .23em .23em 0 black;
    font-size: 1.125rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .02em;
}

.game-card:focus-visible {
    transform: scale(1.05);
    z-index: 1;
}

@media (hover: hover) and (pointer: fine) {
    .game-card:hover {
        transform: scale(1.05);
        z-index: 1;
    }
}

.game-card:focus-visible {
    outline: 2px solid white;
    outline-offset: 12px;
    border-radius: 1rem;
}

/* Tablet: 3 columns */
@media (max-width: 950px) {
    .game-card {
        width: calc((100% - 4rem) / 3);
    }

    /* 3 columns (3 + 3 + 1) */
    .game-card:nth-child(1) {
        --tilt: -5deg;
    }

    .game-card:nth-child(2) {
        --tilt: 5deg;
    }

    .game-card:nth-child(3) {
        --tilt: -5deg;
    }

    .game-card:nth-child(4) {
        --tilt: 5deg;
    }

    .game-card:nth-child(5) {
        --tilt: -5deg;
    }

    .game-card:nth-child(6) {
        --tilt: 5deg;
    }

    .game-card:nth-child(7) {
        --tilt: -5deg;
    }

    .game-name {
        font-size: 1rem;
    }
}

/* Phone: 2 columns */
@media (max-width: 600px) {
    main {
        margin-top: calc(5rem + 48px);
    }

    .games-grid {
        gap: 3rem 1.5rem;
    }

    .game-card {
        width: calc((100% - 1.5rem) / 2);
    }

    /* 2 columns (2 + 2 + 2 + 1) */
    .game-card:nth-child(1) {
        --tilt: -5deg;
    }

    .game-card:nth-child(2) {
        --tilt: 5deg;
    }

    .game-card:nth-child(3) {
        --tilt: 5deg;
    }

    .game-card:nth-child(4) {
        --tilt: -5deg;
    }

    .game-card:nth-child(5) {
        --tilt: -5deg;
    }

    .game-card:nth-child(6) {
        --tilt: 5deg;
    }

    .game-card:nth-child(7) {
        --tilt: -5deg;
    }

    .game-name {
        font-size: .875rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .game-card {
        transition: none;
    }

    .game-card:hover, .game-card:focus-visible {
        transform: rotate(var(--tilt));
    }
}
