/* ========== VARIABLES ========== */
:root {
    --primary: #2c3e50;
    --secondary: #3498db;
    --accent: #e74c3c;
    --light: #ecf0f1;
    --text: #2c3e50;
    --border: #bdc3c7;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* ========== RESET & BASE ========== */
#bv-app, #bv-app * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#bv-app {
    width: 100%;
    min-height: 100vh;
    height: 100vh;
    position: relative;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text);
    overflow: hidden;
}

#bv-app::-webkit-scrollbar {
    width: 8px;
}

#bv-app::-webkit-scrollbar-track {
    background: var(--light);
}

#bv-app::-webkit-scrollbar-thumb {
    background: var(--secondary);
    border-radius: 4px;
}

/* ========== ÉCRANS ========== */
#bv-app .screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

#bv-app .screen.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 20;
}

#bv-app .container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ========== ÉCRAN LISTE DE LIVRES ========== */
#bookListScreen {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

#bookListScreen .container {
    padding: 40px 20px;
}

#bookListScreen h1 {
    color: white;
    text-align: center;
    margin-bottom: 40px;
    font-size: 2.5em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

#bv-app .book-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 30px;
    padding: 20px;
}

#bv-app .book-card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: var(--shadow);
}

#bv-app .book-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
}

#bv-app .book-card-image {
    width: 100%;
    height: 280px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3em;
    color: white;
}

#bv-app .book-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#bv-app .book-card-content {
    padding: 20px;
}

#bv-app .book-card-title {
    font-size: 1.3em;
    font-weight: bold;
    color: var(--text);
    margin-bottom: 10px;
}

#bv-app .book-card-info {
    font-size: 0.9em;
    color: #7f8c8d;
    margin-bottom: 15px;
}

#bv-app .book-card-btn {
    width: 100%;
    padding: 10px;
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    transition: background 0.3s ease;
}

#bv-app .book-card-btn:hover {
    background: #2980b9;
}

#bv-app .empty-message {
    grid-column: 1 / -1;
    text-align: center;
    color: white;
    font-size: 1.2em;
    padding: 40px 20px;
}

/* ========== ÉCRAN MOT DE PASSE ========== */
#passwordScreen {
    background: rgba(0, 0, 0, 0.7);
    z-index: 100;
}

#bv-app .password-box {
    background: white;
    border-radius: 12px;
    padding: 40px;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
}

#bv-app .password-box h2 {
    color: var(--text);
    margin-bottom: 10px;
    font-size: 1.5em;
}

#bv-app .password-box p {
    color: #7f8c8d;
    margin-bottom: 20px;
}

#passwordForm {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#passwordInput {
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.3s ease;
}

#passwordInput:focus {
    outline: none;
    border-color: var(--secondary);
}

#passwordInput.error {
    border-color: var(--accent);
}

#bv-app .error {
    color: var(--accent);
    font-size: 0.9em;
    display: none;
}

#bv-app .error.show {
    display: block;
}

#passwordForm button {
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: background 0.3s ease;
    font-weight: bold;
}

#passwordForm button[type="submit"] {
    background: var(--secondary);
    color: white;
    margin-bottom: 10px;
}

#passwordForm button[type="submit"]:hover {
    background: #2980b9;
}

#passwordForm button#backBtn {
    background: var(--light);
    color: var(--text);
    border: 2px solid var(--border);
}

#passwordForm button#backBtn:hover {
    background: #d5dbdb;
}

/* ========== ÉCRAN VISUALISEUR ========== */
#viewerScreen {
    background: #1a1a1a;
    flex-direction: column;
}

#bv-app .viewer-header {
    background: var(--primary);
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: var(--shadow);
}

#bv-app .menu-btn,
#bv-app .help-btn,
#bv-app .exit-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5em;
    cursor: pointer;
    padding: 8px;
    transition: transform 0.2s ease;
}

#bv-app .menu-btn:hover,
#bv-app .help-btn:hover,
#bv-app .exit-btn:hover {
    transform: scale(1.2);
}

#bv-app .help-btn {
    font-size: 1.15em;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.45);
    font-weight: 700;
    line-height: 1;
}

#viewerTitle {
    flex: 1;
    font-size: 1.3em;
    text-align: center;
}

#bv-app .viewer-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

#bv-app .viewer-help-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 70;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

#bv-app .viewer-help-overlay.active {
    display: flex;
}

#bv-app .viewer-help-modal {
    width: min(680px, 100%);
    max-height: min(78vh, 740px);
    overflow-y: auto;
    background: #ffffff;
    color: #1f2937;
    border-radius: 12px;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.35);
}

#bv-app .viewer-help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
}

#bv-app .viewer-help-header h3 {
    margin: 0;
    font-size: 1.05rem;
}

#bv-app .help-close-btn {
    border: none;
    background: none;
    color: #374151;
    font-size: 1.35rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

#bv-app .viewer-help-body {
    padding: 14px 16px 16px;
    font-size: 0.95rem;
}

#bv-app .viewer-help-body p {
    margin: 0 0 10px;
    line-height: 1.45;
}

#bv-app .book-viewer {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: #000;
    position: relative;
}

#bv-app .viewer-empty-state {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    color: #ecf0f1;
    font-size: 1.1em;
    background: rgba(0, 0, 0, 0.55);
    z-index: 5;
}

#bv-app .viewer-empty-state.active {
    display: flex;
}

#bv-app .page-wrapper {
    display: flex;
    gap: 0;
    width: 100%;
    height: 100%;
    max-width: 1400px;
    perspective: 1000px;
    transform-style: preserve-3d;
    position: relative;
}

#bv-app .page-wrapper.single-page-left,
#bv-app .page-wrapper.single-page-right {
    gap: 0;
    justify-content: center;
}

#bv-app .page-wrapper.single-page-left .page-right,
#bv-app .page-wrapper.single-page-right .page-left {
    display: none;
}

#bv-app .page-wrapper.single-page-left .page-left,
#bv-app .page-wrapper.single-page-right .page-right {
    flex: 0 1 980px;
    width: min(100%, 980px);
}

#bv-app .page {
    flex: 1;
    background: white;
    border-radius: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    position: relative;
    animation: pageFlip 0.6s ease-in-out;
    transform-style: preserve-3d;
    backface-visibility: hidden;
}

#bv-app .page-left {
    border-radius: 6px 0 0 6px;
    box-shadow: -10px 12px 34px rgba(0, 0, 0, 0.26);
}

#bv-app .page-right {
    border-radius: 0 6px 6px 0;
    box-shadow: 10px 12px 34px rgba(0, 0, 0, 0.26);
}

#bv-app .page-left::after,
#bv-app .page-right::before {
    content: none;
}

#bv-app .page-wrapper.single-page-left .page-left,
#bv-app .page-wrapper.single-page-right .page-right {
    border-radius: 6px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

#bv-app .page-wrapper.single-page-left .page-left::after,
#bv-app .page-wrapper.single-page-right .page-right::before {
    display: none;
}

#bv-app .page-wrapper.book-opening .page {
    animation: none;
}

#bv-app .page-wrapper.book-opening .page-right {
    transform-origin: left center;
    z-index: 20;
    animation: coverOpen 0.95s cubic-bezier(0.32, 0.02, 0.18, 1) forwards;
}

#bv-app .page-wrapper.book-opening .page-right .book-cover {
    box-shadow: none;
}

#bv-app .page img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: relative;
    z-index: 2;
}

#bv-app .page-custom-content {
    position: absolute;
    inset: 0;
    display: none;
    z-index: 3;
}

#bv-app .page-custom-content.active {
    display: block;
}

#bv-app .book-cover {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: #f5f5f5;
    background: transparent;
}

#bv-app .book-cover.book-cover-back .book-cover-inner {
    display: none;
}

#bv-app .book-cover-inner {
    width: 82%;
    padding: 32px 20px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(0, 0, 0, 0.28);
    text-align: center;
    box-shadow: 0 18px 28px rgba(0, 0, 0, 0.25);
}

#bv-app .book-cover-title {
    font-size: clamp(20px, 2.5vw, 34px);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    word-break: break-word;
}

#bv-app .book-cover-subtitle {
    margin-top: 14px;
    font-size: clamp(12px, 1.2vw, 16px);
    letter-spacing: 0.06em;
    opacity: 0.92;
    word-break: break-word;
}

#bv-app .cover-texture-linen-blue {
    background-color: #2f5f7f;
    background-image:
        radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.14), transparent 45%),
        repeating-linear-gradient(
            90deg,
            rgba(255, 255, 255, 0.08) 0px,
            rgba(255, 255, 255, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 2px,
            rgba(0, 0, 0, 0.08) 4px
        );
}

#bv-app .cover-texture-linen-cream {
    color: #2d2a25;
    background-color: #ddd2bc;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(0, 0, 0, 0.04) 0px,
            rgba(0, 0, 0, 0.04) 2px,
            rgba(255, 255, 255, 0.24) 2px,
            rgba(255, 255, 255, 0.24) 5px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(0, 0, 0, 0.03) 0px,
            rgba(0, 0, 0, 0.03) 1px,
            rgba(255, 255, 255, 0.18) 1px,
            rgba(255, 255, 255, 0.18) 4px
        );
}

#bv-app .cover-texture-linen-cream .book-cover-inner {
    background: rgba(255, 255, 255, 0.42);
    border-color: rgba(0, 0, 0, 0.18);
}

#bv-app .cover-texture-leather-brown {
    background-color: #5b3a24;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.1), transparent 50%),
        radial-gradient(circle at 80% 70%, rgba(0, 0, 0, 0.22), transparent 45%),
        repeating-linear-gradient(
            45deg,
            rgba(255, 255, 255, 0.03) 0px,
            rgba(255, 255, 255, 0.03) 6px,
            rgba(0, 0, 0, 0.08) 6px,
            rgba(0, 0, 0, 0.08) 12px
        );
}

#bv-app .cover-texture-leather-black {
    background-color: #1f2328;
    background-image:
        radial-gradient(circle at 70% 20%, rgba(255, 255, 255, 0.08), transparent 45%),
        repeating-linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.04) 0px,
            rgba(255, 255, 255, 0.04) 3px,
            rgba(0, 0, 0, 0.12) 3px,
            rgba(0, 0, 0, 0.12) 8px
        );
}

#bv-app .cover-texture-paper-gray {
    color: #262626;
    background-color: #c8c9cc;
    background-image:
        radial-gradient(circle at 12% 22%, rgba(255, 255, 255, 0.3), transparent 35%),
        radial-gradient(circle at 78% 72%, rgba(0, 0, 0, 0.08), transparent 30%),
        repeating-radial-gradient(
            circle at 0 0,
            rgba(0, 0, 0, 0.04) 0px,
            rgba(0, 0, 0, 0.04) 1px,
            transparent 1px,
            transparent 5px
        );
}

#bv-app .cover-texture-paper-gray .book-cover-inner {
    background: rgba(255, 255, 255, 0.36);
    border-color: rgba(0, 0, 0, 0.18);
}

#bv-app .cover-texture-canvas-green {
    background-color: #2d6048;
    background-image:
        repeating-linear-gradient(
            0deg,
            rgba(255, 255, 255, 0.06) 0px,
            rgba(255, 255, 255, 0.06) 2px,
            rgba(0, 0, 0, 0.12) 2px,
            rgba(0, 0, 0, 0.12) 6px
        ),
        repeating-linear-gradient(
            90deg,
            rgba(255, 255, 255, 0.05) 0px,
            rgba(255, 255, 255, 0.05) 1px,
            rgba(0, 0, 0, 0.08) 1px,
            rgba(0, 0, 0, 0.08) 5px
        );
}

#bv-app .cover-texture-custom {
    background-color: transparent;
    background-size: cover;
    background-position: center;
    background-repeat: repeat;
}

#bv-app .cover-texture-none {
    background-color: transparent;
    background-image: none;
}

#bv-app .page-number {
    position: absolute;
    bottom: 10px;
    right: 15px;
    font-size: 0.9em;
    color: #999;
    font-weight: bold;
}

#bv-app .page-left .page-number {
    left: 15px;
    right: auto;
}

@keyframes pageFlip {
    0% {
        opacity: 0.5;
        transform: rotateY(90deg);
    }
    100% {
        opacity: 1;
        transform: rotateY(0deg);
    }
}

@keyframes coverOpen {
    0% {
        transform: rotateY(0deg);
    }
    55% {
        transform: rotateY(-130deg);
    }
    100% {
        transform: rotateY(-170deg);
    }
}

/* ========== CONTRÔLES ========== */
#bv-app .controls {
    background: var(--primary);
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 20px;
    box-shadow: 0 -4px 6px rgba(0, 0, 0, 0.1);
}

#bv-app .control-btn {
    background: var(--secondary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s ease;
}

#bv-app .control-btn:hover {
    background: #2980b9;
}

#bv-app .control-btn:disabled {
    background: #7f8c8d;
    cursor: not-allowed;
    opacity: 0.6;
}

#bv-app .progress {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#pageInfo {
    text-align: center;
    font-size: 0.9em;
}

#bv-app .progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    overflow: hidden;
}

#bv-app .progress-fill {
    height: 100%;
    background: var(--secondary);
    transition: width 0.3s ease;
}

#bv-app .viewer-disclaimer {
    margin: 0;
    padding: 8px 20px 12px;
    background: var(--primary);
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.8rem;
    text-align: center;
}

#bv-app .comment-panel {
    margin: 0 0 16px;
    background: #f8fafc;
    color: #1f2937;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: none;
}

#bv-app .comment-panel h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}

#bv-app .comment-target-label {
    margin: 0 0 10px;
    color: #4b5563;
    font-size: 0.9rem;
}

#bv-app .comment-form {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px 12px;
}

#bv-app .comment-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#bv-app .comment-row label {
    font-size: 0.82rem;
    color: #4b5563;
}

#bv-app .comment-row input,
#bv-app .comment-row select,
#bv-app .comment-row textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 0.92rem;
}

#bv-app .comment-row textarea {
    min-height: 88px;
    resize: vertical;
}

#bv-app .comment-row:last-of-type {
    grid-column: 1 / -1;
}

#bv-app .comment-submit-btn {
    grid-column: 1 / -1;
    justify-self: start;
    border: none;
    border-radius: 6px;
    background: #1f6feb;
    color: #ffffff;
    font-weight: 600;
    padding: 9px 14px;
    cursor: pointer;
}

#bv-app .comment-submit-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

#bv-app .comment-message {
    min-height: 20px;
    margin-top: 8px;
    font-size: 0.88rem;
}

#bv-app .comment-message.is-success {
    color: #166534;
}

#bv-app .comment-message.is-error {
    color: #b91c1c;
}

#bv-app .comment-message.is-info {
    color: #1d4ed8;
}

/* ========== MENU LATÉRAL ========== */
#bv-app .side-menu {
    position: absolute;
    left: -300px;
    top: 0;
    width: 300px;
    height: 100%;
    background: white;
    box-shadow: var(--shadow-lg);
    transition: left 0.3s ease;
    z-index: 50;
    overflow-y: auto;
}

#bv-app .side-menu.active {
    left: 0;
}

#bv-app .menu-content {
    padding: 20px;
}

#bv-app .menu-content h3 {
    color: var(--text);
    margin-bottom: 20px;
    font-size: 1.2em;
}

#bv-app .chapters-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
}

#bv-app .page-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(to right, 
        var(--secondary) 0%, 
        var(--secondary) var(--value, 0%), 
        #ddd var(--value, 0%), 
        #ddd 100%);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

#bv-app .page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--secondary);
    cursor: pointer;
    box-shadow: var(--shadow);
}

#bv-app .page-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--secondary);
    cursor: pointer;
    border: none;
    box-shadow: var(--shadow);
}

#bv-app .slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.9em;
    color: #7f8c8d;
    margin-top: 10px;
}

#bv-app .close-menu-btn {
    width: 100%;
    padding: 12px;
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

#bv-app .close-menu-btn:hover {
    background: #2980b9;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    #bv-app .page-wrapper.book-opening .page-right {
        animation: none;
        transform: none;
    }

    #bv-app .page-wrapper.single-page-left .page-right,
    #bv-app .page-wrapper.single-page-right .page-left {
        display: none;
    }

    #bv-app .page-wrapper.single-page-left .page-left,
    #bv-app .page-wrapper.single-page-right .page-right {
        flex: 1 1 100%;
        width: 100%;
    }

    #bv-app .page-wrapper {
        flex-direction: column;
        gap: 10px;
    }

    #bv-app .page-left,
    #bv-app .page-right {
        border-radius: 4px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    }

    #bv-app .page-left::after,
    #bv-app .page-right::before {
        display: none;
    }

    #bv-app .page {
        flex: 0.6;
    }

    #bv-app .controls {
        flex-wrap: wrap;
    }

    #bv-app .control-btn {
        flex: 1;
        min-width: 100px;
    }

    #bv-app .progress {
        flex-basis: 100%;
        order: 3;
    }

    #bv-app .book-list {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }

    #bookListScreen h1 {
        font-size: 1.8em;
    }

    #bv-app .viewer-header {
        flex-wrap: wrap;
    }

    #viewerTitle {
        flex-basis: 100%;
        order: 2;
    }

    #bv-app .comment-panel {
        padding: 12px;
    }

    #bv-app .comment-form {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    #bv-app .page-wrapper {
        gap: 10px;
    }

    #bv-app .book-viewer {
        padding: 10px;
    }

    #bv-app .controls {
        padding: 10px;
        gap: 10px;
    }

    #bv-app .viewer-disclaimer {
        padding: 8px 10px 12px;
        font-size: 0.75rem;
    }

    #bv-app .comment-panel h3 {
        font-size: 0.95rem;
    }

    #bv-app .book-list {
        grid-template-columns: 1fr;
    }
}
