:root {
    --primary-blue: #30499b;
    --secondary-blue: #4a69bd;
    --text-dark: #333;
    --bg-light: #ffffff;
    --grey-light: #f4f4f4;
    --transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);

    /* Menú */
    --header-h: 70px; /* nav.js lo recalcula según el alto real del header */
    --menu-texto: #2b2b2b;
    --menu-linea: #ececec;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
}

body {
    background-color: var(--bg-light);
    color: var(--text-dark);
    overflow-x: hidden;
}

/* Bloqueo de scroll cuando el menú está abierto en mobile */
body.menu-bloqueado {
    overflow: hidden;
}

a{
    text-decoration: none;
    color: inherit;
}

/* --- Animación Fade-in al scroll --- */
.reveal {
    opacity: 0;
    transform: translateY(40px);
    transition: opacity 1s ease-out, transform 0.8s ease-out;
    will-change: opacity, transform;
}

.reveal.active {
    opacity: 1;
    transform: translateY(0);
}

/* --- Header Sticky --- */
header {
    position: sticky;
    top: 0;
    background: white;
    z-index: 1000;
    padding: 15px 5%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    transition: var(--transition);
}

header.scrolled {
    padding: 8px 5%;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.logo-dgi {
    font-weight: 900;
    color: var(--primary-blue);
    font-size: 1.2rem;
    text-decoration: none;
}

.search-bar {
    flex: 0 1 400px;
    margin: 0 20px;
    display: none; /* Oculto en mobile (en mobile el buscador está dentro del menú) */
}

.search-bar input {
    width: 100%;
    padding: 8px 20px;
    border: 1px solid #ddd;
    border-radius: 25px;
    outline: none;
}

/* --- Botón hamburguesa --- */
.menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    width: 44px;
    height: 44px;
    padding: 10px;
    background: none;
    border: 0;
    cursor: pointer;
}

.menu-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text-dark);
    border-radius: 2px;
    transition: transform .3s ease, opacity .2s ease;
}

.menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

.menu-toggle:focus-visible {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
    border-radius: 4px;
}

/* --- Menú principal (base = mobile, pantalla completa) --- */
.menu-principal {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999; /* debajo del header (1000) */
    background: #fff;
    padding: 14px 24px 40px;
    overflow-y: auto;
    overscroll-behavior: contain;

    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity .25s ease, transform .25s ease, visibility 0s linear .25s;
}

.menu-principal.abierto {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity .25s ease, transform .25s ease, visibility 0s;
}

.menu-search {
    position: relative;
    max-width: 360px;
    margin: 0 auto 10px;
}

.menu-search svg {
    position: absolute;
    left: 14px;
    top: 50%;
    width: 15px;
    height: 15px;
    transform: translateY(-50%);
    color: #666;
    pointer-events: none;
}

.menu-search input {
    width: 100%;
    padding: 10px 16px 10px 38px;
    border: 1px solid #cfcfcf;
    border-radius: 999px;
    font-size: .8rem;
    outline: none;
    transition: border-color .2s;
}

.menu-search input:focus {
    border-color: var(--primary-blue);
}

.menu-principal ul {
    list-style: none;
    max-width: 360px;
    margin: 0 auto;
    border-top: 1px solid var(--menu-linea);
}

.menu-principal li {
    border-bottom: 1px solid var(--menu-linea);
}

.menu-principal a {
    display: block;
    padding: 16px 10px;
    text-align: center;
    font-size: .95rem;
    font-weight: 500;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--menu-texto);
    transition: color .2s, background .2s;
}

.menu-principal a:hover,
.menu-principal a:focus-visible {
    color: var(--primary-blue);
    background: #f7f8fc;
    outline: none;
}

/* Que los anclas del menú no queden tapadas por el header + mini nav */
section[id] {
    scroll-margin-top: calc(var(--header-h) + 60px);
}

/* --- Branding Hero --- */
.branding {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 5%;
    text-align: left;
}

.branding h1 {
    color: var(--primary-blue);
    font-weight: 900;
    font-size: 1.8rem;
    line-height: 1;
    text-transform: uppercase;
    max-width: 250px;
}

.branding span {
    font-size: 0.8rem;
    letter-spacing: 2px;
    color: var(--secondary-blue);
    font-weight: 700;
    display: block;
    margin-top: 5px;
}

.logo-section{
    display: flex;
    align-items: center;
    gap: 15px;
}

.hero-images {
    display: flex;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 40px;
    width: 100%; /* Asegura que ocupe todo el ancho */
}

.hero-image-item {
    flex:1;
    position: relative;
    height: 80px; /* Altura para mobile */
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease 0.2s;
}

.hero-bg {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: transform 0.5s ease;
}

/* Capa de texto (Overlay) */
.hero-overlay {
    position: absolute;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    display: flex;
    align-items: center;
    padding: 10px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1;
    text-align: left;
    text-transform: uppercase;
    transition: opacity 0.3s ease 0.2s;
    opacity: 0;
}

/* --- Estados Hover --- */
.hero-image-item:hover {
    flex: 2.5;  /* El item hovered se expande */
}

.hero-image-item:hover .hero-bg {
    transform: scale(1.1);
}

.hero-image-item:hover .hero-overlay {
    opacity: 1;
}

/* --- Secciones --- */
section.sm-padding-1 { padding-bottom: 0px; }
section.sm-padding-2 { padding-top: 15px; }


section { padding: 40px 5%; }

.section-title {
    font-size: 1.25rem;
    text-transform: uppercase;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 5px;
    margin-bottom: 25px;
    font-weight: 800;
}

/* --- Cards & Hovers --- */
.news-grid {
    display: grid;
    gap: 20px;
}

.card {
    display: flex;
    gap: 15px;
    transition: var(--transition);
    cursor: pointer;
    background: #fff;
    padding: 10px;
    border-radius: 8px;
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 15px 30px rgba(0,0,0,0.08);
}

.card-img {
    width: 100px;
    height: 100px;
    background: #f4f4f4;
    flex-shrink: 0;
    border-radius: 4px;
}

.card-img img {
    border-radius: 4px;
}

.card-content h3 {
    font-size: 1.05rem;
    margin-bottom: 5px;
    color: var(--primary-blue);
}

.card-content p {
    font-size: 0.9rem;
    color: #666;
    line-height: 1.4;
}

.card-content .titles {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.banner-blue {
    background: var(--primary-blue);
    color: white;
    padding: 60px 5%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: 30px;
}

.banner-blue h2 { 
    font-size: 2.7rem; 
    font-weight: 900; 
}

.banner-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    max-width: 300px;
}

.btn-aprender {
    display: inline-block;
    padding: 14px 40px;
    border: 2px solid white;
    color: white;
    text-decoration: none;
    font-weight: bold;
    transition: var(--transition);
}

.btn-aprender:hover {
    background: white;
    color: var(--primary-blue);
}

.mockup-recibo {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: white;
    padding: 20px;
    border-radius: 10px;
    width: 220px;
    height: 280px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}

.historia-banner {
    display: flex;
    /* align-items: stretch; */
    gap: 12px;
    padding: 12px 0;
    margin: 30px 0 0 0;
}

.historia-deco {
    width: 18px;
    flex-shrink: 0;
    background: #dde7f8;
}

.historia-texto {
    flex: 1;
    background: #dde7f8;
    padding: 18px 20px;
    text-align: center;
    color: #222;
    font-family: 'Montserrat', sans-serif;
}

.historia-texto p {
    margin: 0;
    font-size: clamp(0.9rem, 2.5vw, 1.3rem);
    font-weight: 400;
    text-transform: uppercase;
    line-height: 1.15;
}

.historia-anio {
    display: block;
    font-size: clamp(1.8rem, 6vw, 3rem);
    font-weight: 900;
    font-style: italic;
    line-height: 1;
    margin-top: 4px;
}

.historia-cta {
    display: flex;
    align-items: center;
    min-width: 30%;
    gap: 10px;
    padding: 15px 20px;
    background: #dde7f8;
    color: #222;
    text-decoration: none;
    font-family: 'Montserrat', sans-serif;
    transition: background 0.3s;
}

.historia-cta:hover {
    background: #c9d8f3;
}

.historia-icono {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: 2px solid #222;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
}

.historia-cta:hover .historia-icono {
    transform: translateX(4px);
}

.historia-cta-texto {
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    line-height: 1.1;
}


.dynamic-underline {
    position: relative;
    display: inline-block;
    cursor: pointer;
    margin-top: 4px;
}
 
.dynamic-underline::after {
    content: "";
    position: absolute;
    left: -1px;
    bottom: -2px;
    width: 101%;
    height: 2px;
    background: #30499b;
    border-radius: 2px;
 
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s ease-out;
}
 
.dynamic-underline:hover::after {
    transform: scaleX(1);
}

.event-overlay {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    right: -60%;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    width: 100%;
    height: 100%;
    padding: 12px 15px;
    font-size: 1.25rem;
    font-weight: bold;
    text-align: right;
    line-height: 1;
    transition: all 0.5s ease; 
    opacity: 0;
    pointer-events: none;
}

.event-item:hover .event-overlay {
    right: 0;
    opacity: 1; 
}

.event-item img {
    position: absolute;
    transition: transform 0.5s ease;
}

.event-item:hover img {
    transform: scale(1.05); 
}

.only-md {
    display: none;
}

@media (max-width: 400px) {
    .historia-banner { flex-wrap: wrap; }
    .historia-deco { display: none; }
    .historia-cta { width: 100%; justify-content: center; }
}


@media (min-width: 768px) {
    .news-grid { 
        grid-template-columns: 1fr 1fr; 
    }
    .hero-images div { 
        height: 150px; 
    }
    .hero-image-item {
        height: 150px;
    }
    .hero-overlay {
        font-size: 0.9rem;
    }
    .search-bar { display: block; }

    .menu-principal {
        bottom: auto;
        padding: 0;
        overflow: visible;
        border-top: 1px solid var(--menu-linea);
        box-shadow: 0 6px 16px rgba(0, 0, 0, .06);
    }

    .menu-search { 
        display: none; 
    }

    .menu-principal ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
        max-width: 1200px;
        border: 0;
    }

    .menu-principal li { border: 0; }

    .menu-principal a {
        position: relative;
        padding: 14px 18px;
        font-size: .85rem;
    }

    .menu-principal a:hover,
    .menu-principal a:focus-visible {
        background: none;
    }

    .menu-principal a::after {
        content: "";
        position: absolute;
        left: 18px;
        right: 18px;
        bottom: 8px;
        height: 2px;
        background: var(--primary-blue);
        border-radius: 2px;
        transform: scaleX(0);
        transition: transform .25s ease;
    }

    .menu-principal a:hover::after,
    .menu-principal a:focus-visible::after {
        transform: scaleX(1);
    }

    .historia-texto {
        text-align: right;
        min-width: 45%;
        padding: 18px 30px;

    }

    .historia-cta {
        min-width: 40%;
        padding: 15px 30px;
    }

    .historia-cta-texto{
        margin-left: 10px;
        font-size: 1.35rem;
    }

    .only-md {
        display: block;
    }
}

@media (min-width: 1024px) {
    .news-grid { 
        grid-template-columns: repeat(3, 1fr); 
    }
    .card { 
        flex-direction: column; 
    }
    .card-img { 
        width: 100%; 
        height: 180px; 
    }
    .banner-blue { 
        flex-direction: row; 
        justify-content: space-around; 
        text-align: left; 
    }

    .branding{
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 2rem;
        padding: 20px 5%;
    }

    .branding .logo-section{
        /* margin-top: 20px; */
        max-width: max-content;
    }

    .branding .logo-section img{
        width: 175px;
    }

    .branding .logo-section h1{
        font-size: 3rem;
        max-width: 400px;
    }

    .branding .logo-section span{
        font-size: 1.5rem;
    }

    .branding .hero-images{
        display: flex;
        flex-direction: column;
        max-height: 75vh;
        max-width: 25vw;
    }
    
    .branding .hero-images .hero-image-item{
        max-height: 100px;
    }

    .branding .hero-images .hero-image-item .hero-overlay{
        max-height: 100px;
        font-size: 1.25rem;
    }

    section.reveal-sm{
        padding-top: 0px;
    }

    .reveal-sm .news-grid{
        grid-template-columns: repeat(4, 1fr);
    }

    section.banner-blue{
        justify-content: center;
        gap: 75px;
    }

    section.banner-blue .banner-content h2{
        line-height: 1;
        text-align: center;
    }

    section.banner-blue .banner-content a{
        font-size: 1.5rem;
    }

}

@media (min-width: 1280px) {
    section, .branding { padding-left: 15%; padding-right: 15%; }
}

/* Respeta a quien tiene desactivadas las animaciones en el sistema */
@media (prefers-reduced-motion: reduce) {
    .menu-principal,
    .menu-principal.abierto,
    .menu-toggle span,
    .menu-principal a::after {
        transition: none;
    }
}

footer {
    background: #f8f9fa;
    padding: 40px 5%;
    text-align: center;
    font-size: 0.8rem;
    color: #888;
    border-top: 1px solid #eee;
}



/* --- Banner NASA Space Apps --- */
.nasa-banner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 25px;
    padding: 50px 5%;
    background: linear-gradient(120deg, #0b1d4a 0%, var(--primary-blue) 100%);
    color: #fff;
}

.nasa-banner-sede {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .08em;
    opacity: .8;
    margin-bottom: 8px;
}

.nasa-banner h2 {
    font-size: 1.8rem;
    font-weight: 900;
    line-height: 1.1;
    margin-bottom: 12px;
}

.nasa-banner p {
    font-size: .95rem;
    line-height: 1.5;
    max-width: 520px;
    opacity: .9;
}

.nasa-banner .btn-aprender {
    flex-shrink: 0;
}

@media (min-width: 768px) {
    .nasa-banner {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 50px;
    }
    .nasa-banner h2 { font-size: 2.3rem; }
}

@media (min-width: 1280px) {
    .nasa-banner { padding-left: 15%; padding-right: 15%; }
}