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

:root {
    --page-bg: #fffef7;
    --page-shadow: rgba(0, 0, 0, 0.1);
    --spine-color: #f97316;
    --accent-primary: #ff6b6b;
    --accent-secondary: #ff9f43;
    --text-dark: #431407;
    --font-quicksand: 'Quicksand', sans-serif;
}

body {
    font-family: var(--font-quicksand);
    background-color: #fdfcf0;
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    padding: 20px;
    box-sizing: border-box;
}

/* Botón de Música Global */
.global-music-control {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.music-toggle-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b6b 0%, #ff4757 50%, #ff6348 100%);
    color: white;
    border: 4px solid white;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(255, 71, 87, 0.5), 0 0 40px rgba(255, 107, 107, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    animation: float-btn 3s infinite ease-in-out, pulse-glow 2s infinite ease-in-out;
}

.music-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 15px 30px rgba(255, 107, 107, 0.5);
}

.music-toggle-btn.music-off {
    background: #cbd5e1;
    color: #64748b;
    box-shadow: none;
    animation: none;
}

@keyframes float-btn {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 10px 25px rgba(255, 71, 87, 0.5), 0 0 40px rgba(255, 107, 107, 0.3); }
    50% { box-shadow: 0 10px 30px rgba(255, 71, 87, 0.7), 0 0 60px rgba(255, 107, 107, 0.5); }
}

/* Fondo Animado */
.fixed-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
    overflow: hidden;
}

.particle {
    position: absolute;
    color: #fed7aa;
    font-size: 20px;
    animation: fall linear infinite;
}

@keyframes fall {
    from { transform: translateY(-10vh) rotate(0deg); }
    to { transform: translateY(110vh) rotate(360deg); }
}

.btn-back-universe {
    position: absolute;
    top: 20px;
    left: 20px;
    text-decoration: none;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    font-family: 'Fredoka', sans-serif;
    background: rgba(0,0,0,0.2);
    padding: 10px 20px;
    border-radius: 30px;
    backdrop-filter: blur(5px);
    transition: background 0.3s, transform 0.3s;
    z-index: 100;
}
.btn-back-universe:hover {
    background: rgba(0,0,0,0.4);
    transform: translateY(-2px);
}

/* Portada */
.cover-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100vh;
    z-index: 10;
}

.book-cover {
    width: 650px;
    height: 650px;
    background: #e67e22; 
    border-radius: 20px 40px 40px 20px;
    box-shadow: 20px 20px 60px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 40px;
    position: relative;
    overflow: hidden;
    border-left: 15px solid #d35400;
    transition: transform 1.2s cubic-bezier(0.645, 0.045, 0.355, 1), opacity 0.8s ease;
    transform-origin: left center;
    z-index: 5;
}

.cover-container.opening .book-cover {
    transform: rotateY(-140deg);
    opacity: 0;
    pointer-events: none;
}

.cover-container.opening .read-button {
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.5s ease;
}

.cover-image-full-preview {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.cover-image-full-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.read-button {
    background: #ff6b6b;
    color: white;
    border: 4px solid white;
    padding: 18px 40px;
    font-size: 22px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 900;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(255, 107, 107, 0.5);
    transition: all 0.3s ease;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 30px;
}

.read-button:hover {
    transform: translateY(-5px) scale(1.05);
    background: #ff4757;
    box-shadow: 0 15px 35px rgba(255, 107, 107, 0.7);
}

/* Libro abierto y cerrado */
.book-container {
    perspective: 2500px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 1s ease;
}

/* Estado CERRADO: Libro centrado y compacto */
.book-container.closed {
    transform: translateY(0);
}

.book-container.closed .book-wrapper {
    /* Desplazamos el libro a la izquierda la mitad de una página para centrar la tapa */
    transform: translateX(-25%) rotateX(0deg); 
}

.book-container.closed .controls {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.book-container.closed .book-spine {
    opacity: 0;
}

.book-container.closed .read-button {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.read-button {
    position: relative;
    z-index: 1000;
    background: #ff6b6b;
    color: white;
    border: 4px solid white;
    padding: 18px 50px;
    font-size: 24px;
    font-family: 'Fredoka', sans-serif;
    font-weight: 900;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(255, 107, 107, 0.5);
    transition: all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    margin-top: 40px;
    transform: translateY(20px);
}

.book-wrapper {
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-5deg);
    transition: transform 1.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.book {
    display: flex;
    position: relative;
    transform-style: preserve-3d;
}

/* Lomo del libro */
.book-spine {
    width: 40px;
    height: 650px;
    background: linear-gradient(to right, #6d3a1a 0%, var(--spine-color) 20%, #a0522d 50%, var(--spine-color) 80%, #6d3a1a 100%);
    position: absolute;
    left: 50%;
    transform: translateX(-50%) translateZ(-20px);
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.3), 0 0 30px rgba(0, 0, 0, 0.4);
    border-radius: 8px;
    z-index: 0;
    transition: opacity 0.8s ease;
}

.book-spine::before, .book-spine::after {
    content: '';
    position: absolute;
    width: 3px;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
}
.book-spine::before { left: 8px; }
.book-spine::after { right: 8px; }

/* Contenedor de páginas - Efecto Flipbook Fluido Mejorado */
.pages-container {
    position: relative;
    width: 1300px;
    height: 650px;
    perspective: 2500px;
}

/* Página izquierda estática (siempre visible) */
.static-left-page {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    z-index: 0;
    overflow: hidden;
}

.static-left-page .page-back {
    position: relative;
    width: 100%;
    height: 100%;
    transform: none;
    border-radius: 2rem 0 0 2rem;
    background-image: url('https://www.transparenttextures.com/patterns/felt.png'); /* Textura sutil */
}

/* Base de la hoja - Efecto Revista */
.leaf {
    position: absolute;
    top: 0;
    right: 0;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform 1.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    z-index: 1;
    will-change: transform;
}

.leaf.turned {
    transform: rotateY(-180deg);
}

/* Efecto de sombra en el lomo (Gutter) */
.leaf::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(to right, rgba(0,0,0,0.15), transparent);
    z-index: 5;
    pointer-events: none;
}

/* Lados de la hoja (frente y dorso) */
.page-front, .page-back {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--page-bg);
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    transform-style: preserve-3d;
    overflow: hidden;
}

.page-front {
    z-index: 2;
    border-radius: 0 2rem 2rem 0;
    /* Gradiente de curvatura de papel + textura */
    background: linear-gradient(to right, #fdfdfd 0%, var(--page-bg) 5%, var(--page-bg) 95%, #e2e2e2 100%),
                url('https://www.transparenttextures.com/patterns/felt.png');
    box-shadow: inset 10px 0 20px rgba(0,0,0,0.05);
}

.page-back {
    transform: rotateY(180deg);
    border-radius: 2rem 0 0 2rem;
    border-right: 1px solid rgba(0,0,0,0.1);
    /* Gradiente inverso para el dorso + textura */
    background: linear-gradient(to left, #fdfdfd 0%, var(--page-bg) 5%, var(--page-bg) 95%, #e2e2e2 100%), 
                url('https://www.transparenttextures.com/patterns/felt.png');
    box-shadow: inset -10px 0 20px rgba(0,0,0,0.05);
}

/* Sombra dinámica al pasar la página */
.leaf.turned .page-back {
    animation: pageShadowBack 1.2s ease-in-out;
}

.leaf.turning .page-front {
    animation: pageShadowFront 1.2s ease-in-out;
}

@keyframes pageShadowBack {
    0% { filter: brightness(1); }
    50% { filter: brightness(0.85); }
    100% { filter: brightness(1); }
}

@keyframes pageShadowFront {
    0% { filter: brightness(1); }
    50% { filter: brightness(0.7); }
    100% { filter: brightness(1); }
}

/* Page Content Styles */
.page-intro, .page-letter-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    padding: 2.5rem; /* Margen para que la imagen no sea gigante */
    box-sizing: border-box;
}

.page-intro .emoji {
    font-size: 6rem;
    margin-bottom: 1.5rem;
    filter: drop-shadow(0 10px 10px rgba(0,0,0,0.1));
}

.page-intro .title {
    font-size: 3rem;
    font-weight: 900;
    color: var(--text-dark);
    margin: 0;
}

.page-intro .desc {
    font-size: 1.2rem;
    font-weight: 700;
    color: #9a3412;
    margin-top: 1rem;
}

.image-wrapper {
    width: 80%;
    aspect-ratio: 1;
    background: white;
    padding: 1rem;
    border-radius: 2rem;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.letter-circle {
    width: 6rem;
    height: 6rem;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid #ffedd5;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.letter-circle span {
    font-size: 3.5rem;
    font-weight: 900;
    color: #c2410c;
}

.page-decor-top, .page-decor-bottom {
    position: absolute;
    opacity: 0.1;
    font-size: 2.5rem;
    color: var(--text-dark);
}

.page-decor-top { top: 1rem; right: 1rem; }
.page-decor-bottom { bottom: 1rem; left: 1rem; }

.page-number {
    position: absolute;
    bottom: 1rem;
    font-size: 0.8rem;
    font-weight: 900;
    color: #fdba74;
}

.page-front.hide-decor .page-decor-top,
.page-front.hide-decor .page-decor-bottom,
.page-front.hide-decor .page-number {
    display: none !important;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-20px); }
}

.animate-bounce {
    animation: bounce 2s infinite ease-in-out;
}

.page-image-full {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0;
    overflow: hidden;
    padding: 1.5rem; /* Margen para fotos de hoja completa */
    box-sizing: border-box;
}

.page-image-full img {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Cambiado a contain para que no se corte */
    border-radius: 1rem;
}

/* Estilos para el contenedor de letras */
.image-wrapper-large {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.image-wrapper-large img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 10px 20px rgba(0,0,0,0.1));
}

/* Controles */
.book-header-controls {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    width: 100%;
}

.music-btn {
    background: var(--accent-secondary);
    color: white !important;
    padding: 0 25px;
    height: 50px !important;
    width: auto !important;
    border-radius: 30px;
    font-family: 'Fredoka', sans-serif;
    font-size: 18px;
    font-weight: 600;
    animation: pulse 2s infinite;
    gap: 10px;
    text-transform: uppercase;
}

.music-btn.music-off {
    background: #a4b0be;
    animation: none;
    box-shadow: none;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(78, 205, 196, 0); }
    100% { box-shadow: 0 0 0 0 rgba(78, 205, 196, 0); }
}

.controls {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: center;
    margin-top: 40px;
    z-index: 20;
    transition: all 0.8s ease;
}

.control-button {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255, 255, 255, 0.5);
    width: 70px;
    height: 70px;
    border-radius: 50%;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dark);
}

.control-button:hover:not(:disabled) {
    transform: translateY(-4px) scale(1.1);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.3);
    background: var(--accent-secondary);
    color: white;
}

.control-button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-indicator {
    font-size: 20px;
    color: var(--text-dark);
    font-weight: 700;
    padding: 15px 35px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50px;
    backdrop-filter: blur(12px);
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

.hidden { display: none !important; }

/* --- HIPER RESPONSIVE OVERHAUL --- */

/* Ajustes base para asegurar centrado */
.book-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

@media (max-width: 1200px) {
    .book-wrapper { transform: scale(0.85); }
}

@media (max-width: 1000px) {
    .book-wrapper { transform: scale(0.7); }
}

/* Tablet y Móvil (Cambio a Single Page) */
@media (max-width: 768px) {
    body { padding: 15px; }

    .book-wrapper {
        transform: none !important;
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .book {
        width: 90vw;
        max-width: 450px;
        aspect-ratio: 1/1;
        height: auto;
    }

    .pages-container {
        width: 100%;
        height: 100%;
    }

    .leaf {
        width: 100%;
        left: 0;
        right: 0;
        transform-origin: left center;
    }

    /* En móvil, el libro cerrado no se desplaza lateralmente */
    .book-container.closed .book-wrapper {
        transform: none !important;
    }

    .static-left-page, .book-spine {
        display: none !important;
    }

    /* Redondear esquinas en móvil */
    .page-front, .page-back {
        border-radius: 1.5rem !important;
    }

    .controls {
        margin-top: 25px;
        gap: 15px;
        width: 100%;
        justify-content: center;
    }

    .control-button {
        width: 55px;
        height: 55px;
        font-size: 20px;
    }

    .page-indicator {
        font-size: 0.9rem;
        padding: 10px 20px;
    }

    .read-button {
        font-size: 18px;
        padding: 14px 30px;
        width: 80%;
        max-width: 280px;
        position: relative;
        left: auto;
        top: auto;
        transform: none;
        margin-top: 30px;
        opacity: 1;
        pointer-events: all;
    }

    .btn-back-universe {
        font-size: 0.7rem;
        padding: 8px 15px;
    }

    .btn-support-global {
        right: 10px;
        top: 10px;
        font-size: 0.8rem;
        padding: 0.6rem 1.2rem;
    }

    .btn-download-book {
        top: 55px;
        left: 10px;
        font-size: 0.75rem;
    }
}

/* Pantallas muy pequeñas (iPhone SE, etc) */
@media (max-width: 400px) {
    .book { width: 95vw; }
    .control-button { width: 45px; height: 45px; }
    .page-indicator { font-size: 0.8rem; padding: 8px 15px; }
}

/* --- ESTILOS DE BOTONES GLOBALES --- */
.btn-support-global {
    position: fixed;
    top: 20px;
    right: 90px; /* Entre la música y la descarga */
    z-index: 1000;
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.8rem 1.8rem;
    background: linear-gradient(135deg, #ff6b6b 0%, #ff4757 100%);
    color: white;
    text-decoration: none;
    border-radius: 50px;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 800;
    box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
    transition: all 0.3s ease;
    text-transform: uppercase;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.btn-support-global:hover {
    transform: translateY(-3px) scale(1.05);
    filter: brightness(1.1);
}

/* --- BOTÓN DESCARGAR LIBRO (HIPER LLAMATIVO) --- */
.download-cta {
    position: fixed;
    top: 20px;
    right: 280px; /* Movido más a la izquierda para dejar espacio a 'Apóyanos' */
    display: flex;
    align-items: center;
    gap: 15px;
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    padding: 12px 25px;
    border-radius: 20px;
    text-decoration: none;
    color: white;
    font-family: 'Fredoka', sans-serif;
    box-shadow: 0 10px 25px rgba(34, 197, 94, 0.4);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 9999; /* Por encima de TODO */
    border: 3px solid rgba(255, 255, 255, 0.3);
    animation: cta-pulse 3s infinite;
}

.download-cta:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 15px 35px rgba(34, 197, 94, 0.6);
    filter: brightness(1.1);
}

.download-icon {
    font-size: 28px;
    background: rgba(255, 255, 255, 0.2);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 15px;
    animation: icon-bounce 2s infinite ease-in-out;
}

.download-text {
    display: flex;
    flex-direction: column;
}

.download-text .main-text {
    font-size: 1.1rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.download-text .sub-text {
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0.9;
}

@keyframes cta-pulse {
    0% { box-shadow: 0 10px 25px rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 10px 40px rgba(34, 197, 94, 0.7); }
    100% { box-shadow: 0 10px 25px rgba(34, 197, 94, 0.4); }
}

@keyframes icon-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Responsivo para el CTA */
@media (max-width: 1100px) {
    .download-cta {
        padding: 8px 15px;
        right: auto;
        left: 20px;
        top: 80px; /* En tablets lo bajamos un poco */
    }
    .download-text .main-text { font-size: 0.85rem; }
}

@media (max-width: 768px) {
    .download-cta {
        top: auto;
        bottom: 25px; /* Siempre visible abajo */
        right: auto;
        left: 50%;
        transform: translateX(-50%);
        width: 85%;
        max-width: 300px;
        justify-content: center;
        padding: 12px;
    }
    
    .download-cta:hover {
        transform: translateX(-50%) translateY(-3px);
    }

    .download-icon {
        width: 40px;
        height: 40px;
        font-size: 22px;
    }

    .download-text .main-text { font-size: 0.9rem; }
    .download-text .sub-text { font-size: 0.75rem; }
}

@media (max-width: 480px) {
    .download-cta {
        padding: 8px 15px;
        gap: 10px;
    }
}
