/**
 * @file style.css
 * @description
 * 🎨 ESTILO Y MAQUILLAJE DE LA HISTORIA
 * ---------------------------------------------------------------------------
 * Aquí definimos cómo se "ve" el libro. Colores, tamaños, sombras y 
 * lo más importante: ¡la magia 3D!
 * 
 * Usamos variables CSS (como :root) para cambiar colores fácilmente.
 * ---------------------------------------------------------------------------
 * @author Alejandro Salido Gomez
 * @license MIT
 */

/* =========================================
   1. Variables Globales (La paleta de pintor)
   ========================================= */
:root {
    /* Definimos los colores una sola vez para usarlos en todos lados */
    --primary-color: #8D6E63;
    /* Marrón tierra (títulos y botones) */
    --secondary-color: #D7CCC8;
    --accent-color: #FF7043;
    /* Naranja suave (destacados) */
    --text-color: #3E2723;
    /* Texto oscuro para lectura cómoda */
    --bg-color: #F5F5F5;
    /* Fondo de la web */
    --paper-color: #FFFAF0;
    /* Color crema (papel antiguo) */

    /* Dimensiones del libro para PC */
    --book-width: 400px;
    /* Ancho base para escritorio */
    --book-height: 550px;

    /* Velocidad estándar de animaciones */
    --transition-speed: 0.6s;
}

/* =========================================
   2. Reset Básico (Limpieza)
   ========================================= */
* {
    /* box-sizing: border-box hace que el padding no aumente el tamaño total */
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Open Sans', sans-serif;
    /* Tipografía fácil de leer */
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100vh;
    /* Ocupa al menos toda la altura de la pantalla */
    display: flex;
    flex-direction: column;
    /* Organiza todo en columna (header-main-footer) */
}

/* =========================================
   3. Header (Encabezado)
   ========================================= */
.main-header {
    background: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    /* Sombra sutil abajo */
    display: flex;
    justify-content: space-between;
    /* Separa logo a izq y nav a der */
    align-items: center;
    position: relative;
    z-index: 10;
    /* Asegurar que el header quede por encima */
}

/* Tipografía divertida para el logo */
.logo {
    font-family: 'Fredoka One', cursive;
    font-size: 1.5rem;
    color: var(--accent-color);
}

nav ul {
    list-style: none;
    /* Quita los puntos de la lista */
    display: flex;
    gap: 1.5rem;
    /* Espacio entre items del menú */
}

nav a {
    text-decoration: none;
    /* Quita el subrayado feo de los links */
    color: var(--text-color);
    font-weight: 600;
    transition: color 0.3s;
    /* Suaviza el cambio de color al pasar el mouse */
}

nav a:hover {
    color: var(--accent-color);
    /* Cambia a naranja al tocar */
}

/* =========================================
   4. Escena 3D (El escenario)
   ========================================= */
.book-container {
    flex: 1;
    /* Ocupa todo el espacio sobrante */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;

    /* ¡MAGIA 3D! 
       perspective define qué tan "lejos" está el usuario.
       Sin esto, todo se vería plano. */
    perspective: 1500px;

    padding: 2rem;
    background-image: radial-gradient(#e0e0e0 1px, transparent 1px);
    /* Patrón de puntos */
    background-size: 20px 20px;
}

/* =========================================
   5. El Libro (.book)
   ========================================= */
.book {
    position: relative;
    width: var(--book-width);
    height: var(--book-height);

    /* preserve-3d es VITAL. Le dice al navegador que los hijos (.paper)
       viven en un mundo 3D y pueden rotar independientemente. */
    transform-style: preserve-3d;
    transition: transform var(--transition-speed);
}

/* =========================================
   6. Hojas (.paper)
   ========================================= */
.paper {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;

    /* El punto de giro es el borde izquierdo (el lomo del libro) */
    transform-origin: left;

    transition: transform var(--transition-speed);
    transform-style: preserve-3d;
    z-index: 1;
}

/* CARAS DE LA PÁGINA: Frente y Dorso */
.front,
.back {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-color: var(--paper-color);

    /* backface-visibility: hidden oculta la cara "trasera" de un div.
       Así, cuando rotamos, no vemos el contenido al revés a trasluz */
    backface-visibility: hidden;

    border: 1px solid #dcdcdc;
    /* Borde de la hoja */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    text-align: center;
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.1);
    /* Sombra suave para profundidad */
    overflow: hidden;
}

/* Ajuste especial para portadas full-imagen */
.front:has(.full-page-cover),
.back:has(.full-page-cover) {
    padding: 0;
    justify-content: flex-start;
    align-items: flex-start;
}

/* Configuración de cara frontal */
.front {
    z-index: 2;
}

/* Configuración de cara trasera (rotada 180deg inicialmente) */
.back {
    z-index: 1;
    transform: rotateY(180deg);
}

/* Orden de apilamiento inicial (Z-Index) */
/* El Z-Index se maneja dinámicamente en main.js */

/* --- ESTADO VOLTEADO (FLIPPED en Desktop) --- */
.paper.flipped {
    transform: rotateY(-180deg);
    /* Girar hacia la izquierda */
}

/* Ajuste de Z-Index al voltear:
   Cuando una página se voltea, debe ir al fondo de la pila izquierda */
.paper.flipped {
    z-index: 0;
}

/* =========================================
   7. Estilos de Contenido
   ========================================= */
h1,
h2 {
    font-family: 'Fredoka One', cursive;
    color: var(--primary-color);
    margin-bottom: 1rem;
}

.book-img {
    max-width: 90%;
    max-height: 250px;
    border-radius: 10px;
    margin: 1rem 0;
    box-shadow: 3px 3px 8px rgba(0, 0, 0, 0.2);
    object-fit: cover;
}

.chapter-img {
    max-width: 100%;
    max-height: 180px;
    width: auto;
    border-radius: 8px;
    margin: 0.5rem 0 1rem 0;
    display: block;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.15);
}

.author {
    margin-top: 1rem;
    font-style: italic;
    color: #666;
}

/* =========================================
   Controles
   ========================================= */
.controls {
    margin-top: 2rem;
    display: flex;
    gap: 1rem;
}

button {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 50px;
    background-color: var(--primary-color);
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover {
    background-color: var(--accent-color);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(0);
}

/* =========================================
   Estilos Especiales para Páginas Completas
   ========================================= */
.full-page-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

.full-page-cover img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border: 0;
    margin: 0;
    padding: 0;
}

.blank-page {
    background-color: var(--paper-color);
    /* Página completamente en blanco */
}

/* Footer (Pie de página) */
.main-footer {
    text-align: center;
    padding: 1.5rem;
    background-color: var(--text-color);
    color: white;
}

/* =========================================
   Responsive Design (Tablet)
   ========================================= */
@media (max-width: 900px) and (min-width: 601px) {
    :root {
        --book-width: 350px;
        --book-height: 480px;
    }

    .book-container {
        padding: 1.5rem;
    }
}

/* =========================================
   Responsive Design (Móvil - Pantalla Única)
   ========================================= */
@media (max-width: 600px) {
    :root {
        /* En móvil mostramos una sola página (como Kindle) */
        --book-width: 100vw;
        --book-height: 70vh;
        --show-single-page: true;
    }

    .main-header {
        padding: 0.5rem 1rem;
        flex-wrap: nowrap;
        /* Keep logo and nav on same line if possible */
        gap: 1rem;
    }

    .logo {
        font-size: 0.9rem;
        /* Slightly smaller to fit */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    nav ul {
        display: flex;
        /* Show nav in mobile */
        gap: 0.5rem;
        margin: 0;
        padding: 0;
    }

    nav a img {
        width: 20px;
        /* Resize icons for mobile */
        height: auto;
    }

    /* Ajustes adicionales para que el libro no se salga */
    .book-container {
        padding: 0.5rem;
        perspective: 800px;
        background-image: none;
    }

    .book {
        /* Mostrar solo la página derecha en móvil */
        width: var(--book-width);
        height: var(--book-height);
    }

    .paper {
        /* Páginas ocupan toda la pantalla en móvil */
        width: 100%;
        height: 100%;
        transform-origin: center;
    }

    .paper.flipped {
        /* No rotar en móvil, solo cambiar contenido */
        transform: rotateY(0deg);
    }

    .front,
    .back {
        padding: 1rem;
        font-size: 0.9rem;
    }

    .front:has(.full-page-cover),
    .back:has(.full-page-cover) {
        padding: 0;
    }

    /* Mobile Single Page Logic */
    .paper.mobile-flipped .front {
        display: none;
    }

    .paper.mobile-flipped .back {
        display: flex;
        /* Show back */
        transform: rotateY(0deg);
        /* No rotation needed for flat view */
        z-index: 2;
    }

    /* Default mobile state: Back hidden, Front shown */
    .paper .back {
        display: none;
    }

    .paper .front {
        display: flex;
    }

    .book-img {
        max-height: 150px;
    }

    .chapter-img {
        max-height: 120px;
    }

    h1,
    h2 {
        font-size: 1.3rem;
        margin-bottom: 0.8rem;
    }

    button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }

    .controls {
        margin-top: 1rem;
        gap: 0.5rem;
    }

    .main-footer {
        padding: 1rem 0.5rem;
        font-size: 0.75rem;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .main-footer .social-links {
        display: flex;
        flex-wrap: wrap;
        /* Allow wrapping */
        justify-content: center;
        gap: 0.8rem;
    }

    .main-footer p {
        margin: 0;
        line-height: 1.4;
    }
}

/* =========================================
   Responsive Design (Pantalla Muy Pequeña)
   ========================================= */
@media (max-width: 360px) {
    :root {
        --book-height: 60vh;
    }

    .logo {
        font-size: 0.9rem;
    }

    h1,
    h2 {
        font-size: 1.1rem;
        margin-bottom: 0.6rem;
    }

    .front,
    .back {
        padding: 0.8rem;
    }

    button {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }
}