html {
    scrollbar-gutter: stable;
}

html:has(.book-preview[open]),
body:has(> .book-preview[open]) {
    overflow: hidden;
}

.book-preview {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: hidden;
    background: transparent;
    color: #fff;
}

.book-preview::backdrop {
    background: rgb(0 0 0 / 80%);
}

.book-preview-layout {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: clamp(8px, 2vh, 20px);
    box-sizing: border-box;
    height: 100%;
    padding: clamp(12px, 3vw, 32px);
}

.book-preview-header,
.book-preview-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.book-preview-header {
    justify-content: space-between;
}

.book-preview-header h2 {
    margin: 0;
    color: inherit;
    font-size: clamp(1rem, 3vw, 1.4rem);
    font-weight: 600;
    line-height: 1.25;
}

.book-preview-stage {
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
    place-items: center;
    min-width: 0;
    overflow: hidden;
    padding: 4px;
    text-align: center;
    touch-action: pan-y pinch-zoom;
}

.book-preview-stage canvas {
    grid-area: 1 / 1;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    box-shadow: 0 2px 6px #0003;
    cursor: grab;
    user-select: none;
}

@media (prefers-reduced-motion: no-preference) {
    .book-preview[open],
    .book-preview[open]::backdrop {
        animation: book-preview-fade-in 220ms ease-out both;
    }
}

.book-preview-stage.book-preview-zoomed {
    overflow: auto;
    overscroll-behavior: contain;
    place-items: start;
    touch-action: manipulation;
}

.book-preview-zoomed canvas {
    width: var(--book-preview-zoom-width);
    height: auto;
    max-width: none;
    max-height: none;
    cursor: zoom-out;
}

@keyframes book-preview-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.book-preview-message p,
.book-preview-message a {
    color: inherit;
}

.book-preview-message {
    grid-area: 1 / 1;
}

.book-preview-message a {
    text-decoration: underline;
}

.book-preview-controls {
    justify-content: center;
}

.book-preview-status {
    flex: 0 0 12ch;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.book-preview-button {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid #d5d3cd;
    border-radius: 3px;
    background: #fff;
    color: #252525;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.book-preview-button:hover:not(:disabled) {
    background: #e8e6e0;
}

.book-preview-button:disabled {
    opacity: .4;
    cursor: default;
}
