/* Three explicit themes -- Light (default, bare :root), Dark, and Eye (a
   red-on-near-black scheme, the kind used to preserve night vision / cut
   blue light, so unlike Dark it stays within shades of red rather than
   amber+blue). Picked by data-theme on <html>; see applyTheme() in
   reader.js. There's no "follow the system" mode -- a first-time visitor
   gets Dark if their OS prefers it (resolved once in JS), Light
   otherwise, and from then on whichever they pick here sticks. */
:root {
    color-scheme: light;
    --bg: #faf8f4;
    --panel-bg: #ffffff;
    --border: #ddd6c8;
    --text: #2a2620;
    --dim: #8a8372;
    --accent: #8a5a2b;
    --accent-text: #ffffff;
    --accent-bg: #f1e6d4;
    --link: #2b5a8a;
    --marker: #6b7a8a;
    --hover: #fff3d6;
    --font-scale: 1;         /* "Text" (top pane) -- see applyFontScale() */
    --font-scale-bottom: 1;  /* "Interlinear" (bottom pane) */
    font-size: 16px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1a1713;
    --panel-bg: #231f19;
    --border: #3d362b;
    --text: #ece6da;
    --dim: #a39a89;
    --accent: #d9a35a;
    --accent-text: #241a0a;
    --accent-bg: #3a2e1c;
    --link: #7eb0e6;
    --marker: #96a2b5;
    --hover: #40331c;
}

:root[data-theme="eye"] {
    color-scheme: dark;
    --bg: #0d0606;
    --panel-bg: #170a0a;
    --border: #3d1818;
    --text: #d9a3a3;
    --dim: #8a5555;
    --accent: #e0483f;
    --accent-text: #fbe4e4;
    --accent-bg: #2e1010;
    --link: #e0483f;
    --marker: #a35c5c;
    --hover: #3d1515;
}

* { box-sizing: border-box; }

/* Generic show/hide utility, used on the overlays themselves and on the
   book-list/chapter-grid panes within the picker overlay. !important so
   it reliably wins regardless of what else sets display on an element
   carrying it (an overlay is "display: flex" by default, for instance). */
.hidden { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Georgia", "Times New Roman", serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    /* dvh accounts for a mobile browser's address bar showing/hiding,
       which 100vh does not -- falls back to the line above on browsers
       that don't support it. */
    height: 100dvh;
}

/* --- toolbar --- */

#toolbar {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border);
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: 0.9rem;
}

/* A fixed-size square at the top-left -- always visible, collapsed or
   not, so it reads as a persistent menu button rather than part of the
   controls it shows/hides. rem-sized rather than em so it stays the same
   physical size regardless of #toolbar's own font-size (shrunk on
   mobile, see the media query below). */
#toolbar-toggle {
    flex: 0 0 auto;
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-right: 1px solid var(--border);
    background: none;
    color: var(--dim);
    cursor: pointer;
    font-size: 1.1rem;
}
#toolbar-toggle:hover { background: var(--accent-bg); color: var(--text); }

/* The controls proper -- collapsible; flex:1 fills whatever's left of
   the row beside the square toggle, and wraps internally as needed. */
#toolbar-groups {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.25em;
    padding: 0.6em 1em;
}
#toolbar-groups.collapsed { display: none; }

.picker-group { display: flex; align-items: center; gap: 0.5em; }

/* Outside #toolbar-groups (see index.html), so Prev/Next stay reachable
   with the options collapsed -- margin-left:auto pushes it to the far
   right of #toolbar's own row either way, collapsed or not. */
.nav-group {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0.6em 1em;
}

#toolbar label { display: flex; align-items: center; gap: 0.35em; color: var(--dim); }
.font-size-label { color: var(--dim); font-size: 0.85em; }
#toolbar select, #toolbar button {
    font: inherit;
    padding: 0.35em 0.6em;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--panel-bg);
    color: var(--text);
    cursor: pointer;
}
#toolbar select:hover, #toolbar button:hover { border-color: var(--accent); }
#toolbar button:disabled { opacity: 0.35; cursor: default; }
#toolbar button:disabled:hover { border-color: var(--border); }
.picker-btn { font-weight: 600; min-width: 6em; text-align: left; }

/* History back/forward and the bookmark controls -- icon-only, so they
   read as a compact unit distinct from Prev/Next's own text-labelled
   buttons just to their right (margin-left puts daylight between the
   two clusters without a whole new top-level toolbar group). */
.icon-btn { font-size: 1.05em; padding: 0.3em 0.55em; line-height: 1; }
#prev-chapter { margin-left: 0.6em; }
#bookmark-btn.active { color: var(--accent); border-color: var(--accent); }

/* A small segmented control for the theme (light/dark/eye) -- a single
   choice from a short fixed set, so a row of buttons reads at a glance
   as a toggle, rather than a dropdown that has to be opened to see the
   options. */
.segmented-group { display: flex; border: 1px solid var(--border); border-radius: 5px; overflow: hidden; }
.segmented-btn {
    font: inherit;
    border: none;
    border-radius: 0;
    padding: 0.35em 0.7em;
    background: var(--panel-bg);
    color: var(--dim);
    cursor: pointer;
}
.segmented-btn + .segmented-btn { border-left: 1px solid var(--border); }
.segmented-btn:hover { background: var(--accent-bg); color: var(--text); }
.segmented-btn.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented-btn:disabled { opacity: 0.4; cursor: default; }
.segmented-btn:disabled:hover { background: var(--panel-bg); color: var(--dim); }

/* Interlinear off: nothing to put below the main text -- see
   applyInterlinear() in reader.js. The checkbox+label itself
   (#bottom-label's first child) stays visible either way, since it's
   the control that turns this back on. */
.interlinear-group { display: flex; align-items: center; gap: 0.4em; }
.interlinear-label { display: flex; align-items: center; gap: 0.3em; color: var(--dim); cursor: pointer; }
.no-interlinear #bottom-translation,
.no-interlinear #font-size-bottom-group { display: none; }
.font-size-sub { display: flex; align-items: center; gap: 0.5em; }

/* --- reading area --- */

#reader {
    flex: 1;
    overflow-y: auto;
    padding: 1.5em clamp(0.75em, 4vw, 3em);
    max-width: 68em;
    margin: 0 auto;
    width: 100%;
}

.chapter-title {
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: 0.85rem;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 1em;
}

/* One pane came back with nothing at all for this book (a translation
   missing a book entirely -- see renderChapter()'s appendMissingNote(),
   e.g. CEI/Vulgate's Daniel) -- normal-case text, not shouting, since
   it's an expected gap, not an error. */
.missing-note { text-transform: none; letter-spacing: normal; font-style: italic; }

/* A quieter way to move on than scrolling back up to the toolbar's own
   Prev/Next -- smaller and less assertive than those, since it's a
   convenience for someone already reading on, not a primary control. */
.bottom-nav { display: flex; justify-content: flex-end; margin-top: 1.5em; }
.bottom-next {
    font: inherit;
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: 0.8rem;
    padding: 0.4em 0.8em;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: none;
    color: var(--dim);
    cursor: pointer;
}
.bottom-next:hover { border-color: var(--accent); color: var(--accent); }

.verse {
    display: flex;
    gap: 0.75em;
    padding: 0.5em 0;
    border-bottom: 1px solid var(--border);
    align-items: flex-start;
}

.verse-num {
    flex: 0 0 2.4em;
    text-align: right;
    color: var(--accent);
    font-weight: 600;
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: calc(0.8rem * var(--font-scale));
    padding-top: 0.3em;
    user-select: none;
}

.verse-lines { flex: 1; min-width: 0; }

/* Reading text size -- adjustable via the font-size +/- buttons, see
   applyFontScale() in reader.js. Everything inside a verse line (markers,
   <big>/<small>/<sup> letters, ...) is already sized in `em`, so scaling
   just these rules scales the whole verse with them. The top ("Text")
   and bottom ("Interlinear") panes scale independently -- renderChapter()
   tags each line .verse-line-top or .verse-line-bottom, which is what
   picks --font-scale vs --font-scale-bottom below. */
.verse-line {
    line-height: 1.75;
    margin: 0.1em 0;
}
.verse-line.rtl { direction: rtl; text-align: right; }
.verse-line.ltr { direction: ltr; text-align: left; }
.verse-line-top { font-size: calc(1.15rem * var(--font-scale)); }
.verse-line-top.rtl { font-size: calc(1.3rem * var(--font-scale)); }
.verse-line-bottom { font-size: calc(1.15rem * var(--font-scale-bottom)); }
.verse-line-bottom.rtl { font-size: calc(1.3rem * var(--font-scale-bottom)); }

/* A right-to-left top line puts its verse number on the right instead,
   so the number stays next to the start of the verse either way -- the
   same reasoning terminal_bible_reader's gutter-flip uses. */
.verse.top-rtl { flex-direction: row-reverse; }
.verse.top-rtl .verse-num { text-align: left; }

.marker { color: var(--marker); font-size: 0.85em; margin: 0 0.3em; }
.gap { display: inline-block; width: 1.4em; }

big.letter { font-size: 1.3em; font-weight: 700; }
small.letter { font-size: 0.75em; }
sup.letter { vertical-align: super; font-size: 0.7em; }

/* --- WLC clickable words --- */

.w-word { display: inline-block; white-space: nowrap; }
.w-part {
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.1s;
}
.w-part:hover, .w-part:focus-visible { background: var(--hover); outline: none; }
.w-part.active { background: var(--accent-bg); }
.w-punct { color: var(--dim); }
.w-punct.tight { margin: 0 0.05em; }

/* A pronominal suffix: still clickable (shows its grammar), but visually
   quieter since it has no dictionary entry of its own -- see no-lemma
   handling in reader.js. */
.w-part.no-lemma { color: var(--dim); }
.w-part.no-lemma:hover, .w-part.no-lemma:focus-visible { background: var(--accent-bg); }

/* --- overlays (book/chapter picker, lexicon popup) ---
 *
 * Both are full-screen on every size, desktop included: a sticky header
 * (title + close button) above a scrollable body, the overlay itself
 * filling the viewport rather than floating as a centered card. The
 * body's own content is still capped to a comfortable reading width and
 * centered, so a wide desktop window doesn't stretch a BDB entry or the
 * book grid edge to edge -- just the chrome around it is full-screen. */

.overlay {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    background: var(--panel-bg);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.overlay-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
    padding: 0.9em 1.1em;
    border-bottom: 1px solid var(--border);
    font-family: "Helvetica Neue", Arial, sans-serif;
}
.overlay-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overlay-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1.1em;
    max-width: 56em;
    width: 100%;
    margin: 0 auto;
    font-family: "Helvetica Neue", Arial, sans-serif;
}

.book-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(11em, 1fr)); gap: 0.3em; }
.book-list .section-head {
    grid-column: 1 / -1;
    font-weight: 700;
    color: var(--accent);
    margin-top: 0.6em;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.book-list button, .chapter-grid button {
    font: inherit;
    text-align: left;
    padding: 0.45em 0.6em;
    border: 1px solid transparent;
    border-radius: 6px;
    background: none;
    cursor: pointer;
    color: var(--text);
}
.book-list button:hover, .chapter-grid button:hover { background: var(--accent-bg); }
/* A book's own-language title, wherever it's shown (the book picker,
   the chapter heading below) -- isolated with unicode-bidi so a Hebrew
   or Greek title's own internal ordering doesn't get tangled up with
   whatever LTR English text sits next to it. */
.native { color: var(--dim); margin-left: 0.4em; direction: rtl; unicode-bidi: isolate; }

.chapter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(3em, 1fr)); gap: 0.3em; }
.chapter-grid button { text-align: center; }
.chapter-grid-back { grid-column: 1 / -1; margin-bottom: 0.5em; font-weight: 600; }

.close-btn {
    flex: 0 0 auto;
    font-size: 1.6rem;
    line-height: 1;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--dim);
    padding: 0.3em 0.5em;
    border-radius: 6px;
}
.close-btn:hover { color: var(--text); background: var(--accent-bg); }

/* --- account overlay (login / signup) --- */

.auth-intro { color: var(--dim); font-size: 0.9rem; margin-top: 0; }
#auth-form { max-width: 24em; }
.auth-field { display: flex; flex-direction: column; align-items: stretch; gap: 0.3em; margin-bottom: 0.9em; color: var(--dim); }
.auth-field input {
    font: inherit;
    padding: 0.5em 0.6em;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--panel-bg);
    color: var(--text);
}
.auth-field input:focus { outline: none; border-color: var(--accent); }
.auth-error { color: var(--accent); font-size: 0.88rem; }
.auth-submit {
    font: inherit;
    font-weight: 600;
    padding: 0.5em 1em;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
}
.auth-submit:hover { opacity: 0.9; }
.auth-switch { font-size: 0.88rem; }
.auth-switch a { color: var(--link); }

/* --- bookmarks overlay --- */

.bookmark-row {
    display: flex;
    align-items: center;
    gap: 0.5em;
    border-bottom: 1px solid var(--border);
}
.bookmark-goto {
    flex: 1;
    text-align: left;
    background: none;
    border: none;
    padding: 0.7em 0.2em;
    font: inherit;
    color: var(--text);
    cursor: pointer;
}
.bookmark-goto:hover { color: var(--accent); }
.bookmark-time { display: block; font-size: 0.78rem; color: var(--dim); }
.bookmark-remove {
    flex: 0 0 auto;
    background: none;
    border: none;
    color: var(--dim);
    font-size: 1.1rem;
    padding: 0.3em 0.5em;
    cursor: pointer;
    border-radius: 6px;
}
.bookmark-remove:hover { color: var(--text); background: var(--accent-bg); }

/* --- lexicon popup contents --- */

.lex-head { display: flex; align-items: baseline; gap: 0.6em; flex-wrap: wrap; margin-bottom: 0.2em; }
.lex-hebrew { font-family: "Georgia", serif; font-size: 1.8rem; direction: rtl; }
.lex-greek { font-family: "Georgia", serif; font-size: 1.8rem; direction: ltr; }
.lex-xlit { color: var(--dim); font-style: italic; }
.lex-pos { font-size: 0.8rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.lex-gloss { font-size: 1.1rem; margin: 0.3em 0 0.6em; }
.lex-ids { font-size: 0.78rem; color: var(--dim); margin-bottom: 0.8em; }
.lex-morph { font-size: 0.85rem; color: var(--link); margin-bottom: 0.8em; }
.lex-section-title {
    font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
    color: var(--dim); margin: 1em 0 0.3em; border-top: 1px solid var(--border); padding-top: 0.6em;
}
.lex-strong-usage { font-size: 0.9rem; }
.lex-empty { color: var(--dim); font-style: italic; }

/* BDB entry, rendered from BrownDriverBriggs.xml -- see lexicon.py */
.bdb-entry { font-family: "Georgia", serif; font-size: 1rem; direction: ltr; line-height: 1.6; }
.bdb-w { font-weight: 700; direction: rtl; unicode-bidi: isolate; }
.bdb-pos { font-style: italic; color: var(--dim); }
.bdb-def { }
.bdb-foreign { direction: rtl; unicode-bidi: isolate; color: var(--dim); }
.bdb-sense { margin: 0.25em 0 0.25em 1em; }
.bdb-sense::before { content: attr(data-n) ") "; color: var(--accent); font-weight: 600; }
.bdb-sense[data-n=""]::before { content: ""; }
.bdb-ref { color: var(--link); }
.bdb-status { font-size: 0.75rem; color: var(--dim); margin-top: 0.6em; }

/* --- mobile --- */

@media (max-width: 720px) {
    #toolbar { font-size: 0.85rem; flex-wrap: wrap; }
    #toolbar-groups { gap: 0.5em; padding: 0.5em 0.7em; }
    .picker-group { gap: 0.4em; }

    /* Prev/Next stay on the same line as the square toggle (DOM order
       puts #toolbar-groups between them; `order` moves it after instead,
       so it wraps onto its own full-width line below rather than
       squeezing between toggle and nav-group on line 1 -- see
       index.html for why nav-group lives outside #toolbar-groups at
       all). */
    .nav-group { order: 1; margin-left: 0.5em; padding: 0.3em 0; }
    #toolbar-groups { order: 2; flex-basis: 100%; }

    /* Each group becomes its own full-width row -- book/chapter buttons,
       then each translation select on its own line (their labels are
       full sentences, see reader.js's WLC_LABEL; a <select> can't
       usefully share a row with anything else once it might show text
       that long), then the theme switch. Named specifically rather than
       selected via the shared .picker-group base class, which .nav-group
       also carries -- that ambiguity is exactly what put .nav-group at
       100% width here too, wrapping it off the toggle's row below. */
    .bookchapter-group, .translation-group, .theme-group, .font-size-group, .account-group {
        width: 100%;
        margin-left: 0;
    }
    .translation-group { flex-direction: column; align-items: stretch; gap: 0.4em; }
    .translation-group label { justify-content: space-between; }
    /* .interlinear-label is a <label> too (for the checkbox), so the rule
       above also reaches it as a descendant -- spreading its checkbox and
       text apart, which isn't wanted there the way it is for the "Text"
       label's own select. Two classes outweighs the other rule's one
       class + element, so this wins regardless of order. */
    .translation-group .interlinear-label { justify-content: flex-start; }
    #toolbar select { flex: 1; min-width: 0; }
    .interlinear-group { width: 100%; }
    .theme-group { display: flex; justify-content: center; }
    /* Two labelled segmented controls now live in this one row (Text,
       Interlinear) -- wrap lets the second pair drop to its own line on
       a narrow phone instead of overflowing, rather than forcing this
       group to also become a full-width stack like translation-group's
       own controls above. */
    .font-size-group { display: flex; justify-content: center; flex-wrap: wrap; row-gap: 0.4em; }

    /* Touch targets: comfortably above the ~44px rule of thumb. */
    #toolbar button, #toolbar select { padding: 0.55em 0.7em; }
    .nav-group button { padding: 0.4em 0.6em; }

    #reader { padding: 1em 0.75em; }
    .verse { gap: 0.5em; }
    .verse-num { flex-basis: 1.8em; font-size: calc(0.75rem * var(--font-scale)); }
    .verse-line { line-height: 1.65; }
    .verse-line-top { font-size: calc(1.05rem * var(--font-scale)); }
    .verse-line-top.rtl { font-size: calc(1.2rem * var(--font-scale)); }
    .verse-line-bottom { font-size: calc(1.05rem * var(--font-scale-bottom)); }
    .verse-line-bottom.rtl { font-size: calc(1.2rem * var(--font-scale-bottom)); }

    .overlay-header { padding: 0.7em 0.8em; }
    .overlay-header h2 { font-size: 0.95rem; }
    .overlay-body { padding: 0.8em; }
    .close-btn { font-size: 1.8rem; padding: 0.2em 0.45em; }

    .book-list { grid-template-columns: repeat(auto-fill, minmax(9em, 1fr)); }
    .book-list button, .chapter-grid button { padding: 0.65em 0.6em; }
    .chapter-grid { grid-template-columns: repeat(auto-fill, minmax(2.8em, 1fr)); gap: 0.4em; }

    .lex-hebrew, .lex-greek { font-size: 1.5rem; }

    /* The lexicon popup is opened by tapping a word mid-text, usually
       nowhere near the top of the screen -- a floating button at the
       bottom right is reachable right where the thumb already is,
       instead of making every dismissal a reach back up to the header.
       Fixed (not the header's flex flow), so it floats over the
       scrolling body; the book/chapter picker's own close button is
       unaffected, it's still worth a header since that overlay is
       usually opened from the top toolbar itself. */
    #lexicon-close {
        position: fixed;
        right: 1em;
        bottom: calc(1em + env(safe-area-inset-bottom, 0px));
        z-index: 60;
        width: 2.9em;
        height: 2.9em;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--panel-bg);
        border: 1px solid var(--border);
        border-radius: 50%;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    }
}
