/* ============================================================
   Flipbooks – Frontend Styles
   • Edition archive grid  (.fb-archive)
   • Lightbox              (#fbv-lightbox)
   • Viewer (lightbox + page)   (.fb-viewer)
   ============================================================ */

/* ── Reset / tokens ─────────────────────────────────────── */
.fb-archive *,
.fb-viewer *,
#fbv-lightbox * {
    box-sizing: border-box;
}

/* ============================================================
   EDITION ARCHIVE
   ============================================================ */
.fb-archive {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 32px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (max-width: 900px) {
    .fb-archive {
        grid-template-columns: 1fr;
    }
}

/* ── Section labels ──────────────────────────────────────── */
.fb-section-label {
    font-size: 10px !important;
    font-weight: 700 !important;
    letter-spacing: 0.14em !important;
    color: #999 !important;
    text-transform: uppercase !important;
    margin: 0 0 12px !important;
}

/* ── Featured (left) ─────────────────────────────────────── */
.fb-featured {
    display: flex;
    flex-direction: column;
}

.fb-featured-card {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    background: #1a1a1a;
}

.fb-featured-cover {
    display: block;
    position: relative;
    overflow: hidden;
    aspect-ratio: 3/4;
    text-decoration: none !important;
}

.fb-featured-cover img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    transition: transform 0.4s ease !important;
}

.fb-featured-cover:hover img {
    transform: scale(1.03) !important;
}

.fb-no-thumb {
    width: 100% !important;
    height: 100% !important;
    min-height: 340px !important;
    background: linear-gradient(135deg, #222 0%, #333 100%) !important;
}

.fb-featured-overlay {
    position: absolute !important;
    inset: 0 !important;
    background: linear-gradient(to top, rgba(0,0,0,0.72) 0%, transparent 55%) !important;
    display: flex !important;
    align-items: flex-end !important;
    justify-content: center !important;
    padding-bottom: 28px !important;
    opacity: 0 !important;
    transition: opacity 0.3s ease !important;
}

.fb-featured-cover:hover .fb-featured-overlay {
    opacity: 1 !important;
}

.fb-read-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    background: rgba(255,255,255,0.92) !important;
    color: #111 !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    letter-spacing: 0.04em !important;
    padding: 9px 20px !important;
    border-radius: 100px !important;
    backdrop-filter: blur(8px) !important;
    pointer-events: none !important;
}

.fb-featured-meta {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 12px 14px !important;
    background: #111 !important;
}

.fb-featured-title {
    font-size: 13px !important;
    font-weight: 600 !important;
    color: #eee !important;
    flex: 1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

.fb-featured-date {
    font-size: 11px !important;
    color: #888 !important;
    white-space: nowrap !important;
}

.fb-copy-link {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: none !important;
    border: none !important;
    cursor: pointer !important;
    color: #777 !important;
    padding: 3px !important;
    border-radius: 50% !important;
    transition: color 0.2s !important;
    flex-shrink: 0 !important;
}

.fb-copy-link:hover {
    color: #fff !important;
}

/* ── Past editions (right) ───────────────────────────────── */
.fb-past {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.fb-past-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fb-year-tabs {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
}

.fb-year-tab {
    display: inline-flex !important;
    align-items: center !important;
    padding: 5px 14px !important;
    border-radius: 100px !important;
    border: 1px solid rgba(255,255,255,0.12) !important;
    background: transparent !important;
    color: #aaa !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    cursor: pointer !important;
    transition: all 0.18s !important;
    white-space: nowrap !important;
}

.fb-year-tab:hover {
    border-color: rgba(255,255,255,0.3) !important;
    color: #fff !important;
}

.fb-year-tab.is-active {
    background: #fff !important;
    border-color: #fff !important;
    color: #111 !important;
    font-weight: 700 !important;
}

/* ── Grid ────────────────────────────────────────────────── */
.fb-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
    gap: 16px !important;
}

.fb-card {
    background: #1a1a1a !important;
    border-radius: 10px !important;
    overflow: hidden !important;
    box-shadow: 0 4px 14px rgba(0,0,0,0.18) !important;
    transition: transform 0.22s ease, box-shadow 0.22s ease !important;
}

.fb-card:hover {
    transform: translateY(-3px) !important;
    box-shadow: 0 8px 24px rgba(0,0,0,0.28) !important;
}

.fb-card-cover {
    display: block !important;
    position: relative !important;
    overflow: hidden !important;
    aspect-ratio: 3/4 !important;
    text-decoration: none !important;
}

.fb-card-cover img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    transition: transform 0.3s ease !important;
}

.fb-card-cover:hover img {
    transform: scale(1.04) !important;
}

.fb-card-overlay {
    position: absolute !important;
    inset: 0 !important;
    background: rgba(0,0,0,0.36) !important;
    display: flex !important;
    align-items: flex-start !important;
    justify-content: flex-end !important;
    padding: 8px !important;
    opacity: 0 !important;
    transition: opacity 0.22s !important;
}

.fb-card-cover:hover .fb-card-overlay {
    opacity: 1 !important;
}

.fb-copy-icon {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(0,0,0,0.5) !important;
    backdrop-filter: blur(6px) !important;
    border: none !important;
    border-radius: 50% !important;
    width: 32px !important;
    height: 32px !important;
    color: #fff !important;
    cursor: pointer !important;
    transition: background 0.2s !important;
}

.fb-copy-icon:hover {
    background: rgba(255,255,255,0.2) !important;
}

.fb-card-meta {
    padding: 8px 10px !important;
    background: #111 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 2px !important;
}

.fb-card-title {
    font-size: 11px !important;
    font-weight: 600 !important;
    color: #ddd !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
}

.fb-card-date {
    font-size: 10px !important;
    color: #666 !important;
    display: block !important;
}

/* ── Empty state ─────────────────────────────────────────── */
.fb-empty {
    color: #999 !important;
    font-style: italic !important;
}

/* ── Toast ───────────────────────────────────────────────── */
.fb-toast {
    position: fixed !important;
    bottom: 28px !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(20px) !important;
    background: rgba(20,20,20,0.92) !important;
    color: #fff !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    padding: 9px 20px !important;
    border-radius: 100px !important;
    backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    opacity: 0 !important;
    transition: opacity 0.25s, transform 0.25s !important;
    pointer-events: none !important;
    z-index: 99999 !important;
}

.fb-toast.is-visible {
    opacity: 1 !important;
    transform: translateX(-50%) translateY(0) !important;
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
#fbv-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99990;
}

#fbv-lightbox.is-open {
    display: block;
}

body.fbv-lb-open {
    overflow: hidden !important;
}

.fbv-lb-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.78);
    backdrop-filter: blur(6px);
}

.fbv-lb-dialog {
    position: absolute;
    inset: 20px;
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

@media (max-width: 600px) {
    .fbv-lb-dialog { inset: 0; border-radius: 0; }
}

/* ============================================================
   VIEWER  (shared by lightbox + standalone page)
   ============================================================ */

/* ─── Modern (default) ──────────────────────────────────── */
.fb-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #111;
    color: #e8e8e8;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
    position: relative;
    overflow: hidden;
}

/* Topbar */
.fbv-topbar {
    display: flex;
    align-items: center;
    height: 50px;
    padding: 0 12px;
    gap: 8px;
    background: rgba(20,20,20,0.72);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-bottom: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.fbv-topbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
    overflow: hidden;
}

.fbv-title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #ddd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 480px;
}

.fbv-topbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.fbv-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #aaa;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 8px;
    transition: color 0.18s, background 0.18s;
    flex-shrink: 0;
}

.fbv-back svg { flex-shrink: 0; }

.fbv-back:hover {
    color: #fff;
    background: rgba(255,255,255,0.07);
}

/* Buttons */
.fbv-btn {
    background: none;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #bbb;
    transition: color 0.18s, background 0.18s;
    border-radius: 8px;
    padding: 6px;
}

.fbv-btn:hover { color: #fff; background: rgba(255,255,255,0.08); }

.fbv-lb-close {
    flex-shrink: 0;
}

/* Body */
.fbv-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    min-height: 0;
}

/* Thumbnails panel */
.fbv-thumbs {
    width: 140px;
    flex-shrink: 0;
    overflow-y: auto;
    background: rgba(15,15,15,0.8);
    border-right: 1px solid rgba(255,255,255,0.06);
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.fbv-thumbs::-webkit-scrollbar { width: 4px; }
.fbv-thumbs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

.fbv-thumbs-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
}

.fbv-thumb-item {
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: border-color 0.18s, opacity 0.18s;
    position: relative;
    opacity: 0.6;
    width: 110px;
    flex-shrink: 0;
}

.fbv-thumb-item:hover { opacity: 1; border-color: rgba(255,255,255,0.3); }
.fbv-thumb-item.is-active { opacity: 1; border-color: #fff; }

.fbv-thumb-canvas {
    display: block;
    width: 100% !important;
    height: auto !important;
}

.fbv-thumb-num {
    display: block;
    text-align: center;
    font-size: 10px;
    color: #888;
    padding: 3px 0 4px;
    background: rgba(0,0,0,0.5);
}

/* Main area */
.fbv-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
    background: #161616;
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.12) transparent;
}

.fbv-main::-webkit-scrollbar { width: 6px; }
.fbv-main::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

/* ── Book spread ─────────────────────────────────────────── */
.fbv-book-spread {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
    position: relative;
    /* Subtle center-fold shadow */
    filter: drop-shadow(0 12px 48px rgba(0,0,0,0.7));
}

/* Page flip animation */
@keyframes fbv-flip {
    0%   { opacity: 1; transform: perspective(1800px) rotateY(0deg); }
    40%  { opacity: 0.6; transform: perspective(1800px) rotateY(-8deg) scaleX(0.97); }
    100% { opacity: 1; transform: perspective(1800px) rotateY(0deg); }
}

.fbv-book-spread.fbv-anim {
    animation: fbv-flip 0.45s ease;
}

/* Cover (single page centred) */
.fbv-book-spread.is-cover {
    justify-content: center;
}

.fbv-book-spread.is-cover .fbv-page-right {
    display: none;
}

.fbv-book-spread.is-cover .fbv-page-left {
    box-shadow: 0 4px 60px rgba(0,0,0,0.8);
    border-radius: 2px 8px 8px 2px;
}

/* Pages */
.fbv-page {
    position: relative;
    flex-shrink: 0;
    background: #fff;
    line-height: 0;
}

.fbv-page-left {
    box-shadow: inset -4px 0 12px rgba(0,0,0,0.25),
                -2px 0 0 rgba(0,0,0,0.15);
    border-radius: 2px 0 0 2px;
}

.fbv-page-right {
    box-shadow: inset 4px 0 12px rgba(0,0,0,0.25),
                2px 0 0 rgba(0,0,0,0.15);
    border-radius: 0 2px 2px 0;
}

.fbv-page canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

/* ── Text layer (for copy/paste) ─────────────────────────── */
.fbv-text-layer {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
    line-height: 1;
    pointer-events: auto;
    user-select: text;
    -webkit-user-select: text;
}

.fbv-text-layer span,
.fbv-text-layer br {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
    -webkit-text-stroke: 0px transparent;
}

.fbv-text-layer ::selection {
    background: rgba(60, 130, 246, 0.35);
    color: transparent;
}

/* Spinner */
.fbv-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(22,22,22,0.7);
    backdrop-filter: blur(4px);
}

.fbv-spinner span {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: #fff;
    border-radius: 50%;
    animation: fbv-spin 0.7s linear infinite;
}

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

/* Error */
.fbv-error {
    color: #ff6b6b;
    text-align: center;
    padding: 40px 20px;
    font-size: 14px;
}

/* Toolbar */
.fbv-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: 46px;
    padding: 0 12px;
    background: rgba(20,20,20,0.72);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-top: 1px solid rgba(255,255,255,0.07);
    flex-shrink: 0;
}

.fbv-toolbar-sep {
    width: 1px;
    height: 18px;
    background: rgba(255,255,255,0.1);
    margin: 0 6px;
    flex-shrink: 0;
}

.fbv-page-info {
    font-size: 12px;
    color: #aaa;
    min-width: 70px;
    text-align: center;
    flex-shrink: 0;
}

.fbv-zoom-label {
    font-size: 11px;
    color: #888;
    min-width: 36px;
    text-align: center;
    flex-shrink: 0;
}

/* ─── Classic override ──────────────────────────────────── */
.fb-ui-classic .fbv-topbar,
.fb-ui-classic .fbv-toolbar {
    background: #1e1e1e;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-color: #2e2e2e;
}

.fb-ui-classic .fbv-thumbs {
    background: #181818;
    border-color: #2a2a2a;
}

.fb-ui-classic .fbv-main {
    background: #141414;
}

/* ─── Standalone reader page ────────────────────────────── */
.fb-reader-standalone .fb-viewer--page {
    position: fixed;
    inset: 0;
    height: 100vh;
    z-index: 1;
}

/* ─── Mobile ─────────────────────────────────────────────── */
@media (max-width: 640px) {
    .fbv-thumbs {
        width: 80px;
        padding: 8px 4px;
    }
    .fbv-thumb-item { width: 68px; }
    .fbv-title { font-size: 12px; }
    .fbv-toolbar { gap: 0; }
    .fbv-toolbar .fbv-btn { padding: 5px; }
    .fbv-toolbar-sep { margin: 0 3px; }
}
