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

:root {
    /* Colors */
    --primary-color: #2c3e50;
    --secondary-color: #34495e;
    --accent-color: #e74c3c;
    --text-color: #2c3e50;
    --text-light: #7f8c8d;
    --background-color: #f8f9fa;
    --page-color: #ffffff;
    --border-color: #dee2e6;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.15);
    --shadow-dark: rgba(0, 0, 0, 0.3);

    /* Typography */
    --font-heading: 'Crimson Text', serif;
    --font-body: 'Inter', sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 1.875rem;
    --font-size-4xl: 2.25rem;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 3rem;

    /* Layout */
    --sidebar-width: 240px;
    --header-height: 80px;
    --border-radius: 8px;
    --border-radius-lg: 12px;

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-medium: 0.3s ease;
    --transition-slow: 0.5s ease;
}

body {
    font-family: var(--font-body);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    overflow-x: hidden;
}

/* Loading Screen */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--background-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto var(--spacing-md);
}

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

.hidden {
    display: none !important;
}

/* App Layout */
.app {
    min-height: 100vh;
    display: flex;
    background-color: var(--background-color);
}

/* Main Content */
.main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem;
}

.book-container {
    width: 100%;
    max-width: 800px;
}

.book {
    background-color: var(--page-color);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 2px 8px var(--shadow-light);
    padding: 2rem;
}

/* Book Header - Integrated into content */
.book-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
}

.book-header > div:last-child {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-toggle {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.5rem;
    transition: var(--transition-fast);
    border-radius: var(--border-radius);
    min-width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.menu-toggle:hover {
    background-color: var(--background-color);
    color: var(--accent-color);
}

.book-info {
    display: flex;
    justify-content: center;
    width: 100%;
}

.book-title {
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 400;
    color: var(--text-light);
    margin: 0;
    line-height: 1.2;
    text-align: center;
}

.chapter-title-header {
    font-family: var(--font-body);
    font-size: 24px;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
    line-height: 1.2;
    flex: 1;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.nav-button {
    background: none;
    border: none;
    font-size: 32px;
    color: var(--accent-color);
    cursor: pointer;
    padding: 0;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--border-radius);
    min-width: 44px;
    height: 44px;
    line-height: 1;
}

.nav-button:hover:not(:disabled) {
    background-color: var(--background-color);
    transform: scale(1.1);
}

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

/* Chapter Dropdown Menu */
.chapter-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-height: 0;
    overflow: hidden;
    background-color: var(--page-color);
    box-shadow: 0 4px 12px var(--shadow-medium);
    transition: max-height var(--transition-medium);
    z-index: 1000;
}

.chapter-menu.active {
    max-height: 80vh;
    overflow-y: auto;
}

.chapter-menu-content {
    padding: var(--spacing-lg);
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--spacing-sm);
}

.chapter-item {
    display: block;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    background: none;
    border: none;
    border-radius: var(--border-radius);
    text-align: left;
    cursor: pointer;
    transition: var(--transition-fast);
    font-size: var(--font-size-sm);
    color: var(--text-color);
    line-height: 1.4;
    border: 1px solid var(--border-color);
}

.chapter-item:hover {
    background-color: var(--background-color);
    border-color: var(--accent-color);
}

.chapter-item.active {
    background-color: var(--accent-color);
    color: white;
}

.chapter-number {
    font-weight: 600;
    margin-right: var(--spacing-xs);
}

.chapter-item.active .chapter-number {
    color: rgba(255, 255, 255, 0.9);
}

.chapter-name {
    font-weight: 400;
    text-transform: capitalize;
}

/* Book Controls - Hidden */
.book-controls {
    display: none;
}

.control-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--border-color);
    background-color: var(--page-color);
    color: var(--text-color);
    font-size: var(--font-size-2xl);
    cursor: pointer;
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-btn:hover:not(:disabled) {
    border-color: var(--accent-color);
    background-color: var(--accent-color);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-medium);
}

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

.chapter-info {
    text-align: center;
    min-width: 200px;
}

.current-chapter {
    font-size: var(--font-size-lg);
    font-weight: 500;
    color: var(--primary-color);
    display: block;
    margin-bottom: var(--spacing-sm);
}

.progress-bar {
    width: 100%;
    height: 4px;
    background-color: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.progress {
    height: 100%;
    background-color: var(--accent-color);
    border-radius: 2px;
    transition: width var(--transition-medium);
    width: 0%;
}

/* Book Container */
.book-container {
    flex: 1;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: var(--spacing-md);
}

.book {
    display: flex;
    flex-direction: column;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    gap: var(--spacing-lg);
    background-color: var(--page-color);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 8px 32px var(--shadow-medium);
    padding: var(--spacing-xl);
}

.page {
    display: none; /* Hide original two-page layout */
}

.page-content {
    display: none; /* Hide original page content */
}

/* Remove chapter title from book area - now in header */

.facets {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
}

.facet {
    padding: 0;
    border: none;
    background: none;
    transition: none;
}

.facet:hover {
    transform: none;
    box-shadow: none;
    border-color: none;
}

.facet-title {
    font-family: var(--font-body);
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-color);
    margin-bottom: var(--spacing-md);
    line-height: 1.3;
    flex-shrink: 0;
}

.facet-content {
    font-size: 18px;
    line-height: 1.8;
    color: var(--text-color);
}

.facet-paragraph {
    margin: 0 0 var(--spacing-md) 0;
}

.facet-paragraph:last-child {
    margin-bottom: 0;
}

/* Sidebar Overlay for Mobile */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-medium);
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Responsive Design */

/* Tablet */
@media (max-width: 1024px) {
    .book {
        padding: 1.5rem;
    }
    
    .book-header {
        padding-bottom: 1.25rem;
        margin-bottom: 1.75rem;
    }
    
    .facets {
        gap: 1.5rem;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .main {
        padding: 0.1rem;
    }
    
    .book {
        padding: 2rem;
        border-radius: var(--border-radius);
    }
    
    .book-header {
        padding-bottom: 0.5rem;
        margin-bottom: 0.75rem;
        gap: 0.5rem;
    }
    
    .book-header > div:last-child {
        gap: 0.25rem;
    }
    
    .book-title {
        font-size: 12px;
    }
    
    .chapter-title-header {
        font-size: 20px;
    }
    
    .facet-title {
        font-size: 16px;
    }
    
    .facet-content {
        font-size: 16px;
    }
    
    .nav-button {
        min-width: 40px;
        height: 40px;
        font-size: 28px;
    }
    
    .menu-toggle {
        min-width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    .current-chapter {
        font-size: var(--font-size-base);
    }
    
    .chapter-info {
        min-width: 150px;
    }
    
    .mobile-page .chapter-title {
        font-size: var(--font-size-2xl);
        margin-bottom: var(--spacing-lg);
    }
    
    .mobile-page .facets {
        gap: var(--spacing-lg);
    }
    
    .mobile-page .facet {
        padding: var(--spacing-md);
    }
    
    .mobile-page .facet-title {
        font-size: var(--font-size-base);
    }
    
    .mobile-page .facet-content {
        font-size: var(--font-size-sm);
    }
}

/* Medium screens - 2x3 layout */
@media (max-width: 900px) and (min-width: 481px) {
    .book {
        min-height: calc(100vh - var(--header-height) - 60px);
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .header {
        padding: 0 var(--spacing-sm);
        gap: var(--spacing-xs);
    }
    
    .book-title {
        font-size: var(--font-size-base);
    }
    
    .chapter-title-header {
        font-size: var(--font-size-base);
    }
    
    .header-center {
        gap: var(--spacing-xs);
    }
    
    .nav-button {
        min-width: 36px;
        height: 36px;
        font-size: var(--font-size-xl);
        padding: 0;
    }
    
    .menu-toggle {
        min-width: 36px;
        height: 36px;
        font-size: var(--font-size-xl);
    }
    
    .main {
        padding: 0.05rem;
    }
    
    .book {
        padding: 0.05rem;
    }
    
    .facet-title {
        font-size: 16px;
    }
    
    .facet-content {
        font-size: 16px;
    }
    
    .book-title {
        font-size: var(--font-size-base);
    }
    
    .chapter-title-header {
        font-size: var(--font-size-base);
    }
    
    .header {
        padding: 0 var(--spacing-sm);
        gap: var(--spacing-xs);
    }
    
    .book-title {
        font-size: var(--font-size-lg);
    }
    
    .chapter-title-header {
        font-size: var(--font-size-lg);
    }
    
    .header-center {
        gap: var(--spacing-xs);
    }
    
    .nav-button {
        min-width: 36px;
        height: 36px;
        font-size: var(--font-size-2xl);
        padding: 0;
    }
    
    .menu-toggle {
        min-width: 36px;
        height: 36px;
        font-size: var(--font-size-xl);
    }
}

/* Print Styles */
@media print {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "header"
            "main";
    }
    
    .sidebar,
    .book-controls,
    .sidebar-overlay {
        display: none;
    }
    
    .book {
        box-shadow: none;
        border: 1px solid var(--border-color);
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .facets {
        grid-template-columns: repeat(2, 1fr);
        grid-template-rows: repeat(3, 1fr);
        gap: var(--spacing-md);
    }
    
    .facet {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* Focus Styles for Accessibility */
.control-btn:focus,
.chapter-item:focus,
.sidebar-toggle:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    :root {
        --text-color: #000000;
        --background-color: #ffffff;
        --border-color: #000000;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Home Page Styles */
.site-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin: 0 0 0.5rem 0;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.facets-icon {
    flex-shrink: 0;
}

.site-description {
    font-size: 1.125rem;
    color: var(--text-light);
    text-align: center;
    margin: 0;
}

.home-header {
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.collections-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.collection-card {
    display: block;
    padding: 1rem 1.5rem;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    text-decoration: none;
    transition: var(--transition-fast);
}

.collection-card:hover {
    border-color: var(--accent-color);
    background-color: var(--background-color);
    transform: translateX(4px);
}

.collection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.collection-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
}

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

/* Page Header Card - Fixed at top */
.page-header-card {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: 800px;
    background: white;
    box-shadow: 0 2px 8px var(--shadow-light);
    z-index: 1001;
    border-radius: var(--border-radius-lg);
    margin: 0 auto;
}

.page-header-content {
    max-width: 800px;
    margin: 0 auto;
    padding: 0.4rem 0.5rem;
}

/* Book title row with home icon - centered */
.book-title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.2rem;
}

.home-icon {
    text-decoration: none;
    line-height: 1;
    color: var(--primary-color);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    padding: 0.25rem;
    border-radius: var(--border-radius);
}

.home-icon:hover {
    background-color: var(--background-color);
    color: var(--accent-color);
}

.book-title {
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 400;
    color: var(--text-light);
    margin: 0;
    line-height: 1.2;
}

.header-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.chapter-title-header {
    font-family: var(--font-body);
    font-size: 20px;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
    line-height: 1.2;
    flex: 0 1 auto;
}

.menu-toggle {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: 0.25rem;
    transition: var(--transition-fast);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.menu-toggle:hover {
    background-color: var(--background-color);
    color: var(--accent-color);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: auto;
}

/* Navigation buttons */
.nav-btn {
    background: none;
    border: none;
    font-size: 48px;
    color: var(--accent-color);
    cursor: pointer;
    padding: 0.5rem;
    transition: var(--transition-fast);
    border-radius: var(--border-radius);
    min-width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    text-decoration: none;
    line-height: 1;
}

.nav-btn:hover {
    background-color: var(--background-color);
    transform: scale(1.1);
}

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

/* Chapter menu dropdown - positioned below menu button */
.chapter-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 0;
    overflow: hidden;
    background-color: var(--page-color);
    box-shadow: 0 4px 12px var(--shadow-medium);
    transition: max-height var(--transition-medium);
    border-radius: var(--border-radius-lg);
    margin-top: 0.5rem;
}

.chapter-menu.active {
    max-height: 70vh;
    overflow-y: auto;
}

.chapter-menu-content {
    padding: 1rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}

.chapter-item {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    border-radius: var(--border-radius);
    text-align: left;
    cursor: pointer;
    transition: var(--transition-fast);
    font-size: var(--font-size-sm);
    color: var(--text-color);
    line-height: 1.4;
    text-decoration: none;
    border: 1px solid var(--border-color);
}

.chapter-item:hover {
    background-color: var(--background-color);
    border-color: var(--accent-color);
}

.chapter-item.active {
    background-color: var(--accent-color);
    color: white;
    font-weight: 500;
    border-color: var(--accent-color);
}

/* Main content area - adjust for fixed header */
.main {
    padding-top: 80px;
}

/* Remove book wrapper, content goes directly in container */
.book-container {
    width: calc(100% - 2rem);
    max-width: 800px;
    padding: 0;
    margin-top: 1rem;
}

.book {
    background: transparent;
    box-shadow: none;
    padding: 0;
}

/* Facets as individual cards */
.facets {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.facet-card {
    background-color: var(--page-color);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 2px 8px var(--shadow-light);
    padding: 1.5rem;
    transition: var(--transition-fast);
}

.facet-card:hover {
    box-shadow: 0 4px 12px var(--shadow-medium);
}

.facet-title {
    font-family: var(--font-body);
    font-size: 20px;
    font-weight: 600;
    color: var(--accent-color);
    margin: 0 0 1rem 0;
    line-height: 1.3;
}

.facet-content-wrapper {
    font-size: 20px;
    line-height: 1.8;
    color: var(--text-color);
}

.facet-paragraph {
    margin: 0 0 var(--spacing-md) 0;
}

.facet-paragraph:last-child {
    margin-bottom: 0;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .site-title {
        font-size: 2rem;
    }
    
    .site-description {
        font-size: 1rem;
    }
    
    .collection-title {
        font-size: 1.125rem;
    }
    
    .collection-count {
        font-size: 0.75rem;
    }
    
    .page-header-card {
        max-width: calc(100% - 0.5rem);
        width: calc(100% - 0.5rem);
        margin: 0 0.25rem;
        border-radius: var(--border-radius);
    }
    
    .page-header-content {
        padding: 0.35rem 0.75rem;
    }
    
    .book-title {
        font-size: 12px;
    }
    
    .chapter-title-header {
        font-size: 18px;
    }
    
    .nav-btn {
        font-size: 40px;
        min-width: 44px;
        height: 44px;
    }
    
    .chapter-menu {
        border-radius: var(--border-radius);
        max-width: calc(100% - 0.5rem);
        margin-left: 0.25rem;
        margin-right: 0.25rem;
    }
    
    .chapter-menu-content {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    
    .facet-title {
        font-size: 18px;
    }
    
    .facet-content-wrapper {
        font-size: 18px;
    }
    
    .main {
        padding: 70px 0 1rem 0;
    }
    
    .facets {
        gap: 0.5rem;
    }
    
    .facet-card {
        border-radius: var(--border-radius);
        margin: 0.25rem 0.5rem;
    }
    
    .book-container {
        padding: 0;
        width: 100%;
        margin-top: 0.5rem;
    }
}

@media (max-width: 480px) {
    .collection-header {
        flex-direction: row;
        align-items: center;
    }
    
    .collection-title {
        font-size: 1rem;
    }
    
    .nav-btn {
        font-size: 36px;
        min-width: 40px;
        height: 40px;
    }
    
    .chapter-menu-content {
        grid-template-columns: 1fr;
    }
}
