:root {
    --card-size: 120px;
    --gap: 12px;
    --primary-color: #4a90e2;
    --secondary-color: #f5a623;
    --background-color: #f0f8ff;
    --font-color: #333;
}

body {
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background-color: var(--background-color);
    color: var(--font-color);
}

#game-container {
    text-align: center;
    padding: 20px;
}

h1 {
    color: var(--primary-color);
    margin-bottom: 10px;
}

.score {
    font-size: 1.2em;
    margin-bottom: 20px;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(5, var(--card-size));
    grid-template-rows: repeat(2, var(--card-size));
    gap: var(--gap);
    justify-content: center;
    perspective: 1000px;
}

.card {
    width: var(--card-size);
    height: var(--card-size);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    cursor: pointer;
    border-radius: 10px;
}

.card.flipped, .card.matched {
    transform: rotateY(180deg);
    cursor: default;
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    font-size: 5em;
    font-weight: bold;
}

.card-front {
    background-color: white;
    transform: rotateY(180deg);
}

.card-front img {
    max-width: 80%;
    max-height: 80%;
    border-radius: 5px;
}

.card-front.text-card {
    color: var(--primary-color);
}


.card-back {
    background-image: url('card-back.png');
    background-size: cover;
    background-position: center;
}

#restart-button {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 1em;
    border: none;
    border-radius: 5px;
    background-color: var(--secondary-color);
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
}

#restart-button:hover {
    background-color: #d88e1a;
}

#win-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.9);
    padding: 30px;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s ease-out, transform 0.4s ease-out, visibility 0s 0.4s;
    z-index: 100;
}

#win-message.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out, visibility 0s 0s;
}

#win-message h2 {
    margin-top: 0;
    margin-bottom: 25px;
    color: var(--primary-color);
    font-size: 2em;
}

.hidden {
    display: none;
}

/* Responsividade */
@media (max-width: 700px) {
    :root {
        --card-size: 80px;
        --gap: 10px;
    }

    body {
        padding-top: 20px;
        align-items: flex-start;
    }
    
    h1 {
        font-size: 1.8em;
    }

    #game-board {
        grid-template-columns: repeat(4, var(--card-size));
        grid-template-rows: repeat(auto, var(--card-size));
        /* Acomoda as 10 cartas em 3 linhas (4+4+2) */
        width: calc(4 * var(--card-size) + 3 * var(--gap));
        margin: 0 auto;
    }

    .card-face {
        font-size: 3.5em;
    }
}

@media (max-width: 420px) {
    :root {
        --card-size: 70px;
        --gap: 8px;
    }

    #game-container {
        padding: 10px;
    }

    #game-board {
        grid-template-columns: repeat(3, var(--card-size));
        width: calc(3 * var(--card-size) + 2 * var(--gap));
    }
    .card-face {
        font-size: 3em;
    }
}