body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: radial-gradient(circle at top, #1c002b 0%, #0d0018 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    color: #fff;
}

/* --- Title --- */
h1 {
    color: #e3b3ff;
    margin-bottom: 25px;
    font-size: 2.5rem;
    text-shadow: 0 0 10px #bb00ff, 0 0 20px #a600ff, 0 0 40px #a600ff;
    letter-spacing: 1.5px;
    text-align: center;
}

/* --- Game Info Bar --- */
.game-info {
    background: rgba(75, 0, 130, 0.6);
    padding: 12px 20px;
    border-radius: 12px;
    margin-bottom: 25px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    box-shadow: 0 0 15px rgba(187, 0, 255, 0.4);
}

/* --- Restart Button --- */
#restart {
    background: linear-gradient(135deg, #7d26c0, #bb00ff);
    border: none;
    padding: 6px 15px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 0 15px rgba(187, 0, 255, 0.4);
    transition: all 0.3s ease;
}

#restart:hover {
    background: linear-gradient(135deg, #bb00ff, #5a1b8a);
    box-shadow: 0 0 10px #bb00ff, 0 0 10px #bb00ff;
    transform: scale(1.05);
}

/* --- Game Board --- */
.game-board {
    display: grid;
    grid-template-columns: repeat(4, 100px);
    grid-template-rows: repeat(4, 100px);
    gap: 15px;
    perspective: 1200px;
    justify-content: center;
}

/* --- Card --- */
.card {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s ease;
    cursor: pointer;
    border-radius: 14px;
    box-shadow: 0 0 10px rgba(187, 0, 255, 0.3);
}

.card.flip {
    transform: rotateY(180deg);
}

/* --- Card Faces --- */
.front,
.back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 14px;
    transition: all 0.3s ease;
    box-shadow: inset 0 0 15px rgba(187, 0, 255, 0.4);
}

/* Front side (hidden initially) */
.front {
    background: rgba(75, 0, 130, 0.7);
    box-shadow: 0 0 0 0.1px rgba(187, 0, 255, 0.01);
}

/* Back side (visible when flipped) */
.back {
    background: linear-gradient(135deg, #5f2b87, #52066e);
    transform: rotateY(180deg);
    box-shadow: 0 0 0 0.1px rgba(187, 0, 255, 0.01);
}

/* --- Card Image --- */
.front img,
.back img {
    width: 90%;
    height: 95%;
    object-fit: cover;
    border-radius: 10px;
    transition: transform 0.3s ease;
}

.card:hover .front img,
.card:hover .back img {
    transform: scale(0.9);
}

/* --- Glowing Matched Cards --- */
.card.matched {
    box-shadow: 0 0 2px #bb00ff, 0 0 20px #bb00ff;
    animation: wiggle 0.6s ease-out forwards;
    pointer-events: none;
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotateY(180deg) rotate(0deg);
    }

    20% {
        transform: rotateY(180deg) rotate(-8deg);
    }

    40% {
        transform: rotateY(180deg) rotate(8deg);
    }

    60% {
        transform: rotateY(180deg) rotate(-5deg);
    }

    80% {
        transform: rotateY(180deg) rotate(5deg);
    }
}

/* Ensure transforms stack properly */
.card {
    transform-style: preserve-3d;
}

/* --- Score Counters --- */
#moves,
#matches {
    font-weight: bold;
    color: #f2c743;
    text-shadow: 0 0 10px #f2c743, 0 0 20px #f2c743;
}

/* --- background --- */
.particle {
    position: fixed;
    background: rgba(187, 0, 255, 0.5);
    border-radius: 50%;
    pointer-events: none;
    z-index: -1;
    filter: blur(1px);
}

@keyframes float {
    0% {
        transform: translate(0, 0);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        transform: translate(100px, -100px);
        opacity: 0;
    }
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .game-container {
        padding: 5px;
        width: 90vw;
        /* Better width control */
        margin: 10px auto;
        /* Center properly */
        border-width: 1px;
        /* Thinner border on mobile */
    }

    h1 {
        font-size: 1.4rem;
        margin-bottom: 15px;
        text-shadow: 0 0 5px #bb00ff, 0 0 10px #a600ff;
        /* Reduced glow */
    }

    .game-info {
        padding: 10px 15px;
        font-size: 0.8rem;
        flex-direction: column;
        /* Stack elements vertically */
        gap: 8px;
        flex-wrap: wrap;
    }

    #restart {
        padding: 5px 10px;
        font-size: 0.65rem;
    }

    .game-board {
        grid-template-columns: repeat(4, 20vw);
        /* Viewport-based sizing */
        grid-template-rows: repeat(4, 20vw);
        gap: 2vw;
        /* Smaller gap percentage */
        max-width: 100%;
        /* Full container width */
        padding: 0 2vw;
        /* Side padding only */
    }

    .card {
        height: 0;
        padding-bottom: 100%;
        /* Square aspect ratio */
        position: relative;
    }

    .front,
    .back {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }

    .front img,
    .back img {
        width: 85%;
        height: 85%;
    }
}