/* Layout: one printed page — a single reading column under a running head,
   with the closed book's fore-edge along the right side as the progress map
   (gilt where chapters are read, a green ribbon at your place).
   Palette: bookbinding materials only — black ink, paper, gold, green ribbon. */
:root {
    --paper: #f6f5f1;        /* Bible paper, warm neutral */
    --paper-raised: #fcfbf8;
    --paper-sunk: #ecebe5;
    --ink: #1e1e1b;          /* black ink */
    --ink-soft: #4a4943;
    --ink-faint: #75736b;
    --rule: #dad8d0;
    --edge: #dcdad2;         /* unread page edges */
    --edge-alt: #e6e4dd;     /* alternate sections of the edge */
    --gilt: #b08529;         /* read page edges */
    --gilt-soft: #efe3c2;
    --gilt-ink: #7e5d17;     /* verse numbers, chapter numerals */
    --ribbon: #2e5a43;       /* the green ribbon marker and primary actions */
    --ribbon-ink: #ffffff;
    --speech: #6b4422;       /* quoted speech: brown ink */
    --speech-inner: #56602a; /* a quotation inside a quotation: olive */
    --danger: #a3282b;
    --focus: #2f7a52;
    --scrim: rgba(30, 30, 27, 0.38);
    --shadow: 0 1px 2px rgba(30, 30, 27, 0.08), 0 8px 24px rgba(30, 30, 27, 0.12);

    --font-display: "Baskervville", "Libre Baskerville", Baskerville, "Baskerville Old Face", Georgia, serif;
    --font-text: "Literata", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    --font-ui: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-legible: "Atkinson Hyperlegible", "Verdana", system-ui, sans-serif;
    --font-greek: "Gentium Book Plus", "Literata", "Palatino Linotype", serif;
    --font-hebrew: "Noto Serif Hebrew", "SBL Hebrew", "Ezra SIL", serif;

    --reading-size: 19px;
    --reading-leading: 1.7;
    --measure: 36rem;
    --topbar: 3.5rem;
    --edge-width: 14px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]):not([data-theme="sepia"]) {
        --paper: #171716;
        --paper-raised: #1f1f1d;
        --paper-sunk: #111110;
        --ink: #e9e6de;
        --ink-soft: #b5b1a7;
        --ink-faint: #85827a;
        --rule: #2e2d2a;
        --edge: #2c2b28;
        --edge-alt: #242422;
        --gilt: #d2a54e;
        --gilt-soft: #3b321f;
        --gilt-ink: #d8b25e;
        --ribbon: #7bae8f;
        --ribbon-ink: #10140f;
        --speech: #d9bd92;
        --speech-inner: #b9c48e;
        --danger: #ef7a72;
        --focus: #8cc4a3;
        --scrim: rgba(0, 0, 0, 0.55);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.45);
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --paper: #171716;
    --paper-raised: #1f1f1d;
    --paper-sunk: #111110;
    --ink: #e9e6de;
    --ink-soft: #b5b1a7;
    --ink-faint: #85827a;
    --rule: #2e2d2a;
    --edge: #2c2b28;
    --edge-alt: #242422;
    --gilt: #d2a54e;
    --gilt-soft: #3b321f;
    --gilt-ink: #d8b25e;
    --ribbon: #7bae8f;
    --ribbon-ink: #10140f;
    --speech: #d9bd92;
    --speech-inner: #b9c48e;
    --danger: #ef7a72;
    --focus: #8cc4a3;
    --scrim: rgba(0, 0, 0, 0.55);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 28px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
}

:root[data-theme="sepia"] {
    --paper: #f2e8d5;
    --paper-raised: #f8f0e1;
    --paper-sunk: #e7dbc3;
    --ink: #3a2e22;
    --ink-soft: #5f4f3d;
    --ink-faint: #85745e;
    --rule: #d8c9ad;
    --edge: #ddcfb4;
    --edge-alt: #e7dcc6;
    --gilt: #a8771f;
    --gilt-soft: #e6cf9c;
    --gilt-ink: #7d5813;
    --ribbon: #2f5a40;
    --ribbon-ink: #ffffff;
    --speech: #4c5a22;
    --speech-inner: #7a4a1e;
    --danger: #9b2a22;
    --focus: #2f7a52;
    --scrim: rgba(58, 46, 34, 0.35);
    --shadow: 0 1px 2px rgba(58, 46, 34, 0.1), 0 8px 24px rgba(58, 46, 34, 0.14);
    color-scheme: light;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.5;
}

button, input, select, textarea { font: inherit; color: inherit; }

svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

[hidden] { display: none !important; }

/* ---------- Controls ---------- */

.tool {
    display: inline-flex; align-items: center; gap: 0.45rem;
    min-height: 2.5rem; min-width: 2.5rem; padding: 0 0.6rem;
    border: 0; border-radius: 6px; background: transparent; color: var(--ink-soft);
    cursor: pointer;
}
.tool:hover { background: var(--paper-sunk); color: var(--ink); }
.tool:disabled { opacity: 0.35; cursor: default; background: transparent; }
.tool-label { font-size: 0.9rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    min-height: 2.6rem; padding: 0.5rem 1rem;
    border: 1px solid var(--rule); border-radius: 6px;
    background: var(--paper-raised); color: var(--ink);
    font-size: 0.95rem; cursor: pointer; text-align: center;
}
.btn:hover { border-color: var(--ink-faint); }
.btn-primary { background: var(--ribbon); border-color: var(--ribbon); color: var(--ribbon-ink); font-weight: 700; }
.btn-primary:hover { border-color: var(--ribbon); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }

.button-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---------- Top bar and running head ---------- */

.topbar {
    position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
    display: grid; grid-template-columns: auto auto auto 1fr auto auto; align-items: center; gap: 0.5rem;
    height: var(--topbar); padding: 0 calc(var(--edge-width) + 0.75rem) 0 0.75rem;
    background: color-mix(in srgb, var(--paper) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--rule);
}

.brand {
    margin: 0; font-family: var(--font-display); font-size: 1.2rem; letter-spacing: 0.01em; white-space: nowrap;
}

.running-head {
    margin: 0; justify-self: center; min-width: 0;
    font-size: 0.78rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transition: opacity 0.2s ease;
}
.app.scrolled .running-head { opacity: 1; }

.summary {
    display: inline-flex; align-items: center; gap: 0.55rem;
    min-height: 2.5rem; padding: 0 0.6rem; border: 0; border-radius: 6px; background: transparent;
    cursor: pointer; color: var(--ink-soft);
}
.summary:hover { background: var(--paper-sunk); }
.summary-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.summary-text strong { font-size: 0.95rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.summary-text span { font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.ring { width: 1.9rem; height: 1.9rem; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 4; }
.ring-track { stroke: var(--edge); }
.ring-fill { stroke: var(--gilt); stroke-dasharray: 0 100; stroke-linecap: butt; transition: stroke-dasharray 0.4s ease; }

/* ---------- Fore-edge ---------- */

.fore-edge {
    position: fixed; z-index: 15;
    top: calc(env(safe-area-inset-top, 0px) + var(--topbar)); right: 0; bottom: 0;
    width: var(--edge-width);
    background: var(--paper-sunk);
    border-left: 1px solid var(--rule);
}
.fore-edge canvas { display: block; width: 100%; height: 100%; cursor: pointer; }

.ribbon {
    position: absolute; right: 100%; width: 1.4rem; height: 0.55rem; margin-top: -0.275rem;
    background: var(--ribbon);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 0.35rem 50%);
    pointer-events: none; transition: top 0.3s ease, left 0.3s ease;
}

/* Thumb index: section names beside the edge, as cut into a printed Bible */
.thumb-index { position: absolute; top: 0; bottom: 0; right: calc(100% + 0.5rem); width: 0; }
.thumb-index button {
    position: absolute; right: 0; transform: translateY(-50%);
    padding: 0.1rem 0.3rem; border: 0; border-radius: 3px; background: transparent;
    font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap;
    color: var(--ink-faint); cursor: pointer;
}
.thumb-index button:hover { color: var(--ink); background: var(--paper-sunk); }
.thumb-index button.has-current { color: var(--ribbon); }
@media (max-width: 1099px) { .thumb-index { display: none; } }

.edge-tip {
    position: absolute; right: calc(100% + 1.9rem); z-index: 2;
    padding: 0.35rem 0.6rem; border-radius: 6px;
    background: var(--ink); color: var(--paper); box-shadow: var(--shadow);
    font-size: 0.8rem; white-space: nowrap; pointer-events: none; transform: translateY(-50%);
}

/* ---------- Page ---------- */

.page {
    max-width: calc(var(--measure) + 2rem);
    margin: 0 auto;
    padding-inline: max(1rem, 3vw);
    padding-block: 2.5rem 9rem;
}

.loading { padding-block: 6rem; text-align: center; color: var(--ink-faint); font-family: var(--font-display); font-size: 1.3rem; }

.chapter-head { margin-bottom: 1.75rem; }

.book-title {
    margin: 0;
    font-variant-numeric: lining-nums;
    font-family: var(--font-display); font-weight: 400;
    font-size: clamp(2.4rem, 7vw, 3.6rem); line-height: 1.05; letter-spacing: -0.01em;
    text-wrap: balance;
}

.chapter-meta {
    margin: 0.6rem 0 0; color: var(--ink-faint);
    font-size: 0.8rem; letter-spacing: 0.12em; text-transform: uppercase;
    font-variant-numeric: tabular-nums;
}

/* The text itself */
.passage {
    font-family: var(--font-text);
    font-size: var(--reading-size);
    line-height: var(--reading-leading);
    font-optical-sizing: auto;
    hyphens: auto; -webkit-hyphens: auto;
    text-wrap: pretty;
    font-variant-ligatures: common-ligatures;
}
.app[data-typeface="sans"] .passage { font-family: var(--font-legible); }

.passage p { margin: 0 0 0.9em; }
.passage p.verse-line { margin: 0 0 0.35em; }

/* Gilt chapter numeral, set where verse 1 would be */
.drop {
    float: left;
    margin: 0.06em 0.12em -0.1em -0.04em;
    font-family: var(--font-display); font-weight: 400;
    font-size: calc(var(--reading-leading) * 2.55em);
    line-height: 0.82;
    color: var(--gilt-ink);
    font-variant-numeric: lining-nums;
}

.verse-num {
    font-family: var(--font-ui);
    font-size: 0.58em; font-weight: 700;
    color: var(--gilt-ink);
    vertical-align: 0.55em; line-height: 0;
    font-variant-numeric: lining-nums tabular-nums;
}

/* Quotations set apart, as in the original app */
.passage blockquote {
    margin: 0 0 0.9em;
    padding-left: 1.1em;
    border-left: 2px solid var(--rule);
    font-style: italic;
}
.app[data-speech="on"] .passage blockquote { color: var(--speech); }

.app[data-speech="on"] .speech { color: var(--speech); }
.app[data-speech="on"] .speech-2,
.app[data-speech="on"] .speech-4 { color: var(--speech-inner); }

.divine-name { font-variant-caps: small-caps; letter-spacing: 0.04em; }
.sc { font-variant-caps: small-caps; }

.section-heading {
    margin: 1.6em 0 0.5em;
    font-family: var(--font-ui); font-size: 0.75em; font-weight: 700;
    letter-spacing: 0.18em; text-transform: uppercase; color: var(--gilt-ink);
}

.omitted, .editorial-note { font-style: italic; color: var(--ink-faint); font-size: 0.9em; }

/* End of chapter */
.chapter-end {
    margin-top: 2.5rem; padding-top: 1.5rem;
    border-top: 1px solid var(--rule);
    display: grid; justify-items: center; gap: 1rem; text-align: center;
}
.end-mark { margin: 0; font-family: var(--font-display); font-style: italic; font-size: 1.15rem; color: var(--ink-soft); }
.end-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }

.copyright { margin: 3rem 0 0; font-size: 0.72rem; line-height: 1.5; color: var(--ink-faint); }

/* Notices */
.notices { display: grid; gap: 0.75rem; }
.notices:not(:empty) { margin-bottom: 2rem; }
.notice {
    padding: 1rem 1.1rem;
    border: 1px solid var(--rule); border-radius: 8px;
    background: var(--paper-raised);
    font-size: 0.92rem;
}
.notice h2 { margin: 0 0 0.35rem; font-family: var(--font-display); font-weight: 400; font-size: 1.25rem; }
.notice p { margin: 0 0 0.6rem; color: var(--ink-soft); }
.notice ul { margin: 0 0 0.6rem; padding-left: 1.2rem; color: var(--ink-soft); }
.notice .button-row { margin-top: 0.4rem; }
.notice-demo { border-style: dashed; }

/* ---------- Action bar ---------- */

.actionbar {
    position: fixed; z-index: 18;
    left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    transform: translateX(calc(-50% - var(--edge-width) / 2));
    width: min(var(--measure) + 2rem, calc(100% - 2rem - var(--edge-width)));
    display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.25fr) auto; gap: 0.4rem; align-items: center;
    padding: 0.4rem;
    border: 1px solid var(--rule); border-radius: 10px;
    background: var(--paper-raised);
    box-shadow: var(--shadow);
}

.read-toggle {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    min-height: 2.75rem; padding: 0 0.75rem;
    border: 1px solid var(--rule); border-radius: 6px; background: transparent; color: var(--ink);
    cursor: pointer; white-space: nowrap; overflow: hidden;
}
.read-toggle svg { color: var(--ink-faint); }
.read-toggle:hover { border-color: var(--ink-faint); }
.read-toggle[aria-pressed="true"] { background: var(--gilt-soft); border-color: var(--gilt); }
.read-toggle[aria-pressed="true"] svg { color: var(--gilt-ink); stroke-width: 2.4; }

.random { flex-direction: column; gap: 0; min-height: 2.75rem; line-height: 1.15; padding-block: 0.3rem; }
.random small { font-weight: 400; font-size: 0.72rem; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------- Drawers ---------- */

.scrim { position: fixed; inset: 0; z-index: 30; background: var(--scrim); }

.drawer {
    position: fixed; z-index: 31; top: 0; bottom: 0;
    width: min(27rem, 100%);
    display: flex; flex-direction: column;
    background: var(--paper);
    box-shadow: var(--shadow);
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    animation: drawer-in 0.22s ease-out;
}
.drawer-start { left: 0; border-right: 1px solid var(--rule); --from: -100%; }
.drawer-end { right: 0; border-left: 1px solid var(--rule); --from: 100%; }
@keyframes drawer-in { from { transform: translateX(var(--from)); } to { transform: none; } }

.drawer-head {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 0.75rem 0.75rem 0.75rem 1.25rem; border-bottom: 1px solid var(--rule);
}
.drawer-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.5rem; }
.drawer-body { flex: 1; overflow-y: auto; padding: 1.25rem; display: grid; gap: 1.5rem; align-content: start; }

/* Stats */
.stats { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.stat { background: var(--paper-raised); padding: 0.8rem 0.9rem; display: flex; flex-direction: column-reverse; gap: 0.1rem; }
.stat dt { font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); }
.stat dd { margin: 0; font-family: var(--font-display); font-size: 1.7rem; line-height: 1.1; font-variant-numeric: lining-nums tabular-nums; }
.stat dd small { font-family: var(--font-ui); font-size: 0.8rem; color: var(--ink-faint); margin-left: 0.2rem; }

.field { display: grid; gap: 0.4rem; }
.field label, .segmented legend { font-size: 0.85rem; color: var(--ink-soft); }
select, textarea {
    width: 100%; min-height: 2.6rem; padding: 0.5rem 0.65rem;
    border: 1px solid var(--rule); border-radius: 6px; background: var(--paper-raised);
}
textarea { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.8rem; resize: vertical; }

/* Tabs */
.tabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--rule); }
.tabs button {
    padding: 0.5rem 0; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
    background: none; color: var(--ink-faint); cursor: pointer; font-size: 0.92rem;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ribbon); }

/* Book list */
.book-list { display: grid; gap: 1.5rem; }
.section-block h3 {
    display: flex; justify-content: space-between; margin: 0 0 0.4rem;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint);
}
.section-block h3 span { letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }
.section-block ul { list-style: none; margin: 0; padding: 0; }
.book { border-bottom: 1px solid var(--rule); }
.book summary {
    display: grid; grid-template-columns: minmax(6.5rem, 9rem) minmax(0, 1fr) 3.4rem; align-items: center; gap: 0.75rem;
    padding: 0.55rem 0.25rem; cursor: pointer; list-style: none;
}
.book summary::-webkit-details-marker { display: none; }
.book summary:hover .book-name { color: var(--ribbon); }
.book-name { font-family: var(--font-display); font-variant-numeric: lining-nums; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book.is-current .book-name::after { content: ""; display: inline-block; width: 0.45rem; height: 0.45rem; margin-left: 0.4rem; background: var(--ribbon); border-radius: 50%; vertical-align: 0.15em; }
.book-count { font-size: 0.78rem; color: var(--ink-faint); text-align: right; font-variant-numeric: tabular-nums; }
.book.is-done .book-count { color: var(--gilt-ink); font-weight: 700; }
.slivers { display: flex; height: 0.8rem; gap: 1px; min-width: 0; }
.slivers i { flex: 1 1 0; min-width: 0; background: var(--edge); }
.slivers i.read { background: var(--gilt); }
.slivers i.current { background: var(--ribbon); }

.chapter-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr)); gap: 0.3rem;
    padding: 0.2rem 0.25rem 0.9rem;
}
.chapter-grid button {
    min-height: 2.4rem; border: 1px solid var(--rule); border-radius: 4px;
    background: var(--paper-raised); cursor: pointer; font-size: 0.85rem; font-variant-numeric: tabular-nums;
}
.chapter-grid button:hover { border-color: var(--ink-faint); }
.chapter-grid button.read { background: var(--gilt-soft); border-color: var(--gilt); color: var(--ink); }
.chapter-grid button.current { outline: 2px solid var(--ribbon); outline-offset: 1px; }
.chapter-grid button.unavailable { opacity: 0.4; cursor: not-allowed; }

/* Recent */
.recent-list { display: grid; }
.recent-list p.empty { color: var(--ink-faint); font-size: 0.92rem; }
.recent-item { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 0.4rem; padding: 0.5rem 0; border-bottom: 1px solid var(--rule); }
.recent-item .ref { font-family: var(--font-display); font-variant-numeric: lining-nums; font-size: 1.05rem; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; color: var(--ink); }
.recent-item .ref:hover { color: var(--ribbon); }
.recent-item time { display: block; font-family: var(--font-ui); font-size: 0.78rem; color: var(--ink-faint); }
.recent-item .tool { font-size: 0.82rem; }

/* Settings */
.settings-group { display: grid; gap: 1rem; }
.settings-group h3 { margin: 0; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-faint); }
.hint { margin: 0; font-size: 0.85rem; color: var(--ink-faint); }

.segmented { border: 0; margin: 0; padding: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; }
.segmented legend { padding: 0; margin-bottom: 0.4rem; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
    display: flex; align-items: center; justify-content: center; min-height: 2.4rem; padding: 0 0.5rem;
    border: 1px solid var(--rule); margin-left: -1px; background: var(--paper-raised); font-size: 0.88rem; text-align: center;
}
.segmented label:first-of-type span { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmented label:last-of-type span { border-radius: 0 6px 6px 0; }
.segmented input:checked + span { background: var(--ink); color: var(--paper); border-color: var(--ink); position: relative; }
.segmented input:disabled + span { opacity: 0.45; }
.segmented input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; position: relative; }
.serif-sample { font-family: var(--font-text); }
.sans-sample { font-family: var(--font-legible); }

.range label { display: flex; justify-content: space-between; }
.range output { color: var(--ink); font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; accent-color: var(--ribbon); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 1rem; cursor: pointer; font-size: 0.95rem; }
.switch input { appearance: none; -webkit-appearance: none; flex: none; width: 2.6rem; height: 1.5rem; margin: 0; border-radius: 999px; background: var(--edge); position: relative; cursor: pointer; transition: background 0.15s; order: 2; }
.switch input::after { content: ""; position: absolute; top: 0.2rem; left: 0.2rem; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--paper-raised); box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform 0.15s; }
.switch input:checked { background: var(--ribbon); }
.switch input:checked::after { transform: translateX(1.1rem); }

.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }


/* Toast and dialog */
.toast {
    position: fixed; z-index: 40; left: 50%; transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 5.5rem);
    display: flex; align-items: center; gap: 1rem; max-width: calc(100% - 2rem);
    padding: 0.7rem 0.8rem 0.7rem 1rem; border-radius: 8px;
    background: var(--ink); color: var(--paper); box-shadow: var(--shadow); font-size: 0.92rem;
}
.toast-action { border: 0; background: none; color: var(--gilt); font-weight: 700; cursor: pointer; padding: 0.3rem 0.4rem; border-radius: 4px; }

.dialog {
    max-width: min(26rem, calc(100% - 2rem)); padding: 1.4rem;
    border: 1px solid var(--rule); border-radius: 10px;
    background: var(--paper-raised); color: var(--ink); box-shadow: var(--shadow);
}
.dialog::backdrop { background: var(--scrim); }
.dialog h2 { margin: 0 0 0.5rem; font-family: var(--font-display); font-weight: 400; font-size: 1.45rem; }
.dialog p { margin: 0 0 1.2rem; color: var(--ink-soft); }

/* ---------- Greek words ---------- */

.chapter-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; margin-top: 0.9rem; }
.chapter-tools:not(:has(:not([hidden]))) { display: none; }
.chip {
    display: inline-flex; align-items: center; gap: 0.4rem;
    min-height: 2.1rem; padding: 0 0.8rem;
    border: 1px solid var(--rule); border-radius: 999px; background: var(--paper-raised);
    font-size: 0.85rem; color: var(--ink-soft); cursor: pointer;
}
.chip:hover { border-color: var(--ink-faint); color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--gilt-soft); border-color: var(--gilt); color: var(--ink); }
.chip-mark { font-family: var(--font-greek); font-size: 1.1rem; line-height: 1; color: var(--gilt-ink); }
.chapter-tools-hint { font-size: 0.8rem; color: var(--ink-faint); }

.passage .w { border-radius: 2px; }
.passage .w.is-original, .passage .w.is-name { cursor: pointer; text-decoration-thickness: 1px; text-underline-offset: 0.22em; }
.passage .w.is-original { text-decoration: underline dotted var(--gilt); }
/* Names: a solid green hairline, so they read differently from Greek links. */
.passage .w.is-name { text-decoration: underline solid color-mix(in srgb, var(--ribbon) 55%, transparent); }
.passage .w.is-original:hover, .passage .w.is-name:hover { background: var(--gilt-soft); }
.passage .w.is-active, .passage .w.is-linked { background: var(--gilt-soft); text-decoration-style: solid; }
.passage .w.is-flash { animation: verse-flash 2.6s ease-out; }
@keyframes verse-flash { 0%, 40% { background: var(--gilt-soft); } 100% { background: transparent; } }
.passage .verse-num[role="button"], .passage .drop[role="button"] { cursor: pointer; }
.passage .verse-num[role="button"]:hover, .passage .drop[role="button"]:hover { color: var(--ink); }
.chip-mark-names { font-family: var(--font-ui); font-size: 0.9rem; color: var(--ribbon); }

.word-card {
    position: absolute; z-index: 36;
    width: min(27rem, calc(100vw - 2rem)); max-height: min(34rem, 75vh); overflow-y: auto;
    padding: 0.9rem 1.1rem 1rem;
    border: 1px solid var(--rule); border-radius: 10px;
    background: var(--paper-raised); box-shadow: var(--shadow);
    font-size: 0.92rem;
}
.word-card-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin: -0.3rem -0.5rem 0.4rem 0; }
.word-card-ref { margin: 0; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.gk-entry + .gk-entry { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.lemma { margin: 0; font-family: var(--font-greek); font-size: 2rem; line-height: 1.15; }
.lemma-meta { margin: 0.15rem 0 0.7rem; color: var(--ink-soft); }
.lemma-meta a { color: var(--gilt-ink); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.25rem 0.9rem; margin: 0 0 0.8rem; }
.facts dt { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); padding-top: 0.15rem; }
.facts dd { margin: 0; }
.facts [lang="grc"], .gk { font-family: var(--font-greek); }
.definition { position: relative; font-family: var(--font-text); font-size: 0.88rem; line-height: 1.55; color: var(--ink-soft); }
.definition-text { max-height: 7.8em; overflow: hidden; }
.definition.is-open .definition-text { max-height: none; }
.definition-more { margin-top: 0.3rem; padding: 0; border: 0; background: none; color: var(--gilt-ink); font: inherit; font-family: var(--font-ui); font-size: 0.82rem; cursor: pointer; text-decoration: underline; }
.word-note { margin: 0.5rem 0; color: var(--ink-faint); font-size: 0.85rem; }
.gk-forms { margin: 0 0 0.8rem; padding: 0; list-style: none; }
.gk-forms li { padding: 0.2rem 0; }
.gk-forms [lang="grc"] { font-family: var(--font-greek); font-size: 1.05rem; }
.gk-form-parsing { display: block; font-size: 0.82rem; color: var(--ink-soft); }
.word-verse { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--rule); }
.word-verse-label { margin: 0 0 0.4rem; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.interlinear { display: flex; flex-wrap: wrap; gap: 0.15rem 0.2rem; }
.interlinear button {
    display: flex; flex-direction: column; align-items: flex-start; gap: 0.05rem;
    padding: 0.25rem 0.35rem; border: 1px solid transparent; border-radius: 5px;
    background: none; cursor: pointer; text-align: left; line-height: 1.2;
}
.interlinear button:hover { border-color: var(--rule); }
.interlinear button.is-selected { border-color: var(--gilt); background: var(--gilt-soft); }
.interlinear button.is-candidate { border-color: var(--gilt); border-style: dashed; }
.interlinear .gk { font-size: 1.08rem; color: var(--ink); }
.interlinear .tr { font-size: 0.68rem; font-style: italic; color: var(--ink-faint); }
.interlinear .gl { font-size: 0.72rem; color: var(--ink-soft); }
.word-credit { margin: 0.9rem 0 0; font-size: 0.72rem; color: var(--ink-faint); }
.word-credit a { color: inherit; }

@media (max-width: 760px) {
    .word-card {
        position: fixed; left: 0 !important; right: 0; bottom: 0; top: auto !important;
        width: 100%; max-height: 72vh; border-radius: 14px 14px 0 0;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
}

/* ---------- Narrow screens: the fore-edge lies along the top ---------- */

@media (max-width: 760px) {
    :root { --edge-width: 0px; --topbar: 3.25rem; }
    .topbar { grid-template-columns: auto auto 1fr auto auto; padding: 0 0.4rem; }
    .brand { display: none; }
    .tool-label { display: none; }
    .summary-text span { display: none; }
    .fore-edge {
        top: calc(env(safe-area-inset-top, 0px) + var(--topbar)); left: 0; right: 0; bottom: auto;
        width: auto; height: 6px; border-left: 0; border-bottom: 1px solid var(--rule);
    }
    .ribbon {
        right: auto; top: 100% !important; width: 0.6rem; height: 1.4rem; margin-top: 0; margin-left: -0.3rem;
        clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 72%, 0 100%);
    }
    /* Thumb index: section names beside the edge, as cut into a printed Bible */
.thumb-index { position: absolute; top: 0; bottom: 0; right: calc(100% + 0.5rem); width: 0; }
.thumb-index button {
    position: absolute; right: 0; transform: translateY(-50%);
    padding: 0.1rem 0.3rem; border: 0; border-radius: 3px; background: transparent;
    font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap;
    color: var(--ink-faint); cursor: pointer;
}
.thumb-index button:hover { color: var(--ink); background: var(--paper-sunk); }
.thumb-index button.has-current { color: var(--ribbon); }
@media (max-width: 1099px) { .thumb-index { display: none; } }

.edge-tip { right: auto; top: calc(100% + 1.8rem); transform: translateX(-50%); }
    .page { padding-block: 2rem 8rem; }
    .actionbar {
        transform: translateX(-50%);
        width: calc(100% - 1rem); bottom: calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
        grid-template-columns: auto minmax(0, 1fr) minmax(0, 1.3fr) auto;
    }
    .read-toggle span { font-size: 0.9rem; }
    .random { padding-inline: 0.5rem; white-space: nowrap; }
    .random span { font-size: 0.92rem; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 380px) {
    .read-toggle span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}


/* A Psalm's title (superscription), before verse 1 */
.passage .superscription { margin: 0 0 0.9em; font-size: 0.9em; font-style: italic; color: var(--ink-soft); }

/* ------------------------------------------------------------------ *
 * Before this: where a chapter picks up
 * ------------------------------------------------------------------ */
.before { margin-top: 0.7rem; }
.before-line { margin: 0; font-size: 0.86rem; line-height: 1.5; color: var(--ink-faint); }
.before-label { font-family: var(--font-ui); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; margin-right: 0.35rem; }
.before-text { font-family: var(--font-text); font-style: italic; }
.before-text sup { font-style: normal; font-size: 0.7em; color: var(--gilt-ink); }
.before-actions { white-space: nowrap; margin-left: 0.3rem; }
.link-btn {
    padding: 0; border: 0; background: none; cursor: pointer;
    font: inherit; font-family: var(--font-ui); font-size: 0.82rem; color: var(--gilt-ink);
    text-decoration: underline; text-underline-offset: 0.15em;
}
.link-btn:hover { color: var(--ink); }
.link-btn + .link-btn { margin-left: 0.6rem; }

/* ------------------------------------------------------------------ *
 * The chapter note: quiet, optional, at the end of the chapter
 * ------------------------------------------------------------------ */
.chapter-note { margin-top: 1rem; font-size: 0.88rem; }
.note-empty { margin: 0; color: var(--ink-faint); }
.note-hint { color: var(--ink-faint); font-size: 0.8rem; margin-left: 0.4rem; }
.chapter-note .note-hint:only-child, .chapter-note p.note-hint { margin: 0.35rem 0 0; }
.note-saved {
    display: inline-block; max-width: min(32rem, 100%); text-align: left;
    padding: 0.6rem 0.9rem; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper-raised);
}
.note-text { margin: 0 0 0.3rem; white-space: pre-wrap; font-family: var(--font-text); font-style: italic; color: var(--ink-soft); }
.note-label { display: block; margin-bottom: 0.3rem; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.chapter-note textarea {
    width: 100%; min-height: 5rem; padding: 0.55rem 0.7rem; border: 1px solid var(--rule); border-radius: 6px;
    background: var(--paper-raised); color: var(--ink); font: inherit; font-family: var(--font-text); resize: vertical;
}
.note-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }

/* ------------------------------------------------------------------ *
 * Word card additions: names, concordance, related passages
 * ------------------------------------------------------------------ */
.name-entry + .name-entry, .name-entry + .gk-entry { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.name-entry p { margin: 0 0 0.4rem; }
.person-name { margin: 0; font-family: var(--font-display); font-size: 1.7rem; line-height: 1.15; }
.name-entry .facts { margin-top: 0.5rem; }
.concordance { margin: 0 0 0.8rem; font-size: 0.82rem; color: var(--ink-soft); }
.concordance:empty { display: none; }
.concordance .link-btn { margin-left: 0.4rem; }
.word-related:empty, .word-detail:empty { display: none; }
.word-detail:empty + .word-verse { margin-top: 0.4rem; padding-top: 0; border-top: 0; }
.word-related { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--rule); }
.related { margin: 0 0 0.6rem; padding: 0; list-style: none; display: grid; gap: 0.55rem; }
.related li { font-size: 0.85rem; line-height: 1.45; }
.related-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-family: var(--font-text); color: var(--ink-soft); }
.shared-mark { margin-left: 0.4rem; font-family: var(--font-greek); font-size: 0.85rem; color: var(--gilt-ink); }
[lang="he"] { font-family: var(--font-hebrew); }
.lemma[lang="he"] { font-size: 2.1rem; }
.interlinear .gk[lang="he"] { font-family: var(--font-hebrew); font-size: 1.3rem; }
.interlinear[dir="rtl"] button { align-items: flex-end; text-align: right; }
.chip-mark-hebrew { font-family: var(--font-hebrew); font-size: 1rem; color: var(--gilt-ink); }
.facts .parts { display: flex; flex-wrap: wrap; gap: 0.15rem 0.7rem; }
.part [lang="he"] { font-size: 1.15rem; }
.part small { display: block; font-size: 0.72rem; color: var(--ink-faint); }
.part.is-root [lang="he"] { font-weight: 600; }
.part.is-this { background: var(--gilt-soft); border-radius: 4px; padding: 0 0.25em; }
.part.is-this [lang="he"] { font-weight: 700; }

/* ------------------------------------------------------------------ *
 * The study panel: search and what lies behind each result
 * ------------------------------------------------------------------ */
.drawer-wide { width: min(38rem, 100%); }
#study .drawer-head h2 { flex: 1; }
.search-form { display: flex; gap: 0.5rem; }
.search-form input {
    flex: 1; min-width: 0; padding: 0.6rem 0.8rem; border: 1px solid var(--rule); border-radius: 8px;
    background: var(--paper-raised); color: var(--ink); font: inherit; font-size: 1rem;
}
.search-form select { max-width: 11rem; }
.study-view { display: grid; gap: 1.5rem; align-content: start; }
.study-view[aria-busy="true"] { opacity: 0.6; }
.study-note { margin: 0; font-size: 0.85rem; color: var(--ink-faint); }
.study-credit { margin: 0; font-size: 0.75rem; color: var(--ink-faint); }
.study-section { display: grid; gap: 0.6rem; }
.study-section h3, .section-head h3 { margin: 0; font-family: var(--font-ui); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); }
.study-section h3 span, .study-section h3 small { font-weight: 400; letter-spacing: 0; text-transform: none; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.study-head { display: grid; gap: 0.3rem; }
.study-head p { margin: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip span { color: var(--ink-faint); font-size: 0.8em; }
.chip.is-on { background: var(--gilt-soft); border-color: var(--gilt); color: var(--ink); }
.result-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.3rem; }
.result {
    width: 100%; display: grid; gap: 0.1rem; padding: 0.55rem 0.7rem; text-align: left;
    border: 1px solid var(--rule); border-radius: 8px; background: var(--paper-raised); color: var(--ink); cursor: pointer; font: inherit;
}
.result:hover { border-color: var(--ink-faint); }
.result strong { font-weight: 600; }
.result strong.gk { font-family: var(--font-greek); font-size: 1.15rem; font-weight: 400; }
.result em { color: var(--ink-faint); font-size: 0.85rem; }
.result span { font-size: 0.88rem; color: var(--ink-soft); }
.result small { font-size: 0.75rem; color: var(--ink-faint); }
.hits { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.8rem; }
.hit { display: grid; gap: 0.15rem; }
.hit-ref {
    justify-self: start; padding: 0; border: 0; background: none; cursor: pointer;
    font-family: var(--font-ui); font-size: 0.8rem; font-weight: 600; color: var(--gilt-ink);
}
.hit-ref:hover { text-decoration: underline; }
.hit-text { font-family: var(--font-text); font-size: 0.95rem; line-height: 1.55; color: var(--ink); }
.hit-text sup { font-size: 0.65em; color: var(--gilt-ink); }
.hit-text mark { background: var(--gilt-soft); color: inherit; border-radius: 2px; padding: 0 0.05em; }
.hit-text mark.hl-maybe { background: none; text-decoration: underline dashed var(--gilt); text-underline-offset: 0.2em; }
.hit-book { margin: 0.4rem 0 0; font-family: var(--font-display); font-size: 1.15rem; font-weight: 400; }
.hit-book span { font-family: var(--font-ui); font-size: 0.75rem; color: var(--ink-faint); }
.shared { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; font-size: 0.78rem; color: var(--ink-faint); }
.shared .chip { min-height: 1.6rem; padding: 0 0.5rem; font-size: 0.78rem; }
.more { justify-self: start; }
.family { display: grid; grid-template-columns: auto 1fr; gap: 0.4rem 0.9rem; margin: 0; }
.family dt { font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-faint); padding-top: 0.4rem; }
.family dd { margin: 0; }
.topic-lines { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.5rem; }
.topic-lines li { padding-left: calc(var(--depth, 0) * 1.1rem); display: grid; gap: 0.25rem; font-size: 0.92rem; }
.topic-label { color: var(--ink); }
.ref-row { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; font-size: 0.8rem; color: var(--ink-faint); }
.ref-chip {
    padding: 0.1rem 0.45rem; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper-raised);
    font: inherit; font-family: var(--font-ui); font-size: 0.78rem; color: var(--ink-soft); cursor: pointer;
}
.ref-chip:hover { border-color: var(--ink-faint); color: var(--ink); }
.study-home { display: grid; gap: 0.8rem; }
@media (max-width: 760px) {
    .search-form { flex-wrap: wrap; }
    .search-form select { max-width: none; flex: 1; }
}
