/* ==========================================================
   1. PALETA DE COLORES Y CONFIGURACIÓN BASE
   ========================================================== */
   :root {
    --escala-juego: 1; 
    --verde-portada: #7bc542;
    --azul-titulo: #2b3a8c;
    --amarillo-escolar: #f5d020;
    --azul-claro: #4a90d9;
    --rojo-primaria: #c0395a;
    --arena: #f2e6d0;
    --blanco: #ffffff;
    --verde-exito: #4caf50;
}

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

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Quicksand', sans-serif;
    background: linear-gradient(180deg, var(--verde-portada) 0%, var(--arena) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
}

.hidden { display: none !important; }

/* ==========================================================
   2. CONTENEDORES DE PANTALLA (Ajuste de Marco 1024x768)
   ========================================================== */
#contenedor-inicio, #contenedor-libro, #contenedor-mision {
    position: relative;
    width: 1024px;
    height: 768px;
    transform: scale(var(--escala-juego));
    transform-origin: center center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; 
    gap: 30px; 
    background: rgba(255, 255, 255, 0.2); 
    border-radius: 40px;
    padding: 40px;
    border: 8px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 20px 50px rgba(0,0,0,0.1);
    overflow: hidden;
}

/* ==========================================================
   3. ESTILO DE BOTONES "NEUTRAL-ESCOLAR"
   ========================================================== */
.contenedor-botones, .game-footer {
    display: flex;
    gap: 20px;
    z-index: 10;
}

.btn-menu {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 1.2rem;
    padding: 15px 45px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary { 
    background-color: var(--azul-titulo); 
    color: var(--blanco); 
    box-shadow: 0 6px 0 #1a2455; 
}

.btn-secondary { 
    background-color: var(--amarillo-escolar); 
    color: var(--azul-titulo); 
    box-shadow: 0 6px 0 #d4b400; 
}

.btn-verify { 
    background-color: var(--verde-exito); 
    color: white; 
    box-shadow: 0 6px 0 #2e7d32; 
}

.btn-menu:hover { transform: translateY(-2px); }
.btn-menu:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.2);
}

/* ==========================================================
   4. ELEMENTOS DE PORTADA E IMAGEN DECORATIVA
   ========================================================== */
.logo-titulo {
    max-width: 550px;
    height: auto;
    filter: drop-shadow(0 8px 15px rgba(0,0,0,0.15));
}

.img-comunidad {
    max-height: 320px;
    width: auto;
    border-radius: 30px;
    border: 10px solid var(--blanco);
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
}

.img-decorativa-derecha {
    position: absolute;
    bottom: 30px;
    right: 30px;
    max-width: 50px;
    height: auto;
    z-index: 5;
    pointer-events: none;
    filter: drop-shadow(0 5px 10px rgba(0,0,0,0.1));
}

/* ==========================================================
   5. SELECTOR DE BLOQUES (LIBRO ABIERTO) - SOLUCIÓN FINAL
   ========================================================== */
   .titulo-selector {
    color: var(--azul-titulo);
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 10px;
}

.libro-abierto {
    display: flex;
    gap: 15px;
    background: #fdf6e3;
    padding: 30px;
    border-radius: 10px 40px 40px 10px;
    box-shadow: 12px 12px 0px var(--azul-titulo), 25px 25px 40px rgba(0,0,0,0.2);
    border-left: 15px solid var(--azul-titulo);
}

.pagina-bloque {
    width: 220px;
    height: 340px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 15px;
    padding: 0; /* Sin espacio interno */
    transition: all 0.3s ease;
    cursor: pointer;
    overflow: hidden; /* Corta la imagen en las esquinas */
    position: relative;
}

/* Forzamos al contenedor interno (contenido-pagina) a ocupar todo el espacio */
.contenido-pagina {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.pagina-bloque img {
    width: 100% !important; /* Forzamos el ancho total */
    height: 250px !important; /* Altura para que cubra la parte superior */
    object-fit: cover; /* Esto estira la imagen para llenar el recuadro sin deformar */
    display: block;
    margin: 0 0 15px 0; /* Quitamos márgenes laterales */
}

/* Ajuste del botón para que respire un poco abajo */
.pagina-bloque .btn-menu {
    margin-top: auto;
    margin-bottom: 20px;
    padding: 10px 20px;
    font-size: 1rem;
    width: 85%;
    z-index: 2;
}

.pagina-bloque:hover {
    transform: translateY(-8px) rotateY(-3deg);
    box-shadow: 8px 15px 20px rgba(0,0,0,0.1);
}

/* Eliminamos títulos que estorben */
.pagina-bloque h3, .pagina-bloque span {
    display: none;
}

/* ==========================================================
   6. ÁREA DE JUEGO (BLOQUE 01) - DISTRIBUCIÓN GRID 4x3 Y SLOTS
   ========================================================== */
   .game-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* Grilla principal de 12 columnas */
.drop-container, .cards-container {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 12px;
    background: rgba(255, 255, 255, 0.6);
    padding: 16px;
    border-radius: 30px;
    border: 3px dashed var(--azul-claro);
    width: 100%;
    max-width: 920px;
    justify-items: center;
    align-items: center;
    box-sizing: border-box;
    grid-auto-rows: 125px;   /* 👈 CLAVE: todas las filas miden igual */
}

/* Fila 1: Primeros 4 elementos */
.drop-container .slot:nth-child(-n+4),
.cards-container .card-foto:nth-child(-n+4) {
    grid-column: span 3;
}

/* Fila 2: Elementos 5, 6 y 7 centrados */
.drop-container .slot:nth-child(5),
.cards-container .card-foto:nth-child(5) { 
    grid-column: 2 / span 3; 
}

.drop-container .slot:nth-child(6),
.cards-container .card-foto:nth-child(6) { 
    grid-column: 5 / span 3; 
}

.drop-container .slot:nth-child(7),
.cards-container .card-foto:nth-child(7) { 
    grid-column: 8 / span 3; 
}

/* Slots */
.slot {
    position: relative;
    width: 160px;              /* 👈 Ancho fijo */
    height: 125px;             /* 👈 Alto fijo */
    background: #fdfdfd;
    border: 2px dashed var(--azul-claro);
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    overflow: hidden;
    box-sizing: border-box;
}

/* Marcador de número */
.slot-number-footer {
    position: absolute;
    bottom: 3px;
    right: 8px;
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--azul-titulo);
    opacity: 0.8;
    pointer-events: none;
    line-height: 1;
    z-index: 2;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.9);
}

/* Indicador ✔ / ✖ */
.slot-feedback {
    position: absolute;
    top: 4px;
    left: 6px;
    font-size: 1.3rem;
    font-weight: 900;
    z-index: 10;
    pointer-events: none;
}

.slot-correcto {
    border: 3px solid var(--verde-exito) !important;
    background: rgba(200, 230, 201, 0.5);
}
.slot-correcto .slot-feedback { color: var(--verde-exito); }

.slot-incorrecto {
    border: 3px solid var(--rojo-primaria) !important;
    background: rgba(255, 205, 210, 0.5);
}
.slot-incorrecto .slot-feedback { color: var(--rojo-primaria); }

/* ==========================================================
   CARD-FOTO - TAMAÑO UNIFORME FORZADO
   ========================================================== */
.card-foto {
    width: 160px;              /* 👈 Ancho fijo (igual que el slot) */
    height: 125px;             /* 👈 Alto fijo (igual que el slot) */
    background: white;
    padding: 5px;
    border-radius: 15px;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.3s ease;
    border: 3px solid transparent;
    box-sizing: border-box;
    overflow: hidden;          /* 👈 Nada se sale de la card */
}

.card-foto:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18);
}

.card-foto.activada {
    border: 3px solid var(--azul-titulo);
    transform: scale(1.02);
    cursor: grab;
}

.card-foto.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

/* La imagen llena la card y se ve completa */
.card-foto img {
    width: 100%;
    height: 100%;
    object-fit: contain;       /* 👈 Muestra la imagen completa sin recortar */
    object-position: center;
    border-radius: 10px;
    pointer-events: none;
    background: #fdfdfd;
}

.card-foto p, .slot-number {
    display: none;
}

/* ==========================================================
   7. BLOQUE 02: MEMORAMA (REDISEÑO)
   ========================================================== */
   .cards-container[style*="grid"] {
    display: grid !important;
    gap: 15px;
    padding: 20px;
    perspective: 1000px;
    justify-items: center;
    align-items: center;
    grid-auto-rows: min-content;
}

.card-memorama {
    width: 130px; 
    height: 170px;
    cursor: pointer;
    perspective: 1000px;
    flex-shrink: 0;
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

.card-memorama.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    border: 3px solid var(--blanco);
    box-sizing: border-box;   /* Importante para que el borde no altere el tamaño */
    overflow: hidden;         /* Asegura que nada se salga del marco */
}

.card-front {
    background: var(--azul-titulo);
    color: var(--amarillo-escolar);
    font-size: 3.5rem;
    font-weight: 900;
}

.card-back {
    background: var(--blanco);
    transform: rotateY(180deg);
}

/* La imagen siempre ocupa el 100% de la carta con contain,
   así ninguna imagen (horizontal o vertical) deforma la tarjeta */
.card-back img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    display: block;
    padding: 4px;
    box-sizing: border-box;
}

/* Ajustes Memorama Nivel 3 - TAMAÑO UNIFORME */
#cards-container[style*="repeat(4"] .card-memorama {
    width: 105px;
    height: 140px;
    flex-shrink: 0;
}

/* ==========================================================
   8. MODALES Y UI ADICIONAL
   ========================================================== */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: 40px;
}

.modal-contenido {
    background: var(--blanco);
    padding: 30px;
    border-radius: 30px;
    width: 80%;
    max-width: 500px;
    text-align: center;
    border: 5px solid var(--azul-titulo);
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

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

.error-shake { animation: shake 0.4s ease-in-out; }

#marcador-puntos {
    /* Los estilos ya se manejan por JS en inline-css, pero puedes añadir extras aquí */
    font-family: 'Montserrat', sans-serif;
}
/* Ajuste para las imágenes dentro del libro del selector */
.pagina-bloque img {
    width: 100%;
    height: 250px;
    object-fit: contain;  /* ← Muestra la imagen completa */
    object-position: center;
    display: block;
    margin: 0 0 15px 0;
    background: #f9f9f9;  /* Fondo suave por si la imagen tiene transparencia */
}

/* Ocultar el título de texto si prefieres que solo se vea la imagen */
.pagina-bloque h3 {
    display: none; 
}