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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #8b5cf6;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-light: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #10b981;
    --shadow: rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--background) 0%, #1a1f3a 100%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem 0;
    position: relative;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.3s ease;
    position: absolute;
    left: 0;
    top: 2rem;
}

.back-link:hover {
    color: #6366f1;
    background: rgba(99, 102, 241, 0.1);
    transform: translateX(-4px);
}

.back-link svg {
    transition: transform 0.3s ease;
}

.back-link:hover svg {
    transform: translateX(-2px);
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.tagline {
    color: var(--text-muted);
    font-size: 1.1rem;
}

main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.section {
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

.upload-area {
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: 1rem;
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-area:hover {
    border-color: var(--primary);
    background: var(--surface-light);
    transform: translateY(-2px);
}

.upload-area.dragover {
    border-color: var(--primary);
    background: var(--surface-light);
    transform: scale(1.02);
}

.upload-icon {
    color: var(--primary);
    margin-bottom: 1.5rem;
}

.upload-area h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.upload-area p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.btn {
    padding: 0.875rem 2rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
    transform: translateY(-2px);
}

.status-text {
    margin-top: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.processing-container {
    background: var(--surface);
    border-radius: 1rem;
    padding: 4rem 2rem;
    text-align: center;
}

.spinner {
    width: 64px;
    height: 64px;
    border: 4px solid var(--border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 2rem;
}

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

.processing-container h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

.processing-container p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.progress-bar {
    width: 100%;
    max-width: 400px;
    height: 8px;
    background: var(--surface-light);
    border-radius: 4px;
    overflow: hidden;
    margin: 0 auto 1rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    width: 0%;
    transition: width 0.3s ease;
}

.progress-percentage {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.preview-header {
    text-align: center;
    margin-bottom: 2rem;
}

.preview-header h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.preview-header p {
    color: var(--text-muted);
}

.flipbook-container {
    background: var(--surface);
    border-radius: 1rem;
    padding: 3rem 2rem;
    min-height: 650px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 2rem;
    position: relative;
    overflow: visible;
}

.flipbook {
    position: relative;
    width: 100%;
    max-width: 1000px;
    height: 600px;
    margin: 0 auto;
    perspective: 2500px;
    perspective-origin: 50% 50%;
    transform-style: preserve-3d;
}

.flipbook-page {
    position: absolute;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(0.645, 0.045, 0.355, 1),
                box-shadow 1s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.flipbook-page.left {
    left: 0;
    transform-origin: right center;
}

.flipbook-page.right {
    right: 0;
    transform-origin: left center;
}

.flipbook-page.flipping {
    z-index: 100;
}

/* Front face of the page */
.page-front {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: white;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    transform: rotateY(0deg);
}

.flipbook-page.flipping .page-front {
    box-shadow:
        -5px 0 15px rgba(0, 0, 0, 0.2),
        0 0 30px rgba(0, 0, 0, 0.3),
        10px 0 25px rgba(0, 0, 0, 0.25);
}

/* Back face of the page (blank white) */
.page-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: white;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    transform: rotateY(180deg);
    overflow: hidden;
}

.flipbook-page.flipping .page-back {
    box-shadow:
        -5px 0 15px rgba(0, 0, 0, 0.2),
        0 0 30px rgba(0, 0, 0, 0.3),
        10px 0 25px rgba(0, 0, 0, 0.25);
}

/* Shadow gradients on front face during flip */
.page-front::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.1) 0%, transparent 10%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
    z-index: 10;
}

.page-front::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.15) 0%, transparent 20%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 1s ease;
    z-index: 10;
}

.flipbook-page.flipping .page-front::before {
    opacity: 1;
}

.flipbook-page.flipping .page-front::after {
    opacity: 1;
}

/* Shadow on back face */
.page-back::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, transparent 80%, rgba(0, 0, 0, 0.1) 100%);
    pointer-events: none;
    z-index: 1;
}

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

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

.book-spine {
    position: absolute;
    left: 50%;
    top: 0;
    width: 8px;
    height: 100%;
    background: linear-gradient(to bottom, #d4d4d4, #a3a3a3, #d4d4d4);
    transform: translateX(-50%);
    box-shadow:
        inset 2px 0 3px rgba(0, 0, 0, 0.3),
        inset -2px 0 3px rgba(0, 0, 0, 0.3);
    z-index: 50;
}

.preview-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

footer {
    text-align: center;
    padding: 2rem 0;
    color: var(--text-muted);
    margin-top: 4rem;
}

/* Flipbook Navigation */
.flipbook-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.flipbook-nav:hover {
    background: white;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.flipbook-nav.prev {
    left: 1rem;
}

.flipbook-nav.next {
    right: 1rem;
}

.flipbook-nav svg {
    width: 24px;
    height: 24px;
    stroke: var(--background);
    stroke-width: 2;
}

.page-indicator {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.9rem;
    color: var(--background);
    font-weight: 600;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .back-link {
        position: static;
        margin-bottom: 1rem;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .flipbook {
        height: 400px;
    }

    .preview-controls {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }
}
