/* CSS Variables for consistent theming */
:root {
    --header-height: 80px;
    --sidebar-width: 33%;
    --reading-width: 67%;
    
    /* Arthurian Color Palette */
    --deep-red: #8b1538;
    --royal-blue: #1a237e;
    --forest-green: #2e7d32;
    --dark-green: #1b5e20;
    --gold: #d4af37;
    --cream: #faf8f3;
    --parchment: #f5f2e8;
    --stone-gray: #6d7993;
    --dark-brown: #3e2723;
    
    /* Typography */
    --title-font: 'Georgia', 'Times New Roman', serif;
    --body-font: 'Georgia', 'Times New Roman', serif;
}

/* Global reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--body-font);
    background: var(--cream);
    color: var(--dark-brown);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Header */
.main-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: linear-gradient(135deg, var(--deep-red), var(--royal-blue));
    color: white;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 2rem;
    max-width: 100%;
}

.site-title {
    font-family: var(--title-font);
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.title-link {
    color: white;
    text-decoration: none;
    transition: opacity 0.3s ease;
}

.title-link:hover {
    opacity: 0.8;
}

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

#searchInput {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 25px;
    width: 300px;
    font-size: 1rem;
    outline: none;
    background: rgba(255,255,255,0.9);
    color: var(--dark-brown);
}

#searchInput::placeholder {
    color: var(--stone-gray);
}

.search-btn {
    background: var(--gold);
    color: var(--dark-brown);
    border: none;
    padding: 0.5rem 1.5rem;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.search-btn:hover {
    background: #b8941f;
    transform: translateY(-1px);
}

/* Main layout */
.main-container {
    margin-top: var(--header-height);
    display: flex;
    flex-direction: row;
    min-height: calc(100vh - var(--header-height));
}

/* Reading area (left 2/3) */
.reading-area {
    width: var(--reading-width);
    padding: 2rem;
    background: var(--cream);
    border-right: 3px solid var(--gold);
    overflow-y: auto;
    max-height: calc(100vh - var(--header-height));
}

.book-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 1px solid var(--gold);
}

.book-btn {
    background: linear-gradient(135deg, var(--stone-gray), var(--dark-brown));
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    font-family: var(--title-font);
    font-weight: 600;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.book-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.2);
}

.book-btn.active {
    background: linear-gradient(135deg, var(--deep-red), var(--royal-blue));
    box-shadow: 0 4px 12px rgba(139, 21, 56, 0.4);
}

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

/* Content area */
.content-area {
    background: white;
    border-radius: 15px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
    border: 1px solid var(--gold);
    position: relative;
    overflow: hidden;
}

.content-area::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--deep-red), var(--gold), var(--royal-blue));
    border-radius: 15px 15px 0 0;
}

/* Welcome content */
.welcome-content {
    padding: 3rem;
    text-align: center;
}

.welcome-title {
    font-family: var(--title-font);
    font-size: 2.5rem;
    color: var(--deep-red);
    margin-bottom: 0.5rem;
}

.welcome-subtitle {
    font-size: 1.2rem;
    color: var(--stone-gray);
    margin-bottom: 2rem;
    font-style: italic;
}

.instructions-panel {
    background: var(--parchment);
    padding: 2rem;
    border-radius: 10px;
    text-align: left;
    max-width: 800px;
    margin: 0 auto;
}

.instructions-panel h3 {
    color: var(--forest-green);
    margin-bottom: 1.5rem;
    text-align: center;
    font-family: var(--title-font);
}

.instruction-item {
    display: flex;
    align-items: flex-start;
    margin-bottom: 1rem;
    gap: 1rem;
}

.instruction-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.instruction-content {
    flex: 1;
}

.search-hint {
    margin-top: 1.5rem;
    text-align: center;
    color: var(--stone-gray);
    font-style: italic;
}

/* Book overview styles */
.book-overview {
    padding: 3rem;
    text-align: center;
}

.book-header {
    margin-bottom: 2rem;
}

.book-title {
    font-family: var(--title-font);
    font-size: 2.5rem;
    color: var(--deep-red);
    margin-bottom: 1rem;
}

.book-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin: 2rem 0;
}

.stat-item {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--royal-blue);
    font-family: var(--title-font);
}

.stat-label {
    display: block;
    color: var(--stone-gray);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.book-instructions {
    background: var(--parchment);
    padding: 2rem;
    border-radius: 10px;
    color: var(--dark-brown);
}

/* Chapter content - IMPROVED PARAGRAPH FORMATTING */
.chapter-content {
    padding: 2.5rem;
}

.chapter-container {
    padding: 2rem;
}

.chapter-title {
    font-family: var(--title-font);
    font-size: 1.8rem;
    color: var(--deep-red);
    margin-bottom: 0.5rem;
    border-bottom: 2px solid var(--gold);
    padding-bottom: 0.5rem;
    text-align: center;
}

.chapter-heading {
    color: var(--dark-green);
    margin-bottom: 1.5rem;
    color: var(--forest-green);
    text-align: center;
    font-size: 1.3rem;
    font-style: italic;
    font-family: var(--title-font);
}

.chapter-body {
    margin-top: 2rem;
    max-width: none;
    line-height: 1.7;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Ensure proper paragraph spacing and formatting */
.chapter-text {
    margin-bottom: 1.2em;
    line-height: 1.6;
    text-align: justify;
    hyphens: auto;
    text-indent: 1.5em; /* Traditional paragraph indentation */
    font-size: 1.1rem;
    color: var(--dark-brown);
}

/* First paragraph shouldn't be indented */
.chapter-body p:first-child,
.chapter-body .chapter-text:first-child {
    text-indent: 0;
}

/* Drop cap for first letter of first paragraph */
.chapter-body .chapter-text:first-child::first-letter {
    font-family: var(--title-font);
    font-size: 3.5rem;
    line-height: 3rem;
    float: left;
    margin: 0.1rem 0.1rem 0 0;
    color: var(--deep-red);
    font-weight: 600;
}

/* Add some visual debugging - remove this after fixing */
.chapter-text {
    border-left: 2px solid transparent; /* Invisible by default */
}

/* Temporary debugging class - add this to see paragraph boundaries */
.debug-paragraphs .chapter-text {
    border-left: 2px solid rgba(255, 0, 0, 0.3);
    padding-left: 0.5em;
    margin-left: -0.5em;
    background: rgba(255, 255, 0, 0.05);
}

/* Search results */
.search-results-container {
    padding: 2rem;
}

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

.search-results {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.result-item {
    background: var(--parchment);
    border: 1px solid var(--gold);
    border-radius: 10px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.result-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    background: white;
}

.result-title {
    font-weight: 600;
    color: var(--deep-red);
    margin-bottom: 0.5rem;
}

.result-snippet {
    color: var(--dark-brown);
    line-height: 1.6;
    margin-bottom: 0.5rem;
}

.result-snippet mark {
    background: var(--gold);
    color: var(--dark-brown);
    padding: 0.1em 0.2em;
    border-radius: 3px;
}

.result-characters {
    color: var(--stone-gray);
    font-size: 0.9rem;
}

/* Error content */
.error-content {
    text-align: center;
    padding: 3rem;
}

.error-content h2 {
    color: var(--deep-red);
    margin-bottom: 1rem;
}

/* Sidebar (right 1/3) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--parchment);
    padding: 2rem;
    overflow-y: auto;
    max-height: calc(100vh - var(--header-height));
}

.info-panel {
    background: white;
    border-radius: 10px;
    margin-bottom: 1.5rem;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
    border: 1px solid var(--gold);
    overflow: hidden;
}

.panel-header {
    background: linear-gradient(135deg, var(--forest-green), var(--royal-blue));
    color: white;
    padding: 1rem;
    font-family: var(--title-font);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.3s ease;
}

.panel-header:hover {
    background: linear-gradient(135deg, var(--deep-red), var(--royal-blue));
}

.panel-toggle {
    transition: transform 0.3s ease;
}

.panel-header.collapsed .panel-toggle {
    transform: rotate(-90deg);
}

.panel-content {
    padding: 1.5rem;
    max-height: 300px;
    overflow-y: auto;
    transition: max-height 0.3s ease;
}

.panel-content.collapsed {
    max-height: 0;
    padding: 0 1.5rem;
    overflow: hidden;
}

.placeholder-text {
    color: var(--stone-gray);
    font-style: italic;
    text-align: center;
}

/* Chapter list */
.chapter-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chapter-item {
    padding: 1rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--parchment);
}

.chapter-item:hover {
    background: white;
    border-color: var(--gold);
    transform: translateX(5px);
}

.chapter-item.active {
    background: linear-gradient(135deg, var(--gold), #f4d03f);
    border-color: var(--deep-red);
    color: var(--dark-brown);
}

.chapter-item-title {
    font-weight: 600;
    color: var(--deep-red);
    margin-bottom: 0.3rem;
}

.chapter-item-heading {
    font-size: 0.9rem;
    color: var(--forest-green);
    line-height: 1.4;
}

/* Tags */
.character-tag, .theme-tag {
    display: inline-block;
    background: linear-gradient(135deg, var(--gold), #f4d03f);
    color: var(--dark-brown);
    padding: 0.3rem 0.8rem;
    margin: 0.2rem;
    border-radius: 15px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.character-tag:hover, .theme-tag:hover {
    background: var(--deep-red);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Responsive design */
@media (max-width: 1024px) {
    .main-container {
        flex-direction: column;
    }
    
    .reading-area {
        width: 100%;
        border-right: none;
        border-bottom: 3px solid var(--gold);
    }
    
    .sidebar {
        width: 100%;
    }
    
    .header-content {
        flex-direction: column;
        padding: 1rem;
        gap: 1rem;
    }
    
    #searchInput {
        width: 250px;
    }
    
    .book-stats {
        gap: 2rem;
    }
}

@media (max-width: 768px) {
    .book-selector {
        justify-content: center;
    }
    
    .book-btn {
        font-size: 0.9rem;
        padding: 0.4rem 0.8rem;
    }
    
    .welcome-title {
        font-size: 2rem;
    }
    
    .book-title {
        font-size: 2rem;
    }
    
    .instructions-panel {
        padding: 1.5rem;
    }
    
    .chapter-content {
        padding: 1.5rem;
    }
    
    .chapter-container {
        padding: 1rem;
    }
    
    #searchInput {
        width: 200px;
    }
    
    .book-stats {
        flex-direction: column;
        gap: 1rem;
    }
    
    .chapter-text {
        font-size: 1rem;
        text-indent: 1em;
    }
    
    .chapter-body .chapter-text:first-child::first-letter {
        font-size: 2.5rem;
        line-height: 2rem;
    }
}

@media (max-width: 480px) {
    .header-content {
        padding: 0.5rem;
    }
    
    .site-title {
        font-size: 1.4rem;
    }
    
    #searchInput {
        width: 150px;
        font-size: 0.9rem;
    }
    
    .search-btn {
        padding: 0.4rem 1rem;
        font-size: 0.9rem;
    }
    
    .reading-area, .sidebar {
        padding: 1rem;
    }
    
    .welcome-content, .book-overview {
        padding: 2rem 1rem;
    }
    
    .chapter-content {
        padding: 1rem;
    }
}

/* Disclaimer, Credits, and Copyright Section */
.disclaimer-section {
    margin-top: 2rem;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
}

.disclaimer-panel, .credits-panel {
    background: #fff3cd;
    border: 1px solid var(--gold);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    text-align: left;
}

.disclaimer-panel {
    border-left: 4px solid #856404;
}

.credits-panel {
    background: #d1ecf1;
    border-color: #bee5eb;
    border-left: 4px solid #0c5460;
}

.disclaimer-panel h3, .credits-panel h3 {
    color: var(--deep-red);
    margin-bottom: 1rem;
    font-family: var(--title-font);
    text-align: center;
}

.disclaimer-panel p, .credits-panel p {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.links-section {
    margin-top: 1rem;
}

.links-section h4 {
    color: var(--forest-green);
    margin-bottom: 0.5rem;
    font-family: var(--title-font);
}

.links-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.links-section li {
    margin-bottom: 0.5rem;
}

.links-section a, .credits-panel a {
    color: var(--royal-blue);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.links-section a:hover, .credits-panel a:hover {
    color: var(--deep-red);
    text-decoration: underline;
}

.copyright-panel {
    text-align: center;
    padding: 1rem;
    background: var(--parchment);
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.copyright-panel small {
    color: var(--stone-gray);
    font-style: italic;
    line-height: 1.4;
}

/* Responsive adjustments for disclaimer section */
@media (max-width: 768px) {
    .disclaimer-section {
        margin-top: 1.5rem;
    }
    
    .disclaimer-panel, .credits-panel {
        padding: 1rem;
    }
    
    .links-section {
        margin-top: 0.5rem;
    }
}
