/* =============================================
   Storiographer.com - Book-Illustration Design
   Palette: Book Brown
   Colors: #F5ECD7 #2C1810 #3B2316 #7A5C44 #9B111E #7A0E17 #C5953A #4A3728 #5C3D2E
   ============================================= */

/* Reset & Base */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #2C1810;
    font-family: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
    color: #2C1810;
    font-size: 16px;
    line-height: 1.75;
}

/* Paper Texture Overlay */
.paper-texture {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.03;
    mix-blend-mode: multiply;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* =============================================
   Ribbon Bookmark Navigation
   ============================================= */
.bookmark-ribbon {
    position: fixed;
    top: -10px;
    right: 40px;
    width: 40px;
    height: 80px;
    z-index: 500;
    cursor: pointer;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    filter: drop-shadow(2px 2px 4px rgba(44, 24, 16, 0.3));
}

.bookmark-ribbon:hover {
    transform: translateY(12px);
}

.bookmark-ribbon.active {
    transform: translateY(30px);
}

.ribbon-svg {
    width: 100%;
    height: 100%;
}

/* Table of Contents */
.table-of-contents {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100vh;
    background: #3B2316;
    z-index: 400;
    transform: translateX(100%);
    transition: transform 0.6s cubic-bezier(0.68, -0.55, 0.27, 1.55);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: -4px 0 20px rgba(44, 24, 16, 0.5);
}

.table-of-contents.open {
    transform: translateX(0);
}

.toc-inner {
    padding: 40px;
}

.toc-title {
    font-family: 'Cinzel', Georgia, serif;
    font-weight: 400;
    font-size: 1rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #C5953A;
    margin-bottom: 32px;
}

.toc-list {
    list-style: none;
}

.toc-list li {
    margin-bottom: 20px;
}

.toc-list a {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-size: 1.1rem;
    color: #F5ECD7;
    text-decoration: none;
    display: flex;
    align-items: baseline;
    gap: 16px;
    transition: color 0.3s ease;
}

.toc-list a:hover {
    color: #C5953A;
}

.chapter-numeral {
    font-family: 'Cinzel', Georgia, serif;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    color: #C5953A;
    min-width: 30px;
}

/* =============================================
   Book Container
   ============================================= */
.book-container {
    width: 100%;
    height: 100vh;
    perspective: 1200px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 10;
}

.book {
    position: relative;
    width: 90vw;
    max-width: 1200px;
    height: 88vh;
    transform-style: preserve-3d;
}

/* =============================================
   Spread & Pages
   ============================================= */
.spread {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    transform-style: preserve-3d;
}

.spread.active {
    opacity: 1;
    pointer-events: auto;
}

.spread.turning-out {
    animation: pageTurnOut 800ms ease-in-out forwards;
}

.spread.turning-in {
    animation: pageTurnIn 800ms ease-in-out forwards;
}

@keyframes pageTurnOut {
    0% {
        transform: rotateY(0deg);
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
    100% {
        transform: rotateY(-180deg);
        opacity: 0;
    }
}

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

.page {
    flex: 1;
    background: #F5ECD7;
    position: relative;
    overflow: hidden;
    padding: 40px;
}

.page.verso {
    border-right: none;
}

.page.recto {
    border-left: none;
}

/* Dark spread pages (Colophon) */
.page.dark-spread {
    background: #3B2316;
    color: #F5ECD7;
}

/* Book Spine */
.spine {
    width: 3px;
    background: linear-gradient(to bottom, #5C3D2E, #3B2316, #5C3D2E);
    flex-shrink: 0;
    box-shadow: -2px 0 8px rgba(44, 24, 16, 0.3), 2px 0 8px rgba(44, 24, 16, 0.3);
}

.spine.dark-spine {
    background: linear-gradient(to bottom, #C5953A, #7A5C44, #C5953A);
    opacity: 0.5;
}

/* =============================================
   Page Edge Border & Corner Ornaments
   ============================================= */
.page-edge-border {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    border: 1px solid #4A3728;
    pointer-events: none;
    opacity: 0.4;
}

.page-edge-border.dark-border {
    border-color: #C5953A;
    opacity: 0.3;
}

.corner-ornament {
    position: absolute;
    width: 24px;
    height: 24px;
}

.corner-ornament.top-left {
    top: -1px;
    left: -1px;
}

.corner-ornament.top-right {
    top: -1px;
    right: -1px;
}

.corner-ornament.bottom-left {
    bottom: -1px;
    left: -1px;
}

.corner-ornament.bottom-right {
    bottom: -1px;
    right: -1px;
}

/* =============================================
   Typography
   ============================================= */
.chapter-label {
    font-family: 'Cinzel', Georgia, serif;
    font-weight: 400;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #7A5C44;
    margin-bottom: 8px;
}

.chapter-heading {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(2rem, 4vw, 3.6rem);
    letter-spacing: 0.02em;
    color: #2C1810;
    margin-bottom: 16px;
    line-height: 1.2;
}

.site-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: clamp(2.4rem, 5vw, 4.8rem);
    letter-spacing: 0.02em;
    color: #2C1810;
    text-align: center;
    line-height: 1.1;
}

.subtitle {
    font-family: 'Cinzel', Georgia, serif;
    font-weight: 400;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: #7A5C44;
    text-align: center;
    margin-top: 16px;
}

.body-text {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-weight: 400;
    font-size: clamp(1.05rem, 1.8vw, 1.25rem);
    line-height: 1.75;
    color: #2C1810;
    margin-bottom: 1.2em;
    max-width: 55ch;
}

.first-para {
    margin-top: 0;
}

/* Drop Cap */
.drop-cap-block {
    position: relative;
}

.drop-cap {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 700;
    font-size: 6em;
    float: left;
    line-height: 0.75;
    margin-right: 8px;
    margin-top: 8px;
    color: #9B111E;
}

/* Pull Quotes */
.pull-quote {
    margin: 1.5em 0 1.5em 2em;
    padding-left: 1.5em;
    border-left: 2px solid #C5953A;
}

.pull-quote p {
    font-family: 'EB Garamond', Georgia, serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(0.9rem, 1.4vw, 1.1rem);
    letter-spacing: 0.01em;
    color: #7A5C44;
    line-height: 1.7;
}

/* =============================================
   Decorative Rules
   ============================================= */
.decorative-rule {
    display: flex;
    justify-content: center;
    margin: 16px 0 24px;
}

.rule-svg {
    width: 200px;
    height: 12px;
}

/* =============================================
   Verso Content Layouts
   ============================================= */
.verso-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
}

.recto-content {
    padding: 40px 15% 40px 30px;
    height: 100%;
    overflow-y: auto;
    scrollbar-width: none;
}

.recto-content::-webkit-scrollbar {
    display: none;
}

/* Title Page Verso */
.title-verso {
    position: relative;
}

.ornamental-frame {
    position: relative;
    width: 80%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.frame-border {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.title-block {
    text-align: center;
    position: relative;
    z-index: 1;
}

/* Illustration Verso */
.illustration-verso {
    background: transparent;
}

.chapter-illustration {
    max-width: 80%;
    max-height: 70%;
    opacity: 0.85;
}

.quill-illustration {
    width: 250px;
    height: auto;
}

.candle-illustration {
    width: 100px;
    height: auto;
    margin-top: 40px;
}

/* =============================================
   Spot Illustrations
   ============================================= */
.spot-illustration {
    float: right;
    margin: 0 -10px 10px 20px;
    shape-outside: circle(50%);
    opacity: 0.7;
}

.spot-illustration.book-light {
    width: 100px;
    height: 80px;
}

.spot-illustration.magnifier {
    width: 80px;
    height: 80px;
}

/* =============================================
   Tailpiece Ornaments
   ============================================= */
.tailpiece {
    display: flex;
    justify-content: center;
    margin-top: 40px;
    clear: both;
}

.tailpiece-svg {
    width: 120px;
    height: 30px;
}

.final-tailpiece .tailpiece-svg {
    width: 160px;
    height: 50px;
}

/* =============================================
   Bookshelf (Chapter III)
   ============================================= */
.bookshelf {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    height: 60%;
    gap: 4px;
    padding: 20px;
}

.book-spine {
    width: var(--spine-width, 24px);
    height: 80%;
    background: var(--spine-color, #4A3728);
    border-radius: 2px 0 0 2px;
    position: relative;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: inset -2px 0 4px rgba(0, 0, 0, 0.2), 1px 0 2px rgba(0, 0, 0, 0.1);
}

.book-spine::before {
    content: attr(data-title);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-90deg);
    font-family: 'Cinzel', Georgia, serif;
    font-size: 0.55rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #C5953A;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.book-spine:hover {
    transform: translateY(-12px);
    box-shadow: inset -2px 0 4px rgba(0, 0, 0, 0.2), 1px 4px 8px rgba(0, 0, 0, 0.3);
}

.book-spine:hover::before {
    opacity: 1;
}

/* Spine height variation */
.book-spine:nth-child(1) { height: 78%; }
.book-spine:nth-child(2) { height: 82%; }
.book-spine:nth-child(3) { height: 70%; }
.book-spine:nth-child(4) { height: 85%; }
.book-spine:nth-child(5) { height: 76%; }
.book-spine:nth-child(6) { height: 72%; }
.book-spine:nth-child(7) { height: 80%; }

.collection-caption {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: clamp(0.85rem, 1.2vw, 1rem);
    color: #7A5C44;
    text-align: center;
    margin-top: 24px;
    padding: 0 20px;
}

.collection-verso {
    padding-top: 30px;
}

.collection-recto {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
}

/* =============================================
   Colophon (Chapter IV)
   ============================================= */
.colophon-label {
    color: #C5953A;
}

.colophon-heading {
    color: #F5ECD7;
    text-align: center;
}

.colophon-verso {
    text-align: center;
}

.colophon-recto {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.colophon-block {
    text-align: center;
}

.colophon-entry {
    font-family: 'EB Garamond', Georgia, serif;
    font-style: italic;
    font-size: clamp(0.95rem, 1.5vw, 1.15rem);
    color: #F5ECD7;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    flex-wrap: wrap;
}

.colophon-role {
    font-family: 'Cinzel', Georgia, serif;
    font-style: normal;
    font-size: clamp(0.7rem, 1vw, 0.85rem);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #C5953A;
}

.colophon-value {
    font-family: 'Cormorant Garamond', Georgia, serif;
    font-style: normal;
    color: #F5ECD7;
    opacity: 0.85;
}

.fleuron {
    color: #C5953A;
    font-size: 0.8em;
    opacity: 0.6;
}

.colophon-finis {
    font-family: 'Cinzel', Georgia, serif;
    font-size: clamp(0.8rem, 1.2vw, 1rem);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #C5953A;
    text-align: center;
    margin-top: 40px;
    opacity: 0.8;
}

.colophon-rule {
    margin: 16px auto 24px;
}

.final-rule {
    margin-top: 32px;
}

/* =============================================
   Corner Peek (Page Turn Hint)
   ============================================= */
.corner-peek {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 0;
    background: linear-gradient(135deg, transparent 50%, #E2D5BC 50%);
    transition: width 300ms ease-out, height 300ms ease-out;
    cursor: pointer;
    z-index: 50;
}

.corner-peek:hover {
    width: 40px;
    height: 40px;
}

.corner-peek::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, transparent 50%, #D4C7AA 50%);
    opacity: 0.5;
}

/* =============================================
   Page Navigation Buttons
   ============================================= */
.page-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 200;
    background: rgba(245, 236, 215, 0.9);
    border: 1px solid #4A3728;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #4A3728;
    transition: background 0.3s ease, opacity 0.3s ease;
    opacity: 0.5;
}

.page-nav:hover {
    opacity: 1;
    background: #F5ECD7;
}

.page-nav-prev {
    left: 16px;
}

.page-nav-next {
    right: 16px;
}

.page-nav.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Page Indicator */
.page-indicator {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    font-family: 'Cinzel', Georgia, serif;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    color: #7A5C44;
    z-index: 200;
    opacity: 0.6;
}

/* =============================================
   Responsive: Mobile (single page view)
   ============================================= */
@media (max-width: 1024px) {
    .spread {
        flex-direction: column;
    }

    .spine {
        width: 100%;
        height: 3px;
        background: linear-gradient(to right, #5C3D2E, #3B2316, #5C3D2E);
    }

    .page {
        min-height: 100vh;
    }

    .recto-content {
        padding: 30px 10% 30px 10%;
    }

    .verso-content {
        padding: 30px;
    }

    .book {
        width: 96vw;
        height: auto;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .spread {
        position: relative;
        display: none;
    }

    .spread.active {
        display: flex;
    }

    .bookshelf {
        height: 300px;
    }

    .ornamental-frame {
        width: 90%;
    }

    .page-nav {
        top: auto;
        bottom: 60px;
    }

    .page-nav-prev {
        left: 20px;
    }

    .page-nav-next {
        right: 20px;
    }

    .corner-peek {
        display: none;
    }
}

@media (max-width: 600px) {
    .site-title {
        font-size: clamp(2rem, 8vw, 3rem);
    }

    .body-text {
        font-size: 1rem;
    }

    .drop-cap {
        font-size: 4em;
    }

    .chapter-illustration {
        max-width: 60%;
    }

    .page {
        padding: 24px;
    }

    .table-of-contents {
        width: 100%;
    }

    .book-spine {
        width: calc(var(--spine-width, 24px) * 0.75);
    }

    .colophon-entry {
        flex-direction: column;
        gap: 4px;
    }
}

/* =============================================
   Animations & Entrance
   ============================================= */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.spread.active .site-title {
    animation: fadeInUp 1s ease 0.2s both;
}

.spread.active .subtitle {
    animation: fadeInUp 1s ease 0.5s both;
}

.spread.active .drop-cap-block {
    animation: fadeInUp 0.8s ease 0.3s both;
}

.spread.active .chapter-heading {
    animation: fadeInUp 0.8s ease 0.1s both;
}

.spread.active .pull-quote {
    animation: fadeInUp 0.8s ease 0.4s both;
}

/* Gentle glow on gilt elements */
@keyframes giltShimmer {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.fleuron {
    animation: giltShimmer 4s ease-in-out infinite;
}

/* Candle flame flicker */
@keyframes flicker {
    0%, 100% { transform: scale(1) translateY(0); opacity: 0.85; }
    25% { transform: scale(1.02) translateY(-1px); opacity: 0.9; }
    50% { transform: scale(0.98) translateY(1px); opacity: 0.8; }
    75% { transform: scale(1.01) translateY(-0.5px); opacity: 0.88; }
}

.candle-illustration {
    animation: flicker 3s ease-in-out infinite;
}
