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

body {
    font-family: 'Georgia', 'Times New Roman', serif;
    line-height: 1.6;
    color: #333;
    background-color: #f8f7f4;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
}

.header h1 {
    margin-bottom: 1rem;
    font-size: 1.8rem;
}

.version-info {
    position: absolute;
    top: 0.5rem;
    right: 1rem;
    font-size: 0.75rem;
    color: #bdc3c7;
    font-family: 'Courier New', monospace;
    opacity: 0.8;
}

.book-selector select {
    padding: 0.5rem;
    margin-right: 1rem;
    border: none;
    border-radius: 4px;
    background: white;
    color: #333;
    font-size: 1rem;
    cursor: pointer;
    min-width: 200px;
    max-height: 400px;
}

.book-selector select optgroup {
    font-weight: bold;
    color: #2c3e50;
    background-color: #ecf0f1;
}

.book-selector select option {
    padding: 0.5rem;
    background: white;
    color: #333;
}

.book-selector select:disabled {
    background: #ddd;
    cursor: not-allowed;
}

.font-controls {
    display: inline-flex;
    gap: 0.5rem;
    margin-left: 1rem;
}

.font-btn {
    width: 32px;
    height: 32px;
    border: 2px solid #3498db;
    border-radius: 4px;
    background: transparent;
    color: #3498db;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s ease;
}

.font-btn:hover {
    background: #3498db;
    color: white;
}

.font-btn:first-child {
    font-size: 0.8rem;
}

.font-btn:last-child {
    font-size: 1.2rem;
}


/* Compact view styles */
.compact-view .verse-segment {
    display: none;
}

.compact-view .bible-text .verse {
    display: inline;
    margin-right: 0.5rem;
    background: none;
    border: none;
    box-shadow: none;
    padding: 0;
    line-height: 1.8;
}

.compact-view .bible-text .verse-number {
    font-weight: bold;
    color: #7f8c8d;
    margin-right: 0.25rem;
    font-size: 0.85em;
    vertical-align: super;
}

.compact-view .bible-text {
    font-size: 1.1rem;
    line-height: 1.8;
    text-align: justify;
}

.compact-view .explanation {
    display: none;
}

.compact-view .segment-pair {
    display: none;
}

/* Clickable verses in compact mode */
.clickable-verse {
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 3px;
    padding: 2px 4px;
    margin: -2px -4px;
    border: 1px solid transparent;
    position: relative;
}

.clickable-verse:hover {
    background-color: rgba(52, 152, 219, 0.08);
    border-color: rgba(52, 152, 219, 0.15);
}

/* Mobile touch feedback */
.clickable-verse:active {
    background-color: rgba(52, 152, 219, 0.2);
    transform: scale(0.98);
    transition: all 0.1s ease;
}

/* Loading state for verse while explanation loads */
.clickable-verse.loading-explanation {
    background-color: rgba(52, 152, 219, 0.05);
    opacity: 0.7;
}

.clickable-verse.loading-explanation::after {
    content: '';
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border: 1.5px solid #f3f3f3;
    border-top: 1.5px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.verse-expanded {
    background-color: rgba(52, 152, 219, 0.12) !important;
    border-color: rgba(52, 152, 219, 0.3) !important;
    transform: scale(1.01);
}

/* Inline explanation styles */
.inline-explanation {
    display: block;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin: 0.75rem 0;
    padding: 1rem;
    animation: slideInFade 0.4s ease;
    transform-origin: top;
}

@keyframes slideInFade {
    from {
        opacity: 0;
        transform: translateY(-8px) scaleY(0.95);
        max-height: 0;
    }
    to {
        opacity: 1;
        transform: translateY(0) scaleY(1);
        max-height: 500px;
    }
}

.explanation-spinner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #6c757d;
    font-style: italic;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.explanation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e9ecef;
}

.close-explanation {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #6c757d;
    padding: 6px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-explanation:active {
    background-color: rgba(220, 53, 69, 0.1);
    transform: scale(0.95);
}

.close-explanation:hover {
    color: #dc3545;
}

.inline-segment {
    margin-bottom: 1rem;
}

.inline-segment:last-child {
    margin-bottom: 0;
}

.inline-segment em {
    color: #495057;
    font-weight: 500;
}

.explanation-error {
    color: #dc3545;
    text-align: center;
}

.main-content {
    flex: 1;
    position: relative;
}

.chapter-view {
    display: block;
    padding: 1.5rem;
    overflow-y: auto;
    height: calc(100vh - 120px);
}

/* Dynamic font sizing for content areas */
.font-size-small .bible-text,
.font-size-small .segment-text,
.font-size-small .explanation-text { font-size: 0.9rem; }

.font-size-medium .bible-text,
.font-size-medium .segment-text,
.font-size-medium .explanation-text { font-size: 1rem; }

.font-size-large .bible-text,
.font-size-large .segment-text,
.font-size-large .explanation-text { font-size: 1.1rem; }

.font-size-xlarge .bible-text,
.font-size-xlarge .segment-text,
.font-size-xlarge .explanation-text { font-size: 1.25rem; }

.verses-column {
    /* This will contain the single scrolling content */
}

.explanations-column {
    display: none; /* Hide the separate column - content will be integrated */
}

.explanations-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.verse-explanation {
    background: white;
    border-radius: 8px;
    border-left: 4px solid #3498db;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.verse-explanation.loaded {
    opacity: 1;
    transform: translateY(0);
}

.verse-explanation-header {
    background: #f8f9fa;
    padding: 1rem;
    border-bottom: 1px solid #e9ecef;
    font-weight: 600;
    color: #2c3e50;
}

.verse-explanation-content {
    padding: 1.5rem;
}

.verse-explanation.loading {
    background: #f8f9fa;
    border-left-color: #ffd700;
}

.verse-explanation .loading-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #666;
    font-style: italic;
}

.verse-explanation .loading-indicator::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.verse-explanation.error {
    border-left-color: #e74c3c;
    background: #fdf2f2;
}

.error-message {
    color: #e74c3c;
    text-align: center;
    padding: 1rem;
}

/* Corruption Warning Styles */
.verse-corruption-warning {
    background: #fff8e1;
    border: 2px solid #ff9800;
    border-radius: 8px;
    margin: 1rem 0;
    padding: 1rem;
}

.corruption-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.corruption-badge {
    background: #ff9800;
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
}

.corruption-message {
    color: #e65100;
    margin-bottom: 0.75rem;
    font-weight: 500;
}

.corruption-actions {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.regenerate-btn, .show-debug-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ff9800;
    background: white;
    color: #e65100;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.regenerate-btn:hover, .show-debug-btn:hover {
    background: #fff3e0;
}

.debug-info {
    background: #f5f5f5;
    padding: 0.75rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8rem;
    line-height: 1.4;
}

.debug-info > div {
    margin-bottom: 0.5rem;
}

.original-verse-fallback {
    background: #e8f5e8;
    padding: 0.75rem;
    border-radius: 4px;
    border-left: 4px solid #4caf50;
    margin-top: 0.75rem;
}

.verse-number-fallback {
    font-weight: bold;
    color: #2e7d32;
    margin-right: 0.5rem;
}

.verse-text-fallback {
    color: #333;
}

.explanation-metadata {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e9ecef;
    text-align: right;
}

.explanation-metadata small {
    color: #6c757d;
    font-style: italic;
}

.chapter-explanations-title {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid #3498db;
}

.chapter-explanations-title h3 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
}

.generation-status {
    color: #7f8c8d;
    font-style: italic;
    margin: 0;
}

.bible-text {
    font-size: 1.1rem;
    line-height: 2.2;
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.verse {
    display: block;
    cursor: pointer;
    padding: 8px 6px;
    margin: 6px 0;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    position: relative;
}

.verse:hover {
    background-color: rgba(52, 152, 219, 0.1);
}

.verse.highlighted {
    background-color: rgba(241, 196, 15, 0.3);
    border-left: 3px solid #f1c40f;
    padding-left: 8px;
}

.verse.loading-exegesis {
    background-color: rgba(52, 152, 219, 0.2);
    border-left: 3px solid #3498db;
    padding-left: 8px;
    animation: pulse-loading 1.5s infinite ease-in-out;
}

@keyframes pulse-loading {
    0%, 100% {
        background-color: rgba(52, 152, 219, 0.2);
    }
    50% {
        background-color: rgba(52, 152, 219, 0.4);
    }
}

.verse-number {
    font-weight: bold;
    color: #7f8c8d;
    font-size: 0.9em;
    margin-right: 0.5rem;
    user-select: none;
    display: inline-block;
    min-width: 25px;
}

.chapter-title {
    font-size: 1.5rem;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 1.5rem;
    text-align: center;
    border-bottom: 2px solid #34495e;
    padding-bottom: 0.5rem;
}

.chapter-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 2rem 0;
    margin-top: 2rem;
    border-top: 1px solid #ddd;
    gap: 1rem;
}

.nav-button {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 120px;
    justify-content: center;
}

.nav-button:hover {
    background: #2980b9;
    transform: translateY(-1px);
}

.nav-button:active {
    transform: translateY(0);
}

.nav-button:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
    transform: none;
}

.nav-button.prev::before {
    content: "←";
    font-size: 1.2em;
}

.nav-button.next::after {
    content: "→";
    font-size: 1.2em;
}

.chapter-info {
    text-align: center;
    color: #7f8c8d;
    font-size: 0.9rem;
    line-height: 1.4;
}

.welcome-text {
    text-align: center;
    color: #7f8c8d;
    font-style: italic;
    margin-top: 2rem;
}


/* Segment-based Layout */
.segments-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.segment-pair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
    margin-bottom: 1rem;
}

.explanations-container {
    display: none; /* No longer used - explanations integrated with segments */
}

.verse-segment {
    background: white;
    border-radius: 8px;
    border-left: 4px solid #3498db;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem;
}

.verse-segment.loaded {
    opacity: 1;
    transform: translateY(0);
}

.verse-segment.error {
    border-left-color: #e74c3c;
    background: #fdf2f2;
}

.segment-verse-number {
    font-weight: bold;
    color: #7f8c8d;
    font-size: 0.9em;
    min-width: 35px;
    user-select: none;
}

.segment-text {
    font-style: italic;
    font-weight: 500;
    color: #2c3e50;
    font-size: 1.05rem;
    line-height: 1.6;
    flex: 1;
}

.segment-explanation {
    background: white;
    border-radius: 8px;
    border-left: 4px solid #27ae60;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 0.75rem;
}

.segment-explanation.loaded {
    opacity: 1;
    transform: translateY(0);
}

.segment-explanation.error {
    border-left-color: #e74c3c;
    background: #fdf2f2;
}

.explanation-verse-number {
    font-weight: bold;
    color: #27ae60;
    font-size: 0.9em;
    min-width: 35px;
    user-select: none;
}

.explanation-text {
    color: #333;
    line-height: 1.6;
    font-size: 0.95rem;
    flex: 1;
}

.loading-message {
    text-align: center;
    color: #7f8c8d;
    font-style: italic;
    padding: 2rem;
}

/* AI Loading Animation */
.ai-loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #7f8c8d;
    font-style: italic;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #3498db;
    animation: loading-bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes loading-bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.segment-pair.loading {
    opacity: 0.8;
}

.segment-explanation.loading {
    background: #f8f9fa;
    border-left-color: #ffd700;
}

/* AI Attribution */
.ai-info {
    margin-top: 0.5rem;
}

.ai-attribution {
    color: #7f8c8d;
    font-style: italic;
    font-weight: normal;
    font-size: 0.85rem;
}


/* Responsive design for segment pairs */
@media (max-width: 1024px) {
    .segment-pair {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .segment-pair .verse-segment {
        border-bottom: 1px solid #e0e0e0;
        margin-bottom: 0.5rem;
    }
}

/* Responsive design for segment layout */
@media (max-width: 768px) {
    .verse-segment,
    .segment-explanation {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .segment-verse-number,
    .explanation-verse-number {
        min-width: auto;
        margin-bottom: 0.25rem;
    }
    
    .chapter-view {
        padding: 1rem;
    }
}


/* Markdown rendering styles */
.exegesis-content h1, .exegesis-content h2, .exegesis-content h3 {
    color: #2c3e50;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

.exegesis-content h1 {
    font-size: 1.5rem;
    border-bottom: 2px solid #3498db;
    padding-bottom: 0.5rem;
}

.exegesis-content h2 {
    font-size: 1.3rem;
    color: #34495e;
}

.exegesis-content h3 {
    font-size: 1.1rem;
    color: #7f8c8d;
}

.exegesis-content p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.exegesis-content ul, .exegesis-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.exegesis-content li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.exegesis-content blockquote {
    border-left: 4px solid #3498db;
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    background: rgba(52, 152, 219, 0.1);
    font-style: italic;
}

.exegesis-content strong, .exegesis-content b {
    color: #2c3e50;
    font-weight: 600;
}

.exegesis-content em, .exegesis-content i {
    color: #34495e;
}

.exegesis-content code {
    background: #ecf0f1;
    padding: 0.2rem 0.4rem;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
}

/* Bible reference links */
.bible-ref {
    color: #3498db;
    text-decoration: underline;
    cursor: pointer;
    font-weight: 500;
    padding: 0.1rem 0.2rem;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.bible-ref:hover {
    background: rgba(52, 152, 219, 0.1);
    color: #2980b9;
    text-decoration: none;
}

.bible-ref:active {
    background: rgba(52, 152, 219, 0.2);
}

.question-area {
    border-top: 1px solid #ddd;
    padding-top: 1rem;
}

.question-area textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
    font-size: 0.95rem;
}

.question-area button {
    background: #3498db;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    margin-top: 0.5rem;
    transition: background-color 0.2s ease;
}

.question-area button:hover {
    background: #2980b9;
}

.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1001;
    display: none;
    min-width: 150px;
}

.context-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid #eee;
}

.context-item:last-child {
    border-bottom: none;
}

.context-item:hover {
    background: #f5f5f5;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1002;
    flex-direction: column;
    color: white;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid transparent;
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }
    
    
    .reading-area {
        max-width: 100%;
        padding: 1rem;
    }
    
    .header {
        padding: 0.75rem;
    }
    
    .book-selector {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 0.5rem;
        align-items: center;
    }
    
    .book-selector select {
        margin: 0;
        margin-right: 0;
        font-size: 0.9rem;
        padding: 0.4rem;
        min-width: 0;
    }
    
    .book-selector #viewModeSelect {
        grid-column: 1 / -1;
    }
    
    .font-controls {
        grid-column: 1 / -1;
        justify-self: center;
        margin: 0;
        margin-top: 0.25rem;
    }
    
    .font-btn {
        width: 28px;
        height: 28px;
    }
    
    .chapter-navigation {
        flex-direction: row;
        justify-content: space-between;
        gap: 1rem;
        padding: 1.5rem 0;
        position: relative;
    }
    
    .nav-button {
        flex: 1;
        max-width: 120px;
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }
    
    .chapter-info {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        margin: 0;
        text-align: center;
        white-space: nowrap;
        font-size: 0.8rem;
    }
}