:root {
    --agl-fb-bg: #14161a;
    --agl-fb-bar: rgba(20, 22, 26, .82);
    --agl-fb-ink: #e9eaee;
    --agl-fb-dim: #9aa0ab;
    --agl-fb-line: rgba(255, 255, 255, .12);
    --agl-fb-hit: rgba(255, 255, 255, .1);
}

* {
    box-sizing: border-box;
}

html,
body.agl-fb-body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: var(--agl-fb-bg);
    color: var(--agl-fb-ink);
    font: 400 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

#agl-fb-root {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
}

.agl-fb-noscript {
    margin: 0;
    padding: 24px;
    text-align: center;
}

.agl-fb-noscript img {
    max-width: 100%;
    height: auto;
}

/* --------------------------------------------------------------- stage */

.agl-fb-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    overflow: hidden;
}

/* Perspective has to sit on the book's direct parent: the zoom transform on this
   element would otherwise flatten the 3D context and the turn would read as a
   horizontal squash rather than a page lifting off the spine. */
.agl-fb-viewport {
    position: relative;
    transform-origin: 50% 50%;
}

.agl-fb-viewport.is-3d {
    perspective: 1180px;
    perspective-origin: 50% 42%;
}

.agl-fb-stage.is-zoomed .agl-fb-viewport {
    will-change: transform;
}

.agl-fb-stage.is-zoomed {
    cursor: grab;
}

.agl-fb-stage.is-panning {
    cursor: grabbing;
}

.agl-fb-book {
    position: relative;
    transform-style: preserve-3d;
    transition: transform .42s cubic-bezier(.4, 0, .2, 1);
}

.agl-fb-book.is-turning {
    transition: none;
    will-change: transform;
}

/* --------------------------------------------------------------- pages */

.agl-fb-slot {
    position: absolute;
    top: 0;
    height: 100%;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 18px 46px rgba(0, 0, 0, .55);
    /* Keep static pages on the book plane so a turning leaf cannot dive under them. */
    transform: translateZ(0);
}

.agl-fb-slot--left {
    left: 0;
    width: 50%;
    border-radius: 3px 0 0 3px;
}

.agl-fb-slot--right {
    right: 0;
    width: 50%;
    border-radius: 0 3px 3px 0;
}

.agl-fb-slot--solo {
    left: 0;
    width: 100%;
    border-radius: 3px;
}

.agl-fb-slot.is-empty {
    background: #1b1e24;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, .5);
}

.agl-fb-paper {
    position: absolute;
    inset: 0;
    background: #fff no-repeat center;
    background-size: 100% 100%;
    user-select: none;
    -webkit-user-select: none;
}

/* OCR is page-level strings, not glyph boxes. Keep it out of hit-testing and
   selection so a drag turns the leaf instead of painting a full-page highlight. */
.agl-fb-text {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    color: transparent;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

.agl-fb-copy {
    display: none;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 6px;
    max-height: 28vh;
    padding: 8px 12px 10px;
    background: var(--agl-fb-bar);
    border-top: 1px solid var(--agl-fb-line);
    z-index: 21;
}

.agl-fb-copy.is-open {
    display: flex;
}

.agl-fb-copy-label {
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--agl-fb-dim);
}

.agl-fb-copy-body {
    margin: 0;
    max-height: 22vh;
    overflow: auto;
    padding: 8px 10px;
    border-radius: 8px;
    background: #f4f1ea;
    color: #1b1b1b;
    font: 13px/1.45 Georgia, "Times New Roman", serif;
    user-select: text;
    -webkit-user-select: text;
    white-space: pre-wrap;
    cursor: text;
}

.agl-fb-find {
    display: none;
    flex: 0 0 auto;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--agl-fb-bar);
    border-top: 1px solid var(--agl-fb-line);
    z-index: 21;
}

.agl-fb-find.is-open {
    display: flex;
}

.agl-fb-find-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--agl-fb-line);
    border-radius: 8px;
    background: #1c1f26;
    color: var(--agl-fb-ink);
    font: inherit;
}

.agl-fb-find-count {
    flex: 0 0 auto;
    min-width: 52px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    color: var(--agl-fb-dim);
}

.agl-fb-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    opacity: 1;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

.agl-fb-img.is-pending {
    opacity: 0;
}

.agl-fb-img--slice {
    inset: auto;
    top: 0;
    bottom: 0;
    height: 100%;
}

/* The gutter shadow that makes two flat pages read as one bound book. */
.agl-fb-gutter {
    position: absolute;
    top: 0;
    height: 100%;
    width: 8%;
    left: 46%;
    pointer-events: none;
    z-index: 4;
    background: linear-gradient(90deg,
            rgba(0, 0, 0, 0) 0%,
            rgba(0, 0, 0, .16) 38%,
            rgba(0, 0, 0, .26) 50%,
            rgba(0, 0, 0, .16) 62%,
            rgba(0, 0, 0, 0) 100%);
}

/* ---------------------------------------------------------------- leaf */

.agl-fb-curl {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 7;
    pointer-events: none;
    /* Book uses preserve-3d; without a positive Z the canvas shares the slot plane. */
    transform: translateZ(24px);
}

.agl-fb-leaf {
    position: absolute;
    top: 0;
    height: 100%;
    transform-style: preserve-3d;
    will-change: transform;
    z-index: 6;
    pointer-events: none;
}

.agl-fb-leaf--fwd {
    transform-origin: left center;
}

.agl-fb-leaf--back {
    transform-origin: right center;
}

.agl-fb-face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: #fff;
    box-shadow: 0 18px 46px rgba(0, 0, 0, .5);
}

.agl-fb-face--back {
    transform: rotateY(180deg);
}

/* Blank verso for single-up turning, where the sheet's other side is not a page
   we hold an image for. A flat white rectangle reads as a bug; paper does not. */
.agl-fb-blank {
    background:
        linear-gradient(105deg, #f4f2ee 0%, #e8e5df 48%, #dedad2 100%);
}

.agl-fb-shade {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
}

.agl-fb-shade--lift {
    background: linear-gradient(90deg, rgba(0, 0, 0, .5) 0%, rgba(0, 0, 0, .06) 42%, rgba(0, 0, 0, 0) 100%);
}

.agl-fb-shade--liftback {
    background: linear-gradient(270deg, rgba(0, 0, 0, .5) 0%, rgba(0, 0, 0, .06) 42%, rgba(0, 0, 0, 0) 100%);
}

.agl-fb-shade--cast {
    background: linear-gradient(90deg, rgba(0, 0, 0, .45) 0%, rgba(0, 0, 0, .1) 55%, rgba(0, 0, 0, 0) 100%);
}

.agl-fb-shade--castback {
    background: linear-gradient(270deg, rgba(0, 0, 0, .45) 0%, rgba(0, 0, 0, .1) 55%, rgba(0, 0, 0, 0) 100%);
}

/* ------------------------------------------------------------- flippers */

.agl-fb-edge {
    position: absolute;
    top: 0;
    height: 100%;
    width: 13%;
    min-width: 44px;
    max-width: 120px;
    z-index: 8;
    border: 0;
    padding: 0;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    opacity: 0;
    transition: opacity .2s ease;
}

.agl-fb-edge:disabled {
    cursor: default;
    opacity: 0 !important;
}

.agl-fb-stage:hover .agl-fb-edge:not(:disabled),
.agl-fb-edge:focus-visible {
    opacity: 1;
}

.agl-fb-edge--prev {
    left: 0;
}

.agl-fb-edge--next {
    right: 0;
}

.agl-fb-edge span {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(12, 12, 14, .72);
    box-shadow:
        0 0 0 1.5px rgba(255, 255, 255, .92),
        0 2px 10px rgba(0, 0, 0, .28);
    backdrop-filter: blur(6px);
}

.agl-fb-edge svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: #fff;
    stroke-width: 2.25;
    stroke-linecap: round;
    stroke-linejoin: round;
    /* Hard 1px outline so the chevron reads on cream pages and dark plates. */
    filter:
        drop-shadow(1px 0 0 #111)
        drop-shadow(-1px 0 0 #111)
        drop-shadow(0 1px 0 #111)
        drop-shadow(0 -1px 0 #111);
}

.agl-fb-stage.is-zoomed .agl-fb-edge {
    display: none;
}

/* -------------------------------------------------------------- toolbar */

.agl-fb-bar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    background: var(--agl-fb-bar);
    backdrop-filter: saturate(1.4) blur(14px);
    border-top: 1px solid var(--agl-fb-line);
    z-index: 20;
}

.agl-fb-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--agl-fb-dim);
    font-size: 13px;
    padding-right: 8px;
}

.agl-fb-btn {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--agl-fb-ink);
    cursor: pointer;
    transition: background .15s ease, opacity .15s ease;
}

.agl-fb-btn:hover:not(:disabled) {
    background: var(--agl-fb-hit);
}

.agl-fb-btn:disabled {
    opacity: .3;
    cursor: default;
}

.agl-fb-btn[aria-pressed="true"] {
    background: var(--agl-fb-hit);
    color: #fff;
}

.agl-fb-btn svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.agl-fb-pager {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    margin: 0;
    padding: 0 2px;
}

.agl-fb-page {
    width: 3.25em;
    min-height: 36px;
    min-width: 44px;
    padding: 0 6px;
    border: 1px solid var(--agl-fb-line);
    border-radius: 8px;
    background: var(--agl-fb-hit);
    color: var(--agl-fb-ink);
    font: inherit;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    line-height: 1.2;
    text-align: center;
    cursor: text;
}

.agl-fb-page:focus {
    outline: 2px solid #7db1ff;
    outline-offset: 2px;
}

.agl-fb-page[aria-invalid="true"] {
    border-color: #f0a0a0;
}

.agl-fb-page-total {
    color: var(--agl-fb-dim);
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    white-space: nowrap;
    user-select: none;
}

.agl-fb-sep {
    flex: 0 0 auto;
    width: 1px;
    height: 22px;
    margin: 0 4px;
    background: var(--agl-fb-line);
}

.agl-fb-btn:focus-visible,
.agl-fb-edge:focus-visible {
    outline: 2px solid #7db1ff;
    outline-offset: 2px;
}

.agl-fb-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Prefetch tray: must stay in the render tree (not display:none) so the
   browser actually fetches and decodes upcoming pages. */
#agl-fb-cache {
    position: fixed;
    left: 0;
    top: 0;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

#agl-fb-cache .agl-fb-img {
    position: absolute;
    width: 1000px;
    height: auto;
    inset: auto;
}

@media (max-width: 640px) {
    .agl-fb-title {
        display: none;
    }

    .agl-fb-bar {
        gap: 2px;
        justify-content: space-between;
        padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    }

    .agl-fb-btn {
        width: 40px;
        height: 40px;
    }

    .agl-fb-page,
    .agl-fb-pager {
        min-height: 40px;
    }

    .agl-fb-page {
        width: 2.8em;
        font-size: 13px;
    }

    .agl-fb-edge {
        display: none;
    }

    /* Jump-to-end is redundant next to swipe, and keeping it would push the
       download button off a 390 px bar. */
    .agl-fb-btn--jump,
    .agl-fb-sep {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .agl-fb-img.is-pending {
        transition: none;
    }
}
