/**
 * M46+: 3D Book Scene — Premium Spellbook Opening Animation
 * CSS 3D transforms for realistic book opening and page turning
 */

#book-scene-wrapper {
    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, #2d1b35 0%, #0d0514 100%);
    perspective: 1000px;
}

#book-scene-wrapper.hidden {
    display: none;
}

#book {
    width: 550px;
    height: 700px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateY(-15deg) rotateX(0deg);
    filter: drop-shadow(-30px 20px 60px rgba(0, 0, 0, 0.9));
}

.book-element {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 0;
    transform-origin: left center;
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

/* Front cover */
.book-cover {
    background: linear-gradient(135deg, #3d1f4e 0%, #4a235a 40%, #3a1a48 100%);
    border: 2px solid #d4af37;
    z-index: 3;
    transform: rotateY(0deg);
    backface-visibility: visible;
    box-shadow: inset -8px 0 20px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    cursor: pointer;
    border-radius: 0;
}

.book-cover .cover-title {
    font-family: 'Cinzel', 'Georgia', serif;
    color: #d4af37;
    text-align: center;
    padding: 30px;
    font-size: 42px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 1px;
    text-shadow: 0 0 30px rgba(212, 175, 55, 0.5);
    margin: 0;
    transition: opacity 0.25s ease;
}

.book-cover .cover-ornament {
    font-size: 100px;
    filter: drop-shadow(0 0 20px rgba(212, 175, 55, 0.4));
    animation: subtle-float 3s ease-in-out infinite;
    transition: opacity 0.25s ease;
}

.book-cover.is-open .cover-title,
.book-cover.is-open .cover-ornament {
    opacity: 0;
}

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

/* Book pages (center fold) */
.book-pages {
    background: linear-gradient(90deg, #e8d5b7 0%, #f5e6d3 50%, #e8d5b7 100%);
    transform: translateX(4px) rotateY(0deg);
    z-index: 1;
    border-radius: 0;
    box-shadow: inset -3px 0 10px rgba(0, 0, 0, 0.1);
}

/* Back cover */
.book-back {
    background: linear-gradient(135deg, #3a1a48 0%, #4a235a 100%);
    border: 2px solid #d4af37;
    transform: translateZ(-8px);
    z-index: 0;
    border-radius: 0;
}

/* Content page that appears inside open book */
.book-open-page {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--vtt-surface-card, #201530);
    border-radius: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 30px;
    opacity: 0;
    z-index: 5;
}

/* Page turn transition overlay */
.page-turn-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--vtt-surface-card, #201530);
    transform-origin: left center;
    transform: perspective(2000px) rotateY(0deg);
    backface-visibility: hidden;
    pointer-events: none;
}

/* Book rasp/rustle animation */
@keyframes book-rustle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.book-pages.rustling {
    animation: book-rustle 0.15s ease-in-out 3;
}

/* Login form container inside open book */
#login-content {
    position: absolute;
    inset: 0;
    z-index: 9001;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: stretch;
    opacity: 0;
    pointer-events: none;
    background: transparent;
    transition: opacity 0.6s ease-out;
}

#login-content.visible {
    opacity: 1;
    pointer-events: auto;
}

#login-content .login-book-wrapper {
    grid-column: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 34px 16px 34px 34px;
}

#login-content .login-book-content {
    width: 100%;
    max-width: 320px;
    max-height: none;
    overflow: visible;
    padding: 32px 24px 28px;
    gap: 16px;
    background: linear-gradient(180deg, var(--vtt-paper-panel, #fff8ef) 0%, var(--vtt-paper-card, #ead6b2) 100%);
    border: 1px solid var(--vtt-field-border, rgba(75, 35, 90, 0.18));
    box-shadow:
        inset -5px 0 15px rgba(42, 26, 18, 0.08),
        0 16px 32px rgba(42, 26, 18, 0.08);
}

#login-content .login-book-sidecar {
    grid-column: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 34px 34px 34px 16px;
    color: var(--vtt-gold, #caa33b);
    text-align: center;
}

#login-content .login-book-sidecar-inner {
    max-width: 240px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 22px 18px;
    border-radius: 6px;
    background: var(--vtt-sidecar-bg, rgba(255, 248, 238, 0.82));
    border: 1px solid var(--vtt-sidecar-border, rgba(202, 163, 59, 0.18));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

#login-content .book-sidecar-copy {
    color: var(--vtt-sidecar-text, #4a235a);
    font-size: 14px;
    line-height: 1.55;
    max-width: 180px;
}

/* Page number styling — appears on bottom of pages */
.page-number {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    font-family: 'Cinzel', 'Georgia', serif;
    font-size: 0.9rem;
    color: rgba(0, 0, 0, 0.3);
    pointer-events: none;
    user-select: none;
}

/* Bookmark element — visible on right edge of book */
.bookmark {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 8999;
    width: 12px;
    height: 80px;
    background: linear-gradient(90deg, #d4af37 0%, #f5d88d 50%, #d4af37 100%);
    border-radius: 2px 0 0 2px;
    box-shadow: -2px 2px 8px rgba(0, 0, 0, 0.4);
    transition: top 0.3s ease;
}

.bookmark.dashboard { top: 20%; }
.bookmark.campaigns { top: 50%; }
.bookmark.characters { top: 80%; }

/* Enhanced spine/binding shadow */
.book-cover {
    box-shadow: inset -12px 0 25px rgba(0, 0, 0, 0.6),
                inset -1px 0 2px rgba(212, 175, 55, 0.2);
}

.book-pages {
    box-shadow: inset -8px 0 15px rgba(0, 0, 0, 0.3),
                inset -1px 0 1px rgba(0, 0, 0, 0.15);
}

.book-back {
    box-shadow: inset 8px 0 20px rgba(0, 0, 0, 0.5);
}

/* Page edge layering effect — stacked appearance */
.book-element::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 0;
    right: 0;
    height: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

/* Responsive — smaller screens */
@media (max-width: 768px) {
    #book {
        width: 400px;
        height: 550px;
    }

    .book-cover .cover-title {
        font-size: 32px;
        padding: 25px;
    }

    .book-cover .cover-ornament {
        font-size: 80px;
    }

    .book-open-page {
        padding: 30px 20px;
    }

    #login-content {
        grid-template-columns: 1fr;
    }

    #login-content .login-book-wrapper {
        grid-column: 1;
        justify-content: center;
        padding: 24px 20px;
    }

    #login-content .login-book-content {
        max-width: 100%;
        max-height: calc(100% - 48px);
        overflow-y: auto;
    }

    #login-content .login-book-sidecar {
        display: none;
    }
}

@media (max-width: 480px) {
    #book {
        width: 300px;
        height: 400px;
    }

    .book-cover .cover-title {
        font-size: 26px;
        padding: 15px;
    }

    .book-cover .cover-ornament {
        font-size: 64px;
    }

    .book-open-page {
        padding: 20px 15px;
    }

    #login-content {
        grid-template-columns: 1fr;
    }

    #login-content .login-book-wrapper {
        grid-column: 1;
        padding: 18px 14px;
    }

    #login-content .login-book-content {
        max-height: calc(100% - 36px);
    }

    #login-content .login-book-sidecar {
        display: none;
    }
}

/* Accessibility: Focus indicators */
.book-cover:focus-visible {
    outline: 3px solid #d4af37;
    outline-offset: 4px;
}

.book-cover:focus {
    outline: 3px solid #d4af37;
    outline-offset: 4px;
}

/* Keyboard focus indication for book cover */
.book-cover[aria-pressed="false"]:focus::after {
    content: '';
    position: absolute;
    inset: -8px;
    border: 2px dashed #d4af37;
    border-radius: 2px;
    pointer-events: none;
}

/* Accessibility: respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    #book,
    .book-cover,
    .book-pages,
    .cover-ornament,
    .page-turn-overlay,
    #login-content {
        animation: none !important;
        transition: none !important;
    }
}

/* Accessibility: High contrast mode support */
@media (prefers-contrast: more) {
    .book-cover {
        border-width: 3px;
        box-shadow: inset -12px 0 25px rgba(0, 0, 0, 0.8),
                    inset -1px 0 2px rgba(212, 175, 55, 0.4) !important;
    }

    .book-cover .cover-title {
        text-shadow: 0 0 20px rgba(212, 175, 55, 0.6);
    }
}

/* Accessibility: Dark mode for light-on-dark contrast */
@media (prefers-color-scheme: dark) {
    .book-cover .cover-title {
        color: #f5e6d3;  /* Lighter gold for dark mode */
    }
}
