/* PDF Flipbook Animator Styles - Fully Responsive */

:root {
    --primary-color: #2196F3;
    --bg-color: #f5f5f5;
    --text-color: #333;
    --border-color: #ddd;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.container {
    width: 100%;
    height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: row;
}

/* Side Panels Layout (Desktop/Tablet Default) */
.left-panel,
.right-panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.98);
    border-right: 1px solid var(--border-color);
    padding: 15px 10px;
    gap: 20px;
}

.left-panel {
    width: 80px;
    border-right: 1px solid var(--border-color);
}

.right-panel {
    width: 180px;
    border-left: 1px solid var(--border-color);
    border-right: none;
    justify-content: flex-start;
    padding: 20px 15px;
}

/* Side Navigation Buttons (Base Styles) */
.side-nav-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 20px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 60px;
}

.side-nav-btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--primary-color) 85%, black);
    transform: scale(1.05);
    box-shadow: var(--shadow);
}

.side-nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.side-nav-btn .arrow {
    font-size: 2rem;
    line-height: 1;
}

/* Panel Header */
.panel-header {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--primary-color);
}

.panel-header .title {
    font-size: 0.95rem;
    color: var(--primary-color);
    font-weight: 700;
    text-align: center;
    margin: 0;
    line-height: 1.3;
    word-break: break-word;
}

.icon-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: var(--transition);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: color-mix(in srgb, var(--primary-color) 85%, black);
    transform: scale(1.05);
}

.toc-btn-label {
    width: auto;
    padding: 8px 12px;
    font-size: 0.85rem;
    gap: 4px;
    white-space: nowrap;
}

/* Main Content - Full Height */
.main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 0;
    width: 100%;
    height: 100vh;
    perspective: 2400px;
    perspective-origin: center center;
    overflow: hidden;
}

.main.zoomed {
    cursor: grab;
}

.main.panning {
    cursor: grabbing;
}

.flipbook {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: visible;
    background: white;
    position: relative;
    transform: translateZ(0);
    backface-visibility: hidden;
}

#stpageflip-container {
    transform: translateZ(0);
    backface-visibility: hidden;
    /* High-quality image rendering for smooth text */
    image-rendering: auto;
    image-rendering: -webkit-optimize-legibility;
    image-rendering: high-quality;
    -ms-interpolation-mode: bicubic;
}

.page {
    display: none;
    width: 100%;
    height: 100%;
    background: white;
    position: absolute;
    top: 0;
    left: 0;
}

.page.active {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
}

.page img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    
    /* High-quality image rendering for sharp text */
    image-rendering: auto;
    image-rendering: -webkit-optimize-legibility;
    image-rendering: high-quality;
    -ms-interpolation-mode: bicubic;
    
    /* Font smoothing for text in images */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Link Overlay - Clickable PDF Links */
#link-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.pdf-link {
    position: absolute;
    cursor: pointer;
    pointer-events: auto;
    transition: background-color 0.2s ease;
    border-radius: 2px;
}

.pdf-link:hover {
    background-color: rgba(33, 150, 243, 0.2);
}

.pdf-link:active {
    background-color: rgba(33, 150, 243, 0.3);
}

/* Hide links during page flip animation */
#link-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* TOC Drawer */
.toc-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.toc-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

.toc-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 360px;
    max-width: 85vw;
    height: 100vh;
    background: #1a1a2e;
    color: #e0e0e0;
    z-index: 2001;
    transform: translateX(-100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
}

.toc-drawer.visible {
    transform: translateX(0);
}

.toc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #16213e;
    border-bottom: 2px solid var(--primary-color);
    flex-shrink: 0;
}

.toc-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: white;
    margin: 0;
}

.toc-close-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.6rem;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    line-height: 1;
}

.toc-close-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

.toc-search {
    padding: 12px 16px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.toc-search input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s;
}

.toc-search input::placeholder {
    color: #777;
}

.toc-search input:focus {
    border-color: var(--primary-color);
}

.toc-list {
    list-style: none;
    padding: 8px 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.toc-list::-webkit-scrollbar {
    width: 6px;
}

.toc-list::-webkit-scrollbar-track {
    background: transparent;
}

.toc-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.toc-item {
    padding: 10px 20px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.toc-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-left-color: var(--primary-color);
}

.toc-item.active {
    background: rgba(33, 150, 243, 0.15);
    border-left-color: var(--primary-color);
    color: white;
}

.toc-item.hidden {
    display: none;
}

.toc-item-title {
    flex: 1;
    font-size: 0.85rem;
    line-height: 1.4;
    word-break: break-word;
}

.toc-item-page {
    font-size: 0.75rem;
    color: #888;
    flex-shrink: 0;
    padding-top: 2px;
}

.toc-item.active .toc-item-page {
    color: var(--primary-color);
}

/* TOC level indentation */
.toc-item[data-level="1"] {
    padding: 12px 20px;
    font-weight: 700;
    font-size: 0.95rem;
    background: linear-gradient(135deg, rgba(33, 150, 243, 0.15), rgba(33, 150, 243, 0.05));
    border-left: 4px solid var(--primary-color);
    margin-top: 6px;
    color: #fff;
}

.toc-item[data-level="1"]:hover {
    background: linear-gradient(135deg, rgba(33, 150, 243, 0.25), rgba(33, 150, 243, 0.1));
}

.toc-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: 0.65rem;
    margin-right: 6px;
    flex-shrink: 0;
    transition: transform 0.2s;
    color: var(--primary-color);
    cursor: pointer;
    border-radius: 3px;
}

.toc-toggle:hover {
    background: rgba(255,255,255,0.1);
}

.toc-item.collapsed .toc-toggle {
    transform: rotate(-90deg);
}

.toc-item[data-level="2"] {
    padding-left: 40px;
    font-weight: 600;
}

.toc-item[data-level="3"] {
    padding-left: 52px;
    font-weight: 400;
    color: #bbb;
}

.toc-item[data-level="4"] {
    padding-left: 64px;
    font-weight: 400;
    color: #999;
    font-size: 0.8rem;
}

.toc-child-hidden {
    display: none !important;
}

.toc-no-results {
    padding: 20px;
    text-align: center;
    color: #777;
    font-size: 0.85rem;
}

/* Zoom Controls */
.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    margin-top: 10px;
}

.zoom-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 18px;
    transition: var(--transition);
    min-width: 36px;
}

.zoom-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.zoom-btn:active {
    transform: scale(0.95);
}

.zoom-level {
    font-size: 14px;
    font-weight: 600;
    min-width: 50px;
    text-align: center;
    color: var(--text-color);
}

.flipbook.zoomed {
    cursor: grab;
}

.flipbook.panning {
    cursor: grabbing;
    pointer-events: none;
}

.page {
    touch-action: pan-x pan-y pinch-zoom;
    user-select: none;
}

/* Loading Spinner */
.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    display: none;
}

.loading-spinner.show {
    display: block;
}

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Controls - Compact */
.controls {
    flex-shrink: 0;
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    padding: 8px 15px;
    background: rgba(255, 255, 255, 0.95);
}

.nav-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--primary-color) 80%, black);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Page Info */
.page-info {
    text-align: center;
    width: 100%;
    padding: 15px 0;
}

.page-indicator {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    display: block;
}

/* Progress Bar */
.progress-container {
    width: 100%;
    padding: 15px 0;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* Help Text */
.help-text {
    margin-top: auto;
    padding-top: 20px;
    text-align: center;
    color: #666;
    font-size: 0.7rem;
    line-height: 1.6;
    border-top: 1px solid var(--border-color);
}

.help-text p {
    margin: 4px 0;
}

/* Responsive Design with Dynamic Perspective */

/* Mobile: VERTICAL LAYOUT (Header/Footer instead of Side Panels) */
@media (max-width: 767px) {
    /* Switch to vertical column layout */
    .container {
        flex-direction: column;
    }
    
    .main {
        perspective: 1200px;
        order: 2;
        flex: 1;
    }
    
    /* Left panel becomes HEADER at top */
    .left-panel {
        order: 1;
        width: 100%;
        height: auto;
        flex-direction: row;
        padding: 6px 10px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        gap: 8px;
        align-items: center;
    }
    
    /* Right panel becomes FOOTER at bottom */
    .right-panel {
        order: 3;
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 6px 10px;
        border-left: none;
        border-top: 1px solid var(--border-color);
        gap: 6px;
        justify-content: center;
        align-items: center;
    }
    
    /* Header/Footer button styling */
    .side-nav-btn {
        flex-direction: row;
        min-height: auto;
        padding: 8px 14px;
        gap: 8px;
        width: auto;
        flex: 0 0 auto;
    }
    
    .side-nav-btn .arrow {
        font-size: 1.2rem;
    }
    
    .side-nav-btn .label {
        display: inline;
        font-size: 0.85rem;
    }
    
    /* Hide title on mobile to save space */
    .panel-header .title {
        display: none;
    }
    
    /* Panel header becomes a compact button row */
    .panel-header {
        flex-direction: row;
        border-bottom: none;
        border-right: none;
        padding: 0;
        margin: 0;
        gap: 6px;
        flex: 0 0 auto;
        min-width: 0;
    }
    
    .icon-btn {
        width: 36px;
        height: 36px;
        font-size: 1rem;
        padding: 6px;
    }
    
    .toc-btn-label {
        width: auto;
        padding: 6px 8px;
        font-size: 0.75rem;
        height: 36px;
    }
    
    /* Compact zoom controls inline */
    .zoom-controls {
        margin-top: 0;
        padding: 4px 6px;
        gap: 4px;
        flex: 0 0 auto;
        border: 1px solid var(--border-color);
        border-radius: 6px;
    }
    
    .zoom-btn {
        padding: 4px 8px;
        font-size: 14px;
        min-width: 28px;
    }
    
    .zoom-level {
        font-size: 11px;
        min-width: 36px;
    }
    
    /* Page info horizontal */
    .page-info {
        padding: 0;
        flex: 0 0 auto;
    }
    
    .page-indicator {
        font-size: 0.9rem;
        writing-mode: horizontal-tb;
    }
    
    /* Progress bar spans full width at bottom of footer */
    .progress-container {
        padding: 0;
        flex: 1 1 100%;
        max-width: 100%;
        order: 10;
    }
    
    .help-text {
        display: none;
    }
}

/* Tablet: Adjusted side panels */
@media (min-width: 768px) and (max-width: 1023px) {
    .main {
        perspective: 1800px;
    }
    
    .left-panel {
        width: 70px;
    }
    
    .right-panel {
        width: 140px;
    }
    
    .panel-header .title {
        font-size: 0.85rem;
    }
}

/* Desktop: Two-page spread, full perspective */
@media (min-width: 1024px) {
    .main {
        perspective: 2400px;
    }

    .flipbook {
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .page {
        max-width: 50%;
        flex: 0 0 auto;
        position: relative !important;
    }

    .page img {
        max-width: 100%;
        width: auto;
        height: auto;
        object-fit: contain;
    }

    /* Book spine shadow effect between pages */
    .page.active:first-child {
        box-shadow: 3px 0 10px rgba(0,0,0,0.2);
    }

    .page.active + .page.active {
        box-shadow: -3px 0 10px rgba(0,0,0,0.2);
    }
}

/* Extra small mobile devices - Compact header/footer */
@media (max-width: 480px) {
    .left-panel,
    .right-panel {
        padding: 5px 8px;
        gap: 5px;
    }
    
    .side-nav-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }
    
    .side-nav-btn .arrow {
        font-size: 1rem;
    }
    
    .side-nav-btn .label {
        font-size: 0.75rem;
    }
    
    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
        padding: 4px;
    }
    
    .toc-btn-label {
        width: auto;
        padding: 4px 6px;
        font-size: 0.7rem;
        height: 32px;
    }
    
    .zoom-controls {
        padding: 3px 4px;
        gap: 3px;
    }
    
    .zoom-btn {
        padding: 3px 6px;
        font-size: 12px;
        min-width: 24px;
    }
    
    .zoom-level {
        font-size: 10px;
        min-width: 30px;
    }
    
    .page-indicator {
        font-size: 0.8rem;
    }
    
    .progress-container {
        max-width: 100%;
    }
}

/* Fullscreen Mode - Semi-transparent side panels */
.container:fullscreen {
    background: var(--bg-color);
    width: 100vw;
    height: 100vh;
}

.container:fullscreen .left-panel,
.container:fullscreen .right-panel {
    background: rgba(255, 255, 255, 0.85);
    opacity: 0.7;
    transition: opacity 0.3s;
}

.container:fullscreen .left-panel:hover,
.container:fullscreen .right-panel:hover {
    opacity: 1;
}

.container:fullscreen .help-text {
    opacity: 0.6;
}

.container:fullscreen .main {
    height: 100vh;
}

.container:fullscreen .flipbook {
    width: 100%;
    height: 100%;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1a1a1a;
        --text-color: #e0e0e0;
        --border-color: #444;
    }

    body {
        background: var(--bg-color);
        color: var(--text-color);
    }

    .page-indicator {
        background: #2a2a2a;
        color: var(--text-color);
    }
}

/* Print Styles */
@media print {
    .header, .controls, .footer {
        display: none !important;
    }

    .page {
        display: block !important;
        page-break-after: always;
    }

    .page img {
        max-height: 100vh;
        page-break-inside: avoid;
    }
}
