/* Study view: a verse or range with commentary (modules/study.js).
   Mobile first. One <dialog> fills the screen:
     phone:  bar / scripture strip / source panes (swipe) / source rail (thumb zone)
     >=960:  bar across; scripture column left; rail + two panes side by side right
   Colors come from the app theme tokens (light, dark, parchment). */

/* Declared on body, not :root: tokens that reference theme tokens must resolve
   where .dark / .parchment (set on body) apply. */
body {
    /* Commentary gets its own book face, so the commentator's voice reads apart
       from the Scripture text (which keeps --font-verse). System fonts only. */
    --study-font: 'Iowan Old Style', 'Charter', 'Bitstream Charter', 'Sitka Text',
        'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
    --study-focus-bg: #fdf0c4;
    --study-focus-rule: #a96a12;
    --study-link: var(--color-primary);
    --study-meta: var(--color-text-secondary);
    --study-rail-h: 60px;
}
.dark {
    --study-focus-bg: rgba(234, 179, 8, 0.14);
    --study-focus-rule: #e3a83a;
    --study-link: #93b4fd;
}
.parchment {
    --study-focus-bg: #efdca0;
    --study-focus-rule: #7f5b06;
    --study-link: #7a5600;
}

html.study-open { overflow: hidden; }

/* ---------- the dialog ---------- */
dialog.study-view {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    background: var(--color-bg);
    color: var(--color-text);
    overflow: hidden;
}
dialog.study-view::backdrop { background: var(--color-bg); }

.study-shell {
    display: grid;
    height: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "bar" "text" "track" "rail";
}

.study-icon-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--color-text);
    cursor: pointer;
}
.study-icon-btn:hover:not(:disabled) { background: var(--color-surface-hover); }
.study-icon-btn:disabled { opacity: 0.35; cursor: default; }

.study-view :focus-visible,
.study-sheet :focus-visible {
    outline: 2px solid var(--study-link);
    outline-offset: 2px;
}

/* ---------- bar ---------- */
.study-bar {
    grid-area: bar;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: calc(4px + env(safe-area-inset-top)) 6px 4px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}
.study-bar-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.study-bar-title h2 {
    font-family: var(--font-verse);
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.study-bar-title h2:focus { outline: none; }
.study-back {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: -4px;
    padding: 2px 4px;
    border: 0;
    background: none;
    color: var(--study-link);
    font: 500 0.8rem var(--font-sans);
    cursor: pointer;
}
.study-steps { display: flex; }

/* ---------- scripture strip ---------- */
.study-text {
    grid-area: text;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.study-text-body {
    max-height: 30vh;
    max-height: 30dvh;
    overflow-y: auto;
    padding: 10px 18px 6px;
    overscroll-behavior: contain;
}
.study-verses {
    font-family: var(--font-verse);
    font-size: 1.08rem;
    line-height: 1.6;
    color: var(--color-text);
}
.study-verse sup {
    font-family: var(--font-sans);
    font-size: 0.68em;
    font-weight: 600;
    color: var(--color-verse-num);
    margin-right: 0.2em;
}
.study-text-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.study-extend,
.study-collapse,
.study-text-btn {
    min-height: 40px;
    padding: 6px 2px;
    border: 0;
    background: none;
    color: var(--study-link);
    font: 500 0.85rem var(--font-sans);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
}
.study-extend::before { content: "+"; font-weight: 600; }
.study-collapse { margin-left: auto; color: var(--study-meta); }
.study-text-peek {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    padding: 6px 14px 6px 18px;
    border: 0;
    background: none;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
}
.study-text-peek-line {
    flex: 1;
    min-width: 0;
    font-family: var(--font-verse);
    font-size: 0.98rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- source rail ---------- */
.study-rail {
    grid-area: rail;
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: var(--study-rail-h);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)) 2px;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
}
.study-chips {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    /* Room at both ends, so the first and last chips can sit clear of the fades below
       (study.js keeps the active chip CHIP_MARGIN from either edge) */
    padding: 2px 12px 2px 8px;
    /* A chip cut by the edge fades out instead of ending hard against All */
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 6px, #000 calc(100% - 10px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 6px, #000 calc(100% - 10px), transparent 100%);
}
.study-chips::-webkit-scrollbar { display: none; }
.study-chip {
    flex: none;
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    min-height: 44px;
    padding: 0 14px;
    align-items: center;
    border: 1.5px solid var(--color-border);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text);
    font: 600 0.9rem var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
}
.study-chip-scope {
    font-weight: 500;
    font-size: 0.78rem;
    color: var(--study-meta);
    font-variant-numeric: tabular-nums;
}
.study-chip[aria-pressed="true"] {
    background: var(--color-text);
    border-color: var(--color-text);
    color: var(--color-surface);
}
.study-chip[aria-pressed="true"] .study-chip-scope { color: inherit; opacity: 0.8; }
.study-chips-none {
    flex: none;
    padding: 0 8px;
    font: 500 0.8rem var(--font-sans);
    color: var(--study-meta);
    white-space: nowrap;
}
/* Chips and All share the space left of the tools; All never scrolls away */
.study-sources {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}
.study-all-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 44px;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-radius: 999px;
    background: var(--color-bg-secondary);
    color: var(--color-text);
    font: 600 0.85rem var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
}
.study-all-count { font-weight: 500; color: var(--study-meta); font-variant-numeric: tabular-nums; }
.study-all-btn:hover { background: var(--color-surface-hover); }
.study-swap {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 44px;
    padding: 0 10px;
    border: 0;
    border-right: 1px solid var(--color-border);
    border-radius: 0;
    background: none;
    color: var(--study-link);
    font: 600 0.85rem var(--font-sans);
    cursor: pointer;
}

/* Cross-references and Notes: pinned at the thumb end of the rail, after a rule.
   Commentary chips are voices (a pill with a name); these are Scripture's own links and
   the reader's own writing, so they look like tabs: icon and count over a short label. */
.study-tools {
    flex: none;
    display: flex;
    gap: 4px;
    padding-left: 6px;
    margin-left: 2px;
    border-left: 1px solid var(--color-border);
}
.study-tool {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 54px;
    min-height: 48px;
    padding: 3px 6px;
    border: 0;
    border-radius: 10px;
    background: var(--color-bg-secondary);
    color: var(--color-text);
    cursor: pointer;
    font-family: var(--font-sans);
}
.study-tool-top { display: inline-flex; align-items: center; gap: 4px; min-height: 18px; }
.study-tool-count { font: 700 0.82rem var(--font-sans); font-variant-numeric: tabular-nums; }
.study-tool-label { font: 500 0.72rem/1.1 var(--font-sans); color: var(--color-text-secondary); white-space: nowrap; }
.study-tool[aria-pressed="true"] { background: var(--color-text); color: var(--color-surface); }
.study-tool[aria-pressed="true"] .study-tool-label { color: inherit; }
.study-tool:hover:not([aria-pressed="true"]) { background: var(--color-surface-hover); }

/* Phones: commentary is the main use, so the tools give it room. Each tool keeps its icon
   and count (its name is in aria-label and its pane's title); the short label goes. With
   tighter chip padding this shows two whole commentary chips at 360px instead of one. */
@media (max-width: 480px) {
    .study-tools { gap: 2px; padding-left: 4px; margin-left: 0; }
    .study-tool { min-width: 38px; padding: 3px 4px; }
    .study-tool-top { flex-direction: column; gap: 1px; }
    .study-tool-count { font-size: 0.75rem; line-height: 1; min-height: 0.75rem; }
    .study-tool-label {
        position: absolute; width: 1px; height: 1px; overflow: hidden;
        clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
    }
    .study-chip { padding: 0 12px; gap: 5px; }
    .study-chips { gap: 5px; }
    /* The swap button is its icon (its aria-label names the source): the chips need the room */
    .study-swap { min-width: 44px; justify-content: center; padding: 0 8px; }
    .study-swap-name {
        position: absolute; width: 1px; height: 1px; overflow: hidden;
        clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
    }
    /* All stacks its count under the word, like the tools beside it */
    .study-all-btn {
        flex-direction: column;
        gap: 0;
        width: 44px;
        min-height: 48px;
        padding: 0;
        border-radius: 10px;
        line-height: 1.1;
    }
    .study-all-count { font-size: 0.75rem; }
}
@media (max-width: 380px) {
    .study-chip { padding: 0 10px; gap: 4px; }
    .study-chip-scope { font-size: 0.74rem; }
    .study-chips { gap: 4px; padding-left: 6px; }
    .study-sources { gap: 2px; }
}

/* ---------- panes (scroll-snap carousel: swipe between sources) ---------- */
.study-track {
    grid-area: track;
    position: relative;
    display: flex;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
}
.study-track::-webkit-scrollbar { display: none; }
.study-pane {
    flex: 0 0 100%;
    min-width: 0;
    height: 100%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
}
.study-pane-scroll {
    position: relative; /* offsetParent for jumping to marked paragraphs */
    height: 100%;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding: 0 0 48px;
}
.study-pane-scroll:focus { outline: none; }
.study-pane-scroll:focus-visible { outline: 2px solid var(--study-link); outline-offset: -2px; }

.study-pane-head {
    padding: 14px 20px 4px;
    max-width: 40rem;
    margin: 0 auto;
}
.study-who {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    column-gap: 10px;
    width: 100%;
    padding: 4px 0;
    border: 0;
    background: none;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
}
.study-who-name {
    font-family: var(--study-font);
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1.25;
}
.study-who-meta {
    grid-column: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0 12px;
    font: 0.82rem var(--font-sans);
    color: var(--study-meta);
}
.study-who-i { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--study-meta); }
.study-note {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--color-bg-secondary);
    font: 0.85rem/1.45 var(--font-sans);
    color: var(--color-text-secondary);
}
.study-note-btn {
    display: inline;
    margin-left: 4px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--study-link);
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    min-height: 32px;
}

/* ---------- commentary typography ---------- */
.study-pane-body {
    max-width: 40rem;
    margin: 0 auto;
    padding: 0 20px;
    font-family: var(--study-font);
    font-size: 1.0625rem;
    line-height: 1.7;
    color: var(--color-text);
    hyphens: auto;
    -webkit-hyphens: auto;
    overflow-wrap: break-word;
}
.study-entry + .study-entry { margin-top: 1.4em; }
.study-entry-range {
    margin: 1.2em 0 0.4em;
    font: 600 0.8rem var(--font-sans);
    color: var(--study-meta);
}
.study-entry p { margin: 0 0 0.75em; }
.study-lemma { font-style: italic; }

/* Outline markers (I. / 1. / (1.) / [1.] ...) hang in the margin, so a long
   sermon-style exposition reads as the outline it is. Indents are capped for phones. */
.study-entry p.lvl { --indent: 0rem; padding-left: calc(var(--indent) + 1.9em); text-indent: -1.9em; }
.study-entry p.lvl-2 { --indent: 0.7rem; }
.study-entry p.lvl-3 { --indent: 1.4rem; }
.study-entry p.lvl-4 { --indent: 2rem; }
.study-entry p.lvl-5, .study-entry p.lvl-6, .study-entry p.lvl-7 { --indent: 2.4rem; }
.study-mark {
    display: inline-block;
    min-width: 2.32em; /* = 1.9em of the paragraph at 0.82em */
    text-indent: 0;
    font-family: var(--font-sans);
    font-size: 0.82em;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--study-meta);
}
.study-entry p.lvl-1 .study-mark { color: var(--color-text); }

/* Verse markers inside a passage note (Calvin "16.", Catena "Ver. 16.", "Verse 16."):
   the number moves into the margin like a verse number in the text */
.study-entry p.has-vmark { position: relative; }
.study-vmark {
    float: left;
    margin: 0.32em 0.45em 0 0;
    padding: 0 0.35em;
    border-radius: 4px;
    background: var(--color-bg-secondary);
    font: 700 0.72em/1.5 var(--font-sans);
    font-variant-numeric: tabular-nums;
    color: var(--color-text-secondary);
}
.study-entry p.study-headword {
    font-style: italic;
    font-weight: 600;
    margin-bottom: 0.3em;
}

/* Long notes: a jump list of their parts */
.study-toc {
    margin: 0 0 1em;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font: 0.86rem/1.4 var(--font-sans);
}
.study-toc summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    cursor: pointer;
    color: var(--study-link);
    font-weight: 600;
}
.study-toc ol { list-style: none; margin: 0; padding: 0 4px 6px; max-height: 40dvh; overflow-y: auto; }
.study-toc button {
    display: block;
    width: 100%;
    min-height: 40px;
    padding: 6px 8px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.study-toc button:hover { background: var(--color-surface-hover); }
.study-toc b { font-variant-numeric: tabular-nums; margin-right: 0.4em; }

/* A source's wider entries (whole-psalm overview, passage note) after its verse notes */
.study-more {
    margin-top: 1.4em;
    border-top: 1px solid var(--color-border);
}
.study-more > summary {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font: 600 0.92rem var(--font-sans);
    color: var(--study-link);
    list-style: none;
}
.study-more > summary::-webkit-details-marker { display: none; }
.study-more > summary { padding: 8px 0; }
.study-more-hint {
    display: block;
    font: 400 0.8rem/1.35 var(--font-sans);
    color: var(--study-meta);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 96px);
}
.study-more > summary::before { content: "+"; font-size: 1.1em; width: 1em; text-align: center; }
.study-more[open] > summary::before { content: "\2212"; }

/* Credit a license requires, shown with the text (not only in the info sheet) */
.study-credit {
    margin-top: 6px;
    font: 0.78rem/1.4 var(--font-sans);
    color: var(--study-meta);
}

/* The paragraphs about the selected verses, inside a wider passage/chapter note */
.study-entry p.is-focus {
    background: var(--study-focus-bg);
    box-shadow: -10px 0 0 var(--study-focus-bg), -13px 0 0 var(--study-focus-rule),
        10px 0 0 var(--study-focus-bg);
    border-radius: 1px;
}

.study-pane-body a.commentary-ref {
    color: var(--study-link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    white-space: nowrap;
    padding: 2px 0;
}

.study-attribution {
    max-width: 40rem;
    margin: 1.5em auto 0;
    padding: 10px 20px 0;
    border-top: 1px solid var(--color-border);
    font: 0.78rem var(--font-sans);
    color: var(--study-meta);
}

.study-pane-state,
.study-empty {
    display: grid;
    place-items: center;
    gap: 10px;
    padding: 40px 24px;
    text-align: center;
    color: var(--color-text-secondary);
    font: 0.92rem/1.5 var(--font-sans);
}
.study-empty { flex: 0 0 100%; align-content: center; }
.study-empty-title { font: 600 1.05rem var(--font-verse); color: var(--color-text); }

/* ---------- Cross-references and Notes panes ---------- */
.study-tool-title {
    font-family: var(--study-font);
    font-size: 1.3rem;
    font-weight: 600;
    line-height: 1.25;
}
.study-tool-sub {
    margin-top: 2px;
    font: 0.86rem/1.45 var(--font-sans);
    color: var(--study-meta);
}
.xref-order {
    display: inline-flex;
    margin-top: 10px;
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 2px;
}
.xref-order button {
    min-height: 36px;
    padding: 0 14px;
    border: 0;
    border-radius: 999px;
    background: none;
    color: var(--color-text-secondary);
    font: 600 0.82rem var(--font-sans);
    cursor: pointer;
}
.xref-order button[aria-pressed="true"] { background: var(--color-text); color: var(--color-surface); }
.xref-body, .snotes {
    max-width: 40rem;
    margin: 0 auto;
    padding: 0 20px;
}
.xref-group + .xref-group { margin-top: 0.6em; }
.xref-list { list-style: none; margin: 0; padding: 0; }
.xref-list li + li { border-top: 1px solid var(--color-border); }
.xref-item {
    display: block;
    width: 100%;
    padding: 12px 0;
    border: 0;
    background: none;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
}
.xref-item:hover .xref-ref { text-decoration: underline; }
.xref-ref {
    display: block;
    font: 600 0.86rem var(--font-sans);
    color: var(--study-link);
}
.xref-text {
    display: block;
    margin-top: 2px;
    font-family: var(--font-verse);
    font-size: 1.04rem;
    line-height: 1.55;
}
.xref-more {
    width: 100%;
    min-height: 48px;
    margin-top: 8px;
    border: 1.5px solid var(--color-border);
    border-radius: 999px;
    background: none;
    color: var(--color-text);
    font: 600 0.92rem var(--font-sans);
    cursor: pointer;
}
.xref-ptc {
    display: grid;
    gap: 0;
    margin-top: 20px;
    padding-top: 6px;
    border-top: 1px solid var(--color-border);
}
.xref-ptc .study-text-btn { justify-self: start; }
.xref-ptc-hint { font: 0.8rem/1.4 var(--font-sans); color: var(--study-meta); }
#study-peek .study-verse.is-context { color: var(--color-text-secondary); }

.snote {
    padding: 4px 0 4px 14px;
    border-left: 3px solid var(--study-focus-rule);
    margin-bottom: 16px;
}
.snote-text {
    font-family: var(--study-font);
    font-size: 1.0625rem;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}
.snote.is-nearby { border-left-color: var(--color-border); }
.snote-ref {
    min-height: 32px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--study-link);
    font: 600 0.86rem var(--font-sans);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.snote-actions { display: flex; align-items: center; gap: 4px 16px; flex-wrap: wrap; }
.snote-date { font: 0.8rem var(--font-sans); color: var(--study-meta); margin-right: auto; }
.snote-form { display: grid; gap: 8px; margin-bottom: 16px; }
.snote-form textarea {
    width: 100%;
    min-height: 7.5em;
    padding: 10px 12px;
    border: 1.5px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--study-font);
    font-size: 1.0625rem;   /* 16px+ so iOS doesn't zoom on focus */
    line-height: 1.55;
    resize: vertical;
}
.snote-form textarea:focus { border-color: var(--study-link); outline: none; }
.snote-form .study-primary-btn:disabled { opacity: 0.45; cursor: default; }
.snote-add { margin-bottom: 12px; }
.snotes-nearby { margin-top: 8px; }
.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;
}

/* Writing on a phone: the dialog follows the visible area above the keyboard
   (study_panes.js sets the variables), the rail folds and the verses stay, shorter. */
@media (max-width: 959px) {
    dialog.study-view { top: var(--study-vvtop, 0px); height: var(--study-vvh, 100dvh); }
    .study-view.is-writing .study-rail,
    .study-view.is-writing .study-extend,
    .study-view.is-writing .study-collapse,
    .study-view.is-writing .study-tool-sub,
    .study-view.is-writing .snotes-nearby { display: none !important; }
    .study-view.is-writing .study-text-body { max-height: calc(var(--study-vvh, 100dvh) * 0.26); padding-top: 6px; }
    .study-view.is-writing .study-verses { font-size: 0.98rem; line-height: 1.5; }
    .study-view.is-writing .study-pane-head { padding-top: 8px; }
    .study-view.is-writing .snote-form textarea { min-height: 5.5em; }
}

/* ---------- sheets: source info, reference peek, manage sources ---------- */
dialog.study-sheet {
    width: 100%;
    max-width: 100%;
    max-height: 85dvh;
    margin: auto 0 0;
    padding: 0;
    border: 0;
    border-radius: 16px 16px 0 0;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
}
dialog.study-sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog.study-sheet[open] { animation: study-sheet-in 0.18s ease-out; }
@keyframes study-sheet-in { from { transform: translateY(24px); opacity: 0; } }
.study-sheet-inner {
    padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
    font: 0.95rem/1.55 var(--font-sans);
}
.study-sheet-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 -10px 4px 0;
}
.study-sheet-head h3 {
    flex: 1;
    font: 600 1.2rem/1.3 var(--study-font);
}
.study-sheet-inner > p { margin: 0 0 10px; }
.study-sheet-hint { color: var(--color-text-secondary); }
.study-info-who { color: var(--color-text-secondary); }
.study-info-who { display: flex; flex-wrap: wrap; gap: 0 12px; }
.study-info-trad { flex-basis: 100%; }
.study-info-facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 14px;
    margin: 12px 0;
    font-size: 0.88rem;
}
.study-info-facts > div { display: contents; }
.study-info-facts dt { color: var(--color-text-secondary); }
.study-info-here {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border);
}
.study-info-here p { margin-bottom: 10px; }
.study-sheet-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin-top: 14px;
}
.study-primary-btn {
    min-height: 44px;
    padding: 0 18px;
    border: 0;
    border-radius: 999px;
    background: var(--color-text);
    color: var(--color-surface);
    font: 600 0.92rem var(--font-sans);
    cursor: pointer;
}
.study-peek-error { color: var(--color-text-secondary); }
#study-peek .study-verses { max-height: 40dvh; overflow-y: auto; }

/* All: every enabled source and what it has on the selection */
.study-all-list { list-style: none; margin: 0 -8px; padding: 0; max-height: 62dvh; overflow-y: auto; overscroll-behavior: contain; }
.study-all-list li + li { border-top: 1px solid var(--color-border); }
.study-all-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    width: 100%;
    min-height: 44px;
    padding: 10px 8px;
    border: 0;
    border-radius: 10px;
    background: none;
    color: var(--color-text);
    font: inherit;
    text-align: left;
}
button.study-all-item { cursor: pointer; }
button.study-all-item:hover { background: var(--color-surface-hover); }
.study-all-item[aria-current="true"] { background: var(--color-bg-secondary); box-shadow: inset 3px 0 0 var(--color-text); }
.study-all-top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; width: 100%; }
.study-all-short { font: 650 1rem var(--font-sans); }
.study-all-scope { font-size: 0.85rem; color: var(--study-meta); font-variant-numeric: tabular-nums; }
.study-all-here { margin-left: auto; font: 600 0.75rem var(--font-sans); text-transform: uppercase; letter-spacing: 0.04em; }
.study-all-name { font: 0.92rem/1.35 var(--study-font); }
.study-all-trad { font-size: 0.8rem; color: var(--study-meta); }
.study-all-list li.is-empty .study-all-short,
.study-all-list li.is-empty .study-all-name { color: var(--study-meta); }
.study-all-nearest { min-height: 44px; margin: 2px 0 -8px; padding: 0; }
.study-all-choose { min-height: 44px; }

/* Settings > Commentaries: switch and up/down for each source (index.html, modules/study.js) */
.cm-list { list-style: none; margin: 8px 0 0; padding: 0; }
.cm-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border);
}
.cm-name { font-weight: 600; color: var(--color-text); }
.cm-meta { font-size: 0.8rem; color: var(--color-text-secondary); }
.cm-desc {
    margin-top: 2px;
    font-size: 0.82rem;
    line-height: 1.4;
    color: var(--color-text-secondary);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}
.cm-row.is-off .cm-name, .cm-row.is-off .cm-meta, .cm-row.is-off .cm-desc { opacity: 0.55; }
.cm-controls { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
/* The app's switch is 44x24; the label gives it a 44px-tall target */
.cm-switch.toggle-switch { margin: 0; height: 44px; width: 52px; }
.cm-switch .toggle-slider { top: 10px; bottom: 10px; left: 4px; right: 4px; }
.cm-switch input:focus-visible + .toggle-slider { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.cm-switch input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
.cm-move { display: flex; gap: 2px; }
.cm-move-btn {
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
}
.cm-move-btn:hover:not(:disabled) { background: var(--color-surface-hover); }
.cm-move-btn:disabled { opacity: 0.3; cursor: default; }
.cm-move-btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.cm-rule { margin-top: 12px; }
.cm-reset { margin-top: 4px; min-height: 44px; }

/* ---------- entry points in the reader ---------- */
.action-bar-study, .action-bar-xrefs { position: relative; }
.action-bar-count {
    position: absolute;
    top: 2px;
    right: 50%;
    transform: translateX(18px);
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--color-text);
    color: var(--color-surface);
    font: 700 0.68rem/17px var(--font-sans);
    text-align: center;
}
@media (min-width: 601px) {
    /* Wide bar: icon, label, then the count beside it */
    .action-bar-count { position: static; transform: none; order: 3; }
}


/* ---------- Settings: commentary download list ---------- */
.download-hint { margin: 0 0 6px; font-size: 0.8rem; color: var(--color-text-secondary); }
.download-option .download-size {
    margin-left: auto;
    padding-left: 12px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------- wide screens: text column + two sources side by side ---------- */
/* ---------- hymns pane (modules/hymns.js) ---------- */
.hymn-group + .hymn-group { margin-top: 1.25em; }
.hymn-list { list-style: none; margin: 0; padding: 0; }
.hymn-list li + li { border-top: 1px solid var(--color-border); }
.hymn-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    padding: 12px 0;
    border: 0;
    background: none;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
}
.hymn-title { font-family: var(--study-font); font-size: 1.12rem; font-weight: 600; line-height: 1.3; }
.hymn-item:hover .hymn-title { text-decoration: underline; text-underline-offset: 3px; }
.hymn-sub { font: 0.8rem var(--font-sans); color: var(--study-meta); }
.hymn-first { font-family: var(--font-verse); font-style: italic; font-size: 1rem; line-height: 1.45; }
.hymn-first::before { content: '“'; }
.hymn-first::after { content: '”'; }
.hymn-who, .hymn-tune { font: 0.84rem/1.4 var(--font-sans); color: var(--study-meta); }
.hymn-why { margin-top: 4px; font: 0.84rem/1.45 var(--font-sans); color: var(--color-text); }
.hymn-why.is-computed { padding: 4px 8px; border-radius: 6px; background: var(--ws-computed-bg); }
.hymn-why .ws-computed { margin: 0 0.3rem 0 0; vertical-align: 0.05em; }
.hymn-evidence { font-family: var(--font-verse); font-style: italic; }
.hymn-credits p + p { margin-top: 0.4em; }
.hymn-sheet .hymn-sub { margin: -4px 0 6px; }
.hymn-sheet .hymn-first { display: block; margin: 0 0 10px; }
.hymn-facts { margin-bottom: 12px; }
.hymn-sheet-h { margin: 6px 0 2px; font: 600 0.95rem var(--font-sans); }
.hymn-passages { list-style: none; margin: 0 0 10px; padding: 0; }
.hymn-passages li + li { border-top: 1px solid var(--color-border); }
.hymn-passage {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    min-height: 48px;
    padding: 10px 0;
    border: 0;
    background: none;
    color: var(--color-text);
    text-align: left;
    cursor: pointer;
}
.hymn-passage-ref { font: 600 0.92rem var(--font-sans); color: var(--study-link); }
.hymn-also { font: 0.84rem/1.45 var(--font-sans); color: var(--study-meta); margin: 0 0 8px; }

@media (min-width: 960px) {
    .study-shell {
        grid-template-columns: minmax(280px, 26rem) minmax(0, 1fr);
        grid-template-rows: auto auto minmax(0, 1fr);
        grid-template-areas: "bar bar" "text rail" "text track";
    }
    .study-bar { padding-inline: 12px; }
    .study-text {
        border-bottom: 0;
        border-right: 1px solid var(--color-border);
        overflow-y: auto;
    }
    .study-text-body { max-height: none; padding: 20px 24px; overflow: visible; }
    .study-verses { font-size: 1.15rem; line-height: 1.75; }
    .study-text-peek, .study-collapse { display: none !important; }
    .study-view.is-strip-collapsed .study-text-body { display: block !important; }
    .study-rail {
        border-top: 0;
        border-bottom: 1px solid var(--color-border);
        padding-bottom: 6px;
        background: var(--color-bg);
    }
    .study-pane { flex-basis: 50%; }
    .study-pane + .study-pane { border-left: 1px solid var(--color-border); }
    .study-empty { flex-basis: 50%; }
    .study-pane-head, .study-pane-body, .study-attribution, .xref-body, .snotes { padding-inline: 28px; }
    .study-pane.is-active .study-who-name { text-decoration: underline; text-decoration-color: var(--color-text); text-decoration-thickness: 2px; text-underline-offset: 5px; }
    dialog.study-sheet {
        max-width: 32rem;
        margin: auto;
        border-radius: 14px;
    }
}

@media (prefers-reduced-motion: reduce) {
    dialog.study-sheet[open] { animation: none; }
    .study-track, .study-chips { scroll-behavior: auto; }
}
.hymn-sheet .study-attribution { padding-inline: 0; }

/* Similar verses under the cross-references: computed, so set apart by a rule and a mark */
.similar { max-width: 40rem; margin: 20px auto 8px; padding: 16px 20px 0; border-top: 1px solid var(--color-border); }
.similar-title { display: flex; align-items: baseline; gap: 8px; margin: 0 0 4px; font: 650 1rem var(--font-sans); }
.similar-mark { font: 700 1.25rem/1 var(--font-verse); color: var(--srch-mark, var(--color-accent)); }
.similar .study-tool-sub { padding: 0; }
.similar-load { margin-top: 4px; }
@media (min-width: 960px) { .similar { padding-inline: 28px; } }
