.book-viewer-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.book-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6b4423, #8b5a2b);
    border-radius: 14px;
    padding: clamp(8px, 1.5vw, 20px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    box-sizing: border-box;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
}

/* Immersive reading mode: the site navbar is hidden on book pages entirely (see
   body.book-immersive in _Layout.cshtml) so the book can use that space too — the
   floating close ("x") button is the way out instead. */
body.book-immersive header {
    display: none;
}

.ps-book-close {
    position: fixed;
    top: 16px;
    right: 24px;
    z-index: 1010;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #ddd);
    color: var(--ink-secondary, #55606B);
    font-size: 1.2rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    text-decoration: none !important;
    transition: background .15s ease, color .15s ease, transform .15s ease, border-color .15s ease;
}

.ps-book-close:hover {
    background: var(--primary-tint, #eff4fe);
    color: var(--primary, #2563eb);
    border-color: var(--primary, #2563eb);
    transform: scale(1.08) rotate(90deg);
}

/* On the book-reading pages the back link and chapter title float in the top-left
   corner instead of sitting in normal flow above the stage — that flow space (plus
   the now-hidden navbar) is exactly what was capping how tall the book could render. */
.book-page-wide .ps-back-btn {
    position: fixed;
    top: 16px;
    left: 24px;
    z-index: 1010;
    margin-bottom: 0;
}

.book-page-title-float {
    position: fixed;
    top: 62px;
    left: 24px;
    z-index: 1005;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border, #ddd);
    border-radius: 999px;
    padding: 5px 16px;
    font-weight: 700;
    font-size: .85rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
    max-width: min(60vw, 380px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 767px) {
    .book-page-title-float { display: none; }
}

/* Small clearance so the book's own top edge doesn't tuck in under the floating
   back / title / close row — everything below this line is still free to use the
   rest of the viewport. */
.book-page-wide .book-loading,
.book-page-wide .book-viewer-wrap {
    margin-top: 46px;
}

@media (max-width: 576px) {
    .ps-book-close,
    .book-page-wide .ps-back-btn {
        top: 12px;
    }
    .ps-book-close {
        right: 12px;
        width: 36px;
        height: 36px;
        font-size: 1.05rem;
    }
    .book-page-wide .ps-back-btn {
        left: 12px;
        padding: 6px 12px 6px 10px;
        font-size: .8rem;
    }
}

#bookContainer .page {
    background-color: #fffdf7;
    background-size: cover;
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.15);
}

#bookContainer .pdf-page-content {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #fffdf7;
    isolation: isolate;
}

#bookContainer .pdf-page-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

#bookContainer .textLayer {
    position: absolute;
    inset: 0;
    overflow: hidden;
    opacity: 0.22;
    line-height: 1;
    text-align: initial;
    transform-origin: 0 0;
    z-index: 1;
    pointer-events: auto !important;
    cursor: text;
    user-select: text !important;
    -webkit-user-select: text !important;
    touch-action: auto;
}

#bookContainer .textLayer ::selection {
    color: #172a3a;
    background: rgba(48, 132, 220, 0.55);
}

#bookContainer .textLayer span {
    position: absolute;
    color: transparent;
    white-space: pre;
    transform-origin: 0% 0%;
    pointer-events: auto !important;
    user-select: text !important;
    -webkit-user-select: text !important;
}

#bookContainer .textLayer br { position: absolute; }

.book-selection-tools {
    position: fixed;
    z-index: 1100;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 8px;
    background: #172a3a;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
    color: #fff;
}

.book-selection-tool {
    min-width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}

.book-selection-tool:hover { background: rgba(255, 255, 255, .16); }

.book-selection-explanation {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1090;
    width: min(420px, calc(100vw - 32px));
    max-height: min(50vh, 420px);
    overflow: auto;
    padding: 14px;
    border: 1px solid #cbd5df;
    border-radius: 8px;
    background: #fff;
    color: #243443;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .24);
}

/* The book stage plus everything that floats on top of it (nav arrows, page count,
   action buttons) — kept as one positioning context so those controls overlay the
   book instead of taking up their own row and shrinking how big the book can be. */
.book-stage-outer {
    position: relative;
    display: flex;
    justify-content: center;
    width: 100%;
}

.book-nav-float {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: rgba(20, 14, 8, 0.55);
    color: #fff;
    font-size: 1.3rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    transition: transform .15s ease, background .15s ease;
}

.book-nav-float--prev { left: 2px; }
.book-nav-float--next { right: 2px; }

.book-nav-float:hover:not(:disabled) {
    background: rgba(20, 14, 8, 0.85);
    transform: translateY(-50%) scale(1.08);
}

.book-nav-float:disabled {
    opacity: .3;
    cursor: not-allowed;
}

.book-page-pill {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-weight: 600;
    font-size: .8rem;
    padding: 5px 14px;
    border-radius: 999px;
    white-space: nowrap;
}

.book-float-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 5;
    display: flex;
    gap: 8px;
}

.book-float-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    color: #33261a;
    font-size: 1.1rem;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    text-decoration: none !important;
    transition: transform .15s ease, background .15s ease;
}

.book-float-btn:hover {
    background: #fff;
    transform: scale(1.08);
    color: #33261a;
}

.book-float-btn--quiz { color: #1a7a3c; }

.book-notes-panel {
    position: absolute;
    top: 60px;
    right: 10px;
    z-index: 6;
    width: 280px;
    max-width: calc(100vw - 40px);
    background: #fff;
    color: #33261a;
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    padding: 14px;
}

@media (max-width: 576px) {
    .book-nav-float { width: 38px; height: 38px; font-size: 1.1rem; }
    .book-float-btn { width: 36px; height: 36px; font-size: 1rem; }
}

.book-loading {
    text-align: center;
    padding: 3rem 1rem;
    min-height: 40vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.book-loading .spinner-border {
    width: 3rem;
    height: 3rem;
}

.book-progress {
    width: min(260px, 70vw);
    height: 8px;
    background: var(--bg-surface-muted, #e2e8f0);
    border-radius: 4px;
    overflow: hidden;
    margin: 1rem auto .5rem;
}

.book-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #4facfe, #00f2fe);
    transition: width .3s ease;
}

/* Book pages fill the viewport instead of being capped by the normal content
   container — see body.book-page rule in site.css / _Layout. */
@media (min-width: 576px) {
    .book-page-wide {
        max-width: 100% !important;
        padding-left: var(--sp-4, 16px) !important;
        padding-right: var(--sp-4, 16px) !important;
    }
}

/* Celebration */
.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 2000;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    opacity: .9;
    animation-name: confetti-fall;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

@keyframes confetti-fall {
    to {
        transform: translateY(105vh) rotate(720deg);
        opacity: .3;
    }
}

@keyframes pop-in {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}

.celebrate-badge {
    animation: pop-in .5s cubic-bezier(.34, 1.56, .64, 1);
}
