/* ==========================================================================
   MIRIADE Wild — Bibliothèque (library.css)
   Complète styles.css : bandeau, filtres, cartes, pagination, liseuse.
   ========================================================================== */

/* ---------- Bandeau ------------------------------------------------------- */
.library-hero {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap;
    margin-bottom: 22px;
}
.library-hero h1 { font-family: var(--font-display); font-size: clamp(1.8rem, 3.6vw, 2.6rem); letter-spacing: -.02em; }
.library-hero h1 em { font-style: italic; font-weight: 500; color: var(--primary); }
.library-hero p { color: var(--ink-2); margin-top: 6px; }
.library-counts { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.count-pill { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); padding: 6px 12px; border-radius: var(--r-pill); font-size: .82rem; color: var(--ink-2); box-shadow: var(--shadow-1); }
.count-pill b { color: var(--ink); }

/* ---------- Filtres ------------------------------------------------------- */
.library-filters {
    display: none; align-items: center; gap: 12px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    padding: 10px 12px; margin-bottom: 20px; box-shadow: var(--shadow-1);
    position: sticky; top: calc(var(--header-h) + 8px); z-index: 40;
    backdrop-filter: blur(10px);
}
.library-filters.show { display: flex; }
.filter-tabs { display: inline-flex; gap: 2px; background: var(--surface-3); padding: 4px; border-radius: var(--r-pill); }
.filter-tab { border: 0; background: transparent; color: var(--ink-2); padding: 7px 14px; border-radius: var(--r-pill); font-weight: 600; font-size: .86rem; transition: all var(--t-fast); }
.filter-tab.active { background: var(--surface); color: var(--primary-ink); box-shadow: var(--shadow-1); }
.filter-tab:hover:not(.active) { color: var(--ink); }
.library-search { flex: 1; min-width: 200px; position: relative; }
.library-search::before { content: '🔍'; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: .85rem; opacity: .6; }
.library-search input {
    width: 100%; padding: 9px 12px 9px 36px; border: 1.5px solid var(--line-2); border-radius: var(--r-pill);
    background: var(--surface-2); color: var(--ink); font-size: .9rem;
}
.library-search input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.library-sort select {
    padding: 9px 36px 9px 14px; border: 1.5px solid var(--line-2); border-radius: var(--r-pill);
    background: var(--surface-2); color: var(--ink); font-size: .88rem; cursor: pointer;
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%238a889f' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.8' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center; background-repeat: no-repeat; background-size: 16px;
}
.library-sort select:focus { outline: none; border-color: var(--primary); }
.view-toggle { display: inline-flex; gap: 2px; background: var(--surface-3); padding: 4px; border-radius: var(--r-pill); }
.view-toggle button { border: 0; background: transparent; width: 32px; height: 30px; border-radius: var(--r-pill); color: var(--ink-3); }
.view-toggle button.active { background: var(--surface); color: var(--primary-ink); box-shadow: var(--shadow-1); }

/* ---------- Grille & cartes ---------------------------------------------- */
.loading-spinner { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 260px; color: var(--ink-3); }
.stories-grid {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 22px; margin-bottom: 28px;
}
.stories-grid.show { display: grid; }
body.dense .stories-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.story-card {
    position: relative; display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
    box-shadow: var(--shadow-2); overflow: hidden; cursor: pointer;
    transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease);
    animation: fadeUp .4s var(--ease) both;
}
.story-card:nth-child(2) { animation-delay: .04s; }
.story-card:nth-child(3) { animation-delay: .08s; }
.story-card:nth-child(4) { animation-delay: .12s; }
.story-card:nth-child(5) { animation-delay: .16s; }
.story-card:nth-child(6) { animation-delay: .2s; }
.story-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-3); }
.story-card:focus-within { box-shadow: var(--ring), var(--shadow-3); }
.card-cover { position: relative; aspect-ratio: 4 / 3; background: var(--grad-cover); overflow: hidden; }
body.dense .card-cover { aspect-ratio: 3 / 2; }
.card-cover img { width: 100%; height: 100%; object-fit: cover; transition: transform .7s var(--ease); }
.story-card:hover .card-cover img { transform: scale(1.06); }
.cover-placeholder { width: 100%; height: 100%; display: grid; place-items: center; font-size: 3rem; color: #fff; }
.card-cover::after {
    content: ''; position: absolute; inset: auto 0 0 0; height: 55%;
    background: linear-gradient(to top, rgba(15, 14, 27, .65), transparent); pointer-events: none;
}
.card-cover-title {
    position: absolute; left: 14px; right: 14px; bottom: 12px; z-index: 2;
    font-family: var(--font-display); font-weight: 700; color: #fff; font-size: 1.15rem; line-height: 1.2;
    text-shadow: 0 2px 8px rgba(0, 0, 0, .4);
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-overlay {
    position: absolute; inset: 0; z-index: 3;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    background: rgba(15, 14, 27, .45); backdrop-filter: blur(2px);
    opacity: 0; transition: opacity var(--t);
}
.story-card:hover .card-overlay { opacity: 1; }
.btn-overlay { border: 0; border-radius: var(--r-pill); padding: 9px 16px; font-weight: 700; font-size: .85rem; background: #fff; color: #1c1a33; box-shadow: var(--shadow-2); transition: transform var(--t-fast); }
.btn-overlay:hover { transform: scale(1.05); }
.btn-overlay.btn-view { background: var(--grad-primary); color: #fff; }
.card-badges { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 4; display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; pointer-events: none; }
.card-badges > * { pointer-events: auto; }
.favorite-btn {
    width: 34px; height: 34px; border-radius: 50%; border: 0;
    background: rgba(255, 255, 255, .9); font-size: 1rem; display: grid; place-items: center;
    box-shadow: var(--shadow-1); transition: transform var(--t-fast);
}
.favorite-btn:hover { transform: scale(1.12); }
.favorite-btn.on { animation: pop .3s var(--ease); }
@keyframes pop { 50% { transform: scale(1.3); } }
.card-status {
    font-size: .7rem; font-weight: 700; padding: 4px 9px; border-radius: var(--r-pill);
    background: rgba(255, 255, 255, .92); color: #1c1a33; box-shadow: var(--shadow-1);
}
.card-status.partial-images { background: var(--warn-soft); color: var(--accent-ink); }
.card-status.no-images { background: var(--danger-soft); color: var(--danger); }
.card-content { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: .74rem; color: var(--ink-3); }
.card-meta span { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-3); padding: 3px 8px; border-radius: var(--r-pill); }
.card-meta .meta-creator.me { background: var(--success-soft); color: var(--success); font-weight: 600; }
.card-meta .meta-style { background: var(--primary-soft); color: var(--primary-ink); }
.card-meta .meta-shared { background: var(--info-soft); color: var(--info); }
.preview-text { font-size: .88rem; line-height: 1.55; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; flex: 1; }
body.dense .preview-text { -webkit-line-clamp: 2; }
.card-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 2px; }
.page-indicators { display: flex; gap: 4px; align-items: center; }
.page-indicator { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); }
.page-indicator.has-image { background: var(--success); }
.page-indicator.no-image { background: var(--danger); }
.more-pages { font-size: .72rem; color: var(--ink-3); margin-left: 3px; }
.card-actions { display: flex; gap: 6px; align-items: center; }
.btn-card { border: 0; border-radius: var(--r-sm); padding: 7px 12px; font-size: .82rem; font-weight: 600; transition: all var(--t-fast); }
.btn-card.btn-primary { background: var(--primary-soft); color: var(--primary-ink); }
.btn-card.btn-primary:hover { background: var(--primary); color: #fff; }
.btn-card.btn-secondary { width: 32px; height: 32px; padding: 0; border-radius: 50%; background: var(--surface-3); color: var(--ink-2); display: grid; place-items: center; font-size: 1rem; }
.btn-card.btn-secondary:hover { background: var(--line); color: var(--ink); }

.dropdown-menu-portal {
    position: fixed; z-index: 10000; min-width: 200px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
    box-shadow: var(--shadow-3); padding: 6px; animation: popIn .18s var(--ease);
}
.dropdown-menu-portal button {
    width: 100%; text-align: left; border: 0; background: transparent; color: var(--ink);
    padding: 9px 12px; border-radius: var(--r-sm); font-size: .88rem; display: flex; gap: 8px; align-items: center;
    transition: background var(--t-fast);
}
.dropdown-menu-portal button:hover { background: var(--surface-3); }
.dropdown-menu-portal button.danger { color: var(--danger); }
.dropdown-menu-portal button.danger:hover { background: var(--danger-soft); }
.dropdown-menu-portal hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* ---------- Pagination ---------------------------------------------------- */
.pagination-container { display: none; justify-content: center; margin: 8px 0 32px; }
.pagination-container.show { display: flex; }
.pagination-simple { display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-pill); padding: 6px 8px; box-shadow: var(--shadow-1); flex-wrap: wrap; justify-content: center; }
.pagination-btn { border: 0; background: var(--surface-3); color: var(--ink); border-radius: var(--r-pill); padding: 8px 14px; font-weight: 600; font-size: .86rem; transition: all var(--t-fast); }
.pagination-btn:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary-ink); }
.pagination-btn:disabled { opacity: .45; cursor: not-allowed; }
.page-info { font-size: .86rem; color: var(--ink-2); padding: 0 6px; }
.page-selector { padding: 7px 10px; border: 1px solid var(--line-2); border-radius: var(--r-pill); background: var(--surface-2); font-size: .84rem; }
.loading-more-indicator { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 14px; color: var(--ink-3); font-size: .88rem; }

/* ---------- Liseuse (modale plein écran) --------------------------------- */
#story-modal { padding: 0; background: rgba(11, 10, 22, .82); }
#story-modal .modal-content {
    max-width: none; width: 100vw; height: 100vh; max-height: none; border-radius: 0; border: 0;
    background: #12111f; color: #fff;
}
#story-modal .modal-header {
    padding: 10px 18px; border-bottom: 1px solid rgba(255, 255, 255, .08);
    background: rgba(255, 255, 255, .03); gap: 12px;
}
.modal-title-section { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }
.modal-title-section h3 { color: #fff; font-family: var(--font-display); font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-navigation { display: inline-flex; align-items: center; gap: 4px; background: rgba(255, 255, 255, .08); border-radius: var(--r-pill); padding: 3px; flex-shrink: 0; }
.nav-btn { width: 32px; height: 32px; border-radius: 50%; border: 0; background: transparent; color: #fff; font-size: 1.2rem; display: grid; place-items: center; transition: background var(--t-fast); }
.nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, .18); }
.nav-btn:disabled { opacity: .3; cursor: not-allowed; }
.page-counter { font-size: .82rem; min-width: 56px; text-align: center; opacity: .85; }
.modal-controls { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.control-btn {
    height: 36px; min-width: 36px; padding: 0 10px; border-radius: var(--r-pill); border: 1px solid rgba(255, 255, 255, .12);
    background: rgba(255, 255, 255, .06); color: #fff; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px;
    transition: background var(--t-fast);
}
.control-btn:hover { background: rgba(255, 255, 255, .16); }
.control-btn.active { background: var(--accent); color: #1c1a33; border-color: transparent; }
.control-btn .label { font-size: .78rem; font-weight: 600; }
#story-modal .modal-close { background: rgba(255, 255, 255, .1); color: #fff; }
#story-modal .modal-close:hover { background: rgba(255, 255, 255, .22); }
#goto-page { width: 58px; height: 36px; border-radius: var(--r-pill); border: 1px solid rgba(255, 255, 255, .15); background: rgba(255, 255, 255, .06); color: #fff; text-align: center; font-size: .85rem; }

#story-modal .story-viewer {
    flex: 1; min-height: 0; overflow: auto; padding: clamp(12px, 2.5vw, 28px);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 140ms ease, transform 140ms ease;
}
#story-modal .story-viewer.is-transitioning { opacity: 0; }
#story-modal .story-viewer.is-transitioning[data-dir="next"] { transform: translateX(-12px); }
#story-modal .story-viewer.is-transitioning[data-dir="prev"] { transform: translateX(12px); }
#story-modal .story-viewer.is-transitioning[data-dir="jump"] { transform: scale(.99); }

.mw-spread {
    position: relative; width: min(1200px, 100%); height: min(72vh, 760px); min-width: 0;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    border-radius: 22px; overflow: hidden;
    background: #fbf8f2; color: #1c1a33;
    box-shadow: 0 40px 100px -30px rgba(0, 0, 0, .9), 0 0 0 1px rgba(255, 255, 255, .06);
}
.mw-spread::before {
    content: ''; position: absolute; top: 0; bottom: 0; left: 50%; width: 3px; transform: translateX(-50%); z-index: 3; pointer-events: none;
    background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, .25) 15%, rgba(0, 0, 0, .35) 50%, rgba(0, 0, 0, .25) 85%, transparent);
}
.mw-spread > * { min-width: 0; min-height: 0; }
.mw-spread-image { position: relative; overflow: hidden; background: #0f172a; display: flex; align-items: center; justify-content: center; }
.mw-spread-image::before { content: ''; position: absolute; inset: -30px; background-image: var(--mw-image-url); background-size: cover; background-position: center; filter: blur(22px) saturate(1.2); opacity: .6; transform: scale(1.1); }
.mw-spread-image::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle at 50% 45%, rgba(0, 0, 0, .05), rgba(0, 0, 0, .55) 100%); }
.mw-spread-image .page-image { position: relative; z-index: 2; width: 100%; height: 100%; object-fit: contain; }
.mw-spread-image .image-placeholder { position: relative; z-index: 2; color: rgba(255, 255, 255, .7); }
.mw-spread-text {
    position: relative; display: flex; flex-direction: column; padding: clamp(18px, 3vw, 36px);
    background: #fbf8f2;
}
.mw-spread-text::after { content: ''; position: absolute; inset: 0; background: var(--paper); opacity: .22; mix-blend-mode: multiply; pointer-events: none; }
.mw-spread-text > * { position: relative; z-index: 1; }
.mw-page-num { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: #8a889f; font-weight: 700; margin-bottom: 10px; }
.mw-spread-text .page-title { font-family: var(--font-display); font-size: clamp(1.15rem, 1.8vw, 1.6rem); font-weight: 700; color: #1c1a33; margin-bottom: 14px; letter-spacing: -.01em; }
.mw-spread-text .page-text {
    flex: 1; overflow: hidden; font-family: var(--font-display); font-size: 1.1rem; line-height: 1.7; color: #2a2840;
    padding: 4px 2px; border-radius: 10px; outline: none;
}
.mw-spread-text .page-text::first-letter { font-size: 2.4em; float: left; line-height: .85; padding: 4px 8px 0 0; color: var(--primary); font-weight: 700; }
.mw-spread-text .page-text.audio-mode { background: rgba(245, 158, 11, .08); padding: 10px; }
.mw-spread-text .page-text[contenteditable="true"] { background: #fff; box-shadow: 0 0 0 2px var(--primary); padding: 10px; }
.mw-spread-text .page-text[contenteditable="true"]::first-letter { font-size: inherit; float: none; padding: 0; color: inherit; }
.page-note { font-size: .82rem; color: var(--accent-ink); background: var(--warn-soft); padding: 8px 10px; border-radius: 8px; margin-top: 10px; }
.page-edit-bar { display: none; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.page-edit-bar.show { display: flex; }
.page-edit-bar button { border-radius: 8px; padding: 7px 12px; font-size: .85rem; font-weight: 600; border: 1px solid #d4cdbe; background: #fff; color: #1c1a33; }
.page-edit-bar button.primary { background: var(--grad-primary); color: #fff; border-color: transparent; }
.btn-edit-page-text { position: absolute; right: 14px; bottom: 12px; z-index: 2; width: 32px; height: 32px; border-radius: 50%; border: 1px solid #d4cdbe; background: #fff; color: #4e4c66; opacity: .55; transition: opacity var(--t-fast), transform var(--t-fast); }
.btn-edit-page-text:hover { opacity: 1; transform: scale(1.08); }
.reading-highlight-overlay { position: fixed; pointer-events: none; z-index: 6000; background: rgba(245, 158, 11, .45); border-radius: 3px; transition: all .18s ease; animation: readingPulse .6s ease-in-out infinite alternate; }
@keyframes readingPulse { from { background: rgba(245, 158, 11, .35); } to { background: rgba(245, 158, 11, .6); } }

.thumbs-strip {
    display: flex; gap: 8px; padding: 10px 16px 14px; overflow-x: auto; justify-content: center;
    border-top: 1px solid rgba(255, 255, 255, .08); background: rgba(255, 255, 255, .03);
    scrollbar-width: thin;
}
.thumbs-strip img, .thumbs-strip .thumb-empty {
    width: 64px; height: 48px; border-radius: 8px; object-fit: cover; flex-shrink: 0; cursor: pointer;
    opacity: .5; border: 2px solid transparent; transition: opacity var(--t-fast), transform var(--t-fast), border-color var(--t-fast);
}
.thumbs-strip .thumb-empty { display: grid; place-items: center; background: rgba(255, 255, 255, .1); color: #fff; font-size: .8rem; }
.thumbs-strip img:hover, .thumbs-strip .thumb-empty:hover { opacity: .85; transform: translateY(-2px); }
.thumbs-strip .current { opacity: 1; border-color: var(--accent); }

/* Timeline des versions (dans la liseuse) */
.versions-wrap { width: min(760px, 100%); max-height: 100%; overflow: auto; background: var(--surface); color: var(--ink); border-radius: var(--r-xl); padding: 22px; }
.versions-wrap h4 { font-family: var(--font-display); font-size: 1.2rem; margin-bottom: 14px; }
.version-timeline { position: relative; padding-left: 26px; display: grid; gap: 10px; }
.version-timeline::before { content: ''; position: absolute; left: 9px; top: 14px; bottom: 14px; width: 2px; background: var(--line-2); }
.version-timeline-item { position: relative; }
.version-timeline-dot { position: absolute; left: -22px; top: 18px; width: 12px; height: 12px; border-radius: 50%; background: var(--line-2); border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--line-2); }
.version-timeline-item.version-current .version-timeline-dot { background: var(--success); box-shadow: 0 0 0 2px var(--success); }
.version-timeline-card { display: flex; align-items: center; gap: 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 10px 14px; }
.version-timeline-item.version-current .version-timeline-card { border-color: var(--success); background: var(--success-soft); }
.version-timeline-card img, .version-timeline-card .thumb-fallback { width: 68px; height: 68px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.version-timeline-card .thumb-fallback { background: var(--surface-3); display: grid; place-items: center; font-size: 1.4rem; }
.version-timeline-card .v-info { flex: 1; min-width: 0; }
.version-timeline-card .v-info b { display: block; }
.version-timeline-card .v-info small { color: var(--ink-3); display: block; }

@media (max-width: 860px) {
    .library-filters { position: static; }
    #lib-user-pill { display: none !important; }
    #story-modal .modal-header { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
    .modal-title-section { order: 2; width: 100%; justify-content: center; }
    .modal-controls { order: 1; width: 100%; justify-content: flex-end; }
    .mw-spread { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); height: calc(100vh - 170px); border-radius: 14px; }
    .mw-spread::before { display: none; }
    .mw-spread-text { padding: 14px 16px; }
    .mw-spread-text .page-text { font-size: .98rem; line-height: 1.55; }
    .modal-title-section h3 { display: none; }
    .control-btn .label { display: none; }
    #goto-page, #goto-page-btn, #copy-page-text { display: none; }
    .thumbs-strip { display: none; }
}
