/* ============================================
   ENARGEIA — Fiction Library
   Books on shelves. Pull one out to read.
   ============================================ */

html:has(.fiction-page),
html:has(.fiction-page) body {
    overflow: hidden !important;
    height: 100vh;
    height: 100dvh;
}

.fiction-page {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    position: relative;
    background: #08060e;
    display: flex;
    flex-direction: column;
}

/* --- Nav --- */
.fiction-nav {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 50;
}

/* --- Title --- */
.fiction-header {
    text-align: center;
    padding: 1rem 0 0.5rem;
    flex-shrink: 0;
    z-index: 10;
}

.fiction-title {
    font-family: 'Uncial Antiqua', serif;
    font-size: clamp(1.4rem, 4vw, 2.2rem);
    letter-spacing: 0.25em;
    filter: drop-shadow(0 0 15px rgba(255, 126, 179, 0.2));
}

.fiction-subtitle {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.7rem;
    color: #8a8098;
    letter-spacing: 0.15em;
    margin-top: 0.3rem;
}

/* ============================================
   THE BOOKSHELF
   ============================================ */

.bookshelf-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    z-index: 5;
    overflow-y: auto;
}

/* Hide scrollbar but allow scroll */
.bookshelf-area::-webkit-scrollbar { width: 0; }
.bookshelf-area { scrollbar-width: none; }

.bookshelf {
    position: relative;
    width: clamp(320px, 70vw, 800px);
}

/* A single shelf row */
.shelf-row {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    gap: clamp(6px, 1vw, 12px);
    padding: 0 1.5rem;
    min-height: clamp(120px, 15vh, 160px);
}

/* The shelf plank beneath the books */
.shelf-row::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 10px;
    background: linear-gradient(
        180deg,
        #2a1f3a,
        #1a1225 60%,
        #120a1a
    );
    border-top: 1px solid rgba(196, 181, 253, 0.08);
    border-bottom: 2px solid #0a0610;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

/* Shelf bracket hints */
.shelf-row::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100%;
    background:
        linear-gradient(90deg, rgba(26, 18, 37, 0.3) 0px, transparent 40px),
        linear-gradient(270deg, rgba(26, 18, 37, 0.3) 0px, transparent 40px);
    pointer-events: none;
    z-index: 0;
}

/* ============================================
   INDIVIDUAL BOOKS
   ============================================ */

.book {
    position: relative;
    z-index: 2;
    cursor: pointer;
    transition: transform 0.3s ease, filter 0.3s ease;
    flex-shrink: 0;
}

/* Book spine (the visible part on shelf) */
.book-spine {
    width: var(--spine-width, 35px);
    height: var(--spine-height, 110px);
    border-radius: 2px 3px 3px 2px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 3px;
    position: relative;
    overflow: hidden;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(0, 0, 0, 0.3);
}

/* Spine text */
.book-spine-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-family: 'MedievalSharp', cursive;
    font-size: clamp(0.5rem, 1vw, 0.65rem);
    letter-spacing: 0.08em;
    color: var(--spine-text, #f0e6ff);
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-height: calc(var(--spine-height, 110px) - 20px);
}

/* Spine decoration — small line or symbol */
.book-spine::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 20%;
    right: 20%;
    height: 1px;
    background: var(--spine-accent, rgba(255, 255, 255, 0.15));
}

.book-spine::after {
    content: '';
    position: absolute;
    bottom: 6px;
    left: 20%;
    right: 20%;
    height: 1px;
    background: var(--spine-accent, rgba(255, 255, 255, 0.15));
}

/* Hover: book slides up slightly */
.book:hover {
    transform: translateY(-8px);
    filter: brightness(1.2);
}

.book:hover .book-spine {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

/* Tooltip on hover */
.book-tooltip {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%);
    font-family: 'MedievalSharp', cursive;
    font-size: 0.7rem;
    color: #f0e6ff;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    text-shadow: 0 0 8px rgba(196, 181, 253, 0.3);
    background: rgba(8, 6, 14, 0.9);
    padding: 0.2rem 0.5rem;
    border: 1px solid rgba(196, 181, 253, 0.1);
    border-radius: 2px;
    z-index: 30;
}

.book:hover .book-tooltip {
    opacity: 1;
}

/* ============================================
   READING VIEW (book pulled off shelf)
   ============================================ */

.reading-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.reading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

/* Dark backdrop */
.reading-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(5, 2, 8, 0.92);
    backdrop-filter: blur(4px);
}

/* The open book */
.reading-book {
    position: relative;
    width: clamp(340px, 60vw, 700px);
    max-height: 80vh;
    background: rgba(20, 14, 30, 0.98);
    border: 1px solid rgba(196, 181, 253, 0.12);
    border-radius: 3px;
    display: flex;
    flex-direction: column;
    z-index: 101;
    box-shadow:
        0 0 30px rgba(0, 0, 0, 0.5),
        0 0 60px rgba(168, 85, 247, 0.05);
    animation: book-open 0.4s ease-out;
}

@keyframes book-open {
    from {
        transform: scaleY(0.8) scaleX(0.95);
        opacity: 0;
    }
    to {
        transform: scaleY(1) scaleX(1);
        opacity: 1;
    }
}

/* Book header (title bar) */
.reading-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    border-bottom: 1px solid rgba(196, 181, 253, 0.08);
    flex-shrink: 0;
}

.reading-title {
    font-family: 'Uncial Antiqua', serif;
    font-size: clamp(1rem, 2.5vw, 1.3rem);
    letter-spacing: 0.1em;
    color: #f0e6ff;
}

.reading-close {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.8rem;
    color: #8a8098;
    padding: 0.3rem 0.6rem;
    border: 1px solid rgba(196, 181, 253, 0.12);
    background: rgba(26, 18, 37, 0.6);
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.reading-close:hover {
    color: #fca5a5;
    border-color: rgba(252, 165, 165, 0.3);
    background: rgba(252, 165, 165, 0.08);
}

/* Book metadata */
.reading-meta {
    padding: 0.5rem 1rem;
    font-family: 'MedievalSharp', cursive;
    font-size: 0.7rem;
    color: #8a8098;
    letter-spacing: 0.05em;
    border-bottom: 1px solid rgba(196, 181, 253, 0.05);
    flex-shrink: 0;
}

.reading-meta span {
    margin-right: 1.5rem;
}

/* Book content (scrollable) */
.reading-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    font-family: 'MedievalSharp', cursive;
    font-size: clamp(0.85rem, 1.5vw, 0.95rem);
    color: #c8bfdb;
    line-height: 1.9;
}

.reading-content::-webkit-scrollbar { width: 4px; }
.reading-content::-webkit-scrollbar-track { background: transparent; }
.reading-content::-webkit-scrollbar-thumb { background: rgba(196, 181, 253, 0.2); border-radius: 2px; }

/* Content typography */
.reading-content h2 {
    font-family: 'Uncial Antiqua', serif;
    font-size: clamp(1rem, 2vw, 1.2rem);
    color: #f0e6ff;
    letter-spacing: 0.08em;
    margin: 1.5rem 0 0.8rem;
    text-align: center;
}

.reading-content h2:first-child {
    margin-top: 0;
}

.reading-content p {
    margin-bottom: 1rem;
    text-indent: 1.5em;
    max-width: 100%;
}

.reading-content p:first-of-type {
    text-indent: 0;
}

/* Chapter/section break */
.reading-content .section-break {
    text-align: center;
    color: #c4b5fd;
    opacity: 0.4;
    margin: 1.5rem 0;
    font-size: 0.8rem;
    letter-spacing: 0.3em;
}

/* Drop cap for first paragraph of a chapter */
.reading-content .drop-cap::first-letter {
    font-family: 'Uncial Antiqua', serif;
    font-size: 2.5em;
    float: left;
    line-height: 0.8;
    margin-right: 0.1em;
    color: #c4b5fd;
}

/* ============================================
   REDIRECT OVERLAY (for off-site books)
   ============================================ */

.redirect-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: #000;
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    transition: opacity 0.8s ease;
}

.redirect-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.redirect-text {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.85rem;
    color: #8a8098;
    letter-spacing: 0.15em;
    animation: breathe 2s ease-in-out infinite;
}

/* --- Background ambiance --- */
.fiction-page::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 30% 60%, rgba(255, 126, 179, 0.03), transparent 50%),
        radial-gradient(ellipse at 70% 40%, rgba(196, 181, 253, 0.03), transparent 50%);
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .bookshelf {
        width: 95vw;
    }

    .shelf-row {
        padding: 0 0.5rem;
        gap: 4px;
    }

    .shelf-label {
        padding: 0 0.5rem 0.3rem;
    }

    .reading-book {
        width: 95vw;
        max-height: 90vh;
    }
}

/* ============================================
   TABLE OF CONTENTS — IN-BOOK PAGE
   ============================================ */

.story-toc {
    padding: 1rem 0 1.5rem;
    border-bottom: 1px solid rgba(196, 181, 253, 0.08);
    margin-bottom: 1.5rem;
}

.story-toc-title {
    font-family: 'Uncial Antiqua', serif;
    font-size: 0.85rem;
    color: #c4b5fd;
    letter-spacing: 0.15em;
    text-align: center;
    margin-bottom: 0.8rem;
    opacity: 0.7;
}

.story-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

.story-toc li {
    margin-bottom: 0.15rem;
}

.story-toc a {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.78rem;
    color: #8a8098;
    text-decoration: none;
    display: block;
    padding: 0.3rem 0.6rem;
    border-radius: 2px;
    transition: all 0.25s ease;
    letter-spacing: 0.03em;
}

.story-toc a:hover {
    color: #e9dfff;
    background: rgba(196, 181, 253, 0.08);
}

/* ============================================
   STICKY CHAPTER RIBBON
   ============================================ */

.chapter-ribbon {
    position: sticky;
    top: 0;
    z-index: 10;
    opacity: 0;
    transform: translateY(-100%);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    background: rgba(20, 14, 30, 0.95);
    border-bottom: 1px solid rgba(196, 181, 253, 0.1);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.8rem;
}

.chapter-ribbon.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.chapter-ribbon-current {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.7rem;
    color: #c4b5fd;
    letter-spacing: 0.05em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.chapter-ribbon-nav {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.ribbon-btn {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.65rem;
    color: #8a8098;
    padding: 0.2rem 0.45rem;
    border: 1px solid rgba(196, 181, 253, 0.12);
    background: rgba(26, 18, 37, 0.6);
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.ribbon-btn:hover {
    color: #e9dfff;
    border-color: rgba(196, 181, 253, 0.3);
    background: rgba(196, 181, 253, 0.1);
}

/* Ribbon chapter dropdown */
.ribbon-chapters-wrap {
    position: relative;
}

.ribbon-chapters-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 200px;
    max-height: 40vh;
    overflow-y: auto;
    background: rgba(20, 14, 30, 0.98);
    border: 1px solid rgba(196, 181, 253, 0.15);
    border-radius: 3px;
    padding: 0.3rem 0;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-4px);
    transition: all 0.25s ease;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.ribbon-chapters-dropdown::-webkit-scrollbar { width: 4px; }
.ribbon-chapters-dropdown::-webkit-scrollbar-track { background: transparent; }
.ribbon-chapters-dropdown::-webkit-scrollbar-thumb { background: rgba(196, 181, 253, 0.2); border-radius: 2px; }

.ribbon-chapters-dropdown.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.ribbon-chapters-dropdown a {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.72rem;
    color: #8a8098;
    text-decoration: none;
    display: block;
    padding: 0.3rem 0.7rem;
    transition: all 0.2s ease;
}

.ribbon-chapters-dropdown a:hover {
    color: #e9dfff;
    background: rgba(196, 181, 253, 0.08);
}

.ribbon-chapters-dropdown a.current {
    color: #c4b5fd;
    background: rgba(196, 181, 253, 0.06);
}

/* ============================================
   BOOKMARK BUTTON & TOAST
   ============================================ */

.bookmark-btn {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.65rem;
    color: #fde68a;
    padding: 0.2rem 0.45rem;
    border: 1px solid rgba(253, 230, 138, 0.2);
    background: rgba(253, 230, 138, 0.06);
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
}

.bookmark-btn:hover {
    background: rgba(253, 230, 138, 0.12);
    border-color: rgba(253, 230, 138, 0.35);
}

/* Bookmark toast notification */
.bookmark-toast {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    font-family: 'MedievalSharp', cursive;
    font-size: 0.68rem;
    color: #fde68a;
    background: rgba(20, 14, 30, 0.95);
    border: 1px solid rgba(253, 230, 138, 0.2);
    padding: 0.3rem 0.6rem;
    border-radius: 2px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    z-index: 20;
}

.bookmark-toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* Bookmark bar — shown when a bookmark exists on open */
.reading-bookmark-bar {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid rgba(253, 230, 138, 0.08);
    background: rgba(253, 230, 138, 0.03);
}

.reading-bookmark-bar.visible {
    display: flex;
}

.reading-bookmark-bar-text {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.7rem;
    color: #fde68a;
    opacity: 0.8;
    letter-spacing: 0.03em;
    flex: 1;
}

.bookmark-bar-btn {
    font-family: 'MedievalSharp', cursive;
    font-size: 0.68rem;
    padding: 0.2rem 0.5rem;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.bookmark-bar-resume {
    color: #fde68a;
    border: 1px solid rgba(253, 230, 138, 0.25);
    background: rgba(253, 230, 138, 0.08);
}

.bookmark-bar-resume:hover {
    background: rgba(253, 230, 138, 0.15);
    border-color: rgba(253, 230, 138, 0.4);
}

.bookmark-bar-dismiss {
    color: #8a8098;
    border: 1px solid rgba(138, 128, 152, 0.15);
    background: transparent;
}

.bookmark-bar-dismiss:hover {
    color: #fca5a5;
    border-color: rgba(252, 165, 165, 0.25);
}

/* ============================================
   SHELF SECTIONS
   ============================================ */

.shelf-section {
    margin-bottom: 1.2rem;
}

.shelf-section:last-child {
    margin-bottom: 0;
}

.shelf-label {
    font-family: 'MedievalSharp', cursive;
    font-size: clamp(0.6rem, 1.2vw, 0.72rem);
    color: #8a8098;
    letter-spacing: 0.2em;
    text-transform: lowercase;
    padding: 0 1.5rem 0.3rem;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.shelf-section:hover .shelf-label {
    opacity: 1;
}