/* BookSpread (components/BookSpread, motion in js/bookSpread.js): a book
   taken from the shelf, 300 x 440 px with 44 px of pages, opened into a
   two-page spread. Leather in the book's colour (--c), brass from the
   theme, the pages are paper in every theme. */

.book-spread {
    --bs-depth: 44px;
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: grid;
    place-items: center;
    outline: none;
}

.book-spread-dim {
    position: absolute;
    inset: 0;
    background: rgba(5, 3, 2, 0);
    transition: background-color 0.55s ease, backdrop-filter 0.55s ease;
}

.book-spread.is-open .book-spread-dim {
    background: rgba(5, 3, 2, 0.74);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

.book-spread-close {
    position: fixed;
    z-index: 2;
    top: 20px;
    right: 24px;
    padding: 8px 12px;
    border: 1px solid color-mix(in srgb, var(--shelf-brass) 45%, transparent);
    border-radius: 8px;
    background: rgba(10, 6, 3, 0.6);
    color: #eadfc6;
    font: 500 13px/1.2 var(--font-family-ui);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.book-spread.is-open .book-spread-close {
    opacity: 1;
    transition-delay: 0.9s;
}

.book-spread-close:focus-visible {
    outline: 2px solid var(--shelf-brass-hi);
    outline-offset: 2px;
}

.book-spread-fit {
    position: relative;
    width: 300px;
    height: 440px;
}

.book-spread-scene {
    position: absolute;
    inset: 0;
    perspective: 2000px;
    perspective-origin: 50% 40%;
}

.book-spread-book {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
}

.book-spread-book > div {
    position: absolute;
}

.book-spread-back {
    inset: 0;
    border-radius: 3px 8px 8px 3px;
    transform: translateZ(calc(var(--bs-depth) / -2));
    background: url("../images/themes/books/leather_grain.webp") center / 220px, var(--c);
    background-blend-mode: multiply;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}

.book-spread-spine {
    top: 0;
    bottom: 0;
    left: calc(var(--bs-depth) / -2);
    width: var(--bs-depth);
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 8px / 5px;
    transform: rotateY(-90deg);
    background:
        repeating-linear-gradient(180deg, transparent 0 9%, color-mix(in srgb, var(--shelf-brass-hi) 60%, transparent) 9% 9.6%, transparent 9.6% 11%, color-mix(in srgb, var(--shelf-brass-hi) 60%, transparent) 11% 11.6%, transparent 11.6% 88%, color-mix(in srgb, var(--shelf-brass-hi) 60%, transparent) 88% 88.6%, transparent 88.6%),
        linear-gradient(90deg, rgba(0, 0, 0, 0.55), rgba(255, 255, 255, 0.12) 38%, rgba(0, 0, 0, 0.6)),
        url("../images/themes/books/leather_grain.webp") center / 200px,
        var(--c);
    background-blend-mode: normal, normal, multiply, normal;
}

.book-spread-spine span {
    max-height: 66%;
    overflow: hidden;
    color: var(--shelf-brass-hi);
    font: 700 15px/1.1 "Cormorant Garamond", Georgia, serif;
    text-overflow: ellipsis;
    white-space: nowrap;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
}

.book-spread-edge {
    background: repeating-linear-gradient(90deg, #f3ead2 0 1.5px, #d9cba6 1.5px 2.5px);
}

.book-spread-edge--fore {
    top: 4px;
    bottom: 4px;
    left: calc(100% - var(--bs-depth) / 2 - 3px);
    width: calc(var(--bs-depth) - 4px);
    transform: rotateY(90deg);
}

.book-spread-edge--top,
.book-spread-edge--bottom {
    left: 2px;
    right: 5px;
    height: calc(var(--bs-depth) - 4px);
    background: repeating-linear-gradient(0deg, #f3ead2 0 1.5px, #d9cba6 1.5px 2.5px);
}

.book-spread-edge--top {
    top: calc(var(--bs-depth) / -2 + 3px);
    transform: rotateX(90deg);
}

.book-spread-edge--bottom {
    bottom: calc(var(--bs-depth) / -2 + 3px);
    transform: rotateX(-90deg);
}

/* The first page, under the cover. */
.book-spread-page {
    inset: 4px 4px 4px 0;
    display: flex;
    flex-direction: column;
    padding: 34px 30px 26px 34px;
    overflow: hidden;
    border-radius: 0 6px 6px 0;
    transform: translateZ(calc(var(--bs-depth) / 2 - 3px));
    background: linear-gradient(90deg, rgba(120, 90, 40, 0.25), transparent 8%), #f4ead3;
    color: #3b2a16;
}

.book-spread-page h3 {
    margin: 0;
    font: 700 26px/1.08 "Cormorant Garamond", Georgia, serif;
    overflow-wrap: anywhere;
}

.book-spread-by {
    margin: 6px 0 14px;
    color: #6f5228;
    font: italic 500 16px/1.2 "Cormorant Garamond", Georgia, serif;
}

.book-spread-description {
    display: -webkit-box;
    margin: 0 0 10px;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 7;
    font: 16px/1.45 "Cormorant Garamond", Georgia, serif;
}

.book-spread-facts {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 12px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid rgba(122, 90, 44, 0.3);
    color: #6f5228;
    font: 500 12px/1.3 var(--font-family-ui);
}

.book-spread-bar {
    height: 3px;
    margin-top: 8px;
    border-radius: 2px;
    background: rgba(59, 42, 22, 0.15);
}

.book-spread-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: #b48a3a;
}

.book-spread-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.book-spread-action {
    padding: 8px 14px;
    border: 1px solid #3b2a16;
    border-radius: 6px;
    color: #3b2a16;
    font: 600 13px/1.2 var(--font-family-ui);
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.book-spread-action:hover {
    background: rgba(59, 42, 22, 0.08);
}

.book-spread-action--primary {
    background: #3b2a16;
    color: #f3e2b5;
}

.book-spread-action--primary:hover {
    background: #4b371e;
}

.book-spread-action:focus-visible {
    outline: 2px solid #8c6a24;
    outline-offset: 2px;
}

/* The cover: a board hinged at the spine, the picture (or tooled leather)
   outside, the endpaper with the cover as a plate inside. */
.book-spread-cover {
    inset: 0;
    transform-origin: left center;
    transform: translateZ(calc(var(--bs-depth) / 2));
    transform-style: preserve-3d;
}

.book-spread-cover > div {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border-radius: 3px 8px 8px 3px;
    backface-visibility: hidden;
}

.book-spread-cover-out {
    background: url("../images/themes/books/leather_grain.webp") center / 220px, var(--c);
    background-blend-mode: multiply;
}

.book-spread-cover-out img {
    position: absolute;
    z-index: 1;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    animation: book-spread-fade 0.5s ease both;
}

.book-spread-cover-out::after {
    content: "";
    position: absolute;
    z-index: 2;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.15) 3.5%, rgba(255, 255, 255, 0.16) 5%, rgba(0, 0, 0, 0.22) 6.5%, transparent 10%),
        linear-gradient(115deg, transparent 40%, rgba(255, 255, 255, 0.1) 50%, transparent 60%);
}

.book-spread-tooled {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
}

.book-spread-tooled::before {
    content: "";
    position: absolute;
    inset: 12px 12px 12px 20px;
    border: 1.5px solid color-mix(in srgb, var(--shelf-brass-hi) 60%, transparent);
    border-radius: 3px;
}

.book-spread-tooled b {
    position: absolute;
    top: 40px;
    left: 30px;
    right: 22px;
    color: var(--shelf-brass-hi);
    font: 700 26px/1.1 "Cormorant Garamond", Georgia, serif;
    text-align: center;
}

.book-spread-tooled i {
    width: 46%;
    aspect-ratio: 1;
    background: linear-gradient(160deg, var(--shelf-brass-hi), var(--shelf-brass) 50%, var(--shelf-brass-lo));
    -webkit-mask: url("../images/themes/books/rosette.svg") center / contain no-repeat;
    mask: url("../images/themes/books/rosette.svg") center / contain no-repeat;
}

.book-spread-cover-in {
    display: grid;
    place-items: center;
    border-radius: 8px 3px 3px 8px !important;
    transform: rotateY(180deg);
    background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.2), transparent 50%), repeating-linear-gradient(45deg, rgba(120, 80, 40, 0.06) 0 6px, transparent 6px 12px), #efe3c7;
    box-shadow: inset -14px 0 22px rgba(120, 90, 40, 0.3);
}

.book-spread-plate {
    position: relative;
    width: 62%;
    aspect-ratio: 2 / 3;
    overflow: hidden;
    background: url("../images/themes/books/leather_grain.webp") center / 160px, var(--c);
    background-blend-mode: multiply;
    box-shadow: 0 10px 22px rgba(60, 40, 10, 0.4);
    outline: 1px solid rgba(160, 120, 60, 0.5);
    outline-offset: 7px;
}

.book-spread-plate img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    animation: book-spread-fade 0.5s ease both;
}

.book-spread-plate b {
    position: absolute;
    top: 18px;
    left: 10px;
    right: 10px;
    color: var(--shelf-brass-hi);
    font: 700 17px/1.1 "Cormorant Garamond", Georgia, serif;
    text-align: center;
}

@keyframes book-spread-fade {
    from { opacity: 0; }
}

/* The shelf's own book while it is out. */
.is-taken {
    visibility: hidden;
}

@media (prefers-reduced-motion: reduce) {
    .book-spread-dim,
    .book-spread-close {
        transition: none;
    }

    .book-spread-cover-out img,
    .book-spread-plate img {
        animation: none;
    }
}
