:root {
    --carta-width: min(80px, 16vw);
    --carta-height: calc(var(--carta-width) * 1.4);
}

body {
    touch-action: none;
    user-select: none;
}

.carta {
    width: var(--carta-width);
    height: var(--carta-height);
    perspective: 1000px;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.carta:hover {
    transform: translateY(-3px);
}

.carta-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.carta.volteada .carta-inner {
    transform: rotateY(180deg);
}

.carta-frente, .carta-dorso {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 6px;
    overflow: hidden;
    background-color: white;
}

.carta-dorso {
    transform: rotateY(180deg);
}

.carta-frente img, .carta-dorso img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

/* Animaciones */
@keyframes cardEntrance {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#tusCartas .carta {
    animation: cardEntrance 0.3s ease forwards;
    animation-delay: calc(var(--card-index) * 0.1s);
}

/* Responsive */
@media (max-width: 640px) {
    .carta:hover {
        transform: translateY(-5px);
    }
    
    .container {
        padding: 1rem;
    }
}

/* Mejoras visuales */
.mesa {
    background: radial-gradient(circle at center, #2f855a 0%, #1a4731 100%);
    max-height: calc(100vh - 100px);
    overflow: hidden;
}

.carta {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.carta:hover {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
                0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Estado del juego con animación */
#estadoJuego {
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Efectos de hover mejorados */
.carta:hover .carta-inner {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
                0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* Estilos específicos para las cartas del resultado */
.resultado-carta {
    animation: aparecer 0.5s ease-out forwards;
    opacity: 0;
    transform: scale(0.8);
}

.resultado-carta:first-child {
    animation-delay: 0.1s;
}

.resultado-carta:last-child {
    animation-delay: 0.3s;
}

@keyframes aparecer {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Ajustes para el layout flexible */
.flex-grow {
    flex-grow: 1;
}

#cartasCentro {
    position: relative;
    z-index: 2;
    min-height: var(--carta-height);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Asegurarse de que las cartas del jugador y oponente no se superpongan */
#tusCartas, #cartasOponente {
    position: relative;
    z-index: 1;
    padding: 0.5rem;
    min-height: var(--carta-height);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Ajustes responsive */
@media (max-height: 600px) {
    :root {
        --carta-width: min(70px, 14vw);
    }
    
    .carta:hover {
        transform: translateY(-3px);
    }
}

@media (max-height: 500px) {
    :root {
        --carta-width: min(60px, 12vw);
    }
}

/* Estilos para las cartas jugadas en el centro */
.carta-container {
    position: relative;
    display: inline-block;
    margin: 0 1rem;
    animation: cartaEntrada 0.5s ease-out forwards;
}

.jugador-etiqueta {
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 0.9rem;
    white-space: nowrap;
    z-index: 10;
    animation: etiquetaEntrada 0.5s ease-out forwards;
}

@keyframes cartaEntrada {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes etiquetaEntrada {
    from {
        opacity: 0;
        transform: translate(-50%, 10px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

#cartasCentro {
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    padding: 2rem;
}

#cartasCentro .carta {
    transform-origin: center;
    transition: transform 0.3s ease;
}

#cartasCentro .carta:hover {
    transform: scale(1.05);
    z-index: 5;
}
