/* ===== ESTILOS COMPLETOS ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    margin: 0;
    transition: background 0.3s;
}

body.dark {
    background: linear-gradient(135deg, #020617 0%, #0f172a 100%);
}

.game-container {
    max-width: 550px;
    width: 100%;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(16px);
    border-radius: 40px;
    padding: 24px 20px 28px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ===== HEADER ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.title {
    color: white;
    font-size: 24px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
}

.level-badge {
    background: #facc15;
    color: #0f172a;
    font-size: 11px;
    padding: 4px 12px;
    border-radius: 9999px;
    font-weight: bold;
}

.header-buttons {
    display: flex;
    gap: 8px;
}

.icon-btn {
    background: rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.7);
    padding: 8px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    font-size: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 0, 0, 0.5);
    color: white;
}

/* ===== STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.stat-box {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 8px 12px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-label {
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 20px;
    font-weight: bold;
    color: #facc15;
}

.stat-value.green { color: #4ade80; }
.stat-value.purple { color: #a78bfa; }

/* ===== BOARD ===== */
.board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

/* ===== CARTAS ===== */
.card {
    aspect-ratio: 1 / 1;
    background: linear-gradient(145deg, #334155, #1e293b);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 6px 0 #0f172a, 0 4px 12px rgba(0, 0, 0, 0.4);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.05);
    transform: translateY(0);
    position: relative;
    min-height: 80px;
}

.card.hidden {
    background: #1e293b;
    color: transparent !important;
    background-image: radial-gradient(circle at 30% 30%, #334155, #0f172a);
}

.card.hidden::after {
    content: '❓';
    position: absolute;
    color: rgba(255, 255, 255, 0.15);
    font-size: 2rem;
    opacity: 0.4;
}

.card.flipped {
    background: #334155;
    box-shadow: 0 4px 0 #0f172a, 0 0 0 2px #facc15;
    transform: translateY(2px);
}

.card.matched {
    background: #14532d;
    box-shadow: 0 4px 0 #0f172a, 0 0 0 2px #4ade80;
    transform: translateY(2px);
    cursor: default;
    pointer-events: none;
    animation: pulse 0.5s ease;
}

.card.wrong {
    animation: shake 0.4s ease;
}

/* ===== ANIMACIONES ===== */
@keyframes pulse {
    0%, 100% { transform: scale(1) translateY(2px); }
    50% { transform: scale(1.08) translateY(0); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-8px); }
    75% { transform: translateX(8px); }
}

@keyframes popIn {
    0% { transform: scale(0.8) rotate(-5deg); opacity: 0; }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

@keyframes confettiFall {
    0% { transform: translateY(-10px) rotate(0deg) scale(1); opacity: 1; }
    100% { transform: translateY(110vh) rotate(720deg) scale(0); opacity: 0; }
}

/* ===== BOTONES ===== */
.btn-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    flex: 1;
    min-width: 100px;
    padding: 12px 16px;
    border-radius: 9999px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 14px;
}

.btn:active {
    transform: scale(0.95);
}

.btn-yellow {
    background: #facc15;
    color: #0f172a;
    box-shadow: 0 4px 0 #a16207;
}

.btn-yellow:hover {
    background: #fbbf24;
}

.btn-green {
    background: #22c55e;
    color: #0f172a;
    box-shadow: 0 4px 0 #15803d;
}

.btn-green:hover {
    background: #16a34a;
}

.btn-blue {
    background: #3b82f6;
    color: white;
    box-shadow: 0 4px 0 #1d4ed8;
}

.btn-blue:hover {
    background: #2563eb;
}

.btn.hidden {
    display: none;
}

/* ===== CONFETI ===== */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -10px;
    animation: confettiFall linear forwards;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: #1e293b;
    max-width: 400px;
    width: 100%;
    padding: 32px 24px;
    border-radius: 32px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.06);
    animation: popIn 0.3s ease;
}

.modal-emoji {
    font-size: 64px;
    margin-bottom: 8px;
}

.modal-title {
    color: #facc15;
    font-size: 28px;
    font-weight: bold;
    margin-bottom: 8px;
}

.modal-message {
    color: #cbd5e1;
    font-size: 18px;
    margin: 12px 0;
}

.modal-stats {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 16px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    font-size: 14px;
}

.modal-stats span {
    color: #94a3b8;
}

.modal-stats .value {
    color: #facc15;
    font-weight: bold;
}

.modal-stats .value.green { color: #4ade80; }
.modal-stats .value.purple { color: #a78bfa; }
.modal-stats .value.red { color: #f87171; }

.modal-btn {
    width: 100%;
    padding: 14px;
    border-radius: 9999px;
    font-weight: bold;
    border: none;
    cursor: pointer;
    background: #facc15;
    color: #0f172a;
    font-size: 16px;
    box-shadow: 0 4px 0 #a16207;
    transition: all 0.2s;
}

.modal-btn:hover {
    background: #fbbf24;
}

.modal-btn:active {
    transform: scale(0.95);
}

/* ===== ESTADÍSTICAS EN MODAL ===== */
.stats-list {
    text-align: left;
    margin: 16px 0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.stat-item:last-child {
    margin-bottom: 0;
}

.stat-label-custom {
    color: #94a3b8;
}

.stat-value-custom {
    font-weight: bold;
    font-size: 20px;
}

.stat-value-custom.yellow { color: #facc15; }
.stat-value-custom.purple { color: #a78bfa; }
.stat-value-custom.green { color: #4ade80; }
.stat-value-custom.blue { color: #3b82f6; }

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .card { 
        font-size: 2rem; 
        min-height: 65px; 
        border-radius: 12px; 
    }
    .card.hidden::after { 
        font-size: 1.5rem; 
    }
    .game-container { 
        padding: 16px; 
        border-radius: 32px; 
    }
    .board { 
        gap: 8px; 
    }
    .stats-grid { 
        gap: 4px; 
    }
    .stat-value { 
        font-size: 16px; 
    }
}

@media (max-width: 380px) {
    .card { 
        font-size: 1.6rem; 
        min-height: 55px; 
        border-radius: 10px; 
    }
    .card.hidden::after { 
        font-size: 1.2rem; 
    }
    .board { 
        gap: 6px; 
    }
}

@media (min-width: 768px) {
    .card { 
        font-size: 3.5rem; 
        min-height: 100px; 
        border-radius: 20px; 
    }
}


/* ===== VIDAS ===== */
.lives-container {
    text-align: center;
    margin-bottom: 12px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#livesDisplay {
    font-size: 28px;
    letter-spacing: 4px;
    transition: all 0.3s ease;
}

#livesDisplay.pulse {
    animation: heartPulse 0.5s ease;
}

@keyframes heartPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ===== MODAL GAME OVER ===== */
#gameOverModal .modal-box {
    border: 2px solid #ef4444;
}

#gameOverModal .modal-title {
    color: #ef4444;
}

#gameOverAdBtn {
    background: #3b82f6;
    color: white;
    box-shadow: 0 4px 0 #1d4ed8;
}

#gameOverAdBtn:hover {
    background: #2563eb;
}

#gameOverAdBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#gameOverResetBtn {
    background: #475569;
    color: white;
    box-shadow: 0 4px 0 #1e293b;
    font-size: 14px;
}

#gameOverResetBtn:hover {
    background: #334155;
}

/* ===== ANIMACIÓN DE VIDA PERDIDA ===== */
.life-lost {
    animation: lifeLost 0.6s ease;
}

@keyframes lifeLost {
    0% { transform: scale(1); color: #ef4444; }
    50% { transform: scale(0.5); color: #ef4444; opacity: 0.3; }
    100% { transform: scale(1); color: #ef4444; opacity: 1; }
}

/* ===== COOLDOWN INDICATOR ===== */
.ad-cooldown {
    color: #94a3b8;
    font-size: 12px;
    margin-top: 8px;
    display: none;
}

.ad-cooldown.active {
    display: block;
}


/* ===== MEJORAS RESPONSIVE PARA TELEGRAM ===== */

/* Ajustes para todos los dispositivos móviles */
@media (max-width: 480px) {
    /* Contenedor principal */
    .game-container {
        padding: 12px 10px 16px;
        border-radius: 24px;
        max-width: 100%;
    }

    /* Header más compacto */
    .header {
        margin-bottom: 10px;
    }
    
    .title {
        font-size: 18px;
    }
    
    .level-badge {
        font-size: 10px;
        padding: 2px 10px;
    }
    
    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
        padding: 4px;
    }

    /* Stats más pequeños */
    .stats-grid {
        gap: 4px;
        margin-bottom: 8px;
    }
    
    .stat-box {
        padding: 4px 6px;
        border-radius: 8px;
    }
    
    .stat-label {
        font-size: 8px;
    }
    
    .stat-value {
        font-size: 14px;
    }

    /* Vidas */
    .lives-container {
        margin-bottom: 8px;
    }
    
    #livesDisplay {
        font-size: 22px !important;
        letter-spacing: 2px !important;
    }

    /* Tablero - cartas más pequeñas */
    .board {
        gap: 6px;
        margin-bottom: 10px;
    }
    
    .card {
        font-size: 1.6rem;
        min-height: 55px;
        border-radius: 10px;
        box-shadow: 0 4px 0 #0f172a;
    }
    
    .card.hidden::after {
        font-size: 1.2rem;
    }

    /* Botones más pequeños */
    .btn-group {
        gap: 6px;
    }
    
    .btn {
        padding: 10px 12px;
        font-size: 12px;
        min-width: 70px;
        border-radius: 20px;
    }

    /* Modales */
    .modal-box {
        padding: 20px 16px;
        border-radius: 24px;
        max-width: 95%;
    }
    
    .modal-emoji {
        font-size: 48px;
    }
    
    .modal-title {
        font-size: 22px;
    }
    
    .modal-message {
        font-size: 15px;
    }
    
    .modal-stats {
        font-size: 12px;
        padding: 8px;
        grid-template-columns: 1fr 1fr;
    }
    
    .modal-btn {
        padding: 12px;
        font-size: 14px;
    }
}

/* Para pantallas muy pequeñas (menos de 380px) */
@media (max-width: 380px) {
    .card {
        font-size: 1.3rem;
        min-height: 48px;
        border-radius: 8px;
    }
    
    .card.hidden::after {
        font-size: 1rem;
    }
    
    .board {
        gap: 4px;
    }
    
    .stat-value {
        font-size: 12px;
    }
    
    #livesDisplay {
        font-size: 18px !important;
    }
    
    .title {
        font-size: 16px;
    }
    
    .btn {
        font-size: 10px;
        padding: 8px 10px;
        min-width: 60px;
    }
}

/* Para pantallas medianas (tablets) */
@media (min-width: 481px) and (max-width: 768px) {
    .card {
        font-size: 2.2rem;
        min-height: 70px;
    }
    
    .game-container {
        padding: 16px;
        max-width: 100%;
    }
}

/* Para pantallas grandes */
@media (min-width: 769px) {
    .game-container {
        max-width: 550px;
    }
    
    .card {
        font-size: 3rem;
        min-height: 100px;
    }
}

/* ===== MEJORAS DE TELEGRAM ===== */
/* Ocultar el MainButton de Telegram cuando el juego está activo */
.telegram-main-button-hidden .tg-main-button {
    display: none !important;
}

/* Hacer que el juego ocupe toda la pantalla en Telegram */
body.telegram-mobile {
    padding: 0 !important;
    background: #0f172a !important;
}

body.telegram-mobile .game-container {
    border-radius: 0 !important;
    min-height: 100vh;
    padding: 12px 10px 20px;
    background: rgba(255,255,255,0.05);
}

/* Ajustar el contenedor para que use toda la altura */
@media (max-width: 480px) {
    body.telegram-mobile {
        align-items: flex-start !important;
        padding: 8px !important;
    }
    
    body.telegram-mobile .game-container {
        border-radius: 20px !important;
        min-height: 90vh;
    }
}

/* ===== BOTÓN DE SONIDO ===== */
#soundToggle {
    transition: all 0.3s ease;
}

#soundToggle:hover {
    transform: scale(1.1);
}

#soundToggle:active {
    transform: scale(0.9);
}

/* ===== RESPONSIVE: Ajuste para botones del header ===== */
@media (max-width: 480px) {
    .header-buttons {
        gap: 4px;
    }
    
    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
}

@media (max-width: 380px) {
    .header-buttons {
        gap: 3px;
    }
    
    .icon-btn {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
}