/* Custom CSS Design System - Premium Dark Theme & 3D Book Layout */

:root {
    --bg-primary: #0a0b10;
    --bg-secondary: #12131a;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --accent-color: #d4af37; /* Metallic Gold */
    --accent-glow: rgba(212, 175, 55, 0.25);
    --glass-bg: rgba(18, 20, 30, 0.7);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow-premium: 0 20px 40px rgba(0, 0, 0, 0.6);
    --page-width: 600px;
    --page-height: 450px; /* 4:3 Aspect Ratio */
    --transition-speed: 0.8s;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Ambient Radial Glows */
.bg-glow {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    z-index: 0;
    opacity: 0.15;
}

.bg-glow-1 {
    background: var(--accent-color);
    top: -200px;
    left: -200px;
}

.bg-glow-2 {
    background: #7c3aed; /* Deep Purple */
    bottom: -200px;
    right: -200px;
}

/* Header Styling */
.app-header {
    height: 70px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
}

.header-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 15px;
}

.brand-badge {
    background: var(--accent-color);
    color: #000;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 1px;
}

.brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 3px;
    color: var(--text-primary);
}

.brand-separator {
    color: rgba(255, 255, 255, 0.2);
    font-weight: 300;
}

.catalog-title {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 300;
    letter-spacing: 1px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-download {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
}

.btn-download:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

/* Main Flipbook Wrapper */
.flipbook-wrapper {
    flex-grow: 1;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    z-index: 5;
}

/* Floating Navigation Arrows */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.nav-arrow:hover {
    background: var(--accent-color);
    color: #000;
    border-color: var(--accent-color);
    box-shadow: 0 0 15px var(--accent-glow);
}

.nav-arrow:active {
    transform: translateY(-50%) scale(0.95);
}

.nav-arrow-left {
    left: 40px;
}

.nav-arrow-right {
    right: 40px;
}

.nav-arrow:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    background: transparent;
    border-color: var(--glass-border);
    color: var(--text-secondary);
    box-shadow: none;
}

/* Viewer Container & Zooming */
.viewer-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 2000px;
    transition: transform 0.3s ease-out;
}

/* Zoom Mode Styling */
.viewer-container.zoomed {
    cursor: grab;
    overflow: auto;
}

.viewer-container.zoomed:active {
    cursor: grabbing;
}

/* Flipbook Core CSS */
.flipbook {
    position: relative;
    width: calc(var(--page-width) * 2);
    height: var(--page-height);
    transform-style: preserve-3d;
    box-shadow: var(--shadow-premium);
    border-radius: 12px;
    transition: transform 0.5s ease;
}

/* Book Spine shadow */
.book-spine {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 100%;
    background: linear-gradient(to right, 
        rgba(0,0,0,0) 0%, 
        rgba(0,0,0,0.3) 25%, 
        rgba(0,0,0,0.5) 50%, 
        rgba(0,0,0,0.3) 75%, 
        rgba(0,0,0,0) 100%
    );
    z-index: 10;
    pointer-events: none;
}

/* Individual Sheet Container */
.sheet {
    position: absolute;
    top: 0;
    right: 0;
    width: 50%;
    height: 100%;
    transform-origin: left center;
    transform-style: preserve-3d;
    transition: transform var(--transition-speed) cubic-bezier(0.25, 1, 0.5, 1);
    pointer-events: none;
}

/* Enable pointer events only for top sheet faces */
.sheet .page-face {
    pointer-events: auto;
}

/* Page Faces */
.page-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    overflow: hidden;
    background-color: #1a1b26;
    display: flex;
    justify-content: center;
    align-items: center;
}

.page-face img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background-color: #1a1b26;
    user-select: none;
    -webkit-user-drag: none;
}

.page-face.front {
    z-index: 2;
    transform: rotateY(0deg);
    border-radius: 0 8px 8px 0;
}

.page-face.back {
    z-index: 1;
    transform: rotateY(180deg);
    border-radius: 8px 0 0 8px;
}

/* Flipped State */
.sheet.flipped {
    transform: rotateY(-180deg);
}

/* Spine Shadow effect inside pages */
.page-face::after {
    content: '';
    position: absolute;
    top: 0;
    width: 40px;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.page-face.front::after {
    left: 0;
    background: linear-gradient(to right, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0) 100%);
}

.page-face.back::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.25) 0%, rgba(0,0,0,0) 100%);
}

/* Paper Fold / Curl Shadow overlay during turn */
.sheet-shadow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    z-index: 3;
    pointer-events: none;
    backface-visibility: hidden;
    opacity: 0;
    transition: opacity var(--transition-speed) ease;
}

.sheet.flipping .sheet-shadow {
    opacity: 1;
}

/* Controls & Thumbnails Dock */
.controls-dock {
    width: 100%;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    padding: 15px 0 20px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    position: relative;
    z-index: 10;
}

/* Thumbnail Carousel */
.thumbnails-container {
    width: 100%;
    max-width: 900px;
    padding: 0 20px;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) transparent;
}

/* Custom Scrollbar for Thumbnails */
.thumbnails-container::-webkit-scrollbar {
    height: 4px;
}

.thumbnails-container::-webkit-scrollbar-track {
    background: transparent;
}

.thumbnails-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.thumbnails-container::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

.thumbnails-track {
    display: flex;
    gap: 12px;
    padding: 5px 0;
}

.thumb-item {
    flex: 0 0 50px;
    height: 70px;
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0.6;
    position: relative;
}

.thumb-item:hover {
    opacity: 1;
    transform: translateY(-3px);
}

.thumb-item.active {
    opacity: 1;
    border-color: var(--accent-color);
    box-shadow: 0 0 10px var(--accent-glow);
}

.thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    font-size: 0.6rem;
    text-align: center;
    padding: 1px 0;
}

/* Toolbar Control Panel */
.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 6px 20px;
    border-radius: 30px;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.05);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 5px;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 10px;
}

.btn-tool {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}

.btn-tool:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.btn-tool:active {
    transform: scale(0.92);
}

.btn-tool.active-toggle {
    color: var(--accent-color);
    background: var(--accent-glow);
}

.btn-tool:disabled {
    opacity: 0.2;
    cursor: not-allowed;
    background: transparent !important;
    color: var(--text-secondary) !important;
}

/* Pager Info */
.pager-display {
    padding: 0 10px;
}

.page-info {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

#page-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    width: 45px;
    text-align: center;
    padding: 4px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
}

#page-input::-webkit-inner-spin-button,
#page-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#page-input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 5px var(--accent-glow);
}

/* Mobile / Portrait Responsive overrides */
@media (max-width: 1024px) {
    :root {
        --page-width: 440px;
        --page-height: 330px;
    }
}

@media (max-width: 768px) {
    :root {
        --page-width: 360px;
        --page-height: 270px;
    }
    
    .nav-arrow {
        width: 45px;
        height: 45px;
        font-size: 1rem;
    }
    
    .nav-arrow-left { left: 10px; }
    .nav-arrow-right { right: 10px; }
    
    .app-header {
        height: 60px;
    }
    
    .brand h1 {
        font-size: 1.1rem;
        letter-spacing: 1px;
    }
    
    .catalog-title {
        display: none;
    }
    
    .brand-separator {
        display: none;
    }
    
    .btn-download span {
        display: none;
    }
    
    .btn-download {
        padding: 10px;
    }
}

/* Mobile Portrait Mode - Single Page Display */
@media (max-width: 600px) {
    :root {
        --page-width: 90vw;
        --page-height: 67.5vw; /* Keep 4:3 ratio */
    }
    
    .flipbook {
        width: var(--page-width);
        height: var(--page-height);
    }
    
    .sheet {
        width: 100%;
        left: 0;
        right: auto;
        transform-origin: center center;
    }
    
    /* Disable 3D flips in mobile, use fades or sliding transitions */
    .sheet.flipped {
        transform: none;
        display: none; /* Hide flipped pages on mobile to show single active page */
    }
    
    .page-face.back {
        transform: none;
        display: none;
    }
    
    .page-face.front {
        border-radius: 8px;
    }
    
    .book-spine {
        display: none;
    }
    
    .thumbnails-container {
        display: none;
    }
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #06070a;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    z-index: 1000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-overlay.fade-out {
    opacity: 0;
    visibility: hidden;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.05);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loader-text {
    font-size: 0.95rem;
    letter-spacing: 2px;
    color: var(--text-secondary);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
