/* Custom Properties / Design Tokens */
:root {
    --bg-gradient: radial-gradient(ellipse at center, #1c2035 0%, #08090d 100%);
    --panel-bg: rgba(22, 26, 41, 0.75);
    --panel-border: rgba(255, 255, 255, 0.08);
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-glow: rgba(99, 102, 241, 0.35);
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --control-bar-height: 56px;
    --shadow-premium: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --glass-blur: blur(12px);
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Plus Jakarta Sans', 'Outfit', system-ui, -apple-system, sans-serif;
    background: #06070a;
    color: var(--text-main);
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--bg-gradient);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.02); }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.3); }

/* Overlay (Loading) */
.overlay {
    position: absolute;
    inset: 0;
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(7, 9, 15, 0.92);
    backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}
.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* Loading Card */
.loading-card {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: var(--glass-blur);
    padding: 2.5rem 2rem;
    border-radius: 24px;
    width: 90%;
    max-width: 420px;
    text-align: center;
    box-shadow: var(--shadow-premium);
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.overlay.active .loading-card {
    transform: translateY(0);
}

h3 {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.loading-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1.25rem;
}

/* Spinner */
.spinner {
    width: 50px;
    height: 50px;
    position: relative;
    margin: 0 auto 1.25rem auto;
}
.double-bounce1, .double-bounce2 {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--primary-color);
    opacity: 0.6;
    position: absolute;
    top: 0; left: 0;
    animation: bounce 2s infinite ease-in-out;
    filter: drop-shadow(0 0 10px var(--primary-glow));
}
.double-bounce2 { animation-delay: -1s; }

.progress-bar-container {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 0.4rem;
}
.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), #818cf8);
    border-radius: 10px;
    transition: width 0.2s ease;
}
#progress-percentage {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* ===== MAIN VIEWER LAYOUT ===== */
#viewer-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 1;
    transition: opacity 0.5s ease;
}
#viewer-container.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Book Viewport: the area where the book lives */
#book-viewport {
    flex: 1;
    width: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    /* Generous padding: top, sides, and extra bottom to clear the control bar */
    padding: 2rem 4rem calc(var(--control-bar-height) + 2.5rem) 4rem;
    overflow: hidden;
}

#book-container {
    display: flex;
    justify-content: center;
    align-items: center;
    /* Hard cap: the book never exceeds these fractions of the viewport */
    width: 100%;
    height: 100%;
    max-width: 90vw;
    max-height: 85vh;
    perspective: 2000px;
    transform-origin: center center;
    transition: transform 0.2s ease-out;
}

#book {
    box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 30px rgba(0, 0, 0, 0.2);
    background-color: transparent;
    opacity: 0;
    transition: opacity 0.5s ease;
}
#book.ready {
    opacity: 1;
}

/* Pages Styling */
.my-page {
    background-color: #ffffff;
    box-shadow: inset 3px 0 20px rgba(0,0,0,0.08), inset -3px 0 20px rgba(0,0,0,0.08);
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}
.my-page canvas {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

/* ===== FLOATING CONTROL BAR ===== */
#control-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: 92%;
    height: var(--control-bar-height);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    backdrop-filter: var(--glass-blur);
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 1rem;
    gap: 0.25rem;
    box-shadow: var(--shadow-premium);
    z-index: 50;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}
.control-group.left,
.control-group.right {
    flex-shrink: 0;
}
.control-group.navigation {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    margin: 0 0.5rem;
}

.control-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    flex-shrink: 0;
}
.control-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.06);
    transform: scale(1.05);
}
.control-btn:active {
    transform: scale(0.95);
}
.control-btn.active {
    color: white;
    background: var(--primary-color);
    box-shadow: 0 0 10px var(--primary-glow);
}

.page-indicator {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-main);
    padding: 0 0.3rem;
}

#page-num-input {
    width: 36px;
    height: 26px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    border-radius: 6px;
    font-weight: 600;
    font-family: inherit;
    font-size: 0.85rem;
    outline: none;
    transition: var(--transition-smooth);
    -moz-appearance: textfield;
}
#page-num-input::-webkit-outer-spin-button,
#page-num-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
#page-num-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 5px var(--primary-glow);
}
#page-count-separator { color: var(--text-muted); }
#total-pages { color: var(--text-muted); }

/* Divider line between control groups */
.control-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.08);
    margin: 0 0.4rem;
    flex-shrink: 0;
}

/* Animations */
@keyframes bounce {
    0%, 100% { transform: scale(0.0); }
    50% { transform: scale(1.0); }
}

/* ===== RESPONSIVE ===== */

/* Tablet landscape */
@media (max-width: 1100px) {
    #book-viewport {
        padding: 1.5rem 2.5rem calc(var(--control-bar-height) + 2rem) 2.5rem;
    }
}

/* Tablet portrait */
@media (max-width: 900px) {
    #book-viewport {
        padding: 1.25rem 1.5rem calc(var(--control-bar-height) + 1.5rem) 1.5rem;
    }
    #control-bar {
        bottom: 14px;
        height: 50px;
        border-radius: 14px;
        padding: 0 0.75rem;
    }
    .control-btn {
        width: 34px;
        height: 34px;
        font-size: 0.9rem;
    }
    /* Hide zoom and first/last on tablets */
    #zoom-in-btn, #zoom-out-btn,
    #first-page-btn, #last-page-btn {
        display: none;
    }
}

/* Phone */
@media (max-width: 600px) {
    #book-viewport {
        padding: 0.75rem 0.5rem calc(var(--control-bar-height) + 1rem) 0.5rem;
    }
    #control-bar {
        bottom: 10px;
        height: 46px;
        border-radius: 12px;
        padding: 0 0.5rem;
        max-width: 96%;
    }
    .control-btn {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
    }
    .control-group.navigation {
        margin: 0 0.2rem;
    }
    .page-indicator {
        font-size: 0.8rem;
    }
    #page-num-input {
        width: 30px;
        height: 24px;
        font-size: 0.8rem;
    }
    /* Hide non-essential on phones */
    #zoom-in-btn, #zoom-out-btn,
    #first-page-btn, #last-page-btn,
    #autoplay-btn,
    .control-divider {
        display: none;
    }
}

/* Very small phones */
@media (max-width: 400px) {
    #book-viewport {
        padding: 0.5rem 0.25rem calc(var(--control-bar-height) + 0.75rem) 0.25rem;
    }
    #control-bar {
        gap: 0;
        padding: 0 0.35rem;
    }
    .control-btn {
        width: 28px;
        height: 28px;
        font-size: 0.8rem;
    }
}
