/* =========================================
   ESTILOS SECCIÓN: MATEMÁTICAS (RED EDITION)
   ========================================= */

section.matematicas {
    padding: 80px 0;
    /* FONDO ROJO COMO EL ORIGINAL PERO MEJORADO */
    background-color: var(--primary-red); 
    background-image: radial-gradient(circle at top right, #e53935 0%, var(--primary-red) 100%);
    position: relative;
    overflow: hidden;
}

/* Decoración de fondo (Fórmulas sutiles en blanco) */
section.matematicas::before {
    content: '+ - ÷ × √ ∑ π';
    position: absolute;
    top: 5%; left: 5%;
    font-family: serif;
    font-size: 8rem;
    color: rgba(255,255,255,0.05);
    font-weight: bold;
    pointer-events: none;
    transform: rotate(-10deg);
}

.contenido-mate {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    position: relative;
    z-index: 2;
}

/* =========================================
   1. HEADER (Título Blanco)
   ========================================= */
.header-mate {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 50px;
    /* Fondo blanco semitransparente para que el logo resalte */
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    padding: 15px 40px;
    border-radius: 50px;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid rgba(255,255,255,0.2);
}

.header-mate p {
    font-size: 3rem;
    font-weight: 900;
    color: #ffffff; /* Texto Blanco sobre fondo rojo */
    text-transform: uppercase;
    letter-spacing: -1px;
    margin: 0;
    text-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.header-mate img {
    height: 60px;
    width: auto;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.2));
    animation: floatIcon 3s ease-in-out infinite;
}

/* =========================================
   2. GRID PRINCIPAL (Layout 2 Columnas)
   ========================================= */
.contenedor-mate {
    display: grid;
    /* Izquierda (Azul) 40% - Derecha (Materias) 60% */
    grid-template-columns: 1fr 1.5fr; 
    gap: 30px;
    align-items: stretch; /* Estira las cajas para que tengan la misma altura */
}

/* =========================================
   3. TARJETA IZQUIERDA: "TODOS LOS NIVELES" (AZUL)
   ========================================= */
.todos-mate {
    /* La caja azul original, pero bonita */
    background: var(--primary-blue);
    border-radius: 30px;
    padding: 50px 40px;
    color: white;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    border: 2px solid rgba(255,255,255,0.1);
    min-height: 400px; /* Altura mínima para presencia */
}

.texto-todos {
    font-size: 3rem;
    font-weight: 900;
    margin-bottom: 30px;
    line-height: 1.1;
    position: relative;
    z-index: 2;
}

.back-todos {
    position: relative;
    z-index: 2;
    background: rgba(255,255,255,0.1);
    padding: 25px;
    border-radius: 20px;
    border-left: 5px solid var(--primary-red); /* Detalle rojo dentro del azul */
}

.back-todos p {
    font-size: 1.2rem;
    line-height: 1.6;
    margin: 0;
    color: rgba(255,255,255,0.9);
}

/* Decoración de fondo en la tarjeta azul */
.image-back {
    position: absolute;
    bottom: -20px; right: -20px;
    opacity: 0.1;
    transform: rotate(15deg) scale(1.5);
    font-size: 10rem;
    color: white;
    z-index: 1;
}

/* =========================================
   4. SECCIÓN DERECHA: GRID DE MATERIAS
   ========================================= */
/* Este div no existe en el HTML, así que aplicamos el grid a los elementos siguientes */
/* Usamos selectores adyacentes o grid layout general */
/* NOTA: Como en tu HTML las materias están al mismo nivel que .todos-mate, 
   necesitamos decirle al grid principal cómo acomodarlas.
   Pero para lograr el efecto "Columna Derecha", lo mejor visualmente con el HTML actual 
   es hacer que .todos-mate ocupe una fila completa en móvil y columna izq en desktop. */

/* Ajustamos los ítems individuales para que formen la "Columna Derecha" visualmente */
/* Esto requiere un pequeño truco si no cambiamos HTML: usar un subgrid virtual o alinear */
/* Solución fácil: .todos-mate es row-span-2 (ocupa 2 filas de altura) */

.todos-mate {
    grid-row: span 2; /* Ocupa 2 filas de altura */
}

/* Las materias son tarjetas blancas flotantes */
.img-text-mate {
    background: #ffffff;
    border-radius: 25px;
    padding: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-shadow: 0 10px 20px rgba(0,0,0,0.15);
    transition: transform 0.3s ease;
}

.img-text-mate:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0,0,0,0.25);
}

.img-text-mate p {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary-red); /* Texto rojo para conectar con el fondo */
    margin-bottom: 15px;
    text-transform: uppercase;
}

.img-text-mate img {
    height: 90px;
    width: auto;
    object-fit: contain;
    transition: transform 0.4s;
}

.img-text-mate:hover img {
    transform: scale(1.15) rotate(5deg);
}

/* Ajustes específicos para Trigonometría (2 imágenes) */
.img-trigo {
    display: flex;
    gap: 10px;
    justify-content: center;
}
.img-trigo img {
    height: 70px;
}

/* =========================================
   ANIMACIONES
   ========================================= */
@keyframes floatIcon {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* =========================================
   RESPONSIVE
   ========================================= */

/* Desktop: Ajuste del Grid para que parezca Columna Izq vs Derecha */
@media (min-width: 992px) {
    .contenedor-mate {
        /* Definimos explícitamente dónde va cada cosa */
        /* Col 1: Azul | Col 2: Materia | Col 3: Materia */
        grid-template-columns: 1.2fr 1fr 1fr; 
        grid-template-rows: 1fr 1fr; /* 2 Filas */
    }

    /* La tarjeta azul ocupa la columna 1 y las 2 filas de alto */
    .todos-mate {
        grid-column: 1 / 2;
        grid-row: 1 / 3;
        margin-right: 20px; /* Separación visual */
    }

    /* Las materias ocupan las columnas 2 y 3 */
    .algebra { grid-column: 2; grid-row: 1; }
    .bachillerato { grid-column: 3; grid-row: 1; }
    .trigonometria { grid-column: 2; grid-row: 2; }
    .primaria { grid-column: 3; grid-row: 2; }
}

/* Tablet */
@media (max-width: 992px) {
    .contenedor-mate {
        grid-template-columns: 1fr 1fr;
    }
    
    .todos-mate {
        grid-column: span 2; /* Ocupa todo el ancho arriba */
        grid-row: auto;
        min-height: 300px;
        margin-bottom: 20px;
    }
}

/* Móvil */
@media (max-width: 600px) {
    .contenedor-mate {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .todos-mate, .algebra, .bachillerato, .trigonometria, .primaria {
        grid-column: span 1;
    }

    .header-mate {
        flex-direction: column;
        padding: 20px;
        width: 100%;
    }
    
    .header-mate p { font-size: 2.2rem; }
}