/* ===== BASE STYLES ===== */
:root {
    --transition: all 0.3s ease;
}

* {
    box-sizing: border-box;
    transition: var(--transition);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

/* ===== LAYOUT ===== */
main {
    flex: 1;
    padding: 2rem 0;
}

/* ===== NAVIGATION ===== */
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
}

.nav-brand h1 {
    margin: 0;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}

.nav-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
    transform: translateY(-1px);
}

.btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ===== HERO SECTION ===== */
.hero-section {
    text-align: center;
    padding: 4rem 0;
}

.hero-section h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    margin-bottom: 1rem;
}

.hero-section p {
    font-size: clamp(1rem, 3vw, 1.25rem);
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.auth-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== FEATURES ===== */
.features {
    padding: 4rem 0;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.feature-card {
    padding: 2rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    text-align: center;
}

/* ===== STATS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.stat-card {
    padding: 1.5rem;
    background: var(--bg-secondary);
    border-radius: 0.5rem;
    text-align: center;
}

.stat-number {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0;
}

/* ===== BOOK GRID ===== */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.book-card {
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.book-card:hover {
    transform: translateY(-4px);
}

.book-cover {
    height: 200px;
    background: var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cover-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cover-placeholder {
    color: var(--text-secondary);
    font-style: italic;
}

.book-info {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.book-info h3 {
    margin: 0 0 0.5rem 0;
}

.book-info h3 a {
    color: var(--text-primary);
    text-decoration: none;
}

.book-info h3 a:hover {
    color: var(--primary-color);
}

.book-description {
    color: var(--text-secondary);
    margin: 0.5rem 0;
    line-height: 1.4;
    flex: 1;
}

.book-meta {
    display: flex;
    gap: 1rem;
    margin: 1rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.book-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: auto;
}

/* ===== PAGE HEADER ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.search-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.search-input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-width: 200px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

/* ===== FLIPBOOK STYLES ===== */
.flipbook-container {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.flipbook-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin: 1rem 0;
    flex-wrap: wrap;
}

.bottom-controls {
    margin-top: 2rem;
}

.page-info {
    font-weight: bold;
    color: var(--text-primary);
    min-width: 120px;
    text-align: center;
    font-size: 1.1rem;
}

.page-jump {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.page-input {
    width: 60px;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    text-align: center;
    font-size: 1rem;
}

/* StPageFlip Container */
.st-page-flip-container {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    margin: 0 auto;
    max-width: 100%;
}

/* Force high-quality image rendering */
.st-page-flip-container .page-flip .page {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: high-quality;
    background-color: white;
}

/* ===== BOOK DETAIL STYLES ===== */
.book-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 1rem;
}

.book-info h1 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

.book-description {
    color: var(--text-secondary);
    margin: 0.5rem 0;
}

.book-stats {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.progress-indicator {
    text-align: right;
    min-width: 200px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.reading-tips {
    text-align: center;
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
}

.reading-tips p {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ===== FOOTER ===== */
footer {
    text-align: center;
    padding: 2rem;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    nav {
        padding: 1rem;
        flex-direction: column;
        text-align: center;
    }
    
    .nav-actions {
        justify-content: center;
    }
    
    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-form {
        justify-content: center;
    }
    
    .book-header {
        flex-direction: column;
        text-align: center;
    }
    
    .progress-indicator {
        text-align: center;
        width: 100%;
    }
    
    .flipbook-controls {
        gap: 0.5rem;
    }
    
    .flipbook-container {
        padding: 1rem;
    }
    
    .page-info {
        font-size: 1rem;
        min-width: auto;
    }
    
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    .hero-section {
        padding: 2rem 0;
    }
    
    .features {
        padding: 2rem 0;
    }
    
    .book-cover {
        height: 150px;
    }
    
    .book-info {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 10px;
    }
    
    .books-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .features-grid {
        grid-template-columns: 1fr;
    }
    
    .flipbook-controls {
        flex-direction: column;
    }
    
    .page-jump {
        justify-content: center;
    }
    
    .book-meta {
        justify-content: center;
    }
    
    .book-actions {
        justify-content: center;
    }
}

/* ===== DARK MODE ENHANCEMENTS ===== */
[data-theme="dark"] .st-page-flip-container {
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
    border-color: #404040;
}

[data-theme="dark"] .st-page-flip-container .page-flip .page {
    background: #2a2a2a;
}

[data-theme="dark"] .page-input {
    background: #1a1a1a;
    border-color: #404040;
    color: white;
}

[data-theme="dark"] .reading-tips {
    background: #1a1a1a;
}