/* ============================================
   FlipBook Reader — Premium Light/White Contrast UI
   ============================================ */

/* ---------- Design Tokens ---------- */
:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --bg-tertiary: #e2e8f0;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-bg-light: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-border-hover: rgba(0, 0, 0, 0.15);
    --accent-primary: #3b82f6;
    --accent-secondary: #2563eb;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    --accent-glow: rgba(59, 130, 246, 0.35);
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --danger: #ef4444;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --shadow-soft: 0 4px 24px rgba(0, 0, 0, 0.06);
    --shadow-strong: 0 8px 48px rgba(0, 0, 0, 0.12);
    --shadow-glow: 0 0 30px var(--accent-glow);
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    color: var(--text-primary);
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 15% 50%, rgba(59, 130, 246, 0.05) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 20%, rgba(37, 99, 235, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 85%, rgba(14, 165, 233, 0.03) 0%, transparent 45%);
    height: 100%;
    overflow: hidden;
    user-select: none;
}

button {
    font-family: inherit;
    border: none;
    background: none;
    cursor: pointer;
    color: inherit;
    outline: none;
}

input {
    font-family: inherit;
    border: none;
    outline: none;
    background: none;
    color: inherit;
}

.hidden {
    display: none !important;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}


/* ============================================
   LOADING SCREEN
   ============================================ */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse at 30% 40%, rgba(59, 130, 246, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 60%, rgba(37, 99, 235, 0.06) 0%, transparent 50%);
    transition: opacity var(--transition-slow), visibility var(--transition-slow);
}

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

.loading-content {
    text-align: center;
    max-width: 380px;
    padding: 0 24px;
}

/* Animated book icon */
.loading-icon {
    margin-bottom: 28px;
    display: inline-flex;
    position: relative;
}

.loading-icon svg {
    width: 64px;
    height: 64px;
    stroke: var(--accent-primary);
    animation: loadingPulse 2s ease-in-out infinite;
}

@keyframes loadingPulse {
    0%, 100% { transform: scale(1); opacity: 0.8; filter: drop-shadow(0 0 8px var(--accent-glow)); }
    50% { transform: scale(1.08); opacity: 1; filter: drop-shadow(0 0 20px var(--accent-glow)); }
}

.loading-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.loading-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 32px;
    min-height: 1.25em;
}

.progress-container {
    width: 100%;
    height: 4px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: 2px;
    transition: width 0.3s ease;
    box-shadow: 0 0 12px var(--accent-glow);
}

.progress-percentage {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.05em;
}


/* ============================================
   MAIN APP
   ============================================ */
#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity var(--transition-slow);
}

#app.fade-in {
    opacity: 1;
}

/* ---------- Title Bar ---------- */
#title-bar {
    position: relative;
    z-index: 100;
    height: 48px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
}

.title-bar-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.title-bar-content svg {
    width: 20px;
    height: 20px;
    stroke: var(--accent-primary);
    flex-shrink: 0;
}

#doc-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

/* ============================================
   FLIPBOOK CONTAINER
   ============================================ */
#flipbook-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 16px 60px;
}

/* Book wrapper for zoom transform */
#book-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-normal);
    transform-origin: center center;
    /* Soft shadow beneath the book for light UI */
    filter: drop-shadow(0 16px 32px rgba(0, 0, 0, 0.15));
}

#book {
    /* StPageFlip will manage the dimensions */
}

/* Navigation Arrows */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 50;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    opacity: 0.8;
}

.nav-arrow:hover {
    opacity: 1;
    background: #ffffff;
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
    transform: translateY(-50%) scale(1.08);
}

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

.nav-arrow svg {
    width: 22px;
    height: 22px;
}

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

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


/* ============================================
   BOTTOM TOOLBAR
   ============================================ */
#toolbar {
    position: relative;
    z-index: 100;
    padding: 10px 20px 14px;
    display: flex;
    justify-content: center;
}

.toolbar-content {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: var(--glass-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-soft);
}

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

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--glass-border);
    margin: 0 6px;
}

/* Toolbar Button */
.toolbar-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    position: relative;
}

.toolbar-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--accent-primary);
}

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

.toolbar-btn svg {
    width: 18px;
    height: 18px;
}

/* Page Indicator */
#page-indicator {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    padding: 0 6px;
    min-width: 70px;
    text-align: center;
}

/* Go to Page Input */
#page-input {
    width: 48px;
    height: 32px;
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-weight: 600;
    text-align: center;
    padding: 0 4px;
    transition: all var(--transition-fast);
    -moz-appearance: textfield;
}

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

#page-input:focus {
    border-color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.05);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

#page-input::placeholder {
    color: var(--text-muted);
}

#go-to-page-btn {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0 10px;
    color: var(--accent-primary);
    letter-spacing: 0.03em;
}
#go-to-page-btn:hover {
    color: var(--accent-secondary);
}

/* Zoom Level Display */
#zoom-level {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
    padding: 0 2px;
}


/* ============================================
   ANIMATIONS
   ============================================ */

/* Fade in for app */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#app.fade-in #flipbook-container {
    animation: fadeInUp 0.6s ease-out 0.1s both;
}

#app.fade-in #toolbar {
    animation: fadeInUp 0.6s ease-out 0.25s both;
}

#app.fade-in #title-bar {
    animation: fadeInUp 0.4s ease-out 0s both;
}

/* Button ripple effect */
.toolbar-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.toolbar-btn:active::after {
    opacity: 0.05;
}

/* Tooltip (CSS-only) */
.toolbar-btn[title]::before {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 6px 12px;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    color: #ffffff;
    font-size: 0.6875rem;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.toolbar-btn[title]:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}


/* ============================================
   ERROR STATE
   ============================================ */
.loading-subtitle.error {
    color: var(--danger) !important;
}


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

/* Tablet */
@media (max-width: 900px) {
    #flipbook-container {
        padding: 12px 48px;
    }
    
    .nav-arrow {
        width: 40px;
        height: 40px;
    }
    .nav-arrow svg {
        width: 18px;
        height: 18px;
    }
    .nav-arrow-left { left: 6px; }
    .nav-arrow-right { right: 6px; }
}

/* Mobile */
@media (max-width: 640px) {
    #title-bar {
        height: 42px;
        min-height: 42px;
    }
    
    #doc-title {
        font-size: 0.75rem;
        max-width: 200px;
    }
    
    #flipbook-container {
        padding: 8px 36px;
    }
    
    .nav-arrow {
        width: 34px;
        height: 34px;
        opacity: 0.6;
    }
    .nav-arrow svg {
        width: 16px;
        height: 16px;
    }
    .nav-arrow-left { left: 2px; }
    .nav-arrow-right { right: 2px; }
    
    #toolbar {
        padding: 6px 10px 10px;
    }
    
    .toolbar-content {
        gap: 2px;
        padding: 4px 6px;
        border-radius: var(--radius-lg);
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .toolbar-separator {
        height: 20px;
        margin: 0 3px;
    }
    
    .toolbar-btn {
        width: 32px;
        height: 32px;
    }
    .toolbar-btn svg {
        width: 16px;
        height: 16px;
    }
    
    #page-indicator {
        font-size: 0.75rem;
        min-width: 56px;
    }
    
    #page-input {
        width: 40px;
        height: 28px;
        font-size: 0.75rem;
    }
    
    #zoom-level {
        font-size: 0.6875rem;
    }
    
    /* Hide go-to-page on very small screens */
    .toolbar-group.goto-group {
        display: none;
    }
}

/* Very small mobile */
@media (max-width: 400px) {
    .toolbar-group.zoom-group {
        display: none;
    }
}
