/* --- VARIABLES --- */
:root {
    --paper: #f7f4e9;
    --paper-texture: #f0ebd8;
    --ink: #2b2b2b;
    --gold: #C5A059;
    --gold-glow: #ffd700;
    --wax-red: #ae3c3c;
    --wood: #5D4037; 
    --deep-blue: #2c3e50;
    --void-black: #111111;
    
    /* FONTS */
    --font-heading: 'Cinzel Decorative', serif; 
    --font-body: 'Cormorant Garamond', serif;
    --font-ui: 'Lato', sans-serif;
}

/* --- RESET & BASE --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { 
    scroll-behavior: smooth; 
    overflow-x: hidden !important; 
    width: 100%;
}

body {
    background-color: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 19px;
    line-height: 1.8;
    overflow-x: hidden !important; 
    width: 100%;
}

h1, h2, h3 { font-family: var(--font-heading); font-weight: 700; color: var(--wood); }
p { margin-bottom: 1.5rem; font-size: 1.3rem; }
img { max-width: 100%; display: block; }

/* --- ANIMATION CLASSES --- */
.fade-in-up { opacity: 0; transform: translateY(40px); transition: all 1s ease-out; }
.fade-in-left { opacity: 0; transform: translateX(-40px); transition: all 1s ease-out; }
.fade-in-right { opacity: 0; transform: translateX(40px); transition: all 1s ease-out; }
.visible { opacity: 1; transform: translate(0); }

/* --- SPLASH SCREEN (Whimsy Rings) --- */
#splash-screen {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    background-color: var(--void-black);
    transition: opacity 1.5s ease-out, visibility 1.5s;
}

/* The Ring Container */
.ring-container {
    position: relative;
    width: 200px;
    height: 200px;
    margin-bottom: 40px;
}

/* Shared Ring Styles */
.magic-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(197, 160, 89, 0.6);
    box-shadow: 0 0 20px rgba(197, 160, 89, 0.1);
    opacity: 0;
}

/* Ring 1 Animation */
.ring-one {
    border-top: 4px solid var(--gold);
    border-bottom: 1px solid transparent;
    animation: ringDance1 4s cubic-bezier(0.5, 0, 0.5, 1) forwards;
}

/* Ring 2 Animation */
.ring-two {
    border-left: 4px solid var(--gold);
    border-right: 1px solid transparent;
    transform: scale(0.8);
    animation: ringDance2 4s cubic-bezier(0.5, 0, 0.5, 1) forwards;
    animation-delay: 0.2s;
}

/* Whimsy Particles (Optional dust) */
#splash-screen::before {
    content: ''; position: absolute; inset: 0;
    background-image: radial-gradient(white 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.05;
    pointer-events: none;
}

/* The Quote */
.splash-quote {
    font-family: var(--font-heading);
    color: var(--gold);
    font-size: 1.5rem;
    letter-spacing: 2px;
    text-align: center;
    opacity: 0;
    transform: translateY(20px);
    animation: fadeUpQuote 2s ease-out forwards;
    animation-delay: 2.5s;
    text-shadow: 0 0 10px rgba(197, 160, 89, 0.5);
    padding: 0 20px;
}

/* Animations */
@keyframes ringDance1 {
    0% { opacity: 0; transform: rotate(0deg) scale(0.5); }
    40% { opacity: 1; transform: rotate(180deg) scale(1.1); }
    100% { opacity: 1; transform: rotate(360deg) scale(1); border-color: var(--gold); }
}

@keyframes ringDance2 {
    0% { opacity: 0; transform: rotate(0deg) scale(0.5); }
    40% { opacity: 1; transform: rotate(-180deg) scale(0.9); }
    100% { opacity: 1; transform: rotate(-360deg) scale(1); border-color: var(--gold); }
}

@keyframes fadeUpQuote {
    to { opacity: 1; transform: translateY(0); }
}

/* Loaded State */
body.loaded #splash-screen {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* --- NAV --- */
.glass-nav {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(15px);
    padding: 10px 30px; 
    border-radius: 50px;
    border: 1px solid rgba(197, 160, 89, 0.3);
    z-index: 100; box-shadow: 0 5px 25px rgba(0,0,0,0.05);
    width: auto; max-width: 95%;
    display: flex; align-items: center; gap: 30px;
}

.nav-home-logo img {
    height: 35px; width: auto; 
    transition: transform 0.3s;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.1));
}
.nav-home-logo:hover img { transform: scale(1.1); }

.nav-links { display: flex; gap: 25px; align-items: center; }

.nav-links a {
    text-decoration: none; 
    color: var(--ink); 
    font-family: var(--font-heading); 
    font-weight: 400; 
    font-size: 0.85rem; 
    letter-spacing: 1.5px; 
    text-transform: uppercase; 
    transition: 0.3s; 
    position: relative;
    padding-bottom: 2px;
}

.nav-links a::after {
    content: '';
    position: absolute;
    width: 0;
    height: 2px;
    bottom: 0;
    left: 50%;
    background-color: var(--gold);
    transition: all 0.3s ease-in-out;
    transform: translateX(-50%);
}
.nav-links a:hover { color: var(--gold); }
.nav-links a:hover::after { width: 100%; }


/* --- HERO --- */
#home {
    height: 100vh; position: relative;
    background: url('assets/readingspace.jpg') center/cover no-repeat;
    display: flex; align-items: center; justify-content: center;
}
.hero-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.4); }

.hero-content {
    position: relative; z-index: 2; text-align: center;
    padding: 0 20px;
}

.pre-title {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1.4rem;
    color: #e6d6b5; 
    margin-bottom: 10px;
    letter-spacing: 2px;
    text-shadow: 1px 1px 4px rgba(0,0,0,0.8);
    opacity: 0.9;
}

.main-title { 
    font-family: var(--font-heading);
    font-size: 5rem; 
    margin: 0; 
    line-height: 1.1; 
    color: #fff; 
    text-shadow: 2px 4px 10px rgba(0,0,0,0.8);
    letter-spacing: 2px;
}

.title-separator { 
    width: 80px; height: 3px; background: var(--gold); margin: 20px auto; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.sparkle-link-container {
    position: absolute; bottom: 40px; right: 40px; z-index: 10;
    text-decoration: none;
}
.sparkle-btn {
    background: rgba(255,255,255,0.9);
    border: 1px solid var(--gold);
    padding: 12px 25px;
    border-radius: 50px;
    color: var(--wood);
    font-family: var(--font-ui);
    font-weight: 700; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 1px;
    display: flex; align-items: center; gap: 10px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    transition: 0.3s;
}
.sparkle-btn:hover { transform: scale(1.05); background: #fff; }

/* --- SECTIONS SHARED --- */
section { padding: 100px 20px; min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }
.container { max-width: 1200px; margin: 0 auto; width: 100%; }
.section-heading { font-size: 3.5rem; margin-bottom: 20px; color: var(--ink); line-height: 1; }
.section-heading.centered { display: block; text-align: center; }
.section-sub { text-align: center; font-family: var(--font-body); font-style: italic; color: #666; margin-bottom: 50px; font-size: 1.5rem; }

/* --- BIO --- */
.bio-grid { display: grid; grid-template-columns: 1fr 0.8fr; gap: 60px; align-items: center; }
.frame { padding: 15px; background: #fff; box-shadow: 0 15px 35px rgba(0,0,0,0.1); transform: rotate(2deg); transition: 0.5s; }
.frame:hover { transform: rotate(0); }

/* --- LIBRARY --- */
.bookcase-outer {
    background: #ffffff; 
    padding: 40px;
    border-radius: 8px;
    box-shadow: inset 0 0 60px rgba(0,0,0,0.05), 0 10px 30px rgba(0,0,0,0.1);
    border: 1px solid #f0f0f0;
    max-width: 1000px; margin: 0 auto;
}
.bookcase-inner { display: flex; flex-direction: column; }
.shelf-row {
    display: flex; justify-content: center; gap: 50px;
    padding-bottom: 0px; align-items: flex-end; flex-wrap: wrap; position: relative; z-index: 5;
}
.shelf-wood {
    height: 20px; background: linear-gradient(to bottom, #fdfdfd, #e0e0e0);
    width: 100%; margin-top: -10px; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    border-radius: 2px; position: relative; z-index: 4;
}
.book-item { width: 200px; cursor: pointer; text-align: center; position: relative; z-index: 1; margin-bottom: 0; }
.book-cover-wrapper { transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); transform-origin: bottom center; }
.book-item:hover .book-cover-wrapper { transform: translateY(-20px) scale(1.02); }
.book-item img {
    border-radius: 2px 4px 4px 2px; box-shadow: 5px 5px 15px rgba(0,0,0,0.0); 
    aspect-ratio: 2/3; object-fit: cover; transition: box-shadow 0.4s;
}
.book-item:hover img { box-shadow: 0 0 10px rgba(197, 160, 89, 0.8); }

.book-item h3 { 
    font-size: 1.1rem; 
    font-family: var(--font-body); 
    color: var(--ink); 
    font-weight: 700; 
    margin-bottom: 15px; opacity: 0.6; transition: 0.3s; position: relative; 
}
.book-item:hover h3 { opacity: 1; color: var(--gold); }

/* --- PUBLISHERS & CONTACT --- */
#publishers { background-color: #f2efe4; border-top: 1px solid #e0dbcd; border-bottom: 1px solid #e0dbcd; }
.publisher-box { border: 2px solid var(--gold); padding: 60px; background: #fff; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.05); }
.publisher-content { font-size: 1.4rem; max-width: 800px; margin: 0 auto; color: var(--wood); line-height: 1.8; }
.contact-container { text-align: center; max-width: 700px; }
.humble-note { font-style: italic; color: #555; margin-bottom: 30px; }
.letter-form { background: #fff; padding: 30px; border: 1px solid #ddd; box-shadow: 0 10px 30px rgba(0,0,0,0.05); }
textarea#user-message { width: 100%; height: 150px; padding: 20px; font-family: var(--font-body); font-size: 1.2rem; border: 1px solid #ccc; background: repeating-linear-gradient(white, white 24px, #f0f0f0 25px); line-height: 25px; resize: none; margin-bottom: 20px; color: #444; }
textarea#user-message:focus { outline: 2px solid var(--gold); }
.wax-button { display: inline-block; padding: 12px 40px; background: var(--ink); color: #fff; border: none; cursor: pointer; font-family: var(--font-ui); text-transform: uppercase; letter-spacing: 1px; font-size: 0.9rem; border-radius: 2px; transition: 0.3s; }
.wax-button:hover { background: var(--wax-red); }


/* --- BOOK MODAL (RUSTIC & REALISTIC) --- */
.modal { position: fixed; inset: 0; z-index: 10000; visibility: hidden; opacity: 0; transition: 0.5s; display: flex; align-items: center; justify-content: center; }
.modal.open { visibility: visible; opacity: 1; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.85); backdrop-filter: blur(10px); }

.book-open-container { 
    position: relative; z-index: 2; 
    width: 85vw; max-width: 1100px; height: 80vh; max-height: 750px; 
    
    /* Rustic Paper Texture Generation */
    background-color: #e3dac9;
    background-image: 
        linear-gradient(90deg, rgba(0,0,0,0.03) 0%, rgba(0,0,0,0) 5%, rgba(0,0,0,0) 95%, rgba(0,0,0,0.03) 100%),
        repeating-linear-gradient(0deg, transparent, transparent 1px, rgba(139, 69, 19, 0.03) 1px, rgba(139, 69, 19, 0.03) 2px),
        radial-gradient(circle at 50% 50%, transparent 80%, rgba(0,0,0,0.1) 120%);
    
    display: flex; 
    box-shadow: 0 20px 50px rgba(0,0,0,0.5), inset 0 0 100px rgba(62, 39, 35, 0.1); 
    border-radius: 5px; 
    perspective: 2000px; /* Enhanced perspective for real flip */
    border: 1px solid #d7cbb1;
}

/* The Spine Shadow */
.book-spine { 
    position: absolute; left: 50%; top: 0; bottom: 0; width: 60px; 
    background: linear-gradient(90deg, rgba(0,0,0,0.05), rgba(0,0,0,0.2) 40%, rgba(0,0,0,0.2) 60%, rgba(0,0,0,0.05)); 
    transform: translateX(-50%); z-index: 5; 
    pointer-events: none;
}

.book-page { 
    flex: 1; 
    padding: 60px 70px; 
    position: relative; 
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    
    /* NO SCROLLING - FIT CONTENT */
    overflow: hidden; 
    
    transform-style: preserve-3d; 
    backface-visibility: hidden;
    transform-origin: center left; /* Prepare for flip */
    transition: transform 0.8s cubic-bezier(0.645, 0.045, 0.355, 1);
}

/* Page Flip Animations */
.turning-next .left-page { 
    /* Static */
}
.turning-next .right-page { 
    animation: flipRightToLeft 0.9s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
    transform-origin: left center;
}

.turning-prev .left-page {
    animation: flipLeftToRight 0.9s cubic-bezier(0.645, 0.045, 0.355, 1) forwards;
    transform-origin: right center;
    z-index: 10;
}

@keyframes flipRightToLeft {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(-180deg); opacity: 0; }
}

@keyframes flipLeftToRight {
    0% { transform: rotateY(180deg); opacity: 0; }
    100% { transform: rotateY(0deg); opacity: 1; }
}


.left-page { border-right: 1px solid rgba(0,0,0,0.05); }
.right-page { }

.page-content { 
    font-family: var(--font-body); 
    font-size: clamp(1.1rem, 1.8vh, 1.4rem); /* Dynamic sizing to fit without scroll */
    line-height: 1.6; 
    white-space: pre-wrap; 
    color: #3e2723; /* Dark brown ink */
    text-align: justify; 
    width: 100%;
    max-height: 100%;
}

.end-logo { width: 120px; margin: 0 auto; opacity: 0.7; display: block; filter: sepia(1) hue-rotate(-30deg); }
.page-number { 
    position: absolute; bottom: 30px; width: 100%; text-align: center;
    font-family: var(--font-ui); font-size: 0.8rem; color: #8d6e63; letter-spacing: 2px;
}

/* Desktop Controls */
.book-controls { position: absolute; bottom: -70px; left: 0; right: 0; display: flex; justify-content: center; gap: 20px; }
.book-controls button { 
    background: transparent; border: 1px solid rgba(255,255,255,0.4); 
    color: #fff; padding: 10px 30px; cursor: pointer; 
    font-family: var(--font-heading); text-transform: uppercase; transition: 0.3s; font-size: 0.9rem; letter-spacing: 2px;
}
.book-controls button:hover { border-color: var(--gold); color: var(--gold); }
.book-controls button:disabled { opacity: 0.3; cursor: not-allowed; border-color: rgba(255,255,255,0.1); }

.back-library-btn { 
    position: absolute; top: -50px; right: 0; 
    background: none; border: none; color: rgba(255,255,255,0.6); 
    padding: 8px 15px; font-family: var(--font-ui);
    cursor: pointer; transition: 0.3s; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px;
}
.back-library-btn:hover { color: var(--gold); }

/* --- FOOTER --- */
footer { background: var(--ink); color: var(--paper); padding: 80px 20px; text-align: center; border-top: 8px solid var(--gold); }
.footer-title { font-family: var(--font-heading); font-size: 4rem; color: var(--gold); margin-bottom: 20px; letter-spacing: 2px; }
.footer-loc { font-family: var(--font-body); letter-spacing: 0.2em; opacity: 0.6; margin-bottom: 40px; font-size: 1.2rem; }
.tech-credit { margin-top: 20px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-family: var(--font-ui); font-size: 1.0rem; color: #888; }

.edn-text-link {
    font-family: var(--font-body);
    font-size: 1.2rem; 
    letter-spacing: 0.05em;
    color: var(--paper);
    text-decoration: none;
    opacity: 0.6;
    transition: opacity 0.3s;
}
.edn-text-link:hover { opacity: 1; text-decoration: underline; }

/* --- RESPONSIVE MOBILE OPTIMIZATION --- */
@media (max-width: 900px) {
    .main-title { font-size: 3rem; }
    
    /* FIX MOBILE NAV ALIGNMENT */
    .glass-nav { 
        width: 100%; top: 0; left: 0; transform: none; border-radius: 0; border: none; border-bottom: 1px solid var(--gold); 
        justify-content: space-between; padding: 10px 15px;
    }
    .nav-links { gap: 15px; }
    .nav-links a { font-size: 0.7rem; letter-spacing: 1px; font-weight: 700; }

    /* Mobile Bio Portrait Layout */
    .bio-grid { display: flex; flex-direction: column; position: relative; } 
    
    .bio-image { 
        order: -1; 
        position: relative; 
        width: 100%; 
        z-index: 0;
        margin-bottom: -100px; 
    }
    .frame {
        width: 70%; margin-left: auto; transform: rotate(3deg);
        opacity: 0.9; box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    }
    
    .bio-text {
        order: 0; 
        position: relative; 
        z-index: 2; 
        margin-top: 100px; 
        text-shadow: 0 0 20px rgba(247, 244, 233, 1), 0 0 10px rgba(247, 244, 233, 1);
        background: linear-gradient(to bottom, transparent, rgba(247, 244, 233, 0.9) 20%);
        padding: 20px;
    }
    #bio { padding-top: 50px; } 

    .bookcase-outer { padding: 20px; }
    .shelf-row { gap: 30px; }
    
    /* MOBILE BOOK READER FIX */
    .book-open-container { 
        width: 95vw; height: 80dvh; border-radius: 4px; flex-direction: column; 
    }
    
    .book-spine { display: none; }
    .left-page { display: none; } /* Hide left page on mobile */

    .book-page.right-page { 
        padding: 30px 25px; flex: 1; 
        display: flex; 
        align-items: center; 
        justify-content: center; 
        text-align: center;
        border-left: none;
        width: 100%;
        /* Mobile specific animation reset */
        animation: fadeInPage 0.5s ease;
    }
    
    @keyframes fadeInPage { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); }}
    
    .page-content { 
        font-size: 1.1rem; 
        text-align: center;
        background: transparent; 
    }
    
    /* Sticky Footer Controls for Mobile */
    .book-controls {
        position: relative; bottom: auto; left: auto; right: auto;
        background: #f0ebd8; padding: 15px; border-top: 1px solid rgba(0,0,0,0.1); gap: 10px; margin-top: 0;
    }
    .book-controls button { border-color: #aaa; color: #333; flex: 1; padding: 15px 0; }
    .back-library-btn { top: -40px; right: 10px; color: #fff; position: absolute; }

    .sparkle-link-container { bottom: 120px; right: 20px; }
}