 * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: Arial, sans-serif;
    background: linear-gradient(45deg, #ff6b6b, #f7b733, #4caf50, #1e88e5);
    background-size: 600% 600%;
    animation: gradientAnimation 10s ease infinite;
}

/* Encabezado para los intentos */
header {
    position: fixed;
    top: 10px;
    width: 100%;
    text-align: center;
    z-index: 1;
}

#stats {
    color: white;
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
    padding: 10px;
    background-color: rgba(76, 175, 80, 0.8);
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* El wrapper ahora ocupa toda la pantalla para garantizar el centrado */
#wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
    max-width: 600px;
    padding: 20px;
    box-sizing: border-box;
}

/* La cuadrícula del juego */
#game {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 600px;
    box-sizing: border-box;
}

/* Estilos para las tarjetas */
.card {
    width: 140px;
    height: 140px;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
    cursor: pointer;
    border-radius: 10px;
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
    background-color: #ffeb3b;
}

.card.active {
    transform: rotateY(180deg);
}

.card div {
    width: 100%;
    height: 100%;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    backface-visibility: hidden;
    pointer-events: none;
}

.card .face {
    background: #f0f8ff;
    transform: rotateY(180deg);
    font-size: 3.5rem;
    color: #009688;
    font-weight: bold;
}

.card .back {
    background: url(images/back.png) center / contain no-repeat;
    background-color: #ffeb3b;
    transition: transform 0.5s ease;
}

/* Estilos del botón de reinicio */
#resetButton {
    margin-top: 20px;
    padding: 10px 20px;
    font-size: 1.2rem;
    background-color: #ff6347;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
}

#resetButton:hover {
    background-color: #e5533c;
}

/* Animación para que el fondo parpadee en rojo */
@keyframes flashRed {
   0% {
      background-color: red;
   }
   50% {
      background-color: darkred;
   }
   100% {
      background-color: red;
   }
}

/* Clase que aplicamos al body cuando la pareja seleccionada es incorrecta */
.error-flash {
   animation: flashRed 0.5s ease;
   background: red !important; /* Forzamos el fondo a rojo temporalmente */
}


/* Responsividad para pantallas medianas */
@media (max-width: 1024px) {
    #game {
        grid-template-columns: repeat(4, 1fr);
    }

    .card {
        width: 120px;
        height: 120px;
    }

    #stats {
        font-size: 1.6rem;
    }

    #resetButton {
        font-size: 1.1rem;
    }
}

/* Responsividad para pantallas pequeñas */
@media (max-width: 768px) {
    #game {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }

    .card {
        width: 100px;
        height: 100px;
    }

    #stats {
        font-size: 1.4rem;
    }

    #resetButton {
        font-size: 1rem;
    }
}

/* Responsividad para pantallas muy pequeñas */
@media (max-width: 480px) {
    #game {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .card {
        width: 80px;
        height: 80px;
    }

    #stats {
        font-size: 1.2rem;
    }

    #resetButton {
        font-size: 0.9rem;
    }
}