/* style.css - Estilos para libro ilustrado interactivo */

:root {
    --color-cream: #FFFEF9;
    --color-peach: #FFE5B4;
    --color-pink: #FFB6C1;
    --color-mint: #98FB98;
    --color-lavender: #E6E6FA;
    --color-sky: #87CEEB;
    --color-yellow: #FFFACD;
    --shadow-book: 0 20px 60px rgba(0, 0, 0, 0.3);
    --shadow-page: 0 4px 15px rgba(0, 0, 0, 0.1);
    --transition-flip: 0.8s;
    
    /* Nuevas: texto adaptativo por fondo */
    --text-on-night: #ffffff;
    --text-on-forest: #ffffff;
    --text-on-water: #1a1a2e;
    --text-on-ocean: #FFFEF9;
    --text-on-earth: #FFFEF9;
    --text-on-sunset: #4a3728;
    
    /* Nuevas: tamaños para niños */
    --sound-btn-size: 64px;
    --sound-btn-icon: 32px;
}

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

body {
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(135deg, var(--color-lavender) 0%, var(--color-pink) 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    max-width: 1000px;
    perspective: 2000px;
}

/* ===== PORTADA DEL LIBRO ===== */
.book-cover {
    background: linear-gradient(145deg, var(--color-peach), var(--color-pink));
    border-radius: 20px;
    box-shadow: var(--shadow-book);
    padding: 60px 40px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.book-cover::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.2'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    opacity: 0.5;
}

.cover-content {
    position: relative;
    z-index: 1;
}

.cover-emoji {
    font-size: 120px;
    animation: float 3s ease-in-out infinite;
}

.cover-image {
    width: 100%;
    max-width: 400px;
    display: block;
    margin: 0 auto 20px auto;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

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

.cover-title {
    font-size: 3rem;
    color: #5a4a42;
    margin: 20px 0;
    text-shadow: 2px 2px 4px rgba(255, 255, 255, 0.5);
}

.cover-author {
    font-size: 1.4rem;
    color: #7a6a62;
    margin-bottom: 40px;
}

.btn-open-book {
    background: linear-gradient(145deg, var(--color-mint), #7dcea0);
    border: none;
    padding: 18px 45px;
    font-size: 1.4rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    color: #2d5a27;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s, box-shadow 0.3s;
}

.btn-open-book:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

/* ===== LIBRO ABIERTO ===== */
.book {
    display: flex;
    gap: 0;
    box-shadow: var(--shadow-book);
    border-radius: 15px;
    overflow: hidden;
    transform-style: preserve-3d;
}

.page {
    width: 50%;
    min-height: 550px;
    position: relative;
    transform-style: preserve-3d;
}

.page-left {
    background: linear-gradient(90deg, #f5e6d3 0%, #fff 100%);
    border-right: 1px solid #d4c4b0;
}

.page-right {
    background: var(--color-cream);
}

.page-content {
    padding: 40px 30px;
    height: calc(100% - 80px);
    display: flex;
    flex-direction: column;
}

.back-content {
    justify-content: center;
}

/* ===== ANIMACIÓN DE PASAR PÁGINA ===== */
.page-right.flipped {
    transform-origin: left center;
    animation: flipPageRight var(--transition-flip) ease-in-out forwards;
}

@keyframes flipPageRight {
    0% {
        transform: rotateY(0deg);
        z-index: 10;
    }
    100% {
        transform: rotateY(-180deg);
        z-index: 10;
    }
}

/* ===== CONTENIDO DE PÁGINA ===== */
.page-emoji {
    font-size: 48px;
    text-align: center;
    margin-bottom: 15px;
    animation: fadeInScale 0.6s ease-out;
}

.page-illustration {
    width: 100%;
    max-height: 55%;
    object-fit: contain;
    display: block;
    margin: 0 auto 15px auto;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    animation: fadeInScale 0.6s ease-out;
}

@keyframes fadeInScale {
    0% { opacity: 0; transform: scale(0.5); }
    100% { opacity: 1; transform: scale(1); }
}

.page-text {
    font-size: 1.4rem;
    line-height: 2.0;
    font-weight: 600;
    text-align: justify;
    flex-grow: 1;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ===== ICONOS DE SONIDO ===== */
.sound-icon {
    position: absolute;
    width: var(--sound-btn-size);
    height: var(--sound-btn-size);
    background: rgba(255, 255, 255, 0.98);
    border: 3px solid #333;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: var(--sound-btn-icon);
    cursor: pointer;
    box-shadow: 
        0 6px 20px rgba(0, 0, 0, 0.35),
        0 0 0 4px rgba(255, 255, 255, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.5);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), 
                box-shadow 0.2s ease, border-color 0.2s ease;
    z-index: 100;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
}

.sound-icon:hover {
    transform: scale(1.15);
    border-color: #5b2a86;
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.4),
        0 0 0 6px rgba(91, 42, 134, 0.2),
        inset 0 2px 4px rgba(255, 255, 255, 0.5);
}

.sound-icon:active {
    transform: scale(0.95);
}

.sound-icon.playing {
    animation: playing 0.5s infinite;
    border-color: #ff6b6b;
}

@keyframes playing {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ===== NAVEGACIÓN ===== */
.page-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 10px;
    margin-top: auto;
    border-top: 2px dashed #ddd;
}

.btn-nav {
    background: linear-gradient(145deg, var(--color-sky), #5dade2);
    border: none;
    padding: 12px 25px;
    font-size: 1rem;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    color: white;
    border-radius: 25px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    transition: all 0.3s;
}

.btn-nav:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}

.btn-nav:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-indicator {
    font-size: 1.1rem;
    font-weight: 700;
    color: #7a6a62;
}

/* ===== ÍNDICE ===== */
.story-list {
    list-style: none;
    text-align: left;
    margin-bottom: 30px;
}

.story-list li {
    padding: 15px 20px;
    margin: 10px 0;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 1.2rem;
    font-weight: 600;
    color: #5a4a42;
}

.story-list li:hover {
    background: var(--color-mint);
    transform: translateX(5px);
}

.story-page-count {
    font-size: 1rem;
    color: var(--color-text-muted);
    font-weight: 400;
}

/* ===== LOADING ===== */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-spinner {
    font-size: 60px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== UTILIDADES ===== */
.hidden {
    display: none !important;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .book { flex-direction: column; }
    .page { width: 100%; min-height: 400px; }
    .page-left { border-right: none; border-bottom: 1px solid #d4c4b0; }
    .cover-title { font-size: 2rem; }
    .cover-emoji { font-size: 80px; }
    .cover-image { max-width: 280px; }
    .page-emoji { font-size: 36px; }
    .page-text { font-size: 1.1rem; }
    .page-illustration { max-height: 45%; }
}

/* ===== ANIMACIONES DE VOLTEO (nuevas) ===== */
@keyframes flipPageIn {
    from { transform: rotateY(90deg); opacity: 0.5; }
    to { transform: rotateY(0deg); opacity: 1; }
}

/* ===== SELECTORES POR COLOR DE FONDO DE PÁGINA ==== */
.page-content[data-bg="1a1a2e"] { background-color: #1a1a2e; }
.page-content[data-bg="1a1a2e"] .page-text { color: var(--text-on-night); }

.page-content[data-bg="2d5a27"] { background-color: #2d5a27; }
.page-content[data-bg="2d5a27"] .page-text { color: var(--text-on-forest); }

.page-content[data-bg="4a90d9"] { background-color: #4a90d9; }
.page-content[data-bg="4a90d9"] .page-text { color: var(--text-on-water); }

.page-content[data-bg="1e3a5f"] { background-color: #1e3a5f; }
.page-content[data-bg="1e3a5f"] .page-text { color: var(--text-on-ocean); }

.page-content[data-bg="8b6914"] { background-color: #8b6914; }
.page-content[data-bg="8b6914"] .page-text { color: var(--text-on-earth); }

.page-content[data-bg="ffb347"] { background-color: #ffb347; }
.page-content[data-bg="ffb347"] .page-text { color: var(--text-on-sunset); }

/* === MEJORAS RESPONSIVE === */
@media (max-width: 768px) {
    :root { --sound-btn-size: 72px; --sound-btn-icon: 36px; }
    .sound-icon { border-width: 4px; }
    .page-text { font-size: 1.3rem; line-height: 2; }
    .page-illustration { max-height: 45%; }
    .page-emoji { font-size: 36px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 1ms !important;
        transition-duration: 1ms !important;
    }
}

/* ===== ACCESIBILIDAD ===== */
button:focus-visible {
    outline: 4px solid #5b2a86;
    outline-offset: 4px;
}

button:active:not(:disabled) {
    transform: scale(0.96);
}

.story-btn {
    display: block;
    width: 100%;
    padding: 15px 20px;
    text-align: left;
    font-size: 1.2rem;
    font-family: inherit;
    background: rgba(255,255,255,0.7);
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s;
}

.story-btn:hover {
    background: var(--color-mint);
    transform: translateX(5px);
}
