:root {
    --bg-color: #0f172a; /* Dark slate */
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --book-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden; /* Prevent scrolling on the body */
}

/* Background elements */
.app-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

.bg-blur-circle {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    opacity: 0.4;
}

.circle-1 {
    width: 40vw;
    height: 40vw;
    background: #3b82f6;
    top: -10vw;
    left: -10vw;
}

.circle-2 {
    width: 50vw;
    height: 50vw;
    background: #8b5cf6;
    bottom: -15vw;
    right: -10vw;
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
}

/* Header */
.app-header {
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo i {
    color: #60a5fa;
}

.logo h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.badge {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Main Workspace */
.book-workspace {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    perspective: 1500px;
    overflow: hidden;
    /* We will use CSS transform scale to fit the wrapper perfectly here */
}

/* Loading Overlay */
#loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 2rem 3rem;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    z-index: 100;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#loading-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

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

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

.progress-bar {
    width: 250px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    transition: width 0.3s ease;
}

#loading-text {
    font-size: 0.95rem;
    color: var(--text-main);
    letter-spacing: 0.5px;
}

/* Flipbook Styles */
.flipbook-wrapper {
    /* Dimensions will be set via JS */
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0; /* Hidden initially */
    transition: opacity 0.3s ease;
}

.flipbook-wrapper.ready {
    opacity: 1;
}

.flipbook {
    background-color: transparent;
    box-shadow: var(--book-shadow); /* Shadow on the book itself */
    margin: 0 auto;
}

/* Page styling for the flipbook */
.page {
    background-color: #fcfaf8; /* Paper color */
    box-shadow: inset 0 0 30px rgba(0,0,0,0.05); /* Slight inner shadow for paper realism */
    overflow: hidden;
    position: relative;
    /* Optional: add a paper texture */
    /* background-image: url('paper-texture.png'); */
}

/* Center fold gradient to simulate a real book */
.page.--left {
    border-right: 0;
    box-shadow: inset -15px 0 30px -10px rgba(0,0,0,0.15), inset 0 0 10px rgba(0,0,0,0.02);
}

.page.--right {
    border-left: 0;
    box-shadow: inset 15px 0 30px -10px rgba(0,0,0,0.15), inset 0 0 10px rgba(0,0,0,0.02);
}

.page-content {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.page canvas {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Contain ensures the entire page is always visible, never cropped */
    display: block;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.page canvas.rendered {
    opacity: 1;
}

.page-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #94a3b8;
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 1;
}

.page-loader .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(0,0,0,0.1);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Hard page cover style */
.page.cover {
    background-color: #1e293b;
    color: white;
    box-shadow: inset 0 0 50px rgba(0,0,0,0.5);
}
.page.cover canvas {
    object-fit: fill;
}

/* Footer Toolbar */
.app-toolbar {
    height: 64px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    z-index: 10;
    padding: 0 2rem;
}

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

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-main);
    transform: translateY(-2px);
}

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

.page-navigator {
    background: rgba(0,0,0,0.2);
    padding: 6px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.05);
}

.page-navigator .label {
    color: var(--text-muted);
    font-size: 0.9rem;
}

#page-input {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 600;
    width: 45px;
    text-align: center;
    outline: none;
    font-family: inherit;
    /* Hide arrows */
    -moz-appearance: textfield;
}

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

#page-input:focus {
    border-bottom: 2px solid var(--accent);
}

#page-total {
    font-weight: 600;
    color: var(--text-main);
}

/* TOC Sidebar */
#toc-sidebar {
    position: fixed;
    top: 60px;
    left: -350px;
    width: 350px;
    height: calc(100vh - 60px - 64px); /* between header and footer */
    z-index: 50;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
    border-left: none;
    border-radius: 0 16px 16px 0;
}

#toc-sidebar.open {
    left: 0;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--panel-border);
}

.toc-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
}

.toc-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

/* Custom scrollbar for TOC */
.toc-content::-webkit-scrollbar {
    width: 6px;
}
.toc-content::-webkit-scrollbar-track {
    background: transparent;
}
.toc-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
}
.toc-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.4);
}

#toc-list {
    list-style: none;
}

.toc-item {
    margin-bottom: 8px;
}

.toc-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    color: var(--text-muted);
    text-decoration: none;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1.4;
}

.toc-link:hover {
    background: rgba(59, 130, 246, 0.2);
    color: var(--text-main);
    transform: translateX(4px);
    border-left: 3px solid var(--accent);
}

.toc-title {
    flex: 1;
    padding-right: 12px;
}

.toc-page {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--accent);
    background: rgba(255,255,255,0.05);
    padding: 2px 6px;
    border-radius: 4px;
}
