.nav-btns-col-right {
    margin-left: 0.5rem;
}
.nav-btns-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
    margin-right: 0.5rem;
}
.nav-btns-row {
    display: flex;
    flex-direction: row;
    gap: 0.5rem;
}
/* ============================================
   Global Styles
   ============================================ */

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

:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --accent-color: #e74c3c;
    --background-color: #f5f6fa;
    --card-background: #ffffff;
    --text-color: #2c3e50;
    --text-light: #7f8c8d;
    --border-color: #dfe6e9;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ============================================
   Header
   ============================================ */

header {
    background-color: var(--primary-color);
    color: white;
    padding: 1.5rem 0;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

header h1 a {
    color: white;
    text-decoration: none;
    transition: opacity 0.3s;
}

header h1 a:hover {
    opacity: 0.8;
}

.breadcrumb {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    opacity: 0.9;
}

.viewer-header-inline .book-title h2 {
    font-size: 1.3rem;
    color: white;
    margin: 0;
}

.viewer-header-inline .book-year {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

.breadcrumb a {
    color: white;
    text-decoration: none;
}

/* Improve header nav contrast */
header nav a {
    color: rgba(255,255,255,0.95);
    text-decoration: none;
    margin-right: 0.5rem;
}

header nav a:hover {
    color: #ffffff;
    text-decoration: underline;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* ============================================
   Main Content
   ============================================ */

main {
    min-height: calc(100vh - 200px);
    padding: 0.25rem 0;
}

/* ============================================
   Gallery Page
   ============================================ */

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

.gallery-header h2 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.book-count {
    color: var(--text-light);
    font-size: 1rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.gallery-item {
    background: var(--card-background);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.3s, box-shadow 0.3s;
}

.gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-hover);
}

.book-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.book-thumbnail {
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    background-color: #ecf0f1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.no-thumbnail {
    font-size: 4rem;
    opacity: 0.3;
}

.book-info {
    padding: 1.25rem;
}

.book-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.book-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    color: var(--text-light);
}

.book-year {
    font-weight: 500;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-light);
}

.empty-state p {
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.help-text {
    font-size: 0.95rem;
}

.help-text code {
    background-color: #e9ecef;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: monospace;
}

/* ============================================
   Viewer Page
   ============================================ */

.viewer-container {
    /* max-width: 1200px; */
    max-width: 1400px;
    margin: 0 auto;
}

.viewer-header-inline {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.5rem;
    gap: 1rem;
}

.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.25rem;
    padding: 0.5rem 1rem;
    background: var(--card-background);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

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

.header-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.book-title {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
}

.book-title h2 {
    font-size: 1.4rem;
    color: var(--primary-color);
    margin: 0;
}

.book-year {
    color: var(--text-light);
    font-size: 0.9rem;
}

.page-counter {
    font-size: 1rem;
    font-weight: 500;
    color: #fff;
    text-shadow: 0 1px 4px #000;
    white-space: nowrap;
}

.btn-back-compact {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 6px;
    transition: background-color 0.3s;
    font-size: 0.9rem;
    white-space: nowrap;
}

.btn-back-compact:hover {
    background: #1a252f;
}

.viewer-main {
    display: flex;
    align-items: center;
    gap: 0;
    /* height: calc(100vh - 160px); */
    height: calc(100vh - 60px);
}

.page-container {
    flex: 1 1 0%;
    min-width: 0;
    background: #000;
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    perspective: 1200px;
}

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

.page-split {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 100%;
    height: 100%;
}

.page-split .page-img {
    flex: 1 1 50%;
    width: 50%;
    margin: 0;
    border: 0;
}

.page-split.single .page-img {
    flex: 1 1 100%;
    width: 100%;
}

/* Ensure paired pages visually touch at the center (no inner gap).
   Anchor left page content to the right edge and right page content to the left edge. */
#page-image-left.page-img { object-position: right center; }
#page-image-right.page-img { object-position: left center; }

/* Page-turn animations */
@keyframes flipRight {
    0% { transform: rotateY(0deg); filter: brightness(1); }
    50% { transform: rotateY(-18deg); filter: brightness(0.95); }
    100% { transform: rotateY(0deg); filter: brightness(1); }
}

@keyframes flipLeft {
    0% { transform: rotateY(0deg); filter: brightness(1); }
    50% { transform: rotateY(18deg); filter: brightness(0.95); }
    100% { transform: rotateY(0deg); filter: brightness(1); }
}

.page-split.turn-next #page-image-right {
    transform-origin: left center;
    animation: flipRight 480ms ease;
}

.page-split.turn-prev #page-image-left {
    transform-origin: right center;
    animation: flipLeft 480ms ease;
}

.page-split.single.turn-next .page-img {
    transform-origin: left center;
    animation: flipRight 480ms ease;
}

.page-split.single.turn-prev .page-img {
    transform-origin: right center;
    animation: flipLeft 480ms ease;
}

.loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    color: var(--text-light);
}

.nav-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 2rem;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: background-color 0.3s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover:not(:disabled) {
    background: #2980b9;
    transform: scale(1.1);
}

.nav-btn:disabled {
    background: var(--border-color);
    cursor: not-allowed;
    opacity: 0.5;
}

.viewer-actions {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: rgba(52, 152, 219, 0.1);
    color: var(--secondary-color);
    border: 1px solid var(--secondary-color);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.action-btn:hover {
    background: var(--secondary-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

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

.keyboard-hint {
    color: var(--text-light);
    font-size: 0.85rem;
    white-space: nowrap;
}

/* ============================================
   Error Page
   ============================================ */

.error-container {
    text-align: center;
    padding: 4rem 2rem;
}

.error-container h2 {
    color: var(--accent-color);
    font-size: 2rem;
    margin-bottom: 1rem;
}

.error-message {
    color: var(--text-light);
    font-size: 1.1rem;
    margin-bottom: 2rem;
}

/* ============================================
   Footer
   ============================================ */

footer {
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    padding: 1.5rem 0;
    margin-top: 3rem;
}

footer p {
    opacity: 0.8;
    font-size: 0.9rem;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1.5rem;
    }
    
    .viewer-header {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.5rem;
    }
    
    .header-left,
    .header-right {
        flex-direction: column;
        gap: 0.5rem;
        text-align: center;
        width: 100%;
    }
    
    .viewer-actions {
        justify-content: center;
    }
    
    .book-title {
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .viewer-main {
        flex-direction: column;
        /* height: calc(100vh - 250px); */
        height: calc(100vh - 60px);
    }
    
    .nav-btn {
        width: 60px;
        height: 60px;
    }
    
    .page-container {
        min-height: 300px;
    }
    
    .keyboard-hint {
        display: none;
    }
}

@media (max-width: 480px) {
    .gallery-grid {
        grid-template-columns: 1fr;
    }
    
    header h1 {
        font-size: 1.5rem;
    }
    
    .gallery-header h2 {
        font-size: 1.5rem;
    }
}
