/* 3D Book Animation Engine - Questoria */
.book-wrap {
    perspective: 2500px;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 100px 20px;
    background-image: linear-gradient(rgba(0,0,0,0.6), rgba(0,0,0,0.6)), url('/assets/questoria/wizard_study.png');
    background-size: cover;
    background-position: center;
    overflow: hidden;
}

/* Ambient Flickering Torchlight */
.book-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 20% 30%, rgba(255, 180, 50, 0.1), transparent 60%);
    pointer-events: none;
    animation: flicker 4s infinite alternate;
    z-index: 5;
}

@keyframes flicker {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

.book {
    position: relative;
    width: 800px;
    height: 560px;
    transform-style: preserve-3d;
    box-shadow: 0 50px 100px rgba(0,0,0,0.8);
    transform: translateY(60px); /* Preventing header overlap */
    transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Page Stacking - Simulated Thickness */
.book::before {
    content: '';
    position: absolute;
    top: 5px; right: 5px; bottom: 5px; left: 5px;
    background: #f4e4bc; /* Parchment shade */
    background-image: url('/assets/questoria/parchment.png');
    background-size: cover;
    box-shadow: 
        1px 1px 0 #d4c49c,
        2px 2px 0 #c4b48c,
        3px 3px 0 #b4a47c,
        4px 4px 0 #a4946c;
    z-index: -1;
    border-radius: 5px;
    opacity: 0.8;
}

.book-page {
    position: absolute;
    top: 0;
    left: 400px; /* Pivots around center spine */
    width: 400px;
    height: 100%;
    transform-origin: left center;
    transform-style: preserve-3d;
    cursor: pointer;
    z-index: 1;
}

.book-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 400px;
    height: 100%;
    transform-origin: left center;
    transform-style: preserve-3d;
    z-index: 10;
}

.book-cover .front-cover {
    position: absolute;
    inset: 0;
    background-image: url('/assets/questoria/cover.png');
    background-size: cover;
    border-radius: 5px 15px 15px 5px;
    backface-visibility: hidden;
    box-shadow: 10px 0 50px rgba(0,0,0,0.5);
    z-index: 2;
}

.book-cover .back-cover {
    position: absolute;
    inset: 0;
    background-color: #2b114d;
    background-image: url('/assets/questoria/parchment.png');
    background-blend-mode: multiply;
    transform: rotateY(180deg);
    border-radius: 15px 5px 5px 15px;
    backface-visibility: hidden;
    box-shadow: -10px 0 50px rgba(0,0,0,0.5);
}

.spine {
    position: absolute;
    top: 0;
    left: 395px;
    width: 10px;
    height: 100%;
    background: #1a0b30;
    transform: rotateY(90deg);
    transform-origin: left;
    z-index: 5;
}

.book-page .front, .book-page .back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/assets/questoria/parchment.png');
    background-size: cover;
    padding: 40px;
    backface-visibility: hidden;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.2);
    border-radius: 0 10px 10px 0;
}

.book-page .back {
    transform: rotateY(180deg);
    border-radius: 10px 0 0 10px;
}

.book-page.flipped {
    transform: rotateY(-180deg);
}

/* Page Content Styling */
.page-header {
    font-family: var(--font-heading);
    color: #4A2C6A;
    border-bottom: 2px solid rgba(74, 44, 106, 0.2);
    margin-bottom: 20px;
    font-size: 1.6rem;
    background: linear-gradient(135deg, #4A2C6A, #B08D57); /* Gold foil hint */
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

/* Navigation Arrow Overlays */
.nav-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-gold);
    font-size: 2rem;
    cursor: pointer;
    z-index: 10001;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-arrow:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--accent-gold);
    box-shadow: 0 0 30px var(--accent-gold);
    transform: translateY(-50%) scale(1.1);
}

.nav-arrow.prev { left: 40px; }
.nav-arrow.next { right: 40px; }

.nav-arrow.disabled {
    opacity: 0.2;
    cursor: not-allowed;
    filter: grayscale(1);
}

.page-text {
    font-family: 'Merriweather', serif; /* Fairy tale style */
    color: #2D2D2D;
    line-height: 1.8;
    font-size: 1.15rem;
    position: relative;
    padding: 0 10px;
}

/* Advanced Drop Cap Typography */
.page-text::first-letter {
    font-family: var(--font-heading);
    float: left;
    font-size: 4rem;
    line-height: 3.5rem;
    padding-right: 12px;
    padding-top: 4px;
    color: #4A2C6A;
    text-shadow: 2px 2px 0 rgba(176, 141, 87, 0.3);
    font-weight: 900;
}

/* Marginal Runes */
.front::after, .back::after {
    content: 'ᚱᚢᚾᛖᛋ';
    position: absolute;
    bottom: 20px;
    right: 20px;
    font-size: 0.8rem;
    opacity: 0.1;
    letter-spacing: 5px;
    color: #4A2C6A;
}

.illustration {
    width: 100%;
    height: 200px;
    background: rgba(0,0,0,0.05);
    border-radius: 10px;
    margin-bottom: 20px;
    object-fit: cover;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Navigation Buttons */
.book-nav {
    position: fixed;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 30px;
    z-index: 1000;
}

.audio-trigger {
    position: absolute;
    top: 100px;
    right: 50px;
    background: var(--accent-gold);
    color: #000;
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: 700;
    cursor: pointer;
    animation: pulse 2s infinite;
}

/* Cinematic Prelude Styles */
#prelude-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 20000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    overflow: hidden;
}

.cinematic-scene {
    position: absolute;
    inset: 0;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 2s ease-in-out;
}

.cinematic-img {
    position: absolute;
    width: 110%;
    height: 110%;
    object-fit: cover;
    filter: brightness(0.6);
}

.ken-burns {
    animation: kenburns 32s infinite alternate linear;
}

/* Magic Gate Intro Styles */
#gate-container {
    position: fixed;
    inset: 0;
    z-index: 15000;
    background: #000;
    overflow: hidden;
}

#gate-full-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background-image: url('/assets/questoria/gate.png');
    background-size: cover;
    background-position: center;
    z-index: 1;
    transform: scale(1);
}

.gate-story-box {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px); /* Deep glassmorphism */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    text-align: center;
}

#gateStoryInner {
    border: 3px double var(--accent-gold);
    background: rgba(0,0,0,0.6);
    padding: 50px;
    border-radius: 30px;
    max-width: 900px;
    box-shadow: 0 0 50px rgba(0,0,0,0.8), inset 0 0 30px rgba(255, 215, 0, 0.1);
    position: relative;
    overflow: hidden;
}

#gateStoryInner::before {
    content: '';
    position: absolute;
    top: -2px; left: -2px; right: -2px; height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
}

.gate-lore-img {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border: 3px solid var(--accent-gold);
    border-radius: 50%; /* Modern circular avatar */
    box-shadow: 0 0 30px var(--accent-gold), 0 0 60px var(--accent-purple);
    margin-bottom: 30px;
    animation: floating 5.5s ease-in-out infinite;
    background: #000;
}

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

@keyframes kenburns {
    from { transform: scale(1) translate(0, 0); }
    to { transform: scale(1.2) translate(-2%, -2%); }
}

.lore-text {
    position: relative;
    z-index: 10;
    max-width: 800px;
    text-align: center;
    font-family: var(--font-heading);
    font-size: 2.2rem;
    line-height: 1.4;
    text-shadow: 0 0 20px rgba(0,0,0,0.8), 0 0 10px var(--accent-purple);
    padding: 0 40px;
}

.typewriter::after {
    content: '|';
    animation: blink 0.8s infinite;
    color: var(--accent-teal);
}

@keyframes blink {
    50% { opacity: 0; }
}

.skip-intro {
    position: absolute;
    bottom: 40px;
    right: 40px;
    z-index: 30000;
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.skip-intro:hover {
    background: rgba(255,255,255,0.2);
    transform: scale(1.05);
}
