/* Navigation: the running-head title, the passage picker (sheet on phones, panel on
   wide screens, inline on Home), the way-back chip, and the weak word-link state.
   modules/nav.js, modules/wordlink.js. Colors come from the theme tokens
   (light, dark, parchment), declared on body where .dark/.parchment apply. */

body {
    --nav-current-bg: var(--color-primary);
    --nav-current-fg: #ffffff;
    --nav-chip-bg: var(--color-primary-bg);
    --nav-chip-rule: var(--color-primary);
    --nav-sheet-radius: 16px;
}
.dark {
    --nav-chip-bg: rgba(147, 180, 253, 0.12);
    --nav-chip-rule: #93b4fd;
}
.parchment {
    /* the gold primary is too light for white text: use the deep ochre */
    --nav-current-bg: #7f5b06;
    --nav-current-fg: #fffaf0;
    --nav-chip-bg: #efdca0;
    --nav-chip-rule: #7f5b06;
}

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

/* ---------- the running head (header) ---------- */
.header-center { gap: 0.5rem; align-items: center; }
.nav-title {
    display: inline-flex;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    cursor: pointer;
    font: inherit;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}
.nav-title:hover { border-color: var(--color-primary); }
.nav-title-ref {
    font-family: var(--font-verse);
    font-size: 1.1875rem;
    font-weight: 700;
    letter-spacing: -0.005em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.nav-title-tr {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    font-variant-numeric: lining-nums;
}
.nav-title-chev { align-self: center; flex: none; color: var(--color-text-secondary); }

/* The passage heading is the quick way to another chapter of the same book */
.passage-title { margin: 0; min-width: 0; }
.passage-title-btn {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0.25rem 0;
    min-height: 44px;
    cursor: pointer;
    text-align: left;
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 0.2em;
    transition: text-decoration-color var(--transition-fast);
}
.passage-title-btn:hover { text-decoration-color: currentColor; }
.passage-title-btn::after {
    content: "";
    display: inline-block;
    width: 0.4em; height: 0.4em;
    margin-left: 0.45em;
    border-right: 2px solid var(--color-text-secondary);
    border-bottom: 2px solid var(--color-text-secondary);
    transform: translateY(-0.2em) rotate(45deg);
}

@media (max-width: 600px) {
    /* One header row: menu, where you are, search. Read aloud and immersive
       reading are in the menu on phones (P1-5). */
    .header { flex-wrap: nowrap; }
    .header-center { order: 0; width: auto; flex: 1 1 auto; min-width: 0; margin: 0; justify-content: flex-start; }
    .header-right { order: 0; margin-left: 0; }
    .nav-title { flex: 1 1 auto; justify-content: flex-start; }
    .nav-title-chev { margin-left: auto; }
    .header-tts, .header-immersive { display: none !important; }
}
@media (min-width: 601px) {
    .side-menu-tts, .side-menu-phone { display: none !important; }
}

/* ---------- the way back ---------- */
.return-chip {
    display: flex;
    align-items: stretch;
    gap: 0.25rem;
    margin: 0.5rem 0.75rem 0.375rem;
    border: 1px solid var(--nav-chip-rule);
    border-radius: 999px;
    background: var(--nav-chip-bg);
    animation: return-chip-in 180ms ease-out;
}
@keyframes return-chip-in {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: none; }
}
.return-chip button {
    font: inherit;
    color: var(--color-text);
    background: none;
    border: 0;
    min-height: 44px;
    cursor: pointer;
    border-radius: 999px;
}
.return-chip-back {
    flex: 1 1 auto;
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.5rem 0 0.875rem;
    text-align: left;
    font-size: 0.9375rem;
}
.return-chip-back > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.return-chip-back svg { flex: none; color: var(--nav-chip-rule); }
.return-chip-place { font-family: var(--font-verse); font-weight: 700; }
.return-chip-results {
    flex: none;
    padding: 0 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-left: 1px solid var(--color-border) !important;
    border-radius: 0 !important;
}
.return-chip-dismiss {
    flex: none;
    width: 44px;
    display: grid;
    place-items: center;
    color: var(--color-text-secondary) !important;
}
.return-chip button:hover { background: rgba(127, 127, 127, 0.1); }

/* ---------- end of a chapter: the next one, by name ---------- */
.chapter-end {
    display: flex;
    justify-content: flex-end;
    margin: 1.5rem 0 0.5rem;
}
.chapter-end-next {
    display: inline-grid;
    justify-items: end;
    gap: 0.1rem;
    min-height: 44px;
    padding: 0.5rem 1rem;
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    text-align: right;
}
.chapter-end-next:hover { border-color: var(--color-text-secondary); }
.chapter-end-hint { font: 500 0.78rem var(--font-sans); color: var(--color-text-secondary); }
.chapter-end-ref { font: 700 1.05rem var(--font-verse); }
.chapter-end-ref::after { content: " \203A"; }

/* ---------- phones: Scripture first, controls in thumb reach ----------
   Above the text there is only the app header (which hides while scrolling down).
   The passage header's controls move: previous/next chapter to the reading bar at
   the bottom, Original Language to the menu, Share to the selected verses' action
   bar. The reading bar and the action bar share one slot: never two bars. */
.reading-bar, .action-more-wrap { display: none; }
@media (max-width: 600px) {
    .panel-text > .panel-header { display: none; }
    /* The text runs to the bottom of the screen, under the bar; the last verse clears it */
    .main-content { padding-bottom: 0; }
    .panel-text { max-height: calc(100dvh - var(--header-h, 61px)); }
    body.reading-immersed .panel-text { max-height: 100dvh; }
    .panel-text .panel-body { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px)); }
    .panel-text.has-return .panel-body { padding-bottom: calc(10rem + env(safe-area-inset-bottom, 0px)); }
    .reading-bar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: var(--z-overlay-bar);
        display: flex;
        align-items: stretch;
        gap: 2px;
        padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px));
        border-top: 1px solid var(--color-border);
        background: var(--color-surface);
    }
    .reading-bar button {
        min-height: 48px;
        border: 0;
        border-radius: 0.625rem;
        background: none;
        color: var(--color-text);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .reading-bar button:active { background: var(--color-surface-hover); }
    .reading-bar-step {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 0.25rem;
        padding: 0 0.5rem;
        font: 600 0.95rem var(--font-verse);
    }
    .reading-bar-step > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .reading-bar-step svg { flex: none; color: var(--color-text-secondary); }
    .reading-bar-step.is-next { justify-content: flex-end; }
    .reading-bar-step:disabled { opacity: 0.35; cursor: default; }
    .reading-bar-tool {
        flex: none;
        position: relative;
        padding: 0 0.625rem;
        font: 500 0.85rem var(--font-sans);
        color: var(--color-text-secondary) !important;
    }
    .reading-bar-dot {
        position: absolute;
        top: 10px;
        right: 3px;
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: var(--nav-chip-rule);
    }

    /* The way back floats just above the bottom bar instead of pushing the text down */
    .return-chip {
        position: fixed;
        left: 0.75rem;
        right: 0.75rem;
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        z-index: var(--z-overlay-bar);
        margin: 0;
        background: linear-gradient(var(--nav-chip-bg), var(--nav-chip-bg)), var(--color-surface);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
    }
    .return-chip.above-actions { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }

    /* Copy and Memorize sit behind More on phones */
    .action-bar-wide { display: none !important; }
    .action-more-wrap { display: flex; position: relative; }
}
.action-more {
    position: absolute;
    right: 0;
    bottom: calc(100% + 10px);
    z-index: var(--z-dropdown);
    display: grid;
    min-width: 11rem;
    padding: 0.25rem;
    border: 1px solid var(--color-border);
    border-radius: 0.75rem;
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
}
.action-more button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 0 0.875rem;
    border: 0;
    border-radius: 0.5rem;
    background: none;
    color: var(--color-text);
    font: 500 0.95rem var(--font-sans);
    text-align: left;
    cursor: pointer;
}
.action-more button:hover { background: var(--color-surface-hover); }
.action-more-count { font-size: 0.8rem; font-weight: 700; color: var(--color-text-secondary); }

/* ---------- the picker ---------- */
dialog.picker-sheet {
    width: 100%;
    max-width: 640px;
    height: min(86dvh, 760px);
    max-height: none;
    margin: auto auto 0;
    padding: 0;
    border: 0;
    border-radius: var(--nav-sheet-radius) var(--nav-sheet-radius) 0 0;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
    overscroll-behavior: contain;
}
dialog.picker-sheet[open] {
    display: flex;
    flex-direction: column;
    animation: picker-up 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
dialog.picker-sheet::backdrop {
    background: rgba(15, 20, 30, 0.42);
    overflow: hidden;
    overscroll-behavior: contain;
}
@keyframes picker-up {
    from { transform: translateY(24px); opacity: 0.4; }
    to { transform: none; opacity: 1; }
}
@media (min-width: 701px) {
    dialog.picker-sheet {
        margin: 8vh auto auto;
        height: min(80vh, 720px);
        border-radius: var(--radius-lg);
        border: 1px solid var(--color-border);
    }
}
.picker-sheet-head {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 0.5rem 0.25rem 1rem;
}
.picker-grabber {
    position: absolute;
    top: 6px; left: 50%;
    width: 36px; height: 4px;
    margin-left: -18px;
    border-radius: 2px;
    background: var(--color-border);
}
@media (min-width: 701px) { .picker-grabber { display: none; } }
.picker-sheet-head h2 { font-size: 1rem; font-weight: 600; margin: 0; }
.picker-close {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    background: none; border: 0; border-radius: var(--radius);
    color: var(--color-text-secondary);
    cursor: pointer;
}
.picker-sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 1rem calc(1.25rem + env(safe-area-inset-bottom));
}

.picker { display: flex; flex-direction: column; gap: 0.75rem; }

.picker-type { position: relative; margin: 0; }
.picker-type-icon {
    position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%);
    color: var(--color-text-secondary); pointer-events: none;
}
.picker-input {
    width: 100%;
    height: 48px;
    padding: 0 0.875rem 0 2.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    font: inherit;
    font-size: 16px;   /* 16px or more: iOS doesn't zoom on focus */
}
.picker-input::placeholder { color: var(--color-text-secondary); opacity: 0.85; }
.picker-input:focus-visible { outline-offset: 0; }

.picker-go {
    min-height: 48px;
    padding: 0 1rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--nav-current-bg);
    color: var(--nav-current-fg);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}
.picker-go span { font-family: var(--font-verse); font-weight: 700; }
.picker-hint, .picker-empty {
    margin: 0;
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
}

.picker-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.picker-tabs, .picker-translation {
    display: inline-flex;
    padding: 3px;
    border-radius: var(--radius);
    background: var(--color-bg-secondary);
}
.picker-tabs button, .picker-translation button {
    min-height: 38px;
    padding: 0 0.875rem;
    border: 0;
    border-radius: calc(var(--radius) - 2px);
    background: none;
    color: var(--color-text-secondary);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}
.picker-translation button { padding: 0 0.625rem; font-size: 0.8125rem; }
.picker-tabs button[aria-pressed="true"],
.picker-translation button[aria-pressed="true"] {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
}

.picker-testament + .picker-testament { margin-top: 1rem; }
.picker h3 {
    margin: 0 0 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}
.picker-book-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}
@media (min-width: 520px) {
    .picker-book-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
.picker-book {
    min-height: 44px;
    padding: 0.375rem 0.375rem 0.375rem 0.625rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    box-shadow: inset 3px 0 0 var(--genre, var(--color-border));
    color: var(--color-text);
    font-family: var(--font-verse);
    font-size: 0.9375rem;
    line-height: 1.15;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
}
.picker-book:hover { border-color: var(--genre, var(--color-primary)); }
.picker-book.is-current,
.picker-chapter.is-current {
    background: var(--nav-current-bg);
    border-color: var(--nav-current-bg);
    color: var(--nav-current-fg);
    font-weight: 700;
}

.picker-chapters-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.picker-chapters-head h3 {
    margin: 0;
    font-family: var(--font-verse);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}
.picker-all-books {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    min-height: 44px;
    padding: 0 0.75rem 0 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
}
.picker-chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    gap: 6px;
}
.picker-chapter {
    height: 48px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-family: var(--font-verse);
    font-size: 1.0625rem;
    font-variant-numeric: lining-nums tabular-nums;
    cursor: pointer;
}
.picker-chapter:hover { border-color: var(--color-primary); }

.picker-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.picker-list li + li { border-top: 1px solid var(--color-border); }
.picker-list button {
    width: 100%;
    min-height: 52px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.125rem;
    padding: 0.375rem 0.25rem;
    border: 0;
    background: none;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.picker-list-ref { font-family: var(--font-verse); font-weight: 700; font-size: 1.0625rem; }
.picker-list-meta {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

/* ---------- Home ---------- */
.home { max-width: 720px; margin: 0 auto; padding: 0.5rem 0 2rem; }
.home-title {
    margin: 0.25rem 0 1rem;
    font-family: var(--font-verse);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.25;
}
.home-continue {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.125rem;
    margin-bottom: 1.25rem;
    padding: 0.875rem 1rem;
    border: 1px solid var(--nav-chip-rule);
    border-radius: var(--radius-lg);
    background: var(--nav-chip-bg);
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.home-continue-label { font-size: 0.875rem; color: var(--color-text-secondary); }
.home-continue-ref { font-family: var(--font-verse); font-size: 1.25rem; font-weight: 700; }

/* Nothing to study on Home: no empty sheet on phones (P2-5), and the page gets the room */
@media (max-width: 600px) {
    .panel-resources.is-home { display: none; }
    .panel-text.is-home { max-height: none; }
    .main-content:has(.panel-text.is-home) { padding-bottom: 0; }
}

/* ---------- sheet tab bar fits a phone (P2-2): counts become a dot ---------- */
@media (max-width: 600px) {
    .panel-tabs .tab-btn { white-space: nowrap; padding-left: 0.375rem; padding-right: 0.375rem; }
    .panel-tabs .tab-indicator {
        font-size: 0;
        display: inline-block;
        width: 6px; height: 6px;
        margin-left: 4px;
        vertical-align: 0.2em;
        border-radius: 50%;
        background: currentColor;
    }
}

/* ---------- cross-references belong to a verse (P1-6) ---------- */
.crossref-for { margin: 0 0 0.5rem; font-size: 0.875rem; color: var(--color-text-secondary); }
.crossref-for span { font-weight: 600; color: var(--color-text); }

/* ---------- a weak word link ---------- */
.word-unsure p { line-height: 1.55; color: var(--color-text-secondary); }
.word-reveal {
    min-height: 44px;
    padding: 0 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.word-unsure-note {
    margin: 0 0 0.75rem;
    padding: 0.5rem 0.75rem;
    border-left: 3px solid var(--study-focus-rule, #a96a12);
    background: var(--study-focus-bg, #fdf0c4);
    color: var(--color-text);
    font-size: 0.875rem;
    border-radius: 0 var(--radius) var(--radius) 0;
}

@media (prefers-reduced-motion: reduce) {
    .return-chip, dialog.picker-sheet[open] { animation: none; }
}
