/* game5.css - Estilos para el Memory Game - VERSION CORREGIDA */

/* Popup de configuración inicial */
.game5-popup-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5); display: flex; justify-content: center;
    align-items: center; z-index: 1000;
}
.game5-popup-content {
    background-color: white; padding: 1.5rem; border-radius: 8px;
    max-width: 90%; max-height: 90%; overflow-y: auto;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.game5-popup-title {
    margin: 0 0 1rem 0; text-align: center; color: #5d4037; font-size: 1.1rem;
}

/* Secciones del popup */
.game5-list-section, .game5-grid-section { margin-bottom: 0.75rem; }
.game5-section-label { margin: 0 0 0.5rem 0; color: #795548; font-size: 0.9rem; }

/* Contenedor de listas */
.game5-lists-container {
    display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.75rem;
    max-height: 200px; overflow-y: auto;
}
.game5-vocab-list-btn {
    padding: 0.5rem; background-color: var(--pastel-orange); border: none;
    border-radius: 6px; cursor: pointer; transition: var(--transition);
    text-align: left; font-size: 0.85rem; color: #5d4037;
}
.game5-vocab-list-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.game5-vocab-list-btn.selected { background-color: var(--pastel-brown-dark); color: white; }

/* Opciones de grid */
.game5-grid-options { display: flex; flex-wrap: wrap; gap: 0.25rem; justify-content: center; }
.game5-grid-option-btn {
    padding: 0.5rem 0.75rem; background-color: var(--pastel-green); border: none;
    border-radius: 6px; cursor: pointer; transition: var(--transition);
    font-size: 0.8rem; color: #5d4037;
}
.game5-grid-option-btn:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.game5-grid-option-btn.selected { background-color: var(--pastel-green-dark); color: white; }

/* Botones de acción */
.game5-buttons-container { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1rem; }
.game5-start-btn {
    padding: 0.5rem 1.5rem; background-color: var(--pastel-brown-dark); color: white;
    border: none; border-radius: 6px; cursor: pointer; font-size: 0.9rem; font-weight: bold;
}
.game5-cancel-btn {
    padding: 0.5rem 1.5rem; background-color: var(--pastel-orange); color: #5d4037;
    border: none; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}

/* ========== SOLUCIÓN PARA EL ESPACIO EXTRA ========== */

/* RESET COMPLETO DEL GAME-SCREEN CUANDO GAME5 ESTÁ ACTIVO */
#game-screen.game5-active {
    /* Reset total */
    display: block !important;
    position: relative !important;
    width: 100% !important;
    height: auto !important; /* IMPORTANTE: auto, no altura fija */
    min-height: 0 !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    background-color: var(--pastel-green-light) !important;
}

/* Contenedor principal - SIN ESPACIO EXTRA */
.game5-container {
    position: absolute !important;
    top: 60px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 60px !important; /* Fija el bottom al footer */
    width: 100% !important;
    height: auto !important; /* Auto se ajusta al contenido */
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    background-color: var(--pastel-green-light) !important;
    z-index: 10 !important;
}

/* Grid wrapper - OCUPA SOLO EL ESPACIO NECESARIO */
.game5-grid-wrapper {
    flex: 1 !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    overflow: visible !important; /* No scroll interno */
    padding: 10px !important;
    width: 100% !important;
    height: 100% !important; /* 100% del contenedor padre */
    box-sizing: border-box !important;
    background-color: transparent !important;
}

/* Grid de cartas - SIN ALTURA FIJA */
.game5-grid {
    display: grid !important;
    width: auto !important;
    height: auto !important; /* Se ajusta al contenido */
    min-height: 0 !important;
    overflow: visible !important;
    gap: 6px !important;
    padding: 0 !important;
    box-sizing: border-box !important;
    place-items: center !important;
    justify-content: center !important;
    align-content: center !important;
    margin: auto !important; /* Esto centra verticalmente */
    max-width: 100% !important;
    background-color: transparent !important;
    border: none !important;
}

/* ========== CARTAS DE MEMORIA LIMPIAS ========== */
.game5-memory-card {
    aspect-ratio: 1/1.2; perspective: 800px; cursor: pointer; border-radius: 8px;
    overflow: hidden; width: 100%; height: 100%; margin: 0 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.game5-card-inner {
    position: relative; width: 100%; height: 100%;
    transition: transform 0.4s; transform-style: preserve-3d;
}

/* Cara frontal (reverso) */
.game5-card-front {
    position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
    background-color: var(--pastel-brown-dark); border-radius: 8px;
    display: flex; align-items: center; justify-content: center; 
    border: 2px solid #5d4037;
}
.game5-pattern-container {
    width: 80%; height: 80%;
    background-image: radial-gradient(circle, var(--pastel-orange) 1px, transparent 1px);
    background-size: 12px 12px; opacity: 0.7; border-radius: 6px;
}
.game5-yulin-logo { font-size: 1.5rem; position: absolute; z-index: 1; }

/* Cara trasera (contenido) - LIMPIA */
.game5-card-back {
    position: absolute; width: 100%; height: 100%; backface-visibility: hidden;
    background-color: white; border-radius: 8px; transform: rotateY(180deg);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 8px !important; border: 2px solid var(--pastel-orange);
    overflow: hidden; box-sizing: border-box;
}

/* Contenedor de imagen limpio */
.game5-image-container {
    width: 100%; height: 100%; display: flex; align-items: center;
    justify-content: center; background-color: var(--pastel-brown);
    border-radius: 6px; overflow: hidden; position: relative;
}
.game5-image-container.loaded { background-color: var(--pastel-brown); }
.game5-card-image { max-width: 85%; max-height: 85%; object-fit: contain; z-index: 2; }
.game5-image-pattern {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background-image: radial-gradient(circle, rgba(255,255,255,0.3) 0.5px, transparent 0.5px);
    background-size: 10px 10px; border-radius: 6px; z-index: 1;
}

/* Para las cartas de texto */
.game5-card-back.text-card { background-color: var(--pastel-brown); }

/* Contenedor de texto chino LIMPIO */
.game5-text-content {
    width: 100%; height: 100%; display: flex; flex-direction: column;
    align-items: center; justify-content: center; background-color: var(--pastel-brown);
    border-radius: 6px; position: relative; padding: 8px;
}

/* Texto chino y pinyin LIMPIOS */
.game5-chinese-character {
    font-size: 2rem !important; font-weight: bold; color: #5d4037;
    margin: 0 !important; text-align: center; line-height: 1.2; z-index: 2;
}
.game5-pinyin {
    font-size: 0.9rem !important; color: #795548; font-style: italic;
    z-index: 2; margin: 4px 0 0 0 !important;
}

/* Estados de las cartas */
.game5-memory-card.flipped .game5-card-inner { transform: rotateY(180deg); }
.game5-memory-card.matched { opacity: 0.8; cursor: default; }
.game5-memory-card.matched .game5-card-back { border-color: var(--pastel-green-dark); }

/* ========== BOTÓN DE REINICIO EN HEADER ========== */
.game5-restart-btn {
    background: none; border: none; font-size: 1rem; cursor: pointer;
    padding: 0.2rem 0.4rem; margin-right: 0.5rem; border-radius: 4px;
    transition: all 0.2s; opacity: 0.8; display: inline-block !important;
}
.game5-restart-btn:hover { background-color: rgba(255, 255, 255, 0.1); opacity: 1; transform: scale(1.1); }
.game5-restart-btn:active { transform: scale(0.95); }

/* ========== ESTADÍSTICAS ========== */
.game5-stat {
    margin-left: 0.5rem; font-size: 0.9rem; display: inline-block !important;
    vertical-align: middle; color: #5d4037;
}

/* ========== POPUP DE RESULTADOS ========== */
.game5-results-popup {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.8); display: flex; justify-content: center;
    align-items: center; z-index: 2000;
}
.game5-results-content {
    background-color: white; padding: 1.5rem; border-radius: 10px;
    max-width: 400px; width: 90%; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.game5-results-title {
    text-align: center; color: #5d4037; margin: 0 0 1rem 0; font-size: 1.2rem;
}
.game5-results-message {
    text-align: center; font-size: 1rem; margin-bottom: 1.5rem;
    padding: 0.5rem; border-radius: 6px; background-color: var(--pastel-orange);
}
.game5-results-stats { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.5rem; }
.game5-result-stat {
    display: flex; justify-content: space-between; padding: 0.5rem;
    border-bottom: 1px solid var(--pastel-orange); font-size: 0.9rem;
}
.game5-stat-label { font-weight: bold; color: #795548; }
.game5-stat-value { color: #5d4037; font-weight: bold; }
.game5-results-buttons { display: flex; gap: 0.75rem; justify-content: center; }
.game5-play-again-btn, .game5-back-menu-btn {
    padding: 0.5rem 1rem; border: none; border-radius: 6px;
    cursor: pointer; font-size: 0.9rem; transition: var(--transition);
}
.game5-play-again-btn { background-color: var(--pastel-green-dark); color: white; }
.game5-back-menu-btn { background-color: var(--pastel-orange); color: #5d4037; }
.game5-play-again-btn:hover, .game5-back-menu-btn:hover {
    transform: translateY(-2px); box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

/* ========== ESTILOS PARA GAME5 ACTIVO - LIMPIAR ELEMENTOS ========== */
#game-screen.game5-active .game-container,
#game-screen.game5-active #question-container,
#game-screen.game5-active #options-container,
#game-screen.game5-active .timer-bar {
    display: none !important;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .game5-popup-content { padding: 1rem; }
    .game5-grid-options, .game5-buttons-container, .game5-results-buttons { 
        flex-direction: column; gap: 0.5rem; 
    }
    .game5-grid-option-btn, .game5-start-btn, .game5-cancel-btn,
    .game5-play-again-btn, .game5-back-menu-btn { width: 100%; }
    
    /* Ajustes para móviles */
    .game5-grid { gap: 4px !important; }
    .game5-chinese-character { font-size: 1.6rem !important; }
    .game5-pinyin { font-size: 0.8rem !important; }
    .game5-container { 
        top: 50px !important; 
        bottom: 50px !important; /* Ajustar para móviles */
    }
}

@media (min-width: 768px) and (orientation: landscape) {
    .game5-grid { gap: 8px !important; }
    .game5-container { 
        top: 60px !important; 
        bottom: 60px !important;
    }
}

/* Scrollbar sutil */
.game5-grid-wrapper::-webkit-scrollbar { width: 6px; }
.game5-grid-wrapper::-webkit-scrollbar-track { background: rgba(93, 64, 55, 0.05); border-radius: 3px; }
.game5-grid-wrapper::-webkit-scrollbar-thumb { background: rgba(93, 64, 55, 0.15); border-radius: 3px; }
.game5-grid-wrapper::-webkit-scrollbar-thumb:hover { background: rgba(93, 64, 55, 0.25); }

/* ========== ANIMACIONES ========== */
.game5-memory-card { transition: transform 0.2s, opacity 0.2s; }
.game5-memory-card:hover { transform: scale(1.02); }
.game5-memory-card.matched:hover { transform: scale(1); }

/* ========== REGLA EXTRA PARA ASEGURAR QUE NO HAYA ESPACIO ========== */
/* Esta regla fuerza a que todos los elementos dentro de game5-active no tengan espacio extra */
#game-screen.game5-active * {
    box-sizing: border-box !important;
    max-height: 100% !important;
}

/* Eliminar cualquier posible margen/padding heredado en el body/html */
body #game-screen.game5-active,
html #game-screen.game5-active {
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
}
