/* ========================================
   RASTI - Book Viewer Modal
   ======================================== */

@font-face {
    font-family: 'Placard Next';
    src: url('/public/fonts/PlacardNextRegular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Placard Next';
    src: url('/public/fonts/PlacardNextBold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Bison';
    src: url('/public/fonts/Bison-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Bison';
    src: url('/public/fonts/Bison-Bold(PersonalUse).ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url('/public/fonts/Montserrat-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

html.book-viewer-lock,
body.book-viewer-lock {
    overflow: hidden !important;
    overscroll-behavior: contain;
}

/* Modal Overlay */
.book-modal {
    position: fixed;
    inset: 0;
    width: 100vw;
    min-height: 100vh;
    min-height: 100dvh;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    overflow: hidden;
    overscroll-behavior: contain;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    color-scheme: light only;
    --book-viewer-text-color: #1f2a44;
    --book-viewer-front-copy-color: #33363f;
    --book-viewer-front-title-color: #545454;
    --book-viewer-front-subtitle-color: #5b5464;
    --book-viewer-text-page-color: #31415d;
    --book-viewer-dedication-color: #9f9f9e;
}

.book-modal.active {
    opacity: 1;
    visibility: visible;
}

.book-modal .book-modal-content,
.book-modal .flipbook-container,
.book-modal .flipbook,
.book-modal .book-page,
.book-modal .book-page-surface,
.book-modal .book-page-text,
.book-modal .book-page-front-copy,
.book-modal .book-page-front-title,
.book-modal .book-page-front-subtitle {
    color-scheme: light only;
    forced-color-adjust: none;
}

/* Modal Content */
.book-modal-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem;
    box-sizing: border-box;
    width: 100%;
    max-width: 95vw;
    max-height: 95vh;
}

/* Close Button */
.book-modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.75rem;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.book-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Flipbook Container */
.flipbook-container {
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border-radius: 4px;
    overflow: visible;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.flipbook {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: visible;
}

/* Center when showing cover only */
.flipbook-container.cover-mode {
    transform: translateX(0);
    box-shadow: none;
}

/* Center when showing backcover only */
.flipbook-container.backcover-mode {
    transform: translateX(0);
    box-shadow: none;
}

/* Normal position when book is open (two pages) */
.flipbook-container.open-mode {
    transform: translateX(0);
}

/* Page Flip Styles */
.flipbook-container .stf__parent {
    background: transparent !important;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: visible !important;
}

/* Center the cover by shifting left (cover is on right side) */
.flipbook-container.cover-mode .stf__parent {
    transform: translateX(-25%);
}

/* Center the backcover by shifting right (backcover is on left side) */
.flipbook-container.backcover-mode .stf__parent {
    transform: translateX(25%);
}

/* Remove all shadows and backgrounds in cover/backcover mode */
.flipbook-container.cover-mode .stf__wrapper,
.flipbook-container.backcover-mode .stf__wrapper {
    box-shadow: none !important;
    background: transparent !important;
}

.flipbook-container .stf__wrapper {
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
    overflow: visible !important;
}

.flipbook-container .stf__block {
    overflow: visible !important;
}

/* Individual Pages */
.book-page {
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.book-page-surface {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    overflow: hidden;
}

.book-page--cover,
.book-page--backcover,
.book-page--dedication {
    overflow: visible;
}

.book-page--cover .book-page-surface::before,
.book-page--backcover .book-page-surface::after,
.book-page--dedication .book-page-surface::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 24px;
    pointer-events: none;
    z-index: 3;
}

.book-page--cover .book-page-surface::before {
    left: 0;
    border-radius: 8px 0 0 8px;
    background:
        linear-gradient(to right,
            rgba(247, 246, 244, 0.98) 0%,
            rgba(255, 255, 255, 0.99) 6%,
            rgba(252, 251, 249, 0.99) 14%,
            rgba(248, 246, 243, 0.99) 28%,
            rgba(244, 241, 238, 0.99) 42%,
            rgba(252, 251, 249, 0.99) 54%,
            rgba(246, 243, 240, 0.99) 61%,
            rgba(236, 231, 226, 0.36) 68%,
            rgba(222, 216, 211, 0.30) 73%,
            rgba(205, 199, 193, 0.28) 78%,
            rgba(220, 214, 209, 0.26) 84%,
            rgba(234, 229, 224, 0.25) 90%,
            rgba(245, 242, 239, 0.10) 96%,
            rgba(255, 255, 255, 0.01) 100%
        ),
        linear-gradient(to right,
            rgba(255, 255, 255, 0.28) 0%,
            rgba(255, 255, 255, 0.08) 18%,
            rgba(255, 255, 255, 0.00) 52%,
            rgba(255, 255, 255, 0.04) 70%,
            rgba(255, 255, 255, 0.00) 100%
        ),
        linear-gradient(to bottom,
            rgba(246, 244, 241, 0.98) 0%,
            rgba(235, 231, 226, 0.98) 50%,
            rgba(248, 246, 243, 0.98) 100%
        );
    box-shadow:
        inset -2px 0 3px rgba(0, 0, 0, 0.07),
        inset 2px 0 2px rgba(255, 255, 255, 0.42),
        1px 0 0 rgba(206, 200, 194, 0.22);
    border-right: 1px solid rgba(206, 200, 194, 0.22);
}

.book-page--backcover .book-page-surface::after,
.book-page--dedication .book-page-surface::after {
    right: 0;
    border-radius: 0 8px 8px 0;
    background:
        linear-gradient(to left,
            rgba(247, 246, 244, 0.98) 0%,
            rgba(255, 255, 255, 1) 6%,
            rgba(252, 251, 249, 0.99) 14%,
            rgba(248, 246, 243, 0.97) 28%,
            rgba(244, 241, 238, 0.94) 42%,
            rgba(252, 251, 249, 0.90) 54%,
            rgba(246, 243, 240, 0.78) 61%,
            rgba(236, 231, 226, 0.36) 68%,
            rgba(222, 216, 211, 0.20) 73%,
            rgba(205, 199, 193, 0.28) 78%,
            rgba(220, 214, 209, 0.20) 84%,
            rgba(234, 229, 224, 0.12) 90%,
            rgba(245, 242, 239, 0.07) 96%,
            rgba(255, 255, 255, 0.03) 100%
        ),
        linear-gradient(to left,
            rgba(255, 255, 255, 0.28) 0%,
            rgba(255, 255, 255, 0.08) 18%,
            rgba(255, 255, 255, 0.00) 52%,
            rgba(255, 255, 255, 0.04) 70%,
            rgba(255, 255, 255, 0.00) 100%
        ),
        linear-gradient(to bottom,
            rgba(246, 244, 241, 0.98) 0%,
            rgba(235, 231, 226, 0.98) 50%,
            rgba(248, 246, 243, 0.98) 100%
        );
    box-shadow:
        inset 2px 0 3px rgba(0, 0, 0, 0.07),
        inset -2px 0 2px rgba(255, 255, 255, 0.42),
        -1px 0 0 rgba(206, 200, 194, 0.22);
    border-left: 1px solid rgba(206, 200, 194, 0.22);
}

.book-page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #ffffff;
}

.book-page-text {
    position: absolute;
    left: 8%;
    top: 5%;
    width: 84%;
    height: 35%;
    z-index: 2;
    font-family: var(--font-sans);
    color: var(--book-viewer-text-color, #1f2a44);
    -webkit-text-fill-color: var(--book-viewer-text-color, #1f2a44);
    --viewer-font-size-base: clamp(12px, 1.6vw, 18px);
    font-size: var(--viewer-font-size-base);
    line-height: 1.25;
    text-align: left;
    white-space: pre-wrap;
    overflow: hidden;
    user-select: text;
    cursor: default;
    box-sizing: border-box;
}

.book-page-text[contenteditable="true"] {
    outline: none;
}

.book-page-text.book-page-title {
    font-family: var(--font-display);
    text-align: center;
    --viewer-font-size-base: clamp(16px, 2.4vw, 30px);
    font-size: var(--viewer-font-size-base);
    line-height: 1.1;
}

.book-page-front-copy {
    position: absolute;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--book-viewer-front-copy-color, #33363f);
    -webkit-text-fill-color: var(--book-viewer-front-copy-color, #33363f);
    overflow: hidden;
    box-sizing: border-box;
    padding: 4.5% 5.5%;
}

.book-page-front-title {
    font-family: 'Placard Next', var(--font-display), sans-serif;
    font-weight: 400;
    font-size: 120px;
    line-height: 1.08;
    letter-spacing: 0.015em;
    text-transform: uppercase;
    color: var(--book-viewer-front-title-color, #545454);
    -webkit-text-fill-color: var(--book-viewer-front-title-color, #545454);
    width: auto;
    max-width: 100%;
    margin: 0;
    overflow-wrap: break-word;
    word-break: normal;
    white-space: normal;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-rendering: geometricPrecision;
}

.book-page-front-line {
    display: block;
    width: max-content;
    max-width: none;
    white-space: nowrap;
    margin: 0;
}

.book-page-front-subtitle {
    max-width: 24ch;
    font-family: 'Placard Next', var(--font-display), sans-serif;
    font-size: clamp(12px, 1.7vw, 20px);
    font-weight: 400;
    line-height: 1.15;
    letter-spacing: 0.01em;
    color: var(--book-viewer-front-subtitle-color, #5b5464);
    -webkit-text-fill-color: var(--book-viewer-front-subtitle-color, #5b5464);
    text-wrap: balance;
}

.book-page-text--text-page {
    font-family: 'Montserrat', var(--font-ui), sans-serif;
    font-weight: 400;
    color: var(--book-viewer-text-page-color, #31415d);
    -webkit-text-fill-color: var(--book-viewer-text-page-color, #31415d);
    --viewer-font-size-base: 0.95rem;
    font-size: var(--viewer-font-size-base);
    line-height: 1.55;
    text-align: center;
    text-justify: auto;
    hyphens: manual;
    padding: 0.75rem 0.85rem;
}

.book-page-text--dedication {
    color: var(--book-viewer-dedication-color, #9f9f9e);
    -webkit-text-fill-color: var(--book-viewer-dedication-color, #9f9f9e);
    font-family: 'Bison', var(--font-display), sans-serif;
    font-weight: 400;
    --viewer-font-size-base: 28px;
    font-size: var(--viewer-font-size-base);
    font-style: normal;
    letter-spacing: 0.035em;
    line-height: 1.28;
    text-wrap: balance;
    box-sizing: border-box;
    padding: 7% 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: scaleY(0.92);
    transform-origin: center center;
}

@media (forced-colors: active) {
    .book-modal .book-page-text {
        color: var(--book-viewer-text-color, #1f2a44) !important;
        -webkit-text-fill-color: var(--book-viewer-text-color, #1f2a44) !important;
        forced-color-adjust: none;
    }

    .book-modal .book-page-front-copy {
        color: var(--book-viewer-front-copy-color, #33363f) !important;
        -webkit-text-fill-color: var(--book-viewer-front-copy-color, #33363f) !important;
        forced-color-adjust: none;
    }

    .book-modal .book-page-front-title {
        color: var(--book-viewer-front-title-color, #545454) !important;
        -webkit-text-fill-color: var(--book-viewer-front-title-color, #545454) !important;
        forced-color-adjust: none;
    }

    .book-modal .book-page-front-subtitle {
        color: var(--book-viewer-front-subtitle-color, #5b5464) !important;
        -webkit-text-fill-color: var(--book-viewer-front-subtitle-color, #5b5464) !important;
        forced-color-adjust: none;
    }

    .book-modal .book-page-text--text-page {
        color: var(--book-viewer-text-page-color, #31415d) !important;
        -webkit-text-fill-color: var(--book-viewer-text-page-color, #31415d) !important;
    }

    .book-modal .book-page-text--dedication {
        color: var(--book-viewer-dedication-color, #9f9f9e) !important;
        -webkit-text-fill-color: var(--book-viewer-dedication-color, #9f9f9e) !important;
    }
}


.book-highlight {
    position: absolute;
    border: none;
    background: rgba(255, 214, 102, 0.55);
    border-radius: 4px;
    transform: scaleY(0.92);
    transform-origin: top center;
    cursor: pointer;
    z-index: 3;
    padding: 0;
    mix-blend-mode: multiply;
}

.book-highlight:focus-visible {
    outline: 2px solid rgba(189, 61, 117, 0.6);
    outline-offset: 2px;
}

.book-note-bubble {
    position: absolute;
    max-width: 280px;
    background: #fff5f8;
    border: 1px solid #f1b4c8;
    color: #3f3f46;
    border-radius: 16px;
    padding: 0.75rem 0.9rem;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    z-index: 6;
}

.book-note-bubble.active {
    opacity: 1;
    transform: translateY(0);
}

.book-note-bubble::after {
    content: "";
    position: absolute;
    left: 28px;
    bottom: -10px;
    border-width: 10px 10px 0 10px;
    border-style: solid;
    border-color: #fff5f8 transparent transparent transparent;
    filter: drop-shadow(0 -1px 0 #f1b4c8);
}

.book-note-bubble.bubble-bottom::after {
    top: -10px;
    bottom: auto;
    border-width: 0 10px 10px 10px;
    border-color: transparent transparent #fff5f8 transparent;
    filter: drop-shadow(0 1px 0 #f1b4c8);
}

.book-note-bubble .bubble-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #bd3d75;
    margin-bottom: 0.25rem;
}

.book-note-bubble .bubble-text {
    font-size: 0.9rem;
    line-height: 1.45;
    color: #3f3f46;
}

.book-highlight-editor-box {
    position: absolute;
    border: 2px dashed rgba(189, 61, 117, 0.9);
    background: rgba(189, 61, 117, 0.12);
    border-radius: 6px;
    z-index: 5;
    pointer-events: none;
}

.book-highlight-editor-indicator {
    position: absolute;
    top: 18px;
    right: 18px;
    background: rgba(189, 61, 117, 0.12);
    color: #bd3d75;
    border: 1px solid rgba(189, 61, 117, 0.3);
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    display: none;
    z-index: 6;
}

.book-modal.highlight-editor-active .book-highlight-editor-indicator {
    display: inline-flex;
}

/* Book Controls */
.book-controls {
    display: flex;
    align-items: center;
    gap: 2rem;
    background: rgba(255, 255, 255, 0.15);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    backdrop-filter: blur(10px);
}

.book-controls button {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 1.25rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-controls button:hover:not(:disabled) {
    background: var(--primary);
    color: white;
}

.book-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-indicator {
    color: white;
    font-size: 0.95rem;
    font-weight: 500;
    min-width: 80px;
    text-align: center;
}

/* Book Title in Modal */
.book-modal-title {
    color: white;
    font-family: var(--font-display);
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: -0.5rem;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.book-modal.mobile-landscape-spread .book-controls {
    display: none;
}

.book-modal.mobile-landscape-spread .book-modal-title {
    display: none;
}

.book-modal.mobile-single-page .flipbook-container.cover-mode .stf__parent,
.book-modal.mobile-single-page .flipbook-container.backcover-mode .stf__parent {
    transform: translateX(0);
}

/* Responsive */
@media (max-width: 768px) {
    .book-page-text--text-page {
        font-size: clamp(12px, 1.45vw, 18px);
    }

    .book-modal {
        align-items: stretch;
        justify-content: center;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .book-modal-content {
        min-height: 100vh;
        min-height: 100dvh;
        max-width: 100vw;
        max-height: none;
        padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem max(0.75rem, env(safe-area-inset-bottom));
        gap: 1rem;
        justify-content: center;
    }

    .book-modal-title {
        font-size: 1.1rem;
        padding: 0 3.5rem 0 2.5rem;
        line-height: 1.3;
    }

    .flipbook-container {
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    }

    .book-controls {
        gap: 0.75rem;
        padding: 0.5rem 1rem;
    }

    .book-controls button {
        width: 36px;
        height: 36px;
        font-size: 1.1rem;
    }

    .page-indicator {
        font-size: 0.85rem;
        min-width: 60px;
    }

    .book-modal-close {
        position: fixed;
        top: max(10px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
        width: 36px;
        height: 36px;
        font-size: 1.5rem;
        background: rgba(0, 0, 0, 0.4);
        z-index: 10;
    }
}

@media (max-width: 480px) {
    .book-page-text--text-page {
        font-size: clamp(11px, 1.35vw, 16px);
    }

    .book-modal-content {
        padding: max(0.5rem, env(safe-area-inset-top)) 0.5rem max(0.5rem, env(safe-area-inset-bottom));
        gap: 0.75rem;
    }

    .book-modal-title {
        font-size: 1rem;
        margin-bottom: 0;
    }

    .book-controls {
        gap: 0.5rem;
        padding: 0.4rem 0.75rem;
    }

    .book-controls button {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    .page-indicator {
        font-size: 0.8rem;
        min-width: 50px;
    }

    .book-modal-close {
        top: max(8px, env(safe-area-inset-top));
        right: max(8px, env(safe-area-inset-right));
        width: 32px;
        height: 32px;
        font-size: 1.25rem;
    }
}

@media (orientation: landscape) and (max-height: 560px) {
    .book-modal .book-controls,
    .book-modal .book-modal-title {
        display: none !important;
    }

    .book-modal-content {
        padding: 0.35rem;
        gap: 0.35rem;
        max-width: 98vw;
        max-height: 98vh;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .book-modal-close {
        top: max(4px, env(safe-area-inset-top));
        right: max(6px, env(safe-area-inset-right));
    }
}

/* Removed drag hint - cleaner interface */
