/* reader.css */

/* --- VARIABLES & THEME ENGINE --- */
:root {
    /* Light / Sepia (Default) */
    --bg-app: #fcfbf9;
    --bg-panel: #f2f0eb;
    --bg-hover: #e6e4df;
    --bg-select: #fceeb5; /* Warm yellow highlight */
    --bg-select-subtle: #fffbe6; /* Verse flash */
    
    --text-main: #363330;
    --text-muted: #75726e;
    --text-link: #2a5b8f;
    --text-ref-term: #245079;

    --ref-c1: #005ab5; 
    --ref-c2: #d55e00; 
    --ref-c3: #008f68; 
    --ref-c4: #9c27b0;
    --ref-font-weight: 600;

    --border: 1px solid #e0ded9;
    --book-spine-def: #ccc;

    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-serif: 'Source Serif 4', serif;
    
    --header-height: 48px;
}

/* Dark Mode - "IDE Comfort" Palette */
body.dark-mode {
    /* 1. Backgrounds: Deep Blue-Greys */
    --bg-app: #22272e;  
    --bg-panel: #1c2128; 
    --bg-hover: #373e47;

    /* 2. Selections: Muted Gold/Brown */
    --bg-select: #ffdd003d; 
    --bg-select-subtle: #2e2920;
    
    /* 3. Text: Silver, not White */
    --text-main: #cdd9e5; 
    --text-muted: #768390;
    
    /* 4. Links: Pastel Blue */
    --text-link: #539bf5; 
    
    /* 5. Ref Terms: Soft Sage / Slate */
    --text-ref-term: #7eb5e2; 

    --ref-c1: #56b4e9; 
    --ref-c2: #f0ab00; 
    --ref-c3: #00c49a; 
    --ref-c4: #e07aab;
    --ref-font-weight: 500;
    
    /* Borders */
    --border: 1px solid #444c56;
    --book-spine-def: #555;
}

* { box-sizing: border-box; }

body, html { 
    height: 100dvh; margin: 0; padding: 0;
    font-family: var(--font-ui); color: var(--text-main);
    background: var(--bg-app); overflow: hidden;
    font-size: 16px;
}

/* Scrollbars - Theme Aware */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d6d3ce; border-radius: 4px; }
body.dark-mode ::-webkit-scrollbar-thumb { background: #444; }
::-webkit-scrollbar-thumb:hover { background: #bdb9b3; }
body.dark-mode ::-webkit-scrollbar-thumb:hover { background: #555; }

/* Layout */
.app-grid {
    display: grid; grid-template-columns: 240px 1fr; 
    height: 100dvh;
}

/* --- NAVIGATION --- */
/* Wrapper for Logo + Text */
.nav-home-link {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
    margin-right: auto; 
}

/* PWA/Standalone Mode Only: Disable the link */
@media all and (display-mode: standalone) {
    .nav-home-link {
        pointer-events: none; 
        cursor: default;      
    }
}

.nav-pane {
    background: var(--bg-panel); border-right: var(--border);
    display: flex; flex-direction: column; overflow: hidden;
}

.nav-header-container {
    padding: 14px 16px; background: var(--bg-panel);
    border-bottom: var(--border); display: flex; align-items: center;
    font-weight: 600; color: var(--text-main); z-index: 10;
}
.site-logo { height: 24px; width: 24px; margin-right: 10px; opacity: 0.9; }
.nav-header-link { text-decoration: none; color: inherit; margin-right: auto; } 

/* Theme Toggle Button */
.theme-toggle-btn {
    background: transparent; border: 1px solid transparent;
    color: var(--text-muted); cursor: pointer; padding: 4px 8px;
    border-radius: 4px; font-size: 1.1rem; line-height: 1;
    transition: all 0.2s;
}
.theme-toggle-btn:hover { background: var(--bg-hover); color: var(--text-main); }

.nav-content { flex: 1; overflow-y: auto; padding-bottom: 20px; }

/* Book Items */
.nav-book-item { border-bottom: 1px solid transparent; }

.nav-book-header {
    padding: 9px 12px 9px 16px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text-muted);
    display: flex; justify-content: space-between; align-items: center;
    transition: all 0.1s ease-in-out;
    border-left: 6px solid var(--book-color, var(--book-spine-def)); 
    background: transparent;
}

.nav-book-header:hover { 
    background: var(--bg-hover); 
    color: var(--text-main); 
}

.nav-book-header.active-book {
    background: var(--bg-app); 
    font-weight: 600;
    color: var(--text-main);
    border-left-width: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.nav-chapter-grid {
    display: none;
    grid-template-columns: repeat(5, 1fr); gap: 4px;
    padding: 10px 16px; background: var(--bg-app);
    border-bottom: var(--border);
    border-left: 6px solid var(--book-color, var(--book-spine-def));
}
.nav-chapter-grid.show { display: grid; }

.nav-chap-num {
    text-align: center; padding: 6px 0;
    border-radius: 4px; font-size: 0.85rem;
    color: var(--text-muted); text-decoration: none;
    background: var(--bg-panel); transition: all 0.1s;
}
.nav-chap-num:hover { background: var(--bg-hover); color: var(--text-main); }

.nav-chap-num.active-chap { 
    background: var(--book-color, var(--text-link)); 
    color: white; font-weight: 600; 
    text-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

/* Shared Reference Styles (Global for Ref Pane) */
.verse.ref-selected {
    background-color: var(--bg-select-subtle);
    border-left: 3px solid #f0c040;
    padding-left: 8px; margin-left: -11px;
    transition: background-color 0.5s ease-out, border-left-color 0.3s;
}

/* Removed @keyframes flash-highlight to prevent timing flickers */
.verse.ref-selected { animation: flash-highlight 1.5s ease-out; }

/* --- CONTENT AREA --- */
#main-content-wrapper {
    display: flex; height: 100%; overflow: hidden;
    position: relative; background: var(--bg-app);
}
.htmx-indicator-main { opacity: 1; transition: opacity 0.2s; }
.htmx-indicator-main.htmx-request { opacity: 0.5; pointer-events: none; }

/* Mobile Toggles */
.nav-toggle, .pane-toggle {
    position: fixed; z-index: 1000;
    background: var(--bg-app); border: var(--border);
    color: var(--text-muted); box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.nav-toggle { display: none; top: 12px; left: 12px; width: 40px; height: 40px; border-radius: 4px; }
.pane-toggle { display: none; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--text-link); color: white; border: none; }

@media (max-width: 768px) {
    .app-grid { grid-template-columns: 1fr; }
    
    /* Navigation Pane Animation */
    .nav-pane { 
        position: fixed; top: 0; left: 0; bottom: 0; width: 280px; z-index: 1100; 
        transform: translateX(-100%); transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); 
        box-shadow: 2px 0 10px rgba(0,0,0,0.1); 
    }
    .nav-pane.nav-open { transform: translateX(0); }
    .nav-toggle, .pane-toggle { display: flex; }

    /* --- ANIMATION LOGIC START --- */
    
    /* 1. The Wrapper acts as the masking viewport */
    #main-content-wrapper {
        position: relative;
        overflow: hidden;
        width: 100%;
        height: 100%;
        display: block; /* Override flex behavior on mobile */
    }

    /* 2. Base state for both Panes */
    #main-content-wrapper .left-column, 
    #main-content-wrapper .right-pane { 
        position: absolute;
        top: 0; left: 0;
        width: 100%; 
        height: 100%;
        overflow-y: auto; 
        transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1); 
        
        display: flex !important; 
        flex: none;
        opacity: 1;
    }

    /* 3. Default State (Text View) */
    #main-content-wrapper .left-column {
        transform: translateX(0);
        z-index: 5;
    }
    #main-content-wrapper .right-pane { 
        transform: translateX(100%);
        z-index: 10;
        border-left: none; 
        background: var(--bg-panel); 
    }

    /* 4. Active State (Reference View) */
    #main-content-wrapper.resize-right .left-column { 
        transform: translateX(-30%); 
    }

    #main-content-wrapper.resize-right .right-pane { 
        transform: translateX(0);
        box-shadow: -5px 0 15px rgba(0,0,0,0.05); 
    }
    
    #main-content-wrapper.resize-left .left-column { display: flex; }
    #main-content-wrapper.resize-left .right-pane { display: flex; }
    #main-content-wrapper[data-resize-state="normal"] .right-pane { display: flex; }
}

/* Layout containers */
.left-column { 
    flex: 1.3; display: flex; flex-direction: column; height: 100%; 
    overflow: hidden; background: var(--bg-app); 
}
.left-pane { flex: 1; overflow-y: auto; padding-bottom: 60px; }

/* Headers */
.text-sticky-header { 
    position: sticky; top: 0; z-index: 30; 
    background: var(--bg-app); 
    border-bottom: var(--border); height: var(--header-height); 
    display: flex; align-items: center; justify-content: center; 
    font-family: var(--font-ui); font-weight: 600; color: var(--text-main); 
    opacity: 0.98;
}

.scripture-container { padding: 20px 24px; max-width: 48rem; margin: 0 auto; }

.verse { 
    margin-bottom: 8px; line-height: 1.65; 
    font-family: var(--font-serif); font-size: 1.1rem; color: var(--text-main); 
}

.verse-number { 
    font-family: var(--font-ui); font-size: 0.75rem; 
    color: var(--text-ref-term); font-weight: 600; margin-right: 6px; 
    user-select: none; vertical-align: 2px; cursor: pointer; 
    padding: 3px 5px; border-radius: 3px; 
    background-color: rgba(127, 127, 127, 0.13);
}
.verse-number:hover { background: var(--bg-hover); color: var(--text-main); }
.verse-number.active { background: var(--bg-select); color: #443300; }
body.dark-mode .verse-number.active { color: #ffd700; }

/* --- THE NEW SLATE COLOR --- */
.has-refs { 
    color: var(--ref-color, var(--text-muted));  
    cursor: pointer;
    font-weight: var(--ref-font-weight);
    transition: background-color 0.1s, border-color 0.1s; 
}
.has-refs:hover { 
    background-color: var(--bg-hover);
}

.has-refs.term-active { 
    background-color: var(--bg-select);
}

/* Utility Classes for the Color Cycle */
.ref-c1 { --ref-color: var(--ref-c1); }
.ref-c2 { --ref-color: var(--ref-c2); }
.ref-c3 { --ref-color: var(--ref-c3); }
.ref-c4 { --ref-color: var(--ref-c4); }

/* --- RIGHT PANE STYLES --- */
.right-pane { 
    flex: 1; background: var(--bg-panel); border-left: var(--border); 
    display: flex; flex-direction: column; height: 100%; 
    overflow-y: auto; position: relative; 
    padding-bottom: 100px;
}

.ref-sticky-header, .ref-static-header { 
    position: sticky; top: 0; z-index: 20; height: var(--header-height); 
    background: var(--bg-panel); border-bottom: var(--border); 
    color: var(--text-main); 
    display: flex; align-items: center; 
    justify-content: center; padding: 0 16px; 
    font-family: var(--font-ui); font-weight: 700; font-size: 0.95rem; 
}

.ref-group-header { 
    position: sticky; top: var(--header-height); z-index: 19; 
    padding: 8px 12px; font-size: 0.8rem; font-weight: 700; 
    
    color: var(--ref-group-color, var(--text-link)); 
    border-left: 4px solid var(--ref-group-color, transparent);
    
    background: var(--bg-hover); 
    text-transform: uppercase; letter-spacing: 0.05em; 
    border-bottom: var(--border); border-top: var(--border); 
    transition: color 0.2s, border-left-color 0.2s;
}

.initial-message { color: var(--text-muted); font-style: italic; text-align: center; padding: 40px 20px; font-size: 0.9rem; }

.ref-group { margin-bottom: 0; background: var(--bg-app); }
.ref-item { padding: 14px 16px; border-bottom: 1px solid transparent; border-color: var(--border); }
.ref-item:last-child { border-bottom: none; }

.ref-citation { 
    display: block; 
    font-family: var(--font-ui); 
    font-weight: 600; 
    font-size: 1rem;  
    color: var(--text-link); 
    text-decoration: none; 
    margin-bottom: 6px;  
}
.ref-citation:hover { text-decoration: underline; }

.ref-text { 
    font-family: var(--font-serif); 
    font-size: 1rem;  
    color: var(--text-main); 
    line-height: 1.5; 
    opacity: 1;  
}
.ref-verse-num { font-size: 0.7em; font-weight: bold; color: var(--text-muted); vertical-align: top; margin-right: 2px; }
.ref-separator {
    color: var(--text-muted);
    font-weight: bold;
    margin: 0 2px;
    background-color: rgba(128, 128, 128, 0.25);
    padding: 1px 3px; 
    border-radius: 2px;
    user-select: none; 
    vertical-align: 1px; 
    font-size: 0.8em;
}

/* Language Picker */
.trans-select-wrapper {
    margin-left: auto; 
    margin-right: 12px;
    position: relative;
}

.trans-select {
    appearance: none;
    -webkit-appearance: none;
    background-color: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 4px 24px 4px 8px; /* Room for chevron */
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2375726e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 4px center;
    background-size: 14px;
}

.trans-select:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
}

.trans-select:focus {
    outline: none;
    border-color: var(--border);
}

/* --- Copyright Footer --- */
.copyright-footer {
    padding: 10px;
    font-family: var(--font-ui);
    font-size: 0.7rem;
    color: #88888887;
    text-align: center;
    max-width: 40rem;
    margin: 3rem auto;
    margin-bottom: 0;
}

.copyright-footer p {
    margin: 0;
    line-height: 1.4;
}

/* Form Styles */
.ref-header-input {
    width: 100%;
    background: transparent;
    border: none;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: inherit; 
    outline: none;
    padding: 0;
    margin: 0;
    cursor: text;
}

.ref-header-input:focus {
    background: rgba(0,0,0,0.05);
}

.ref-group-header-form {
    position: sticky; top: var(--header-height); z-index: 19; 
    padding: 8px 12px; 
    border-left: 4px solid var(--ref-group-color, transparent);
    background: var(--bg-hover); 
    border-bottom: var(--border); border-top: var(--border); 
}

/* Text Expander */
.ref-text-expander {
    cursor: pointer;
    color: #888;
    font-size: 0.8em;
    font-weight: bold;
    margin-left: 5px;
    user-select: none;
}
.ref-text-expander:hover {
    color: #333;
    text-decoration: underline;
}
.ref-text-expander.expanded {
    font-size: 0.75em;
    color: #999;
    font-weight: normal;
}