/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    background-color: #fafafa;
    color: #333;
    overflow-x: hidden;
}

/* Header */
.app-header {
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #2c3e50;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dark-mode-toggle {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.dark-mode-toggle:hover {
    background: #e9ecef;
    transform: scale(1.05);
}

.file-upload-btn {
    background: #3498db;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 0.2s ease;
    border: none;
    display: inline-block;
}

.file-upload-btn:hover {
    background: #2980b9;
}

/* Main Layout */
.app-main {
    min-height: calc(100vh - 80px);
}

/* Book Selection Section */
.book-selection {
    max-width: 1200px;
    margin: 0 auto;
    padding: 4rem 2rem;
    text-align: center;
}

.book-selection h2 {
    margin-bottom: 3rem;
    font-size: 2.5rem;
    color: #2c3e50;
    font-weight: 200;
    letter-spacing: -0.02em;
}

.books-grid {
    display: grid;
    gap: 3rem;
    margin-bottom: 3rem;
    justify-items: center;
    
    /* Adaptive grid based on number of books */
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* Single book - center elegantly */
.books-grid[data-book-count="1"] {
    max-width: 400px;
    margin: 0 auto 3rem auto;
    grid-template-columns: 1fr;
}

/* Two books - side by side */
.books-grid[data-book-count="2"] {
    max-width: 800px;
    margin: 0 auto 3rem auto;
    grid-template-columns: repeat(2, 1fr);
    gap: 4rem;
}

/* Three books - optimal layout */
.books-grid[data-book-count="3"] {
    max-width: 1000px;
    margin: 0 auto 3rem auto;
    grid-template-columns: repeat(3, 1fr);
    gap: 3rem;
}

/* Four or more books - responsive grid */
.books-grid[data-book-count]:not([data-book-count="1"]):not([data-book-count="2"]):not([data-book-count="3"]) {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 3rem;
}

.loading-books {
    grid-column: 1 / -1;
    text-align: center;
    color: #7f8c8d;
    font-style: italic;
    margin: 2rem 0;
}

.upload-section {
    margin-top: 3rem;
}

.upload-section h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
    color: #2c3e50;
    font-weight: 400;
}

.book-card {
    background: white;
    border-radius: 16px;
    padding: 2.5rem 2rem;
    box-shadow: 0 2px 20px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 320px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.04);
    position: relative;
    overflow: hidden;
}

.book-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #3498db, #27ae60);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
}

.book-card:hover::before {
    transform: scaleX(1);
}

.book-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

.book-cover {
    font-size: 4.5rem;
    margin-bottom: 1.5rem;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    color: #2c3e50;
    font-weight: 600;
    line-height: 1.3;
    min-height: 3.9rem;
    display: flex;
    align-items: center;
    text-align: center;
}

.book-author {
    color: #7f8c8d;
    font-style: italic;
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 400;
}

.book-description {
    color: #95a5a6;
    font-size: 0.9rem;
    margin-bottom: 2rem;
    line-height: 1.5;
    min-height: 2.7rem;
}

.read-btn {
    background: linear-gradient(135deg, #27ae60, #2ecc71);
    color: white;
    border: none;
    padding: 0.875rem 2.5rem;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    letter-spacing: 0.5px;
}

.read-btn:hover {
    background: linear-gradient(135deg, #229954, #27ae60);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.3);
}

/* Upload Area */
.upload-area {
    border: 2px dashed #bdc3c7;
    border-radius: 8px;
    padding: 3rem 2rem;
    background: #ecf0f1;
    color: #7f8c8d;
    transition: all 0.2s ease;
    cursor: pointer;
}

.upload-area:hover {
    border-color: #3498db;
    background: #e8f4f8;
    color: #2980b9;
}

.upload-area.dragover {
    border-color: #27ae60;
    background: #e8f5e8;
    color: #27ae60;
}

/* Status Overlay */
.status-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.status-content {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    text-align: center;
    max-width: 400px;
    width: 90%;
}

/* Loading Spinner */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

.loading-spinner p {
    color: #7f8c8d;
    margin: 0;
}

/* Error Messages */
.error-message h3 {
    color: #e74c3c;
    margin-bottom: 1rem;
}

.error-message p {
    color: #7f8c8d;
    margin-bottom: 1.5rem;
}

.retry-btn {
    background: #e74c3c;
    color: white;
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.retry-btn:hover {
    background: #c0392b;
}

/* Dark Mode Classes */
body.dark-mode {
    background-color: #1a1a1a;
    color: #e0e0e0;
}

body.dark-mode .app-header {
    background: #2d2d2d;
    border-bottom-color: #3d3d3d;
}

body.dark-mode .app-header h1 {
    color: #f0f0f0;
}

body.dark-mode .dark-mode-toggle {
    background: #3d3d3d;
    border-color: #4d4d4d;
    color: #f0f0f0;
}

body.dark-mode .dark-mode-toggle:hover {
    background: #4d4d4d;
}

body.dark-mode .book-selection h2 {
    color: #f0f0f0;
}

body.dark-mode .book-card {
    background: #2d2d2d;
    border: 1px solid #3d3d3d;
}

body.dark-mode .book-card h3 {
    color: #f0f0f0;
}

body.dark-mode .book-author {
    color: #b0b0b0;
}

body.dark-mode .book-description {
    color: #a0a0a0;
}

body.dark-mode .upload-area {
    background: #2d2d2d;
    border-color: #4d4d4d;
    color: #b0b0b0;
}

body.dark-mode .upload-area:hover {
    background: #3d3d3d;
    border-color: #3498db;
    color: #3498db;
}

body.dark-mode .upload-area.dragover {
    background: #2d4d2d;
    border-color: #27ae60;
    color: #27ae60;
}

/* Window-level Drag and Drop Feedback */
body.drag-active::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(52, 152, 219, 0.1);
    border: 3px dashed #3498db;
    z-index: 999;
    pointer-events: none;
    animation: pulse-border 1.5s ease-in-out infinite alternate;
}

body.drag-active::after {
    content: 'Drop your EPUB file anywhere to upload';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(52, 152, 219, 0.95);
    color: white;
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 500;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

body.dark-mode.drag-active::before {
    background: rgba(52, 152, 219, 0.15);
    border-color: #3498db;
}

body.dark-mode.drag-active::after {
    background: rgba(52, 152, 219, 0.9);
}

@keyframes pulse-border {
    0% { 
        border-color: #3498db;
        background: rgba(52, 152, 219, 0.05);
    }
    100% { 
        border-color: #2980b9;
        background: rgba(52, 152, 219, 0.15);
    }
}

body.dark-mode .status-content {
    background: #2d2d2d;
    color: #e0e0e0;
}

body.dark-mode .loading-spinner p {
    color: #b0b0b0;
}

body.dark-mode .error-message p {
    color: #b0b0b0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    .app-header h1 {
        font-size: 1.3rem;
    }
    
    .book-selection {
        padding: 2rem 1rem;
    }
    
    .book-selection h2 {
        font-size: 1.5rem;
    }
    
    .book-card {
        padding: 1.5rem;
    }
    
    .upload-area {
        padding: 2rem 1rem;
    }
}

@media (max-width: 480px) {
    .book-cover {
        font-size: 3rem;
    }
    
    .book-card h3 {
        font-size: 1.2rem;
    }
    
    .status-content {
        padding: 1.5rem;
    }
}
