/*
 * jac-flipbook · styles
 *
 * Theme it per site by overriding the custom properties, e.g.
 *   .jfb { --jfb-accent: #6a9f2a; }
 */
.jfb {
    --jfb-bg: #2a2c30;
    --jfb-bg-glow: #44474d;
    --jfb-fg: #f2f2f2;
    --jfb-muted: rgba(242, 242, 242, 0.62);
    --jfb-accent: #4f9cf0;
    --jfb-bar-bg: rgba(18, 19, 22, 0.88);
    --jfb-btn-hover: rgba(255, 255, 255, 0.12);
    --jfb-radius: 8px;
    --jfb-height: min(82vh, 780px);

    position: relative;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: 100%;
    height: var(--jfb-height);
    min-height: 320px;
    overflow: hidden;
    color: var(--jfb-fg);
    background: radial-gradient(ellipse at 50% 42%, var(--jfb-bg-glow) 0%, var(--jfb-bg) 72%);
    font: 14px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.jfb *,
.jfb *::before,
.jfb *::after {
    box-sizing: border-box;
}

.jfb:focus-visible {
    box-shadow: inset 0 0 0 2px var(--jfb-accent);
}

/* fills its container / the window (viewer page, fancybox iframe) */
.jfb--fill {
    --jfb-height: 100%;
    min-height: 0;
}

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

.jfb__viewport {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.jfb__stage {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.jfb--fill .jfb__stage,
.jfb.is-fullscreen .jfb__stage,
.jfb:fullscreen .jfb__stage,
.jfb.is-zoomed .jfb__stage {
    touch-action: none;
}

.jfb.is-zoomed .jfb__stage {
    cursor: grab;
}

.jfb.is-zoomed .jfb__stage:active {
    cursor: grabbing;
}

/* ---------- loading / error ---------- */

.jfb__overlay {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    text-align: center;
    pointer-events: none;
}

.jfb.is-loading .jfb__overlay,
.jfb.is-error .jfb__overlay {
    display: flex;
}

.jfb.is-error .jfb__overlay {
    pointer-events: auto;
}

.jfb__spinner {
    width: 38px;
    height: 38px;
    border: 3px solid rgba(255, 255, 255, 0.18);
    border-top-color: var(--jfb-accent);
    border-radius: 50%;
    animation: jfb-spin 0.9s linear infinite;
}

.jfb.is-error .jfb__spinner,
.jfb.is-error .jfb__progress {
    display: none;
}

.jfb__progress {
    width: min(240px, 60%);
    height: 3px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.jfb__progress span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--jfb-accent);
    transition: width 0.2s ease;
}

.jfb__message {
    margin: 0;
    color: var(--jfb-muted);
}

.jfb__error-link {
    color: var(--jfb-fg);
    text-decoration: underline;
}

@keyframes jfb-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- edge arrows ---------- */

.jfb__edge {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 88px;
    margin-top: -44px;
    padding: 0;
    color: var(--jfb-fg);
    background: rgba(0, 0, 0, 0.28);
    border: 0;
    border-radius: var(--jfb-radius);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.jfb__edge--prev {
    left: 8px;
}

.jfb__edge--next {
    right: 8px;
}

.jfb.is-ready:hover .jfb__edge:not(:disabled),
.jfb__edge:focus-visible {
    opacity: 1;
}

.jfb__edge:hover {
    background: rgba(0, 0, 0, 0.5);
}

.jfb__edge:disabled {
    visibility: hidden;
}

.jfb__edge svg {
    width: 28px;
    height: 28px;
}

@media (hover: none) {
    .jfb__edge {
        display: none;
    }
}

/* ---------- thumbnails ---------- */

.jfb__thumbs {
    flex: 0 0 auto;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(0, 0, 0, 0.32);
    scrollbar-width: thin;
}

.jfb__thumbs[hidden] {
    display: none;
}

.jfb__thumbs-list {
    display: flex;
    gap: 6px;
    margin: 0;
    padding: 10px 12px;
    list-style: none;
}

.jfb__thumb {
    flex: 0 0 auto;
}

.jfb__thumb-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 3px;
    color: var(--jfb-muted);
    font: inherit;
    font-size: 11px;
    background: none;
    border: 2px solid transparent;
    border-radius: 4px;
    cursor: pointer;
}

.jfb__thumb-canvas {
    display: block;
    width: auto;
    height: 84px;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.jfb__thumb-btn:hover {
    color: var(--jfb-fg);
}

.jfb__thumb.is-current .jfb__thumb-btn {
    color: var(--jfb-fg);
    border-color: var(--jfb-accent);
}

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

.jfb__toolbar {
    position: relative;
    z-index: 3;
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 12px;
    padding: 6px 10px;
    background: var(--jfb-bar-bg);
}

.jfb__title {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    color: var(--jfb-muted);
    white-space: nowrap;
    text-overflow: ellipsis;
}

.jfb__group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.jfb__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    color: var(--jfb-fg);
    text-decoration: none;
    background: none;
    border: 0;
    border-radius: var(--jfb-radius);
    cursor: pointer;
    transition: background-color 0.15s ease, opacity 0.15s ease;
}

.jfb__btn:hover:not(:disabled),
.jfb__btn.is-active {
    background: var(--jfb-btn-hover);
}

.jfb__btn.is-active {
    color: var(--jfb-accent);
}

.jfb__btn:disabled {
    opacity: 0.32;
    cursor: default;
}

.jfb__btn:focus-visible,
.jfb__thumb-btn:focus-visible,
.jfb__input:focus-visible {
    outline: 2px solid var(--jfb-accent);
    outline-offset: 1px;
}

.jfb svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.jfb__pager {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0 4px;
    color: var(--jfb-muted);
    white-space: nowrap;
}

.jfb__input {
    width: auto;
    min-width: 3.2em;
    height: 30px;
    padding: 0 6px;
    color: var(--jfb-fg);
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
}

.jfb__input:disabled {
    opacity: 0.4;
}

.jfb__total {
    font-variant-numeric: tabular-nums;
}

.jfb__sr {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

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

    .jfb__toolbar {
        justify-content: center;
        padding: 4px 6px;
    }

    .jfb__btn {
        width: 36px;
        height: 36px;
    }
}

/* ---------- fullscreen ---------- */

.jfb:fullscreen {
    width: 100%;
    height: 100%;
    --jfb-height: 100%;
}

.jfb:-webkit-full-screen {
    width: 100%;
    height: 100%;
}

/* CSS fallback where the Fullscreen API is missing (iPhone) */
.jfb.is-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    width: 100%;
    height: 100%;
    min-height: 0;
}

@media (prefers-reduced-motion: reduce) {
    .jfb *,
    .jfb *::before,
    .jfb *::after {
        transition: none !important;
        animation-duration: 0.01ms !important;
    }
}
