/**
 * Book Reader Styles
 * Optimized for comfortable long-form reading
 * 
 * Design principles:
 * - Optimal line length (50-75 characters)
 * - Generous line height for eye tracking
 * - High-contrast but not harsh text
 * - Warm, paper-like background
 * - Clear visual hierarchy
 */

/* === CSS Variables for Theming === */
:root {
    /* Reading colors - warm, paper-like tones */
    --reader-bg: #faf8f5;
    --reader-surface: #fffdf9;
    --reader-text: #2c2a26;
    --reader-text-secondary: #5c5850;
    --reader-text-muted: #8a857a;
    --reader-border: #e8e4dc;
    --reader-accent: #3b6eb5;
    --reader-accent-light: #e8f0fa;

    /* Typography */
    --font-serif: 'Merriweather', 'Georgia', 'Times New Roman', serif;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

    /* Optimal reading font size (18-21px is ideal for long-form) */
    --font-size-base: 19px;
    --line-height: 1.9;
    --paragraph-spacing: 1.6em;
}

/* === Reader Layout === */
.book-reader {
    display: flex;
    min-height: 100vh;
    background: var(--reader-bg);
}

/* === Progress Bar === */
.reader-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--reader-border);
    z-index: 1000;
}

.reader-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--reader-accent), #1d4ed8);
    width: 0%;
    transition: width 0.1s ease-out;
}

/* === Header === */
.reader-header {
    position: fixed;
    top: 3px;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--reader-surface);
    border-bottom: 1px solid var(--reader-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    z-index: 999;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.reader-header-back {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--reader-text-muted);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s;
}

.reader-header-back:hover {
    color: var(--reader-accent);
}

.reader-header-title {
    flex: 1;
    text-align: center;
    font-weight: 500;
    font-size: 15px;
    color: var(--reader-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 20px;
    font-family: var(--font-sans);
}

.reader-header-actions {
    display: flex;
    gap: 12px;
}

/* === Sidebar === */
.reader-sidebar {
    position: fixed;
    top: 55px;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--reader-surface);
    border-right: 1px solid var(--reader-border);
    overflow-y: auto;
    padding: 20px 0;
    z-index: 998;
    scrollbar-width: thin;
}

.reader-sidebar::-webkit-scrollbar {
    width: 6px;
}

.reader-sidebar::-webkit-scrollbar-thumb {
    background: var(--reader-border);
    border-radius: 3px;
}

.reader-sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--reader-text-muted);
    padding: 0 20px 12px;
    margin: 0;
    font-family: var(--font-sans);
}

.chapter-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chapter-nav-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 20px;
    cursor: pointer;
    transition: all 0.2s;
    border-left: 3px solid transparent;
    text-decoration: none;
    color: var(--reader-text-secondary);
}

.chapter-nav-item:hover {
    background: var(--reader-accent-light);
    color: var(--reader-accent);
}

.chapter-nav-item.active {
    background: var(--reader-accent-light);
    border-left-color: var(--reader-accent);
    color: var(--reader-accent);
    font-weight: 500;
}

.chapter-nav-number {
    width: 24px;
    height: 24px;
    background: var(--reader-border);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    font-family: var(--font-sans);
}

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

.chapter-nav-title {
    font-size: 13px;
    line-height: 1.4;
}

/* === Content Area === */
.reader-content {
    flex: 1;
    margin-left: 280px;
    margin-top: 55px;
    padding: 60px 40px 120px;
    background: var(--reader-bg);
}

.reader-content-inner {
    max-width: 680px;
    margin: 0 auto;
    /* Center the content for optimal reading */
}

/* === Chapter Styles === */
.book-chapter {
    padding: 48px 0;
    border-bottom: 1px solid var(--reader-border);
}

.book-chapter:last-child {
    border-bottom: none;
}

.chapter-header {
    margin-bottom: 40px;
    text-align: center;
}

.chapter-number {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: var(--reader-accent);
    margin-bottom: 12px;
    font-family: var(--font-sans);
}

.chapter-title {
    font-family: var(--font-serif);
    font-size: 32px;
    font-weight: 700;
    color: var(--reader-text);
    line-height: 1.25;
    margin: 0;
    letter-spacing: -0.01em;
}

/* === Reading Typography - Optimized for Long Sessions === */
.chapter-content {
    font-family: var(--font-serif);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    color: var(--reader-text);
    /* Improve text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    /* Optimal word spacing for readability */
    word-spacing: 0.03em;
}

.chapter-content p {
    margin: 0 0 var(--paragraph-spacing);
    /* First-line indent for better paragraph distinction */
    /* text-indent: 1.5em; */
    /* Uncomment for traditional book style */
}

.chapter-content p:first-of-type {
    text-indent: 0;
}

.chapter-content h2 {
    font-family: var(--font-serif);
    font-size: 24px;
    font-weight: 700;
    color: var(--reader-text);
    margin: 2.5em 0 1.2em;
    line-height: 1.3;
}

.chapter-content h3 {
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 600;
    color: var(--reader-text);
    margin: 2em 0 1em;
    line-height: 1.35;
}

/* === Blockquotes - Scripture/Quotes === */
.chapter-content blockquote,
.scripture-quote {
    background: rgba(59, 110, 181, 0.04);
    border-left: 3px solid var(--reader-accent);
    border-radius: 0 6px 6px 0;
    padding: 24px 28px;
    margin: 2em 0 2em 0;
    position: relative;
}

.chapter-content blockquote p,
.scripture-quote p {
    font-family: var(--font-serif);
    font-style: italic;
    font-size: 18px;
    line-height: 1.85;
    color: var(--reader-text-secondary);
    margin: 0;
}

.scripture-quote::before {
    content: '"';
    position: absolute;
    left: 12px;
    top: 8px;
    font-size: 40px;
    color: var(--reader-border);
    font-family: Georgia, serif;
    line-height: 1;
}

/* === Lists - Questions & Items === */
.chapter-content ul,
.chapter-content ol {
    margin: 1.8em 0;
    padding-left: 0;
    list-style: none;
}

.chapter-content li {
    position: relative;
    padding-left: 28px;
    margin-bottom: 0.9em;
    line-height: 1.75;
}

.chapter-content ul li::before {
    content: '•';
    position: absolute;
    left: 8px;
    color: var(--reader-accent);
    font-weight: bold;
}

.chapter-content ol {
    counter-reset: list-counter;
}

.chapter-content ol li {
    counter-increment: list-counter;
}

.chapter-content ol li::before {
    content: counter(list-counter) '.';
    position: absolute;
    left: 0;
    color: var(--reader-accent);
    font-weight: 600;
    font-family: var(--font-sans);
    font-size: 14px;
}

/* === Question-style content (detected from the PDF) === */
.chapter-content p:has(br) {
    /* Multi-line paragraphs with soft breaks - likely questions or verse content */
    line-height: 2;
}

/* Question bullet styling for content like "What really matters..." */
.numbered-para {
    position: relative;
    padding-left: 48px;
}

/* Detect question patterns and style them nicely */
.numbered-para:has(> .para-num) {
    /* Extra spacing for paragraph clarity */
    margin-bottom: 1.8em;
}

/* === Paragraph Numbering === */
.para-num {
    position: absolute;
    left: 0;
    top: 0.35em;
    width: 38px;
    font-size: 12px;
    font-weight: 500;
    color: var(--reader-text-muted);
    text-align: right;
    padding-right: 14px;
    user-select: none;
    opacity: 0.4;
    transition: opacity 0.2s;
    font-family: var(--font-sans);
}

.numbered-para:hover .para-num {
    opacity: 0.8;
    color: var(--reader-accent);
}

/* === Chapter Subheadings === */
.chapter-subheading {
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 600;
    color: var(--reader-text);
    text-align: center;
    margin: 3em 0 2em;
    padding: 24px 0;
    border-top: 1px solid var(--reader-border);
    border-bottom: 1px solid var(--reader-border);
    letter-spacing: 0.01em;
}

/* === Bullet Items === */
.bullet-item {
    padding-left: 72px;
    position: relative;
}

.bullet-item .bullet-marker {
    position: absolute;
    left: 48px;
    top: 0.4em;
    width: 8px;
    height: 8px;
    background: var(--reader-accent);
    border-radius: 50%;
}

.bullet-item+.bullet-item {
    margin-top: -0.8em;
}

/* === Paragraph Highlighting from Search === */
.numbered-para:target,
.chapter-subheading:target,
.scripture-quote:target,
.flash-target {
    background: linear-gradient(90deg, rgba(254, 240, 138, 0.6) 0%, transparent 100%);
    animation: paragraph-highlight 2.5s ease-out;
    border-radius: 4px;
    padding-top: 8px;
    padding-bottom: 8px;
    margin-top: -8px;
    margin-bottom: calc(var(--paragraph-spacing) - 8px);
}

@keyframes paragraph-highlight {
    0% {
        background: rgba(254, 240, 138, 0.9);
        box-shadow: 0 0 30px rgba(254, 240, 138, 0.6);
        transform: translateX(5px);
    }

    10% {
        transform: translateX(0);
    }

    50% {
        background: rgba(254, 240, 138, 0.7);
    }

    100% {
        background: linear-gradient(90deg, rgba(254, 240, 138, 0.6) 0%, transparent 100%);
    }
}


.search-highlight {
    background: linear-gradient(180deg, transparent 50%, rgba(254, 240, 138, 0.5) 50%);
    padding: 1px 2px;
    border-radius: 2px;
    transition: background 0.3s ease;
}

.search-highlight.active {
    background: rgba(254, 240, 138, 0.9) !important;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
    animation: highlight-flash 1.5s ease-out;
}

@keyframes highlight-flash {
    0% {
        background: rgba(251, 191, 36, 1);
        transform: scale(1.05);
    }

    50% {
        background: rgba(251, 191, 36, 0.8);
        transform: scale(1.02);
    }

    100% {
        background: rgba(254, 240, 138, 0.9);
        transform: scale(1);
    }
}

/* === Chapter Divider === */
.chapter-divider {
    text-align: center;
    padding: 48px 0;
    color: var(--reader-text-muted);
    position: relative;
}

.chapter-divider span {
    display: inline-block;
    padding: 0 24px;
    background: var(--reader-bg);
    position: relative;
    z-index: 1;
}

.chapter-divider::before {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 50%;
    width: 200px;
    height: 1px;
    background: var(--reader-border);
}

/* === Mobile Responsive === */
@media (max-width: 1024px) {
    .reader-sidebar {
        width: 260px;
    }

    .reader-content {
        margin-left: 260px;
        padding: 48px 32px 100px;
    }

    .reader-content-inner {
        max-width: 600px;
    }
}

@media (max-width: 768px) {
    :root {
        --font-size-base: 18px;
        --line-height: 1.85;
    }

    .reader-sidebar {
        display: none;
        position: fixed;
        top: 55px;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        background: var(--reader-surface);
        z-index: 1000;
    }

    .reader-sidebar.open {
        display: block;
    }

    .reader-content {
        margin-left: 0;
        padding: 32px 20px 80px;
    }

    .chapter-title {
        font-size: 26px;
    }

    .numbered-para {
        padding-left: 0;
    }

    .para-num {
        display: none;
    }

    .reader-header-title {
        font-size: 14px;
    }

    .chapter-header {
        margin-bottom: 32px;
    }
}

/* === Print Styles === */
@media print {

    .reader-header,
    .reader-sidebar,
    .reader-progress {
        display: none !important;
    }

    .reader-content {
        margin: 0;
        padding: 0;
    }

    .book-chapter {
        page-break-before: always;
    }

    .book-chapter:first-child {
        page-break-before: avoid;
    }
}

/* === Dark Mode - Easier on Eyes for Night Reading === */
@media (prefers-color-scheme: dark) {
    :root {
        --reader-bg: #1a1915;
        --reader-surface: #242320;
        --reader-text: #e8e4dc;
        --reader-text-secondary: #b5b0a6;
        --reader-text-muted: #7a766c;
        --reader-border: #3a3832;
        --reader-accent: #7cb3f0;
        --reader-accent-light: rgba(124, 179, 240, 0.1);
    }

    .chapter-content blockquote,
    .scripture-quote {
        background: rgba(124, 179, 240, 0.05);
    }
}

/* === Sepia Mode (can be toggled via class) === */
.book-reader.sepia {
    --reader-bg: #f5ecd9;
    --reader-surface: #fdf8ed;
    --reader-text: #433422;
    --reader-text-secondary: #6b5d4d;
    --reader-text-muted: #9a8a76;
    --reader-border: #e0d5c3;
    --reader-accent: #8b6914;
    --reader-accent-light: rgba(139, 105, 20, 0.08);
}

/* === Focus Mode (optional class) === */
.book-reader.focus-mode .reader-sidebar {
    opacity: 0.3;
    transition: opacity 0.3s;
}

.book-reader.focus-mode .reader-sidebar:hover {
    opacity: 1;
}

.book-reader.focus-mode .reader-header {
    opacity: 0.6;
    transition: opacity 0.3s;
}

.book-reader.focus-mode .reader-header:hover {
    opacity: 1;
}