/* ============================================
   Diario de Gratitud - LunaLu
   Diseño profesional con anillos de cuaderno
   ============================================ */

:root {
    --paper: #faf7f2;
    --paper-shadow: #e8e2d8;
    --ink: #2c2419;
    --ink-muted: #5a5045;
    --accent: #8b7355;
    --accent-light: #c4b49a;
    --ring-metal: linear-gradient(135deg, #9ca3af 0%, #6b7280 30%, #4b5563 50%, #6b7280 70%, #9ca3af 100%);
    --ring-silver: linear-gradient(135deg, #e5e7eb 0%, #9ca3af 25%, #6b7280 50%, #9ca3af 75%, #d1d5db 100%);
    --ring-gold: linear-gradient(135deg, #fef3c7 0%, #f59e0b 30%, #b45309 50%, #f59e0b 70%, #fde68a 100%);
    --ring-shadow: rgba(0, 0, 0, 0.25);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-family: 'Cormorant Garamond', 'Georgia', 'Times New Roman', serif;
    background: 
        radial-gradient(ellipse at 50% 100%, rgba(255, 255, 255, 0.9) 0%, transparent 60%),
        radial-gradient(ellipse at 20% 80%, rgba(250, 248, 245, 0.8) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(245, 242, 238, 0.6) 0%, transparent 50%),
        linear-gradient(180deg, #fafaf8 0%, #f5f3ef 50%, #f0ede8 100%);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start; /* evita que el libro se recorte al centrar verticalmente */
}

.notebook-wrapper {
    width: 100%;
    max-width: 960px;
    padding: 1.5rem;
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}
/* Página standalone: visor más grande en pantallas anchas */
@media (min-width: 992px) {
    body:not(.embed-mode) .notebook-wrapper {
        max-width: 1280px;
        padding: 1rem 2rem;
    }
}
@media (min-width: 1200px) {
    body:not(.embed-mode) .notebook-wrapper {
        max-width: 90vw;
        padding: 1rem;
    }
}

/* Header */
.notebook-header {
    text-align: center;
    margin-bottom: 1rem;
}

.notebook-brand {
    margin: 0;
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--ink);
}

.notebook-subtitle {
    margin: 0.25rem 0 0;
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    color: var(--accent);
    font-style: italic;
    letter-spacing: 0.15em;
}

/* Escena del cuaderno con anillos */
.notebook-scene {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    flex: 1 1 auto;
    padding: 1rem 0;
}

/* Anillos del cuaderno - vista cenital (spine del cuaderno) */
.notebook-rings {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    transform: translateX(-50%);
    width: 24px;
    z-index: 10;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.rings-spine {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    transform: translateX(-50%);
    width: 8px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(139, 115, 85, 0.2) 30%, 
        rgba(139, 115, 85, 0.35) 50%, 
        rgba(139, 115, 85, 0.2) 70%, 
        transparent 100%);
    border-radius: 2px;
}

.rings-row {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.ring {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ring-metal);
    box-shadow: 
        inset 1px 1px 2px rgba(255, 255, 255, 0.5),
        inset -1px -1px 1px rgba(0, 0, 0, 0.2),
        0 1px 3px var(--ring-shadow);
    border: 1px solid rgba(107, 114, 128, 0.4);
}

.notebook-rings[data-ring-color="silver"] .ring {
    background: var(--ring-silver);
    box-shadow: 
        inset 1px 1px 2px rgba(255, 255, 255, 0.6),
        inset -1px -1px 1px rgba(0, 0, 0, 0.15),
        0 1px 3px rgba(0, 0, 0, 0.2);
    border-color: rgba(156, 163, 175, 0.5);
}

.notebook-rings[data-ring-color="gold"] .ring {
    background: var(--ring-gold);
    border-color: rgba(180, 83, 9, 0.4);
}

/* Banda elástica - visible cuando el libro está cerrado */
.elastic-band {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 70%;
    max-height: 320px;
    background: linear-gradient(90deg,
        transparent 0%,
        rgba(88, 28, 135, 0.15) 20%,
        rgba(126, 34, 206, 0.85) 40%,
        rgba(126, 34, 206, 0.9) 60%,
        rgba(126, 34, 206, 0.85) 80%,
        transparent 100%);
    border-radius: 2px;
    z-index: 9;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    box-shadow: inset 1px 0 2px rgba(0, 0, 0, 0.2);
}

.elastic-band[data-visible="true"] {
    opacity: 1;
}

/* Contenedor del libro */
.notebook-book-container {
    position: relative;
    width: 100%;
    min-height: 280px;
    max-height: min(calc(100vh - 180px), 680px); /* evita recorte: deja espacio para header + controles */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
}

/* Tapas duras - efecto de grosor cuando el libro está cerrado */
.notebook-scene[data-cover-type="hard"][data-spread="closed"] #notebook-book {
    position: relative;
}

.notebook-scene[data-cover-type="hard"][data-spread="closed"] #notebook-book::before,
.notebook-scene[data-cover-type="hard"][data-spread="closed"] #notebook-book::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 10px;
    z-index: 5;
    pointer-events: none;
}

.notebook-scene[data-cover-type="hard"][data-spread="closed"] #notebook-book::before {
    left: 0;
    background: linear-gradient(to right,
        rgba(50, 42, 35, 0.5) 0%,
        rgba(70, 60, 50, 0.25) 50%,
        transparent 100%);
    box-shadow: inset 3px 0 6px rgba(0, 0, 0, 0.2);
}

.notebook-scene[data-cover-type="hard"][data-spread="closed"] #notebook-book::after {
    right: 0;
    background: linear-gradient(to left,
        rgba(50, 42, 35, 0.5) 0%,
        rgba(70, 60, 50, 0.25) 50%,
        transparent 100%);
    box-shadow: inset -3px 0 6px rgba(0, 0, 0, 0.2);
}

.notebook-scene,
.notebook-book-container,
#notebook-book {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.notebook-scene img,
#notebook-book canvas {
    pointer-events: none;
    -webkit-user-drag: none;
    user-drag: none;
}

/* Marca de agua muy sutil - no debe dificultar la lectura */
.watermark-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 80px,
        rgba(139, 115, 85, 0.012) 80px,
        rgba(139, 115, 85, 0.012) 81px
    );
    background-size: 100% 100%;
}

.notebook-book {
    width: 100%;
    min-height: 260px;
    max-height: min(calc(100vh - 200px), 650px); /* cabe en viewport sin solapar controles */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    filter: drop-shadow(0 8px 24px rgba(44, 36, 25, 0.12));
    image-rendering: -webkit-optimize-contrast;
    transition: filter 0.4s ease, transform 0.4s ease;
}

/* Libro cerrado - efecto 3D y sombra más pronunciada */
.notebook-scene[data-spread="closed"] .notebook-book {
    filter: 
        drop-shadow(0 2px 4px rgba(44, 36, 25, 0.08))
        drop-shadow(0 12px 32px rgba(44, 36, 25, 0.2))
        drop-shadow(0 24px 48px rgba(44, 36, 25, 0.12));
}

/* Libro abierto - sombra más suave como páginas apoyadas */
.notebook-scene[data-spread="open"] .notebook-book {
    filter: 
        drop-shadow(0 4px 12px rgba(44, 36, 25, 0.1))
        drop-shadow(0 16px 40px rgba(44, 36, 25, 0.15));
}

/* Etiquetas Portada / Contraportada - solo visibles cuando cerrado */
.cover-labels {
    position: absolute;
    inset: 0;
    display: flex;
    pointer-events: none;
    z-index: 8;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.notebook-scene[data-spread="closed"] .cover-labels {
    opacity: 1;
}

.cover-label {
    flex: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 1rem;
    font-size: clamp(0.75rem, 2vw, 0.9rem);
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(90, 80, 69, 0.7);
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
}

.cover-label--portada {
    padding-right: 15%;
}

.cover-label--contraportada {
    padding-left: 15%;
}

/* Indicación para abrir el libro */
.cover-hint {
    position: absolute;
    bottom: -2rem;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    font-size: clamp(0.75rem, 1.8vw, 0.85rem);
    color: var(--ink-muted);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.6s ease 0.3s;
}

.notebook-scene[data-spread="closed"] .cover-hint {
    opacity: 0.8;
}

/* Línea sutil en el lomo cuando cerrado - refuerza la idea de libro cerrado */
.notebook-scene[data-spread="closed"] .rings-spine {
    width: 12px;
    background: linear-gradient(90deg, 
        transparent 0%, 
        rgba(60, 50, 40, 0.15) 20%, 
        rgba(60, 50, 40, 0.35) 40%,
        rgba(70, 60, 50, 0.45) 50%,
        rgba(60, 50, 40, 0.35) 60%,
        rgba(60, 50, 40, 0.15) 80%, 
        transparent 100%);
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.06);
}

/* Controles de navegación */
.notebook-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding: 1rem;
    margin-top: 0.5rem;
    margin-bottom: 1rem; /* separación clara del libro para que no se solapen */
    flex-shrink: 0;
}

.btn-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1.25rem;
    font-size: clamp(0.9rem, 2vw, 1rem);
    font-family: inherit;
    font-weight: 500;
    border: 1px solid var(--accent-light);
    border-radius: 6px;
    background: var(--paper);
    color: var(--ink);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-nav:hover:not(:disabled) {
    background: var(--accent-light);
    color: var(--ink);
    border-color: var(--accent);
}

.btn-nav:active:not(:disabled) {
    transform: scale(0.98);
}

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

.btn-nav svg {
    flex-shrink: 0;
}

.page-indicator-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 140px;
}

.page-indicator {
    font-size: clamp(0.85rem, 2vw, 0.95rem);
    color: var(--ink-muted);
}

.progress-bar {
    width: 100%;
    max-width: 120px;
    height: 4px;
    background: rgba(139, 115, 85, 0.2);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-light), var(--accent));
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(250, 247, 242, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 1000;
    transition: opacity 0.4s ease, visibility 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid transparent;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    font-size: 1rem;
    color: var(--ink-muted);
}

/* ============================================
   Responsive - Móviles
   ============================================ */

@media (max-width: 768px) {
    .notebook-wrapper {
        padding: 1rem;
    }

    .notebook-scene {
        min-height: 0;
    }

    .notebook-book-container {
        max-height: min(calc(100vh - 160px), 65vh);
    }

    .notebook-book {
        min-height: 260px;
        max-height: min(calc(100vh - 180px), 62vh);
    }

    .rings-row {
        gap: 4px;
    }

    .ring {
        width: 8px;
        height: 8px;
    }

    .elastic-band {
        width: 10px;
    }

    .notebook-controls {
        gap: 1rem;
    }

    .btn-nav {
        padding: 0.55rem 1rem;
    }
}

@media (max-width: 480px) {
    .notebook-book-container,
    .notebook-book {
        min-height: 260px;
        max-height: 55vh;
    }

    .ring {
        width: 7px;
        height: 7px;
    }

    .elastic-band {
        width: 8px;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .notebook-book {
        max-height: 70vh;
    }
}

/* ============================================
   Visor plano (embed): doble página a ancho completo, sin márgenes
   ============================================ */
.flat-spread-viewer {
    display: none;
}
/* En embed: visor a ancho completo, sin contenedor que lo limite */
.embed-mode .notebook-wrapper.flat-viewer-active .flat-spread-viewer,
.embed-mode .notebook-wrapper.flat-viewer-active #flatSpreadViewer[hidden] {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0 !important;
    flex: 1 1 0 !important;
    min-height: 92% !important; /* deja espacio para controles + padding y que no se corten */
    width: 100% !important;
    max-width: none !important; /* sin límite de ancho */
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
    order: 1;
    position: relative;
    z-index: 0;
    overflow: hidden !important;
}
/* Móvil embed: no desbordar, pero sin max-width que restrinja dentro del iframe */
@media (max-width: 767px) {
    .embed-mode .notebook-wrapper.flat-viewer-active .flat-spread-viewer,
    .embed-mode .notebook-wrapper.flat-viewer-active #flatSpreadViewer[hidden] {
        max-width: none !important;
        min-width: 0 !important;
    }
}
.embed-mode .notebook-wrapper.flat-viewer-active .notebook-scene {
    display: none !important;
}
/* Cada página: imagen completa sin recortar; fondo blanco (sin margen plomo) */
.embed-mode .flat-spread-viewer .flat-page {
    min-width: 0 !important;
    min-height: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background-size: contain !important;
    background-repeat: no-repeat !important;
    background-color: #fff !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}
/* Página izquierda: pegada al lomo, centrada; sin sombra gris */
.embed-mode .flat-spread-viewer .flat-page--left {
    background-position: right center !important;
    box-shadow: none !important;
}
/* Página derecha: pegada al lomo, centrada; sin sombra gris */
.embed-mode .flat-spread-viewer .flat-page--right {
    background-position: left center !important;
    box-shadow: none !important;
}
.flat-page {
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    background-color: #fff;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}
.flat-page--left {
    background-position: center right;
}
.flat-page--right {
    background-position: center left;
}

/* ============================================
   Modo embed: iframe en Tienda Nube
   ============================================ */
.embed-mode .notebook-header {
    display: none !important;
}
.embed-mode .cover-hint {
    display: none !important;
}
.embed-mode .cover-labels {
    display: none !important;
}
.embed-mode .elastic-band {
    display: none !important;
}
/* En embed ningún contenedor limita el ancho del visor (html tiene la clase embed-mode) */
html.embed-mode,
.embed-mode html,
.embed-mode body {
    height: 100% !important;
    min-height: 360px !important;
    width: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
    overflow: hidden !important;
    overflow-x: hidden !important;
    gap: 0 !important;
}
.embed-mode body {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
}
.embed-mode .notebook-wrapper {
    padding: 0 !important;
    padding-bottom: 12px !important; /* espacio abajo para que los botones no choquen con el contenedor */
    margin: 0 !important;
    gap: 0 !important;
    max-width: none !important;
    width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
    overflow-x: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0 !important;
    min-height: 100% !important;
    height: 100% !important;
    justify-content: flex-start !important;
}
.embed-mode .notebook-scene {
    flex: 1 1 0;
    min-height: 0;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    width: 100%;
    align-self: stretch;
    align-items: stretch;
    display: flex;
    overflow: hidden;
}
.embed-mode .notebook-book-container {
    width: 100%;
    flex: 1 1 0;
    min-height: 0;
    max-height: none;
    display: flex;
    justify-content: center;
    align-items: stretch;
    padding: 0 !important;
    margin: 0 !important;
    gap: 0 !important;
    filter: none !important;
    overflow: hidden;
}
.embed-mode .notebook-book {
    width: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
    align-self: stretch;
    filter: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Embed: controles visibles completos; padding abajo para no chocar con el contenedor de TN */
.embed-mode .notebook-controls {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    order: 2;
    flex-wrap: wrap !important;
    justify-content: center !important;
    margin: 0 !important;
    padding: 0.4rem 0.75rem 0.6rem !important; /* más abajo para que no se corten en el iframe */
    gap: 0.5rem !important;
    position: relative;
    z-index: 1;
    min-height: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    overflow: visible !important;
}
@media (max-width: 768px) {
    .embed-mode .notebook-controls {
        padding: 0.35rem 0.6rem !important;
        gap: 0.4rem !important;
    }
}
/* Botones e indicador más compactos en embed para que no se corten */
.embed-mode .notebook-controls .btn-nav {
    padding: 0.4rem 0.75rem !important;
    font-size: 0.875rem !important;
}
.embed-mode .notebook-controls .btn-nav svg {
    width: 18px !important;
    height: 18px !important;
}
.embed-mode .notebook-controls .page-indicator {
    font-size: 0.8125rem !important;
}
/* En embed el wrapper del indicador puede encoger para no cortarse */
.embed-mode .page-indicator-wrapper {
    min-width: 0 !important;
    flex: 0 1 auto !important;
}
.page-indicator-wrapper {
    min-width: 0;
    flex: 0 1 auto;
}
@media (max-width: 768px) {
    .notebook-controls {
        gap: 0.5rem;
        padding: 0.5rem 0.25rem;
    }
    .btn-nav {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }
    .btn-nav svg {
        width: 20px;
        height: 20px;
    }
    .page-indicator {
        font-size: 0.85rem;
        font-weight: 500;
    }
}
@media (max-width: 480px) {
    .notebook-controls {
        gap: 0.35rem;
        padding: 0.4rem 0.2rem;
    }
    .btn-nav {
        padding: 0.45rem 0.6rem;
        font-size: 0.8125rem;
    }
    .page-indicator {
        font-size: 0.8rem;
    }
}

/* Embed móvil: sin bordes; controles compactos; visor sin recorte */
@media (max-width: 768px) {
    .embed-mode .notebook-wrapper {
        padding: 0;
    }
    .embed-mode .notebook-scene {
        padding: 0;
    }
    .embed-mode .page-indicator {
        font-size: 0.875rem;
        font-weight: 500;
        color: var(--ink);
    }
    .embed-mode .flat-spread-viewer {
        width: 100% !important;
        max-width: 100% !important;
    }
}
