/* ===============================
   VARIABLES GENERALES
================================ */
:root {
    --bg-color: #05070a;
    --envelope-color: #161b33;
    --envelope-light: #1f2647;
    --flap-color: #252a41;
    --accent-gold: #d4af37;
    --letter-bg: #fdfdfd;

    /* Tamaños fluidos */
    --fs-xl:  clamp(1.6rem, 5vw, 2.5rem);
    --fs-lg:  clamp(1.2rem, 3.5vw, 1.8rem);
    --fs-md:  clamp(0.9rem, 2.5vw, 1.1rem);
    --fs-sm:  clamp(0.75rem, 2vw, 0.9rem);
    --fs-xs:  clamp(0.65rem, 1.6vw, 0.75rem);

    /* Sobre: todo se deriva de --env-w */
    --env-w:      clamp(260px, 80vw, 320px);
    --env-h:      calc(var(--env-w) * 0.67);
    --half:       calc(var(--env-w) / 2);
    --flap-h:     calc(var(--env-h) * 0.575);
    --side-h:     calc(var(--env-h) * 0.5);
    --bottom-h:   calc(var(--env-h) * 0.55);
    --seal-size:  clamp(40px, 10vw, 55px);
    --lift:       clamp(-120px, -28vw, -175px);
}

/* ===============================
   RESET Y BASE
================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html { font-size: 16px; }

body {
    margin: 0;
    min-height: 100svh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle, #0b0d17 0%, #05070a 100%);
    font-family: 'Cormorant Garamond', serif;
    overflow: hidden;
    -webkit-text-size-adjust: 100%;
}

/* ===============================
   FONDO
================================ */
.sky-background {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: radial-gradient(ellipse at bottom, #1B2735 0%, #05070a 100%);
    overflow: hidden;
}

/* ===============================
   ESTRELLAS
================================ */
.stars {
    width: 1px;
    height: 1px;
    background: transparent;
    box-shadow:
        10vw 20vh #fff, 35vw 45vh #fff, 80vw 15vh #fff, 60vw 70vh #fff,
        15vw 90vh #fff, 45vw 10vh #fff, 90vw 80vh #fff, 25vw 35vh #fff,
        5vw  5vh  #fff, 95vw 95vh #fff, 50vw 50vh #fff, 75vw 25vh #fff,
        20vw 80vh #fff, 40vw 30vh #fff, 70vw 60vh #fff, 85vw 10vh #fff;
    animation: twinkle 5s infinite ease-in-out;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.7; }
    50%       { opacity: 1;   }
}

/* ===============================
   ESTRELLAS FUGACES
================================ */
.shooting-star {
    position: absolute;
    top: 0;
    left: 50%;
    width: clamp(60px, 12vw, 100px);
    height: 2px;
    background: linear-gradient(-45deg, #fff, rgba(0,0,255,0));
    filter: drop-shadow(0 0 6px #fff);
    opacity: 0;
    z-index: -1;
    animation: shooting 4s infinite ease-in-out;
}

.shooting-star:nth-child(2) { top: 10%; left: 80%; animation-delay: 1s;   }
.shooting-star:nth-child(3) { top: 30%; left: 40%; animation-delay: 2.5s; }
.shooting-star:nth-child(4) { top: 50%; left: 90%; animation-delay: 0.5s; }

@keyframes shooting {
    0%   { transform: translateX(200px)  translateY(-200px) rotate(45deg); opacity: 1; }
    20%  { transform: translateX(-400px) translateY(400px)  rotate(45deg); opacity: 0; }
    100% { opacity: 0; }
}

/* ===============================
   SECUENCIA DE LUNAS
================================ */
.moon-sequence {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;          /* Nunca apila las lunas */
    gap: clamp(2px, 1.5vw, 18px);
    margin-bottom: clamp(24px, 6vw, 50px);
    position: relative;
    top: clamp(-40px, -7vw, -70px);
    width: 100%;
    overflow: visible;
}

.moon {
    opacity: 0;
    animation:
        aparecer 1s forwards,
        floatMoon 4s ease-in-out infinite;
}

.moon img {
    width:  clamp(28px, 10vw, 90px);
    height: clamp(28px, 10vw, 90px);
    object-fit: contain;
    filter:
        drop-shadow(0 0 8px rgba(255,255,255,.4))
        drop-shadow(0 0 20px rgba(255,255,200,.25));
    transition: all .4s ease;
}

/* Luna llena destacada */
.moon:nth-child(4) img {
    width:  clamp(44px, 14vw, 130px);
    height: clamp(44px, 14vw, 130px);
    filter:
        drop-shadow(0 0 20px rgba(255,255,255,.9))
        drop-shadow(0 0 50px rgba(255,255,200,.8))
        drop-shadow(0 0 90px rgba(255,220,100,.6));
    animation: pulseMoon 3s ease-in-out infinite;
}

.moon:nth-child(4) {
    position: relative;
}

.moon:nth-child(4)::after {
    content: "";
    position: absolute;
    inset: -20px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(212,175,55,.4), transparent 70%);
    z-index: -1;
    animation: halo 3s ease-in-out infinite;
}

.moon:hover img { transform: scale(1.15); }

.moon:nth-child(1) { animation-delay: .1s; }
.moon:nth-child(2) { animation-delay: .3s; }
.moon:nth-child(3) { animation-delay: .5s; }
.moon:nth-child(4) { animation-delay: .7s; }
.moon:nth-child(5) { animation-delay: .9s; }
.moon:nth-child(6) { animation-delay: 1.1s; }
.moon:nth-child(7) { animation-delay: 1.3s; }

@keyframes aparecer {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0);    }
}

@keyframes floatMoon {
    0%, 100% { transform: translateY(0);    }
    50%       { transform: translateY(-12px); }
}

@keyframes pulseMoon {
    0%, 100% { transform: scale(1);    }
    50%       { transform: scale(1.08); }
}

@keyframes halo {
    0%, 100% { transform: scale(1);    opacity: .6; }
    50%       { transform: scale(1.15); opacity: 1;  }
}

/* ===============================
   CONTENEDOR PRINCIPAL
================================ */
.contenedor {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
    padding: clamp(16px, 5vw, 40px);
    width: 100%;
}

/* ===============================
   SOBRE — COMPLETAMENTE FLUIDO
================================ */
.envelope-wrapper {
    position: relative;
    width: var(--env-w);
    height: var(--env-h);
    background-color: var(--envelope-color);
    border-radius: 0 0 10px 10px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.8);
    cursor: pointer;
    perspective: 1000px;
    margin-top: clamp(60px, 15vw, 110px);
    z-index: 9999;
    isolation: isolate;
}

/* Título "MIS XV" */
.main-title {
    position: absolute;
    top: clamp(-130px, -38vw, -110px);
    left: 50%;
    transform: translateX(-50%);

    width: clamp(240px, 90vw, 500px);
    text-align: center;

    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: clamp(1.3rem, 5vw, 2.6rem);
    letter-spacing: clamp(1px, 0.5vw, 4px);
    text-transform: uppercase;
    line-height: 1.3;

    color: var(--accent-gold);
    z-index: 9999;
    pointer-events: none;

    text-shadow:
        0 0 10px rgba(212,175,55,.5),
        0 0 20px rgba(212,175,55,.3),
        0 0 40px rgba(212,175,55,.2);

}

@media (max-width: 360px) {
    .main-title {
        font-size: clamp(1rem, 7vw, 1.3rem);
        top: -95px;
        width: 95vw;
        letter-spacing: 1px;
    }
}

@media (min-width: 768px) {
    .main-title {
        font-size: clamp(1.8rem, 3.5vw, 2.4rem);
        top: -140px;
        width: clamp(300px, 60vw, 500px);
    }
}

@media (min-width: 1024px) {
    .main-title {
        font-size: 2.2rem;
        top: -150px;
        width: 420px;
    }
}

@keyframes pulse-grow {
    0%, 100% {
        transform: translateX(-50%) scale(1);
    }

    50% {
        transform: translateX(-50%) scale(1.05);
    }
}
/* Texto de instrucción */
.instruction {
    position: absolute;

    top: -45px;

    left: 50%;
    transform: translateX(-50%);

    width: max-content;

    text-align: center;

    color: #fff;

    font-family: 'Cinzel', serif;

    font-size: var(--fs-xs);

    z-index: 9999;

    animation: pulse-grow 2s infinite ease-in-out;
}

/* ---- SOLAPA ---- */
.flap {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-left:  var(--half)   solid transparent;
    border-right: var(--half)   solid transparent;
    border-top:   var(--flap-h) solid var(--flap-color);
    transform-origin: top;
    transition: transform 0.6s ease-in-out;
    z-index: 5;
    
}

/* ---- SELLO ---- */
.seal {
    position: absolute;
    top: calc(var(--flap-h) * 0.72);
    left: 50%;
    transform: translateX(-50%);
    width:  var(--seal-size);
    height: var(--seal-size);
    background: radial-gradient(circle, #d4af37, #aa8a2e);
    border-radius: 50%;
    z-index: 6;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(14px, 4vw, 24px);
    transition: all 0.4s ease;
    
}

/* ---- CARTA ---- */
.letter {
    position: absolute;
    bottom: -10px;
    left: 50%;
    width: 78%;
    height: 92%;
    background: var(--letter-bg);
    border-radius: 8px;
    padding: clamp(12px, 3vw, 18px);
    color: #333;
    text-align: center;
    z-index: 1;
    opacity: 0;
    transform: translateX(-50%) translateY(45px) scale(0.88);
    transform-origin: bottom center;
    transition:
        transform 1s ease-in-out 0.45s,
        opacity   0.4s ease-in-out 0.45s,
        z-index   0s linear 0.9s;
    box-shadow: 0 12px 25px rgba(0,0,0,.35);
}

/* ---- CARAS DEL SOBRE ---- */
.envelope-front {
    position: absolute;
    width: 0;
    height: 0;
    z-index: 4;
}

.envelope-front-left {
    border-left:   var(--half)   solid var(--envelope-light);
    border-top:    var(--side-h) solid transparent;
    border-bottom: var(--side-h) solid transparent;
    left: 0;
}

.envelope-front-right {
    border-right:  var(--half)   solid var(--envelope-light);
    border-top:    var(--side-h) solid transparent;
    border-bottom: var(--side-h) solid transparent;
    right: 0;
}

.envelope-front-bottom {
    border-bottom: var(--bottom-h) solid var(--envelope-color);
    border-left:   var(--half)     solid transparent;
    border-right:  var(--half)     solid transparent;
    bottom: 0;
}

/* ---- ANIMACIONES AL ABRIR ---- */
.envelope-wrapper.open .flap {
    transform: rotateX(180deg);
    z-index: 0;
}

.envelope-wrapper.open .seal {
    opacity: 0;
    transform: translateX(-50%) scale(0);
}

.envelope-wrapper.open .letter {
    opacity: 1;
    z-index: 99999;
    transform: translateX(-50%) translateY(var(--lift)) scale(1);
}

/* ---- BORDE DORADO DENTRO DE LA CARTA ---- */
.letter-border {
    width: 100%;
    height: 100%;
    border: 2px solid var(--accent-gold);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    background:
        linear-gradient(135deg, rgba(212,175,55,.08), transparent),
        #fff;
}

.letter-border h2 {
    font-family: 'Great Vibes', cursive;
    font-size: clamp(1.4rem, 5vw, 2.2rem);
    color: var(--accent-gold);
    text-shadow: 0 0 8px rgba(212,175,55,.25);
    text-align: center;
    padding: 8px;
}

/* ===============================
   FRASE DEBAJO DEL SOBRE
================================ */
.mensaje-extra {
    margin-top: clamp(16px, 4vw, 25px);
    text-align: center;
    font-family: 'Cormorant Garamond', serif;
    font-style: italic;
    font-size: clamp(0.95rem, 3vw, 1.2rem);
    color: #fff;
    opacity: 0.9;
    max-width: min(90%, 480px);
    line-height: 1.5;
}

/* ===============================
   RESPONSIVE — PANTALLAS MUY PEQUEÑAS (≤ 360px)
================================ */
@media (max-width: 360px) {
    :root {
        --env-w: 88vw;
    }

    .moon-sequence { gap: 6px; }
}

/* ===============================
   RESPONSIVE — TABLET (≥ 768px)
================================ */
@media (min-width: 768px) {
    :root {
        --env-w: clamp(300px, 45vw, 340px);
    }
}

/* ===============================
   RESPONSIVE — ESCRITORIO (≥ 1024px)
================================ */
@media (min-width: 1024px) {
    :root {
        --env-w: 320px;
        --lift: -175px;
    }

    .contenedor { gap: 20px; }
}