/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
    --bg-dark: #070b19;
    --bg-gradient: radial-gradient(circle at center, #0e1731 0%, #050814 100%);
    --bg-card: rgba(15, 23, 42, 0.45);
    --bg-control: rgba(255, 255, 255, 0.08);
    --bg-control-hover: rgba(255, 255, 255, 0.15);
    --primary: #38bdf8;
    --primary-glow: rgba(56, 189, 248, 0.3);
    --accent: #a78bfa;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.08);
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    --blur: blur(16px);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   GLOBAL STYLES & RESET
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    background-image: var(--bg-gradient);
    color: var(--text);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==========================================================================
   LOADING SCREEN
   ========================================================================== */
.loader-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-dark);
    background-image: var(--bg-gradient);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), transform 0.6s ease;
}

.loader-container.fade-out {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.05);
}

.loader-content {
    text-align: center;
    max-width: 320px;
    padding: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(56, 189, 248, 0.1);
    border-radius: 50%;
    border-top-color: var(--primary);
    margin: 0 auto 24px;
    animation: spin 1s linear infinite;
    box-shadow: 0 0 15px var(--primary-glow);
}

.loader-content h2 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 1.5rem;
    margin-bottom: 8px;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, var(--text) 30%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.loader-content p {
    font-family: 'Inter', sans-serif;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 300;
}

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

/* ==========================================================================
   MAIN APP STRUCTURE
   ========================================================================== */
#app {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ambient-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, rgba(56, 189, 248, 0.08) 0%, rgba(167, 139, 250, 0.03) 50%, rgba(0, 0, 0, 0) 70%);
    pointer-events: none;
    z-index: 0;
}

/* ==========================================================================
   HEADER SECTION
   ========================================================================== */
.app-header {
    position: relative;
    z-index: 10;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
    background-color: rgba(7, 11, 25, 0.3);
}

.header-logo {
    display: flex;
    flex-direction: column;
}

.logo-title {
    font-family: 'Cinzel', serif;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--text);
}

.logo-subtitle {
    font-family: 'Outfit', sans-serif;
    font-size: 0.75rem;
    color: var(--primary);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-weight: 500;
}

.header-actions {
    display: flex;
    gap: 12px;
}

/* ==========================================================================
   BUTTONS STYLING
   ========================================================================== */
.icon-button {
    background: var(--bg-control);
    border: 1px solid var(--border);
    color: var(--text);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
}

.icon-button:hover {
    background: var(--bg-control-hover);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.2);
}

.icon-button:active {
    transform: translateY(0);
}

.icon-button svg {
    transition: transform 0.2s ease;
}

.icon-button:hover svg {
    scale: 1.05;
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   BOOK CONTAINER & VIEWPORT
   ========================================================================== */
.book-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    z-index: 5;
    padding: 20px;
    overflow: hidden;
}

.zoom-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    transform-origin: center center;
    transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1);
    will-change: transform;
}

.zoom-wrapper.zoomed {
    cursor: grab;
}

.zoom-wrapper.zoomed:active {
    cursor: grabbing;
}

.book-viewport {
    position: relative;
    /* Landscape spread A3 ratio (2-page layout) by default */
    width: 90vw;
    height: calc(90vw / 1.414);
    max-height: 62vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.5s cubic-bezier(0.25, 1, 0.5, 1);
    filter: drop-shadow(0 20px 40px rgba(0, 0, 0, 0.65));
}

.book-viewport.align-right-page {
    transform: translateX(-25%);
}

.book-viewport.align-left-page {
    transform: translateX(25%);
}

.book-viewport.align-center {
    transform: translateX(0);
}

@media (min-width: 769px) {
    .book-viewport {
        width: min(92vw, 130vh);
        height: calc(min(92vw, 130vh) / 1.414); /* Desktop height boundary constraint */
        max-height: 72vh;
    }
}

.book-3d {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
}

/* ==========================================================================
   PAGE STYLING (PAGEFLIP LIBRARY)
   ========================================================================== */
.page {
    background-color: #0b1120;
    overflow: hidden;
}

.page-content {
    width: 100%;
    height: 100%;
    position: relative;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.3);
}

.pdf-page-img {
    width: 100%;
    height: 100%;
    object-fit: fill;
    display: block;
}

/* Page shadows/spine effects */
.page-content::before {
    content: '';
    position: absolute;
    top: 0;
    width: 30px;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    opacity: 0.8;
    transition: var(--transition);
}

/* Dynamic Left/Right Spine Shadow Added by page-flip classes */
.page.--left .page-content::before {
    right: 0;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0) 100%);
}

.page.--right .page-content::before {
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0) 100%);
}

/* Hard covers shadow override */
.page[data-density="hard"] .page-content::before {
    opacity: 0.15;
}

/* ==========================================================================
   CONTROLS PANEL
   ========================================================================== */
.app-controls {
    position: relative;
    z-index: 10;
    padding: 16px 20px 24px;
    backdrop-filter: var(--blur);
    background-color: rgba(7, 11, 25, 0.4);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
}

.controls-container {
    width: 100%;
    max-width: 720px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.nav-button {
    background: var(--bg-control);
    border: 1px solid var(--border);
    color: var(--text);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.nav-button:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #070b19;
    transform: scale(1.08);
    box-shadow: 0 0 15px var(--primary-glow);
}

.nav-button:active {
    transform: scale(0.98);
}

.controls-middle {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* ==========================================================================
   CUSTOM SLIDER DESIGN
   ========================================================================== */
.page-slider-wrap {
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    padding: 4px 0;
}

#page-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.12);
    outline: none;
    cursor: pointer;
    z-index: 2;
}

#page-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid #070b19;
    cursor: pointer;
    transition: transform 0.1s ease;
    box-shadow: 0 0 8px var(--primary-glow);
}

#page-slider::-webkit-slider-thumb:hover {
    transform: scale(1.25);
    background: var(--text);
}

#page-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    border: 3px solid #070b19;
    cursor: pointer;
    transition: transform 0.1s ease;
    box-shadow: 0 0 8px var(--primary-glow);
}

#page-slider::-moz-range-thumb:hover {
    transform: scale(1.25);
    background: var(--text);
}

.slider-progress {
    position: absolute;
    left: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--accent) 0%, var(--primary) 100%);
    border-radius: 3px;
    pointer-events: none;
    z-index: 1;
}

/* ==========================================================================
   PAGE INFO & ZOOM DISPLAY
   ========================================================================== */
.page-info {
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    color: var(--text);
}

.zoom-controls {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 8px;
    gap: 8px;
}

.icon-button-small {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition);
}

.icon-button-small:hover {
    background: var(--bg-control-hover);
    color: var(--primary);
}

#zoom-display {
    font-size: 0.75rem;
    font-weight: 600;
    width: 36px;
    text-align: center;
    color: var(--text);
}

/* ==========================================================================
   MOBILE & LANDSCAPE RESPONSIVENESS OVERRIDES
   ========================================================================== */

/* Zoom scale handling */
.zoom-active {
    overflow: auto !important;
}

/* Adjustments for mobile screen details */
@media (max-width: 600px) {
    .app-header {
        padding: 12px 16px;
    }
    
    .logo-title {
        font-size: 1rem;
    }

    .nav-button {
        width: 42px;
        height: 42px;
    }

    .app-controls {
        padding: 12px 16px 20px;
    }

    .controls-container {
        gap: 8px;
    }
    
    .page-info {
        font-size: 0.8rem;
    }
}

/* Landscape orientation on mobile adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .app-header {
        padding: 8px 16px;
    }
    
    .logo-title {
        font-size: 0.95rem;
    }
    
    .logo-subtitle {
        display: none;
    }

    .book-viewport {
        max-height: 52vh;
    }

    .app-controls {
        padding: 6px 16px 8px;
    }
    
    .controls-middle {
        flex-direction: row;
        justify-content: space-between;
        gap: 16px;
        width: 100%;
    }

    .page-slider-wrap {
        flex: 1;
    }

    .zoom-controls {
        padding: 2px 6px;
    }
}
