/* Plugin CSS owns geometry and motion. Per-instance values arrive through a
   nonce-backed style block from BookCoverComponent, avoiding inline style attrs. */
.va-book-container {
    --va-book-resolved-width: var(--va-book-width, 22.5rem);
    --va-book-resolved-height: var(--va-book-height, 33.75rem);
    --va-book-resolved-depth: var(--va-book-depth, 3.125rem);
    --va-book-unit-x: calc(var(--va-book-resolved-width) / 360);
    --va-book-unit-y: calc(var(--va-book-resolved-height) / 540);
    --va-book-unit-z: calc(var(--va-book-resolved-depth) / 50);

    position: relative;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--va-book-resolved-width);
    height: var(--va-book-resolved-height);
    margin: 0 auto;
    perspective: var(--va-book-perspective, calc(var(--va-book-unit-x) * 2500));
    transform-style: preserve-3d;
    filter: drop-shadow(
        0
        calc(var(--va-book-unit-y) * 30)
        calc(var(--va-book-unit-x) * 60)
        rgb(2 6 23 / 50%)
    );
    cursor: grab;
    pointer-events: auto;
}

.va-book-container::after {
    position: absolute;
    z-index: -1;
    inset: calc(var(--va-book-unit-x) * -18);
    background: radial-gradient(
        circle at 50% 40%,
        var(--va-book-glow, rgb(255 255 255 / 22%)),
        transparent 60%
    );
    filter: blur(calc(var(--va-book-unit-x) * 12));
    pointer-events: none;
    content: "";
}

@keyframes va-book-float {
    0% {
        transform: rotateY(var(--va-book-ry0, 30deg)) rotateX(var(--va-book-rx0, 10deg)) translateY(0);
    }

    50% {
        transform: rotateY(var(--va-book-ry50, 25deg)) rotateX(var(--va-book-rx50, 15deg))
            translateY(var(--va-book-lift, calc(var(--va-book-unit-y) * -20)));
    }

    100% {
        transform: rotateY(var(--va-book-ry0, 30deg)) rotateX(var(--va-book-rx0, 10deg)) translateY(0);
    }
}

.va-book {
    position: absolute;
    width: var(--va-book-resolved-width);
    height: var(--va-book-resolved-height);
    transform: rotateY(var(--va-book-ry0, 30deg));
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(0.2, 0.8, 0.2, 1);
    will-change: transform;
    pointer-events: none;
}

.va-book--idle {
    animation: va-book-float 8s ease-in-out infinite;
}

@media (hover: hover) {
    .va-book-container:hover .va-book--idle {
        animation: none !important;
        transition: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .va-book--idle {
        animation: none;
    }
}

@media (max-width: 48rem) {
    .va-book-container[data-va-book-id] {
        --va-book-mobile-width: calc(100vw - 1.5rem);
        --va-book-width: var(--va-book-mobile-width);
    }
}

.va-book__face {
    position: absolute;
    box-sizing: border-box;
    backface-visibility: hidden;
}

.va-book__face--front {
    top: 50%;
    left: 50%;
    width: var(--va-book-resolved-width);
    height: var(--va-book-resolved-height);
    transform: translate(-50%, -50%) translateZ(calc(var(--va-book-resolved-depth) / 2));
}

.va-book__face--front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius:
        calc(var(--va-book-unit-x) * 2)
        calc(var(--va-book-unit-x) * 4)
        calc(var(--va-book-unit-x) * 4)
        calc(var(--va-book-unit-x) * 2);
    box-shadow:
        inset calc(var(--va-book-unit-x) * 4) 0 calc(var(--va-book-unit-x) * 12) rgb(0 0 0 / 20%),
        0 calc(var(--va-book-unit-y) * 18) calc(var(--va-book-unit-x) * 35) rgb(2 6 23 / 45%);
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.va-book__face--back {
    top: 50%;
    left: 50%;
    width: var(--va-book-resolved-width);
    height: var(--va-book-resolved-height);
    border-radius:
        calc(var(--va-book-unit-x) * 4)
        calc(var(--va-book-unit-x) * 2)
        calc(var(--va-book-unit-x) * 2)
        calc(var(--va-book-unit-x) * 4);
    background: linear-gradient(135deg, var(--va-book-spine-color, #1e293b), var(--va-book-spine-dark, #0f172a));
    box-shadow:
        calc(var(--va-book-unit-x) * -10)
        calc(var(--va-book-unit-y) * 10)
        calc(var(--va-book-unit-x) * 50)
        rgb(0 0 0 / 30%),
        inset 0 0 calc(var(--va-book-unit-z) * 20)
        var(--va-book-spine-hl, rgb(255 255 255 / 8%));
    transform: translate(-50%, -50%) rotateY(180deg) translateZ(calc(var(--va-book-resolved-depth) / 2));
}

.va-book__face--right {
    top: 50%;
    left: 50%;
    width: calc(var(--va-book-resolved-depth) + var(--va-book-unit-x));
    height: var(--va-book-resolved-height);
    background: linear-gradient(
        90deg,
        #e2e2e2 0%,
        #f7f7f7 20%,
        var(--va-book-page-color, #f0f0f0) 40%,
        #f7f7f7 60%,
        #e2e2e2 100%
    );
    box-shadow: inset 0 0 calc(var(--va-book-unit-z) * 8) rgb(0 0 0 / 12%);
    transform: translate(-50%, -50%) rotateY(90deg) translateZ(calc(var(--va-book-resolved-width) / 2));
}

.va-book__face--left {
    top: 50%;
    left: 50%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: calc(var(--va-book-resolved-depth) + var(--va-book-unit-x));
    height: var(--va-book-resolved-height);
    padding: calc(var(--va-book-unit-y) * 24) 0;
    color: #fff;
    background: linear-gradient(180deg, var(--va-book-spine-color, #1e293b), var(--va-book-spine-dark, #0f172a));
    box-shadow: inset calc(var(--va-book-unit-z) * 5) 0 calc(var(--va-book-unit-z) * 14) rgb(0 0 0 / 30%);
    text-orientation: mixed;
    transform: translate(-50%, -50%) rotateY(-90deg) translateZ(calc(var(--va-book-resolved-width) / 2));
    writing-mode: vertical-rl;
}

.va-book__spine-title {
    font-size: calc(var(--va-book-unit-z) * 14);
    font-weight: 700;
    letter-spacing: 0.1em;
    white-space: nowrap;
}

.va-book__spine-author {
    color: rgb(255 255 255 / 65%);
    font-size: calc(var(--va-book-unit-z) * 11);
    font-weight: 400;
    white-space: nowrap;
}

.va-book__face--top,
.va-book__face--bottom {
    top: 50%;
    left: 50%;
    width: var(--va-book-resolved-width);
    height: calc(var(--va-book-resolved-depth) + var(--va-book-unit-x));
    background: linear-gradient(90deg, #e2e2e2 0%, #f7f7f7 50%, #e2e2e2 100%);
    box-shadow: inset 0 0 calc(var(--va-book-unit-z) * 5) rgb(0 0 0 / 10%);
}

.va-book__face--top {
    transform: translate(-50%, -50%) rotateX(90deg) translateZ(calc(var(--va-book-resolved-height) / 2));
}

.va-book__face--bottom {
    transform: translate(-50%, -50%) rotateX(-90deg) translateZ(calc(var(--va-book-resolved-height) / 2));
}

/* The same spread is clipped onto three faces at one physical scale. Runtime reads the decoded image's
   dimensions; resizing the width anchor then scales both the texture and calculated spine without new reads. */
.va-book-container[data-va-book-wrap] .va-book__face--front img {
    object-position: right center;
}

.va-book-container[data-va-book-wrap] .va-book__face--back img,
.va-book-container[data-va-book-wrap] .va-book__face--left img {
    display: none;
}

.va-book-container[data-va-book-wrap="ready"] .va-book__face--front,
.va-book-container[data-va-book-wrap="ready"] .va-book__face--back,
.va-book-container[data-va-book-wrap="ready"] .va-book__face--left {
    overflow: hidden;
    padding: 0;
}

.va-book-container[data-va-book-wrap="ready"] .va-book__face img {
    position: absolute;
    display: block;
    top: 0;
    width: calc(var(--va-book-resolved-width) * var(--va-book-wrap-width));
    height: var(--va-book-resolved-height);
    max-width: none;
    border-radius: 0;
    object-fit: fill;
    pointer-events: none;
}

.va-book-container[data-va-book-wrap="ready"] .va-book__face--front img {
    left: calc(-1 * (var(--va-book-resolved-width) + var(--va-book-resolved-depth)));
}

.va-book-container[data-va-book-wrap="ready"] .va-book__face--back img {
    left: 0;
}

.va-book-container[data-va-book-wrap="ready"] .va-book__face--left img {
    left: calc(-1 * var(--va-book-resolved-width));
}

.va-book-container[data-va-book-wrap="ready"] .va-book__spine-title,
.va-book-container[data-va-book-wrap="ready"] .va-book__spine-author {
    display: none;
}
