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

body {
    font-family: 'Georgia', serif;
    background: 
        radial-gradient(circle at 20% 50%, rgba(184, 149, 106, 0.02) 0%, transparent 50%),
        radial-gradient(circle at 80% 50%, rgba(166, 124, 82, 0.02) 0%, transparent 50%),
        repeating-linear-gradient(45deg, #fafafa 0px, #fafafa 10px, #f9f9f9 10px, #f9f9f9 20px),
        linear-gradient(to bottom, #ffffff 0%, #FFF9F0 100%);
    min-height: 100vh;
    perspective: 2500px;
    position: relative;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}

/* Navbar */
nav {
    background: linear-gradient(90deg, #FFECC7 0%, #FFE5D0 50%, #FFDDC1 100%);
    padding: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 2000;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}

nav ul {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 3rem;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
}

nav li {
    margin: 0;
}

nav a {
    color: #6B5D52;
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: bold;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    transition: all 0.3s ease;
    display: inline-block;
}

nav a:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
}

/* Elementos decorativos de fondo */
body::before {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    border: 2px solid rgba(255, 236, 199, 0.15);
    border-radius: 50%;
    top: 10%;
    left: 10%;
    animation: float 20s infinite ease-in-out;
}

body::after {
    content: '';
    position: absolute;
    width: 200px;
    height: 200px;
    border: 2px solid rgba(255, 229, 208, 0.15);
    border-radius: 50%;
    bottom: 15%;
    right: 15%;
    animation: float 15s infinite ease-in-out reverse;
}

@keyframes float {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(5deg); }
}

/* Contenedor principal del libro con mantel */
.book-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    height: 650px;
    margin: 40px auto;
    padding: 50px;
    
    /* Mantel decorativo con patrón de encaje */
    background: 
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 2px,
            rgba(255, 236, 199, 0.1) 2px,
            rgba(255, 236, 199, 0.1) 4px
        ),
        repeating-linear-gradient(
            90deg,
            transparent,
            transparent 2px,
            rgba(255, 229, 208, 0.1) 2px,
            rgba(255, 229, 208, 0.1) 4px
        ),
        radial-gradient(circle at 30% 40%, rgba(255, 236, 199, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 70% 60%, rgba(255, 229, 208, 0.15) 0%, transparent 50%),
        linear-gradient(135deg, #FFECC7 0%, #FFE5D0 50%, #FFDDC1 100%);
    
    border-radius: 20px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.6),
        0 0 0 1px rgba(184, 149, 106, 0.1);
    
    /* Borde decorativo del mantel */
    border: 10px solid transparent;
    border-image: repeating-linear-gradient(
        45deg,
        #D4C5A9,
        #D4C5A9 10px,
        #E5D4B8 10px,
        #E5D4B8 20px
    ) 10;
}

/* Patrón de encaje decorativo en las esquinas */
.book-container::before,
.book-container::after {
    content: '❦';
    position: absolute;
    font-size: 40px;
    color: rgba(184, 149, 106, 0.2);
    text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}

.book-container::before {
    top: 20px;
    left: 20px;
}

.book-container::after {
    bottom: 20px;
    right: 20px;
}

.book {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.book-base {
    position: absolute;
    width: 50%;
    height: 100%;
    background: linear-gradient(135deg, #FFF9F0 0%, #FFF5E8 50%, #FFF9F0 100%);
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
    z-index: 1;
}

.book-base.left {
    left: 0;
    border-right: 1px solid #F5E6D3;
    background: 
        radial-gradient(circle at 10% 20%, rgba(184, 149, 106, 0.03) 0%, transparent 30%),
        linear-gradient(135deg, #FFF9F0 0%, #FFF5E8 50%, #FFF9F0 100%);
}

.book-base.right {
    right: 0;
    border-left: 1px solid #F5E6D3;
    background: 
        radial-gradient(circle at 90% 20%, rgba(184, 149, 106, 0.03) 0%, transparent 30%),
        linear-gradient(135deg, #FFF9F0 0%, #FFF5E8 50%, #FFF9F0 100%);
}

.spine {
    position: absolute;
    width: 50px;
    height: 100%;
    background: 
        linear-gradient(to right, 
            #8B7355 0%, 
            #A6826E 10%,
            #B89578 20%,
            #C5A582 40%,
            #B89578 60%,
            #A6826E 80%,
            #8B7355 100%);
    left: 50%;
    transform: translateX(-50%) translateZ(-25px);
    box-shadow: 
        inset 0 0 30px rgba(0,0,0,0.4),
        inset 0 10px 10px rgba(255, 236, 199, 0.2);
    z-index: 0;
    border-top: 3px solid #D4C5A9;
    border-bottom: 3px solid #D4C5A9;
}

.spine::before,
.spine::after {
    content: '';
    position: absolute;
    width: 80%;
    height: 2px;
    background: linear-gradient(to right, transparent, #E5D4B8, transparent);
    left: 10%;
}

.spine::before { top: 25%; }
.spine::after { bottom: 25%; }

.page {
    position: absolute;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform 1.2s cubic-bezier(0.65, 0.05, 0.36, 1);
    cursor: pointer;
    left: 50%;
}

.page:hover {
    filter: brightness(1.03);
}

.page-front {
    position: absolute;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 90% 20%, rgba(184, 149, 106, 0.03) 0%, transparent 30%),
        linear-gradient(to left, #FFFEF8 0%, #FFFCF5 5%, #FFFEF8 10%);
    backface-visibility: hidden;
    border: 1px solid #F5E6D3;
    border-left: none;
    box-shadow: 
        inset -5px 0 10px rgba(0,0,0,0.03),
        5px 5px 15px rgba(0,0,0,0.15);
    padding: 15px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.page-back {
    position: absolute;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 10% 20%, rgba(184, 149, 106, 0.03) 0%, transparent 30%),
        linear-gradient(to right, #FFFEF8 0%, #FFFCF5 5%, #FFFEF8 10%);
    backface-visibility: hidden;
    transform: rotateY(180deg);
    border: 1px solid #F5E6D3;
    border-right: none;
    box-shadow: 
        inset 5px 0 10px rgba(0,0,0,0.03),
        -5px 5px 15px rgba(0,0,0,0.15);
    padding: 15px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.gold-divider {
    width: 100%;
    height: 25px;
    background-image: url('https://static.vecteezy.com/system/resources/previews/034/487/734/non_2x/gold-frame-page-divider-free-png.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin-bottom: 8px;
    opacity: 0.5;
    flex-shrink: 0;
    filter: sepia(0.3) hue-rotate(-10deg) saturate(0.8);
}

.photos-container {
    display: flex;
    gap: 8px;
    flex: 1;
    min-height: 0;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    align-content: center;
}

/* Layouts */
.layout-single {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.layout-double {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.layout-triple {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.layout-quad {
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 10px;
    padding: 5px;
}

/* Marco estilo Polaroid */
.polaroid {
    background: #ffffff;
    padding: 10px 10px 35px 10px;
    box-shadow: 
        0 4px 8px rgba(0,0,0,0.08),
        0 6px 20px rgba(0,0,0,0.1);
    position: relative;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.polaroid:hover {
    transform: translateY(-3px) rotate(0deg) !important;
    box-shadow: 
        0 6px 12px rgba(0,0,0,0.12),
        0 10px 30px rgba(184, 149, 106, 0.15);
}

/* Rotaciones aleatorias sutiles */
.polaroid:nth-child(odd) {
    transform: rotate(-1deg);
}

.polaroid:nth-child(even) {
    transform: rotate(1deg);
}

.polaroid:nth-child(3n) {
    transform: rotate(-0.5deg);
}

.polaroid-image {
    width: 100%;
    aspect-ratio: 1/1;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid #e8e8e8;
}

.polaroid-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.polaroid-caption {
    position: absolute;
    bottom: 5px;
    left: 10px;
    right: 10px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tamaños de Polaroid según layout */
.layout-single .polaroid {
    max-width: 280px;
    max-height: 90%;
}

.layout-double .polaroid {
    flex: 1;
    max-width: 45%;
    max-height: 85%;
}

.layout-triple .polaroid {
    width: calc(50% - 10px);
    max-height: 40%;
}

.layout-triple .polaroid:first-child {
    width: 100%;
    max-height: 48%;
}

.layout-quad .polaroid {
    width: 100%;
    height: 100%;
    padding: 8px 8px 25px 8px;
}

.layout-quad .polaroid-caption {
    font-size: 8px;
    bottom: 3px;
}

.page.flipped {
    transform: rotateY(-180deg);
    z-index: auto;
}

.cover {
    position: absolute;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    transform-origin: left center;
    transition: transform 1.2s cubic-bezier(0.65, 0.05, 0.36, 1);
    cursor: pointer;
    left: 50%;
    z-index: 100;
}

.cover-front {
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, #B89578 0%, #A6826E 50%, #8B7355 100%);
    backface-visibility: hidden;
    border: 5px solid #D4C5A9;
    box-shadow: 
        0 20px 50px rgba(0,0,0,0.3),
        inset 0 0 50px rgba(212, 197, 169, 0.15);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #FFF9F0;
    padding: 40px 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.cover-front::before {
    content: '';
    position: absolute;
    width: 85%;
    height: 85%;
    border: 3px solid #D4C5A9;
    box-shadow: 
        inset 0 0 30px rgba(212, 197, 169, 0.2),
        0 0 20px rgba(212, 197, 169, 0.15);
    pointer-events: none;
}

.cover-front::after {
    content: '✦';
    position: absolute;
    font-size: 50px;
    color: #E5D4B8;
    top: 20px;
    opacity: 0.4;
    text-shadow: 0 0 20px rgba(229, 212, 184, 0.5);
}

.cover-ornament-bottom {
    position: absolute;
    bottom: 20px;
    font-size: 30px;
    color: #E5D4B8;
    opacity: 0.4;
    text-shadow: 0 0 20px rgba(229, 212, 184, 0.5);
}

.cover-front h1 {
    font-size: 36px;
    margin-bottom: 15px;
    text-shadow: 
        3px 3px 6px rgba(0,0,0,0.4),
        0 0 20px rgba(229, 212, 184, 0.3);
    letter-spacing: 3px;
    z-index: 1;
    color: #FFF5E8;
    font-variant: small-caps;
}

.cover-front p {
    font-size: 14px;
    font-style: italic;
    color: #FFF9F0;
    margin-top: 10px;
    z-index: 1;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.cover-back {
    position: absolute;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 10% 20%, rgba(184, 149, 106, 0.03) 0%, transparent 30%),
        linear-gradient(to right, #FFFEF8 0%, #FFFCF5 5%, #FFFEF8 10%);
    backface-visibility: hidden;
    transform: rotateY(180deg);
    border: 1px solid #F5E6D3;
    border-right: none;
    box-shadow: inset 5px 0 10px rgba(0,0,0,0.03);
}

.cover.opened {
    transform: rotateY(-180deg);
    z-index: 1;
}

.page-number {
    position: absolute;
    bottom: 10px;
    font-size: 11px;
    color: #A6826E;
    font-family: 'Georgia', serif;
    font-style: italic;
    text-shadow: 1px 1px 2px rgba(255,255,255,0.8);
    z-index: 10;
}

.page-front .page-number {
    right: 15px;
}

.page-back .page-number {
    left: 15px;
}

/* CORREGIDO: Back cover oculta completamente */
.back-cover {
    position: absolute;
    width: 50%;
    height: 100%;
    background: radial-gradient(circle at 50% 50%, #B89578 0%, #A6826E 50%, #8B7355 100%);
    border: 5px solid #D4C5A9;
    box-shadow: 
        0 20px 50px rgba(0,0,0,0.25),
        inset 0 0 50px rgba(212, 197, 169, 0.15);
    left: 0;
    z-index: -1;
    transform: translateZ(-30px);
    opacity: 0;
    visibility: hidden;
}

.page::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(to left, rgba(0,0,0,0) 0%, rgba(0,0,0,0.05) 100%);
    opacity: 0;
    transition: opacity 1.2s;
    pointer-events: none;
    z-index: 10;
}

.page.flipped::before {
    opacity: 1;
}

.image-loading {
    color: #B8956A;
    font-size: 12px;
    font-style: italic;
}

@media (max-width: 768px) {
    body {
        padding: 0;
        perspective: 1500px;
    }

    body::before,
    body::after {
        width: 200px;
        height: 200px;
    }

    nav {
        padding: 1rem;
    }

    nav ul {
        gap: 1rem;
    }

    nav a {
        font-size: 1rem;
        padding: 0.4rem 0.8rem;
    }

    .book-container {
        max-width: 100%;
        height: 500px;
        margin: 20px auto;
        padding: 30px;
        border: 6px solid transparent;
    }

    .book-container::before,
    .book-container::after {
        font-size: 30px;
    }

    .spine {
        width: 30px;
    }

    .cover-front h1 {
        font-size: 24px;
    }

    .cover-front p {
        font-size: 12px;
    }

    .page-front, .page-back {
        padding: 12px;
    }

    .gold-divider {
        height: 20px;
    }

    .layout-single .polaroid {
        max-width: 200px;
    }

    .polaroid {
        padding: 8px 8px 25px 8px;
    }

    .polaroid-caption {
        font-size: 8px;
    }
}

@media (max-width: 480px) {
    body::before,
    body::after {
        display: none;
    }

    nav {
        padding: 0.8rem;
    }

    nav ul {
        gap: 0.5rem;
        flex-direction: column;
        align-items: center;
    }

    nav a {
        font-size: 0.95rem;
    }

    .book-container {
        height: 400px;
        margin: 15px auto;
        padding: 20px;
        border: 5px solid transparent;
    }

    .book-container::before,
    .book-container::after {
        font-size: 25px;
    }

    .cover-front h1 {
        font-size: 20px;
    }

    .cover-front::after {
        font-size: 35px;
    }

    .cover-ornament-bottom {
        font-size: 20px;
    }

    .page-front, .page-back {
        padding: 10px;
    }

    .gold-divider {
        height: 18px;
    }

    .layout-triple .polaroid,
    .layout-quad .polaroid {
        width: 100%;
    }

    .layout-triple {
        flex-direction: column;
    }

    .layout-triple .polaroid:first-child {
        max-height: 35%;
    }

    .layout-triple .polaroid {
        width: 100%;
        max-height: 30%;
    }
}