.spb-book3d-section {
    margin: 24px 0;
    padding: 20px;
    border: 1px solid #e2e2e2;
    border-radius: 8px;
    background: #fbfbfb;
}

.spb-book3d-title {
    margin: 0 0 6px;
    font-size: 20px;
}

.spb-book3d-meta {
    margin: 12px 0 0;
    font-size: 13px;
    color: #5f6368;
}

.spb-book3d-hint {
    margin: 2px 0 0;
    font-size: 12px;
    color: #8a8f98;
}

.spb-b3d-stage {
    position: relative;
    perspective: 1600px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 380px;
    padding: 30px 0 50px;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-y;
}

.spb-b3d-stage.spb-b3d-dragging {
    cursor: grabbing;
}

.spb-b3d-book {
    position: relative;
    width: var(--b3d-w, 220px);
    height: var(--b3d-h, 300px);
    transform-style: preserve-3d;
    transform: rotateX(6deg) rotateY(24deg);
    transition: transform 0.25s ease;
}

.spb-b3d-stage.spb-b3d-dragging .spb-b3d-book {
    transition: none;
}

.spb-b3d-face,
.spb-b3d-block,
.spb-b3d-edge,
.spb-b3d-spine {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    backface-visibility: hidden;
}

.spb-b3d-face {
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.spb-b3d-front {
    transform: translateZ(calc(var(--b3d-d, 20px) / 2));
}

.spb-b3d-back {
    transform: translateZ(calc(var(--b3d-d, 20px) / -2)) rotateY(180deg);
}

.spb-b3d-block {
    transform: translateZ(calc(var(--b3d-d, 20px) / -2));
    background-color: #f4f0e7;
    background-image: repeating-linear-gradient(to bottom, #fbf8f1 0 2px, #e4dbc9 2px 3px);
}

.spb-b3d-edge {
    left: 100%;
    width: var(--b3d-d, 20px);
    transform-origin: left center;
    transform: translateZ(calc(var(--b3d-d, 20px) / 2)) rotateY(90deg);
    background-color: #f8f4eb;
    background-image: repeating-linear-gradient(to bottom, #fffdf8 0 2px, #d9cfbc 2px 3px);
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.18);
}

.spb-b3d-spine {
    width: var(--b3d-d, 20px);
    transform-origin: left center;
    transform: translateZ(calc(var(--b3d-d, 20px) / -2)) rotateY(-90deg);
    background-size: 100% 100%;
    background-color: #efe9dd;
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.25);
}

/* -------------------------------------------------------------------------
 * Auto-generated spine text (title + author) — used only when the author has
 * NOT uploaded spine artwork. Runs along the spine; font size scales with the
 * calculated spine width (--b3d-d, derived from the page count).
 * ------------------------------------------------------------------------- */
.spb-b3d-spine-text {
    position: absolute;
    inset: 0;
    display: flex;
    /* vertical-rl: row stacks the spans top -> bottom along the spine */
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 0.55em;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    padding: 8px 1px;
    overflow: hidden;
    color: #ffffff;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(6px, calc(var(--b3d-d, 20px) * 0.36), 14px);
    line-height: 1.1;
    text-align: center;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.65);
    background: linear-gradient(90deg, #101018 0%, #34354c 25%, #4a4b66 50%, #34354c 75%, #101018 100%);
    box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.35);
    backface-visibility: hidden;
    pointer-events: none;
}

.spb-b3d-spine-title,
.spb-b3d-spine-author {
    display: block;
    max-width: 100%;
    max-height: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.spb-b3d-spine-title {
    font-weight: 700;
    letter-spacing: 0.04em;
}

.spb-b3d-spine-author {
    font-weight: 400;
    font-style: italic;
    font-size: 0.86em;
    opacity: 0.88;
}

/* ==========================================================================
 * ISBN barcode on the back cover — drawn from the ISBN the author supplied
 * on the ACF form. Skipped entirely when the artwork already carries the
 * ISBN (isbn_on_back_cover = yes) so a book never shows two barcodes.
 * Scales with the face (--b3d-w) so it stays proportional at any size.
 * ========================================================================== */
.spb-b3d-isbn {
    position: absolute;
    right: 6%;
    bottom: 5%;
    width: 42%;
    max-width: 170px;
    padding: 6px 7px 4px;
    background: #ffffff;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    line-height: 0;
    backface-visibility: hidden;
    pointer-events: none;
}

.spb-b3d-isbn svg {
    display: block;
    width: 100%;
    height: auto;
}

.spb-b3d-isbn-digits text {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 8px;
    font-weight: 500;
    letter-spacing: 0.02em;
}

/* -------------------------------------------------------------------------
 * Fallback notice: author requested + paid for an ISBN that is not assigned
 * yet — a dashed stamp reading "ISBN to be assigned".
 * ------------------------------------------------------------------------- */
.spb-b3d-isbn-pending {
    position: absolute;
    right: 6%;
    bottom: 5%;
    width: 48%;
    max-width: 190px;
    padding: clamp(6px, calc(var(--b3d-w, 220px) * 0.045), 12px) clamp(7px, calc(var(--b3d-w, 220px) * 0.05), 14px);
    display: flex;
    flex-direction: column;
    gap: 3px;
    text-align: center;
    background: rgba(255, 255, 255, 0.94);
    border: 1.5px dashed #6c5ce7;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
    backface-visibility: hidden;
    pointer-events: none;
}

.spb-b3d-isbn-pending-title {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: clamp(7px, calc(var(--b3d-w, 220px) * 0.05), 13px);
    font-weight: 700;
    line-height: 1.2;
    color: #4f46e5;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.spb-b3d-isbn-pending-note {
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: clamp(6px, calc(var(--b3d-w, 220px) * 0.036), 9.5px);
    line-height: 1.35;
    color: #4b5563;
}

.spb-b3d-shadow {
    position: absolute;
    left: 50%;
    bottom: 8px;
    width: calc(var(--b3d-w, 220px) * 1.2);
    height: 28px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0) 70%);
    filter: blur(2px);
    pointer-events: none;
}

.spb-b3d-loading,
.spb-b3d-empty {
    text-align: center;
    padding: 40px 20px;
    font-size: 15px;
    color: #666;
}

.spb-b3d-empty {
    color: #d63638;
    background: #fcf0f1;
    border: 1px solid #d63638;
    border-radius: 4px;
}

.spb-b3d-btn {
    display: inline-block;
    background: #2271b1;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 10px 22px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    margin: 12px 0;
    transition: background 0.2s ease;
}

.spb-b3d-btn:hover {
    background: #135e96;
}

.spb-b3d-btn[disabled] {
    background: #c3c4c7;
    cursor: not-allowed;
}

.spb-b3d-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.spb-b3d-modal-content {
    background: #f7f7f7;
    border-radius: 8px;
    max-width: 720px;
    width: 100%;
    max-height: 92vh;
    overflow: auto;
    padding: 20px;
    position: relative;
}

.spb-b3d-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.spb-b3d-modal-header h3 {
    margin: 0;
    font-size: 20px;
}

.spb-b3d-close {
    background: #d33;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
}

.spb-b3d-close:hover {
    background: #a22;
}

.spb-b3d-modal .spb-b3d-stage {
    background: #fff;
    border: 1px solid #e6e6e6;
    border-radius: 6px;
}

@media (max-width: 640px) {
    .spb-b3d-stage {
        min-height: 300px;
    }
}
