﻿/* â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•
   Ebooks â€” Digital Library experience
   â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â•â• */

:root {
    /* Typography */
    --lib-display: "Fraunces", Georgia, "Times New Roman", serif;
    --lib-body: "Literata", Georgia, serif;
    --lib-ui: "DM Sans", system-ui, -apple-system, sans-serif;
    --lib-mono: "IBM Plex Mono", ui-monospace, monospace;
    --lib-font: var(--lib-ui);

    /* Mahogany reading-room palette */
    --lib-bg: #070504;
    --lib-bg-elevated: #100c09;
    --lib-parchment: #f4ead8;
    --lib-parchment-soft: #e8dcc8;
    --lib-wood: #2a1810;
    --lib-wood-light: #4a3020;
    --lib-shelf: linear-gradient(180deg, #6b4423 0%, #4a2f1a 42%, #2a1810 100%);
    --lib-shelf-edge: #8b6040;
    --lib-brass: #c9a227;
    --lib-brass-light: #e8c547;
    --lib-copper: #b87333;
    --lib-amber: #d4922a;
    --lib-amber-glow: rgba(212, 146, 42, 0.32);
    --lib-burgundy: rgba(107, 45, 45, 0.22);
    --lib-gold: #d4a574;
    --lib-text: var(--lib-parchment);
    --lib-muted: #9a8878;
    --lib-border: rgba(212, 165, 116, 0.2);
    --lib-glass: rgba(14, 10, 8, 0.82);
    --lib-radius: 16px;
    --lib-shadow-warm: 0 24px 64px rgba(0, 0, 0, 0.55);
}

body.lib-page {
    background: var(--lib-bg);
    color: var(--lib-text);
    font-family: var(--lib-ui);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body.lib-page #root > div:first-child {
    margin-left: 0 !important;
    margin-right: 0 !important;
    width: 100% !important;
}

body.lib-page .rcx-glass-home-back {
    display: inline-flex;
}

body.lib-page .lib-shell {
    padding-top: calc(52px + env(safe-area-inset-top, 0px));
}

#root {
    min-height: 100vh;
}

/* â”€â”€ Shell â”€â”€ */
.lib-shell {
    min-height: 100vh;
    font-family: var(--lib-ui);
    color: var(--lib-text);
    background:
        radial-gradient(ellipse 75% 50% at 50% -10%, var(--lib-amber-glow), transparent 58%),
        radial-gradient(ellipse 38% 28% at 10% 28%, var(--lib-burgundy), transparent 52%),
        radial-gradient(ellipse 32% 24% at 90% 32%, rgba(184, 115, 51, 0.14), transparent 48%),
        linear-gradient(175deg, #0f0b08 0%, var(--lib-bg) 38%, #040302 100%);
    position: relative;
}

.lib-shell::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

.lib-shell::after {
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse 88% 78% at 50% 42%, transparent 35%, rgba(0, 0, 0, 0.5) 100%);
    pointer-events: none;
    z-index: 0;
}

.lib-main {
    margin-left: 0;
    padding: 0 24px 32px;
    position: relative;
    z-index: 1;
}

@media (max-width: 768px) {
    .lib-main {
        padding: 0 16px 24px;
    }
}

/* â”€â”€ Hero â”€â”€ */
.lib-hero {
    position: relative;
    padding: 48px 0 36px;
    max-width: 1200px;
    margin: 0 auto;
}

.lib-hero__lamp {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    height: 140px;
    background: radial-gradient(ellipse at center, rgba(232, 197, 71, 0.22) 0%, rgba(212, 146, 42, 0.08) 45%, transparent 72%);
    pointer-events: none;
    filter: blur(10px);
}

.lib-hero__badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    border-radius: 999px;
    font-family: var(--lib-ui);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--lib-brass-light);
    background: rgba(201, 162, 39, 0.1);
    border: 1px solid rgba(201, 162, 39, 0.28);
    margin-bottom: 18px;
}

.lib-hero__title {
    font-family: var(--lib-display);
    font-size: clamp(2.25rem, 5.5vw, 3.25rem);
    font-weight: 700;
    font-variation-settings: "SOFT" 50, "WONK" 0;
    margin: 0 0 14px;
    line-height: 1.08;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #fef9ef 0%, var(--lib-gold) 42%, var(--lib-copper) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.lib-hero__sub {
    margin: 0 0 30px;
    max-width: 580px;
    font-family: var(--lib-body);
    font-size: 1.08rem;
    font-weight: 400;
    font-style: italic;
    line-height: 1.75;
    color: var(--lib-parchment-soft);
    opacity: 0.88;
}

.lib-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: center;
    margin-bottom: 24px;
}

.lib-search {
    flex: 1;
    min-width: 220px;
    max-width: 420px;
    position: relative;
}

.lib-search i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--lib-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

.lib-search input {
    width: 100%;
    padding: 14px 16px 14px 44px;
    border-radius: 14px;
    border: 1px solid var(--lib-border);
    background: var(--lib-glass);
    backdrop-filter: blur(14px) saturate(130%);
    color: var(--lib-parchment);
    font-size: 0.95rem;
    font-family: var(--lib-ui);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.lib-search input::placeholder {
    color: var(--lib-muted);
    font-style: italic;
}

.lib-search input:focus {
    border-color: rgba(201, 162, 39, 0.5);
    box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.12);
    background: rgba(18, 14, 10, 0.92);
}

.lib-stats {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.lib-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 20px;
    border-radius: 14px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
    border: 1px solid var(--lib-border);
    min-width: 88px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.lib-stat strong {
    font-family: var(--lib-mono);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--lib-brass-light);
    line-height: 1.2;
}

.lib-stat span {
    font-family: var(--lib-ui);
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--lib-muted);
    margin-top: 4px;
}

/* â”€â”€ Category filters â”€â”€ */
.lib-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 32px;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
}

.lib-filter-pill {
    padding: 9px 18px;
    border-radius: 999px;
    border: 1px solid var(--lib-border);
    background: rgba(255, 255, 255, 0.03);
    color: var(--lib-muted);
    font-size: 0.84rem;
    font-family: var(--lib-ui);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.22s ease;
}

.lib-filter-pill:hover {
    border-color: rgba(201, 162, 39, 0.38);
    color: var(--lib-parchment);
    background: rgba(201, 162, 39, 0.06);
}

.lib-filter-pill.is-active {
    background: linear-gradient(135deg, rgba(201, 162, 39, 0.2), rgba(184, 115, 51, 0.12));
    border-color: rgba(201, 162, 39, 0.5);
    color: var(--lib-brass-light);
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(201, 162, 39, 0.12);
}

/* â”€â”€ Shelves â”€â”€ */
.lib-catalog {
    max-width: 1200px;
    margin: 0 auto;
}

.lib-shelf-section {
    margin-bottom: 48px;
    animation: lib-fade-up 0.5s ease backwards;
}

.lib-shelf-section:nth-child(2) { animation-delay: 0.05s; }
.lib-shelf-section:nth-child(3) { animation-delay: 0.1s; }
.lib-shelf-section:nth-child(4) { animation-delay: 0.15s; }

@keyframes lib-fade-up {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.lib-shelf-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding-left: 4px;
}

.lib-shelf-head h2 {
    margin: 0;
    font-family: var(--lib-display);
    font-size: 1.35rem;
    font-weight: 600;
    font-variation-settings: "SOFT" 40;
    letter-spacing: -0.01em;
    color: var(--lib-gold);
    display: flex;
    align-items: center;
    gap: 10px;
}

.lib-shelf-head h2 i {
    font-size: 0.75rem;
    color: var(--lib-brass);
    opacity: 0.85;
}

.lib-shelf-count {
    font-family: var(--lib-mono);
    font-size: 0.75rem;
    color: var(--lib-muted);
    letter-spacing: 0.04em;
}

.lib-shelf {
    position: relative;
    padding-bottom: 8px;
}

.lib-shelf-books {
    display: flex;
    flex-wrap: wrap;
    gap: 18px 22px;
    align-items: flex-end;
    padding: 0 8px 14px;
    min-height: 200px;
}

.lib-shelf-plank {
    height: 14px;
    border-radius: 2px 2px 4px 4px;
    background: var(--lib-shelf);
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.5),
        0 1px 0 var(--lib-shelf-edge) inset,
        0 -2px 6px rgba(0, 0, 0, 0.3) inset;
    position: relative;
}

.lib-shelf-plank::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -3px;
    height: 3px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
}

/* â”€â”€ Book on shelf â”€â”€ */
.lib-book {
    width: 130px;
    cursor: pointer;
    flex-shrink: 0;
    transform: rotate(var(--book-tilt, 0deg)) translateY(0);
    transform-origin: bottom center;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.25s;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
}

.lib-book:hover {
    transform: rotate(0deg) translateY(-18px) scale(1.06);
    filter: drop-shadow(0 20px 28px rgba(0, 0, 0, 0.55));
    z-index: 2;
}

.lib-book:active {
    transform: rotate(0deg) translateY(-10px) scale(1.02);
}

.lib-book__cover {
    width: 100%;
    aspect-ratio: 2 / 3;
    border-radius: 2px 6px 6px 2px;
    background-size: cover;
    background-position: center;
    position: relative;
    overflow: hidden;
    box-shadow:
        inset -4px 0 8px rgba(0, 0, 0, 0.35),
        inset 2px 0 4px rgba(255, 255, 255, 0.08);
}

.lib-book__spine {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 10px;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.55) 0%, rgba(255, 255, 255, 0.12) 40%, rgba(0, 0, 0, 0.4) 100%);
    pointer-events: none;
}

.lib-book__pages {
    position: absolute;
    right: 0;
    top: 4px;
    bottom: 4px;
    width: 5px;
    background: repeating-linear-gradient(
        to bottom,
        #f5f0e8 0px,
        #f5f0e8 2px,
        #e8dfd0 3px,
        #e8dfd0 4px
    );
    border-radius: 0 2px 2px 0;
    box-shadow: -1px 0 3px rgba(0, 0, 0, 0.2);
}

.lib-book__shine {
    position: absolute;
    inset: 0;
    background: linear-gradient(125deg, rgba(255, 255, 255, 0.18) 0%, transparent 40%, transparent 100%);
    pointer-events: none;
}

.lib-book__title {
    margin-top: 10px;
    font-family: var(--lib-display);
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--lib-parchment);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-align: center;
    padding: 0 2px;
}

.lib-book__meta {
    margin-top: 5px;
    font-family: var(--lib-mono);
    font-size: 0.68rem;
    color: var(--lib-muted);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    letter-spacing: 0.03em;
}

/* â”€â”€ States â”€â”€ */
.lib-loading,
.lib-empty {
    text-align: center;
    padding: 60px 24px;
    color: var(--lib-muted);
    font-family: var(--lib-body);
}

.lib-loading i,
.lib-empty i {
    font-size: 2.5rem;
    color: var(--lib-brass);
    opacity: 0.65;
    margin-bottom: 16px;
    display: block;
}

.lib-loading p,
.lib-empty p {
    margin: 0;
    font-size: 1.05rem;
    font-style: italic;
}

.lib-gate {
    max-width: 520px;
    margin: 40px auto;
    padding: 48px 32px;
    text-align: center;
    border-radius: 20px;
    background: rgba(107, 45, 45, 0.12);
    border: 1px solid rgba(180, 80, 60, 0.35);
    box-shadow: var(--lib-shadow-warm);
}

.lib-gate i {
    font-size: 3rem;
    color: #c9705a;
    margin-bottom: 16px;
}

.lib-gate h2 {
    margin: 0 0 10px;
    font-family: var(--lib-display);
    font-size: 1.55rem;
    font-weight: 600;
    color: var(--lib-parchment);
}

.lib-gate p {
    margin: 0 0 8px;
    font-family: var(--lib-body);
    color: var(--lib-muted);
    line-height: 1.65;
}

.lib-no-results {
    text-align: center;
    padding: 48px 24px;
    color: var(--lib-muted);
    font-family: var(--lib-body);
    font-style: italic;
}

.lib-no-results i {
    font-size: 2rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.lib-ad-wrap {
    max-width: 1200px;
    margin: 0 auto 18px;
}

/* â”€â”€ Responsive books â”€â”€ */
@media (max-width: 768px) {
    .lib-hero {
        padding: 32px 0 24px;
    }

    .lib-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .lib-search {
        max-width: none;
    }

    .lib-stats {
        justify-content: center;
    }

    .lib-book {
        width: 110px;
    }

    .lib-shelf-books {
        gap: 14px 16px;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .lib-book {
        width: 100px;
    }
}


/* ═══ 3D Reader modal ═══ */
/* Reader modal - 3D book animation */
.ebook-reader-overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at top, rgba(102,126,234,0.25), rgba(0,0,0,0.98));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 0;
    perspective: 1600px;
}
.ebook-reader-shell {
    width: 100%;
    max-width: 1200px;
    height: 100vh;
    max-height: 100vh;
    background: radial-gradient(circle at left top, #f5f0e8 0%, #e4d8c3 35%, #d1c3aa 60%, #1a1a1a 100%);
    border-radius: 0;
    box-shadow: 0 25px 70px rgba(0,0,0,0.9);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform-origin: left center;
    transform: rotateY(-18deg) translateX(12px) scale(0.96);
    animation: ebookBookOpen 0.7s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}
/* Enhanced 3D book effect for mobile with page-turning animation */
@media (max-width: 768px) {
    .ebook-reader-overlay {
        perspective: 1200px;
        -webkit-perspective: 1200px;
    }
    .ebook-reader-shell {
        transform: rotateY(-12deg) translateX(8px) scale(0.98);
        animation: ebookBookOpenMobile 0.8s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
        background: radial-gradient(circle at left top, #f5f0e8 0%, #e4d8c3 35%, #d1c3aa 60%, #1a1a1a 100%);
        transform-style: preserve-3d;
        -webkit-transform-style: preserve-3d;
    }
    .ebook-reader-shell::before {
        display: block;
        width: 18px;
    }
    .ebook-reader-shell::after {
        display: block;
        width: 20px;
    }
}
@keyframes ebookBookOpenMobile {
    0% {
        transform: rotateY(-20deg) translateX(30px) scale(0.92);
        opacity: 0;
    }
    50% {
        transform: rotateY(-8deg) translateX(5px) scale(0.96);
        opacity: 0.8;
    }
    100% {
        transform: rotateY(-12deg) translateX(8px) scale(0.98);
        opacity: 1;
    }
}
/* Simulated spine / pages thickness */
.ebook-reader-shell::before {
    content: "";
    position: absolute;
    top: 6%;
    bottom: 6%;
    left: 0;
    width: 22px;
    background:
        linear-gradient(to right, rgba(0,0,0,0.45), rgba(0,0,0,0.2) 35%, rgba(255,255,255,0.2) 55%, rgba(0,0,0,0.35)),
        repeating-linear-gradient(
            to bottom,
            rgba(255,255,255,0.45),
            rgba(255,255,255,0.45) 2px,
            rgba(230,220,200,0.7) 3px,
            rgba(230,220,200,0.7) 4px
        );
    box-shadow: inset -3px 0 6px rgba(0,0,0,0.35);
    z-index: 2;
}
/* Right edge highlight to enhance 3D */
.ebook-reader-shell::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 26px;
    height: 100%;
    background: linear-gradient(to left, rgba(0,0,0,0.7), rgba(0,0,0,0.0));
    pointer-events: none;
}
@keyframes ebookBookOpen {
    0% {
        transform: rotateY(-24deg) translateX(40px) scale(0.9);
        opacity: 0;
    }
    40% {
        transform: rotateY(-10deg) translateX(10px) scale(0.96);
        opacity: 1;
    }
    100% {
        transform: rotateY(0deg) translateX(0) scale(1);
        opacity: 1;
    }
}
/* Page turning effect - subtle animation on scroll */
@keyframes pageTurn {
    0% {
        transform: rotateY(0deg);
    }
    50% {
        transform: rotateY(-2deg);
    }
    100% {
        transform: rotateY(0deg);
    }
}

/* ===== Real book spread + 3D page flip (desktop) ===== */
.ebook-bookstage {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1600px;
    transform-style: preserve-3d;
}
.ebook-book {
    width: min(980px, 100%);
    height: min(68vh, 760px);
    max-height: calc(100vh - 210px);
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.25s ease;
}
@media (max-width: 900px) {
    .ebook-book {
        height: min(62vh, 680px);
    }
}
.ebook-spread {
    width: 100%;
    height: 100%;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 22px 1fr;
    align-items: stretch;
    transform-style: preserve-3d;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 22px 55px rgba(0,0,0,0.55);
    background: #f7f1e6;
}
.ebook-gutter {
    position: relative;
    background: linear-gradient(to right, rgba(0,0,0,0.35), rgba(0,0,0,0.08) 40%, rgba(255,255,255,0.15) 55%, rgba(0,0,0,0.22));
    box-shadow: inset -8px 0 20px rgba(0,0,0,0.25), inset 8px 0 20px rgba(0,0,0,0.18);
}
.ebook-page {
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    background-color: #fdfaf5;
    position: relative;
    transform-style: preserve-3d;
}
.ebook-page-left {
    box-shadow: inset -22px 0 30px rgba(0,0,0,0.28);
}
.ebook-page-right {
    box-shadow: inset 22px 0 30px rgba(0,0,0,0.18);
}
/* a tiny "paper" texture overlay */
.ebook-page::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 30%, rgba(0,0,0,0.035), transparent 40%),
        radial-gradient(circle at 70% 60%, rgba(0,0,0,0.03), transparent 45%);
    pointer-events: none;
    mix-blend-mode: multiply;
    opacity: 0.8;
}

/* Turning sheet */
.ebook-turn-sheet {
    position: absolute;
    top: 0;
    bottom: 0;
    width: calc((100% - 22px) / 2);
    transform-style: preserve-3d;
    z-index: 6;
    pointer-events: none;
    filter: drop-shadow(0 12px 22px rgba(0,0,0,0.35));
}
.ebook-turn-sheet .front,
.ebook-turn-sheet .back {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    background-color: #fdfaf5;
}
.ebook-turn-sheet .front::after,
.ebook-turn-sheet .back::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Next: flip the right page to reveal next-left on the back */
.ebook-turn-sheet.next {
    right: 0;
    transform-origin: left center;
    animation: ebookFlipNext 520ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.ebook-turn-sheet.next .front::after {
    background: linear-gradient(to right, rgba(0,0,0,0.18), rgba(0,0,0,0.0) 55%);
}
.ebook-turn-sheet.next .back {
    transform: rotateY(180deg);
}
.ebook-turn-sheet.next .back::after {
    background: linear-gradient(to left, rgba(0,0,0,0.22), rgba(0,0,0,0.0) 55%);
}
@keyframes ebookFlipNext {
    0% { transform: rotateY(0deg); }
    60% { transform: rotateY(-150deg); }
    100% { transform: rotateY(-180deg); }
}

/* Prev: flip the left page backwards */
.ebook-turn-sheet.prev {
    left: 0;
    transform-origin: right center;
    animation: ebookFlipPrev 520ms cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
.ebook-turn-sheet.prev .front::after {
    background: linear-gradient(to left, rgba(0,0,0,0.18), rgba(0,0,0,0.0) 55%);
}
.ebook-turn-sheet.prev .back {
    transform: rotateY(180deg);
}
.ebook-turn-sheet.prev .back::after {
    background: linear-gradient(to right, rgba(0,0,0,0.22), rgba(0,0,0,0.0) 55%);
}
@keyframes ebookFlipPrev {
    0% { transform: rotateY(0deg); }
    60% { transform: rotateY(150deg); }
    100% { transform: rotateY(180deg); }
}

/* Single-page (mobile) keeps your existing feel */
.ebook-single {
    width: 100%;
    height: 100%;
    display: flex;
}
.ebook-page-single {
    width: 100%;
    height: 100%;
    border-radius: 14px;
    box-shadow: 0 18px 45px rgba(0,0,0,0.55);
    animation: pageTurn 0.6s ease;
}
/* Add subtle page shadow on mobile for depth */
@media (max-width: 768px) {
    .ebook-reader-pages {
        box-shadow: 
            inset -15px 0 30px rgba(0,0,0,0.4),
            inset 15px 0 30px rgba(0,0,0,0.2);
    }
}
.ebook-reader-spine {
    display: none; /* Hide spine on all devices for cleaner mobile experience */
}
.ebook-reader-pages {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    height: 100%;
    overflow: hidden;
    position: relative;
    z-index: 3;
}
.ebook-reader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.8);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    color: #ffffff;
    font-size: 0.9rem;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-wrap: wrap;
    gap: 12px;
}
.ebook-reader-header > span:first-child {
    flex: 1;
    min-width: 200px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ebook-reader-iframe-wrap {
    flex: 1;
    background:
        repeating-linear-gradient(
            to bottom,
            #fdfaf5,
            #fdfaf5 18px,
            #f4ebdd 19px
        );
    border-radius: 0;
    overflow: hidden;
    box-shadow:
        inset 0 0 0 1px rgba(0,0,0,0.15),
        inset 20px 0 35px rgba(0,0,0,0.35);
    position: relative;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    min-height: 0;
    transform-style: preserve-3d;
    -webkit-transform-style: preserve-3d;
}
/* Realistic book page effect */
.ebook-reader-iframe-wrap::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(to right, 
        rgba(0,0,0,0.1) 0%,
        rgba(0,0,0,0.05) 50%,
        transparent 100%);
    z-index: 1;
    pointer-events: none;
}
/* Page shadow effect */
.ebook-reader-iframe-wrap::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(to left, 
        rgba(0,0,0,0.15) 0%,
        transparent 100%);
    z-index: 1;
    pointer-events: none;
}
@media (max-width: 768px) {
    .ebook-reader-iframe-wrap {
        background:
            repeating-linear-gradient(
                to bottom,
                #fdfaf5,
                #fdfaf5 18px,
                #f4ebdd 19px
            );
        box-shadow:
            inset 0 0 0 1px rgba(0,0,0,0.15),
            inset 15px 0 30px rgba(0,0,0,0.3);
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        transform-style: preserve-3d;
        -webkit-transform-style: preserve-3d;
    }
    .ebook-reader-iframe-wrap::before,
    .ebook-reader-iframe-wrap::after {
        display: block;
    }
}
.ebook-reader-iframe-wrap iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    pointer-events: auto;
    flex: 1;
    min-height: 0;
}
@media (max-width: 768px) {
    .ebook-reader-iframe-wrap iframe {
        min-height: 100%;
        height: auto;
    }
}
/* Allow scrolling and interaction in ebook reader */
.ebook-reader-iframe-wrap {
    -webkit-touch-callout: none;
}
/* Allow text selection for reading, but prevent right-click menu */
.ebook-reader-iframe-wrap iframe {
    -webkit-touch-callout: none;
}
/* Disable PDF toolbar buttons */
.ebook-reader-iframe-wrap iframe[src*="ebook_stream"] {
    pointer-events: auto;
}
/* Prevent all interactions that could lead to saving */
.ebook-reader-overlay,
.ebook-reader-shell,
.ebook-reader-pages {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
}

/* Prevent text selection in iframe wrapper */
.ebook-reader-iframe-wrap {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
    pointer-events: auto;
}

/* Disable selection highlighting */
.ebook-reader-iframe-wrap * {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
}
/* Disable right-click but allow scrolling and normal interaction */
body.ebook-reader-active {
    -webkit-touch-callout: none;
}
/* Prevent right-click context menu but allow normal interactions */
.ebook-reader-active .ebook-reader-iframe-wrap {
    -webkit-touch-callout: none;
}

/* ===== Screenshot deterrents (watermark + blur shield) ===== */
.ebook-watermark {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 20;
    opacity: 0.12;
    mix-blend-mode: multiply;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateZ(0);
}
.ebook-watermark .wm-inner {
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(0,0,0,0.7);
    font-size: clamp(14px, 2vw, 28px);
    transform: rotate(-22deg);
    text-shadow:
        0 1px 0 rgba(255,255,255,0.35),
        0 12px 22px rgba(0,0,0,0.12);
    padding: 18px 24px;
    border-radius: 14px;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.25), rgba(255,255,255,0.02));
    border: 1px solid rgba(0,0,0,0.06);
}

.ebook-blur-shield {
    position: absolute;
    inset: 0;
    z-index: 30;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.ebook-blur-shield-text {
    color: rgba(255,255,255,0.92);
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 14px 18px;
    border-radius: 999px;
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.18);
    box-shadow: 0 18px 40px rgba(0,0,0,0.35);
}
.ebook-reader-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    z-index: 11;
    min-height: 44px;
    touch-action: manipulation;
}
.ebook-reader-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}
.ebook-reader-close:active {
    transform: scale(0.95);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .ebook-reader-overlay {
        padding: 0;
        align-items: stretch;
    }
    .ebook-reader-shell {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    .ebook-reader-pages {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 0;
    }
    .ebook-reader-header {
        padding: 12px 16px;
        font-size: 0.85rem;
        flex-direction: column;
        align-items: flex-start;
        flex-shrink: 0;
    }
    .ebook-reader-header > span:first-child {
        width: 100%;
        margin-bottom: 8px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .ebook-reader-header > span:last-child {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .ebook-reader-close {
        top: 12px;
        right: 16px;
        padding: 10px 14px;
        font-size: 0.85rem;
        min-height: 44px;
        min-width: 44px;
    }
    }

@media (max-width: 480px) {
    .ebook-reader-header {
        padding: 10px 12px;
        font-size: 0.8rem;
    }
    .ebook-reader-close {
        top: 10px;
        right: 12px;
        padding: 10px 12px;
        font-size: 0.8rem;
        min-width: 44px;
        min-height: 44px;
    }
    .ebook-reader-iframe-wrap {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    }

/* Touch-friendly improvements with 3D book effect */
@media (max-width: 768px) {
    .ebook-reader-iframe-wrap {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y pinch-zoom;
    }
    .ebook-reader-iframe-wrap iframe {
        touch-action: pan-y pinch-zoom;
    }
    /* Keep 3D book effect on mobile with enhanced visuals */
    .ebook-reader-shell::before {
        display: block;
        width: 18px;
        background:
            linear-gradient(to right, rgba(0,0,0,0.5), rgba(0,0,0,0.25) 35%, rgba(255,255,255,0.25) 55%, rgba(0,0,0,0.4)),
            repeating-linear-gradient(
                to bottom,
                rgba(255,255,255,0.5),
                rgba(255,255,255,0.5) 2px,
                rgba(230,220,200,0.75) 3px,
                rgba(230,220,200,0.75) 4px
            );
    }
    .ebook-reader-shell::after {
        display: block;
        width: 20px;
        background: linear-gradient(to left, rgba(0,0,0,0.6), rgba(0,0,0,0.0));
    }
}
/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    .ebook-reader-overlay {
        -webkit-overflow-scrolling: touch;
        -webkit-perspective: 1200px;
    }
    .ebook-reader-iframe-wrap {
        -webkit-overflow-scrolling: touch;
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        -webkit-transform-style: preserve-3d;
    }
    .ebook-reader-shell {
        transform: translateZ(0);
        -webkit-transform: translateZ(0);
        -webkit-transform-style: preserve-3d;
        -webkit-backface-visibility: hidden;
    }
    .ebook-reader-pages {
        -webkit-transform-style: preserve-3d;
    }
}
/* Android specific fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    .ebook-reader-iframe-wrap {
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
    .ebook-reader-shell {
        will-change: transform;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
}
/* Enhanced 3D perspective for better book effect */
@media (max-width: 768px) {
    .ebook-reader-overlay {
        perspective: 1000px;
        -webkit-perspective: 1000px;
    }
}

