/* Open Pardes — color theme and base styles
   Parchment-toned light mode, deep slate dark mode.
   Designed for long reading sessions. */

/* ============ Color tokens ============ */

:root {
    /* Parchment background tones */
    --bg-base:        #FAF8F3;
    --bg-elevated:    #FFFCF6;
    --bg-recessed:    #F4F0E6;
    --bg-overlay:     rgba(40, 30, 20, 0.55);

    /* Text */
    --text-primary:   #2A2825;
    --text-secondary: #5F5E5A;
    --text-tertiary:  #8E8C85;
    --text-on-accent: #FFFFFF;

    /* Borders */
    --border-default: #E5E3DA;
    --border-strong:  #D3D1C7;
    --border-subtle:  #EFEDE4;

    /* Accent colors */
    --accent:         #3C3489;   /* deep indigo for primary actions */
    --accent-hover:   #2F2870;
    --accent-soft:    #ECE9F4;
    --accent-on-soft: #2F2870;

    --link:           #185FA5;   /* blue for verse links and inline links */
    --link-hover:     #0F4779;
    --link-visited:   #553A85;

    --warm:           #854F0B;   /* copper/amber for bookmarks, highlights */
    --warm-hover:     #6B3F08;
    --warm-soft:      #FDF6E8;

    --success:        #0F6E56;
    --success-soft:   #E3F1EB;

    --warning:        #B05A0D;
    --danger:         #B23A2F;

    /* Hebrew text always looks better in a serif */
    --font-hebrew:    'Noto Serif Hebrew', 'Frank Ruhl Libre', serif;
    --font-english:   'Frank Ruhl Libre', 'Iowan Old Style', Georgia, serif;
    --font-ui:        'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    /* Sizing */
    --container-max:  72rem;
    --radius-sm:      4px;
    --radius:         8px;
    --radius-lg:      12px;
    --shadow-subtle:  0 1px 3px rgba(40, 30, 20, 0.06);
    --shadow:         0 4px 12px rgba(40, 30, 20, 0.10);
}

.dark {
    --bg-base:        #1A1F2E;
    --bg-elevated:    #232938;
    --bg-recessed:    #141828;
    --bg-overlay:     rgba(0, 0, 0, 0.7);

    --text-primary:   #E8E4D6;
    --text-secondary: #A8A496;
    --text-tertiary:  #7A7768;
    --text-on-accent: #FFFFFF;

    --border-default: #2E3445;
    --border-strong:  #3A4156;
    --border-subtle:  #252A3B;

    --accent:         #9C92E0;
    --accent-hover:   #B5ABEC;
    --accent-soft:    #2D2A48;
    --accent-on-soft: #B5ABEC;

    --link:           #7AB3E8;
    --link-hover:     #99C3EE;
    --link-visited:   #B5A3D6;

    --warm:           #D9A961;
    --warm-hover:     #E5BC7E;
    --warm-soft:      #332B1A;

    --success:        #4FB59A;
    --danger:         #E07A6E;
}

/* ============ Base ============ */

* { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    /* Prevent any descendant from causing horizontal scroll on iOS Safari */
    overflow-x: clip;
}

body {
    margin: 0;
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: clip;
}

/* Belt-and-suspenders: prevent any common element from exceeding viewport width */
img, video, table, pre {
    max-width: 100%;
}

[dir="rtl"] body { font-family: var(--font-hebrew); }

a {
    color: var(--link);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
a:hover { color: var(--link-hover); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

button { font: inherit; cursor: pointer; }

.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 1rem;
}

/* ============ Header ============ */

.site-header {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-default);
    position: sticky; top: 0; z-index: 50;
}

.site-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    gap: 1rem;
}

.brand {
    text-decoration: none;
    color: var(--accent);
    font-weight: 600;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}
.brand-he { font-family: var(--font-hebrew); font-size: 1.25rem; }
.brand-en { font-family: var(--font-english); font-size: 1rem; color: var(--text-secondary); font-weight: 500; }
[dir="rtl"] .brand-en { font-size: 0.9rem; }

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.95rem;
}
.nav-link:hover { background: var(--bg-recessed); color: var(--text-primary); }
.nav-link-primary {
    background: var(--accent);
    color: var(--text-on-accent);
}
.nav-link-primary:hover {
    background: var(--accent-hover);
    color: var(--text-on-accent);
}
.nav-link-muted { color: var(--text-secondary); font-size: 0.85rem; }

.theme-toggle {
    background: none;
    border: 1px solid var(--border-default);
    border-radius: var(--radius);
    width: 2rem; height: 2rem;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-secondary);
}
.theme-toggle:hover { background: var(--bg-recessed); }
.theme-icon-dark { display: none; }
.dark .theme-icon-light { display: none; }
.dark .theme-icon-dark { display: inline; }

/* ============ Welcome page ============ */

.welcome-hero {
    text-align: center;
    padding: 3rem 1rem 2rem;
}
.welcome-title-he {
    font-family: var(--font-hebrew);
    font-size: 2.5rem;
    color: var(--accent);
    margin: 0 0 0.25rem;
    font-weight: 500;
}
.welcome-title-en {
    font-family: var(--font-english);
    font-size: 1.5rem;
    color: var(--accent);
    margin: 0 0 0.75rem;
    font-weight: 500;
}
.welcome-tagline {
    color: var(--text-secondary);
    font-size: 1.05rem;
    margin: 0;
}

.welcome-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    max-width: 56rem;
    margin: 0 auto;
    padding: 0 1rem;
}

.welcome-card {
    display: block;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.welcome-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    text-decoration: none;
}
.welcome-card-icon {
    font-size: 1.75rem;
    color: var(--accent);
    margin-bottom: 0.5rem;
}
.welcome-card-icon.warm { color: var(--warm); }
.welcome-card-icon.success { color: var(--success); }
.welcome-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 0.25rem;
    color: var(--text-primary);
}
.welcome-card-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
}

.welcome-featured {
    max-width: 56rem;
    margin: 2rem auto;
    padding: 0 1rem;
}
.featured-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}
.featured-eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin: 0 0 0.5rem;
    font-weight: 600;
}
.featured-title-he {
    font-family: var(--font-hebrew);
    font-size: 1.5rem;
    color: var(--text-primary);
    margin: 0 0 0.25rem;
    font-weight: 500;
}
.featured-title-en {
    font-family: var(--font-english);
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0 0 0.5rem;
}
.featured-meta {
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin: 0;
}

/* ============ Forms ============ */

.form-container {
    max-width: 28rem;
    margin: 3rem auto;
    padding: 0 1rem;
}

.form-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.form-title {
    font-size: 1.5rem;
    margin: 0 0 0.5rem;
    color: var(--text-primary);
}
.form-subtitle {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 0 0 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}
.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}
.form-help {
    font-size: 0.8rem;
    color: var(--text-tertiary);
    margin: 0.25rem 0 0;
}
.form-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-base);
    color: var(--text-primary);
    font: inherit;
    font-size: 1rem;
}
.form-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}

.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    background: var(--accent);
    color: var(--text-on-accent);
    border: none;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s;
}
.btn:hover { background: var(--accent-hover); color: var(--text-on-accent); text-decoration: none; }
.btn-block { display: block; width: 100%; }
.btn-secondary {
    background: var(--bg-recessed);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--border-subtle); color: var(--text-primary); }

/* ============ Messages ============ */

.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.95rem;
}
.flash-info    { background: var(--accent-soft); color: var(--accent-on-soft); }
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-warning { background: var(--warm-soft); color: var(--warm); }
.flash-error   { background: #FCE4E1; color: var(--danger); }
.dark .flash-error { background: #3B1F1C; color: var(--danger); }

/* ============ Footer ============ */

.site-footer {
    margin-top: 3rem;
    padding: 1.5rem 0;
    border-top: 1px solid var(--border-default);
    color: var(--text-secondary);
    font-size: 0.875rem;
}
.footer-row {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 0 1rem;
}
.footer-link {
    color: var(--link);
    text-decoration: none;
}
.footer-link:hover { color: var(--link-hover); text-decoration: underline; }
.footer-link-button {
    background: none; border: none; padding: 0; cursor: pointer;
    font: inherit; color: var(--link);
}
.footer-donate { color: var(--warm); }
.footer-donate:hover { color: var(--warm-hover); }
.footer-sep { color: var(--text-tertiary); }

/* ============ Toast ============ */

.op-toast {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: var(--bg-base);
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    z-index: 200;
    font-size: 0.9rem;
}
.op-toast.visible { opacity: 1; }

/* ============ Error pages ============ */

.error-page {
    text-align: center;
    padding: 4rem 1rem;
}
.error-code {
    font-size: 4rem;
    color: var(--accent);
    margin: 0;
    font-weight: 500;
}
.error-message {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin: 0.5rem 0 1.5rem;
}

/* ============ Viewer (study page) ============ */

:root {
    --reading-size: 18px;
    --reading-font: 'Noto Serif Hebrew', 'Frank Ruhl Libre', serif;
    --divider-h: 18px;
    --split-pct: 50;
}

body.study-page {
    overflow: hidden;  /* viewer manages its own scrolling */
}
body.study-page #main-content {
    height: calc(100vh - 56px);   /* full viewport minus header */
    height: calc(100dvh - 56px);
}

/* App shell — grid layout with flexible top, scrollable middle, fixed bottom */
.reader-shell {
    display: grid;
    grid-template-rows: auto 1fr auto;
    height: 100%;
}

/* Top strip */
.reader-top {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-default);
    max-height: 45vh;
    max-height: 45dvh;
    overflow-y: auto;
}
.reader-top-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    flex-wrap: wrap;
}
.reader-pickers, .reader-tools {
    display: flex; align-items: center; gap: 0.4rem;
    flex-wrap: nowrap;
}
.reader-select {
    background: var(--bg-base);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.3rem 0.5rem;
    font: inherit; font-size: 0.875rem;
}
.reader-select-sm { max-width: 7rem; font-size: 0.75rem; }
.reader-progress { font-size: 0.75rem; color: var(--text-tertiary); padding: 0 0.25rem; }
.reader-btn {
    background: var(--bg-base);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 0.3rem 0.6rem;
    font: inherit; font-size: 0.8rem; cursor: pointer;
    transition: background 0.15s;
}
.reader-btn:hover { background: var(--bg-recessed); }
.reader-btn.active { background: var(--accent-soft); color: var(--accent-on-soft); border-color: var(--accent); }
.reader-btn-sm { padding: 0.2rem 0.5rem; font-size: 0.75rem; }
.reader-btn-sq { width: 1.75rem; height: 1.75rem; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.reader-font-display {
    display: inline-block; min-width: 1.5rem; text-align: center;
    font-size: 0.75rem; font-variant-numeric: tabular-nums; color: var(--text-secondary);
}

/* Base text strip */
.base-text-strip {
    padding: 0.5rem 0.75rem 0.75rem;
    border-top: 1px solid var(--border-subtle);
}
.base-text-header {
    display: flex; justify-content: space-between; align-items: center;
    gap: 0.5rem; margin-bottom: 0.4rem;
}
.base-text-eyebrow {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-secondary); font-weight: 600;
}
.base-text-actions { display: flex; align-items: center; gap: 0.4rem; }
.base-text-body {
    background: var(--bg-recessed);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}
.base-text-body .reading-text {
    font-size: clamp(14px, calc(var(--reading-size) * 0.9), 22px);
    line-height: 1.7;
    font-family: var(--reading-font);
}

/* Commentary mode toggle bar */
.commentary-bar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    border-top: 1px solid var(--border-subtle);
}
.commentary-label {
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
    color: var(--text-secondary); font-weight: 600;
}
.commentary-actions { display: flex; align-items: center; gap: 0.4rem; }

/* HE/EN small toggles */
.lang-toggle, .mode-toggle {
    display: inline-flex;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.base-lang-btn, .mode-btn {
    background: var(--bg-base);
    border: none;
    padding: 0.25rem 0.6rem;
    font: inherit; font-size: 0.75rem;
    color: var(--text-primary);
    cursor: pointer;
    border-inline-end: 1px solid var(--border-strong);
}
.base-lang-btn:last-child, .mode-btn:last-child { border-inline-end: none; }
.base-lang-btn.active, .mode-btn.active {
    background: var(--accent); color: var(--text-on-accent);
}

/* Reading area — split view */
.reading-area {
    overflow: hidden;
    min-height: 0;
    position: relative;
    background: var(--bg-base);
    display: grid;
    grid-template-rows: calc(var(--split-pct) * 1% - var(--divider-h) / 2)
                        var(--divider-h)
                        calc((100 - var(--split-pct)) * 1% - var(--divider-h) / 2);
}
.reader-shell.mode-he .reading-area,
.reader-shell.mode-en .reading-area {
    display: block;
}
.reader-shell.mode-he .pane-en,
.reader-shell.mode-he .divider { display: none; }
.reader-shell.mode-en .pane-he,
.reader-shell.mode-en .divider { display: none; }
.reader-shell.mode-he .pane-he,
.reader-shell.mode-en .pane-en { height: 100%; }

.pane {
    overflow-y: auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0;
}
.reading-text {
    font-family: var(--reading-font);
    font-size: var(--reading-size);
    line-height: 1.85;
}
.pane-he .reading-text { /* Hebrew already RTL from inline dir attr */ }
.pane-en .reading-text { font-family: var(--font-english); color: var(--text-secondary); }

/* Paragraph blocks */
.para {
    padding: 0.4rem 1rem;
    margin-bottom: 0.2rem;
    border-inline-start: 2px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    position: relative;
}
.para:hover { background: var(--bg-recessed); }
.para.active {
    background: var(--accent-soft);
    border-inline-start-color: var(--accent);
}
/* Brief flash when arriving from a search result */
.para.flash-highlight {
    animation: flash-pulse 2.4s ease-out;
}
@keyframes flash-pulse {
    0%, 60%   { background: var(--warm-soft); border-inline-start-color: var(--warm); }
    100%      { background: var(--accent-soft); border-inline-start-color: var(--accent); }
}

.seg-num {
    color: var(--text-tertiary);
    font-size: 0.7em;
    font-family: var(--font-ui);
    font-weight: 400;
    vertical-align: 0.15em;
    user-select: none;
    white-space: nowrap;
}
[dir="rtl"] .seg-num { margin-left: 0.4em; }
[dir="ltr"] .seg-num { margin-right: 0.4em; }

.verse-link {
    color: var(--link);
    text-decoration: underline;
    text-decoration-style: dotted;
    cursor: pointer;
}
.verse-link:hover { color: var(--link-hover); }

.empty-pane {
    padding: 2rem 1rem; text-align: center;
}

/* Divider */
.divider {
    background: var(--bg-recessed);
    border-top: 1px solid var(--border-default);
    border-bottom: 1px solid var(--border-default);
    cursor: ns-resize;
    display: flex; align-items: center; justify-content: center;
    position: relative;
    touch-action: none;
    user-select: none;
}
.divider-grip { display: flex; gap: 4px; }
.divider-grip span {
    width: 4px; height: 4px; border-radius: 50%;
    background: var(--border-strong);
}
.divider:hover .divider-grip span { background: var(--text-tertiary); }
.divider:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.divider-label {
    position: absolute;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    top: 50%; transform: translateY(-50%);
    font-family: var(--font-ui);
}
[dir="rtl"] .divider-label { right: 0.75rem; }
[dir="ltr"] .divider-label { left: 0.75rem; }

/* Bottom nav */
.reader-bottom {
    background: var(--bg-elevated);
    border-top: 1px solid var(--border-default);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    height: 4rem;
}
.bottom-btn {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 0.15rem;
    background: none; border: none;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    font: inherit;
}
.bottom-btn:hover { background: var(--bg-recessed); color: var(--text-primary); text-decoration: none; }
.bottom-icon { font-size: 1.25rem; line-height: 1; }
.bottom-label { font-size: 0.65rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }

/* Modals */
.modal-backdrop {
    position: fixed; inset: 0;
    background: var(--bg-overlay);
    display: none; align-items: center; justify-content: center;
    z-index: 100; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    max-width: 36rem; width: 100%;
    max-height: 90vh; display: flex; flex-direction: column;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-default);
}
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-close {
    background: none; border: none;
    font-size: 1.5rem; line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 0.5rem;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 1rem 1.25rem; overflow-y: auto; flex: 1; }

.modal-actions {
    display: flex; gap: 0.5rem; justify-content: flex-end;
    margin-top: 0.75rem;
}

/* Notes */
.notes-list { max-height: 16rem; overflow-y: auto; margin-bottom: 1rem; }
.note-card {
    background: var(--bg-recessed);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 0.75rem;
    margin-bottom: 0.5rem;
}
.note-card-small {
    background: var(--bg-recessed);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    margin: 0.4rem 0;
    font-size: 0.875rem;
}
.note-meta {
    display: flex; justify-content: space-between; align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem; color: var(--text-secondary);
    margin-bottom: 0.35rem;
}
.note-body { white-space: pre-wrap; line-height: 1.5; font-size: 0.95rem; }
.note-actions { display: inline-flex; gap: 0.25rem; align-items: center; }
.note-action {
    background: none; border: none;
    color: var(--text-secondary);
    font-size: 0.9rem; cursor: pointer;
    padding: 0.25rem;
}
.note-action:hover { color: var(--accent); }
.note-delete {
    background: none; border: none;
    color: var(--danger);
    font-size: 0.9rem; cursor: pointer;
    padding: 0.25rem;
}
.note-delete:hover { opacity: 0.7; }

.badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 0.7rem;
    font-size: 0.65rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-public { background: var(--success-soft); color: var(--success); }

.note-form { padding-top: 0.5rem; border-top: 1px solid var(--border-subtle); }
.note-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}
.note-form-header .form-label { margin: 0; }
.note-dir-toggle {
    display: inline-flex;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.note-dir-btn {
    background: var(--bg-base);
    border: none;
    padding: 0.2rem 0.55rem;
    font: inherit;
    font-size: 0.75rem;
    color: var(--text-primary);
    cursor: pointer;
    border-inline-end: 1px solid var(--border-strong);
}
.note-dir-btn:last-child { border-inline-end: none; }
.note-dir-btn.active {
    background: var(--accent);
    color: var(--text-on-accent);
}
.note-form textarea {
    margin-top: 0.4rem; resize: vertical; min-height: 5rem;
    font-family: var(--font-ui); line-height: 1.5;
}
.note-form .checkbox-label {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.85rem; color: var(--text-secondary);
    margin-top: 0.5rem;
}
.note-signin-msg {
    text-align: center; padding: 1rem; color: var(--text-secondary);
}

.notes-group {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
}
.notes-group-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.6rem 0.75rem;
    background: var(--bg-recessed);
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500; font-size: 0.9rem;
}
.notes-group-header:hover { background: var(--border-subtle); }

/* Bookmarks */
.bookmark-row {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    margin-bottom: 0.4rem;
}
.bookmark-row:hover { background: var(--bg-recessed); }
.bookmark-link {
    flex: 1; text-decoration: none; color: var(--text-primary);
}
.bookmark-title { font-weight: 500; font-size: 0.95rem; }
.bookmark-date { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 0.15rem; }

/* Verse popup */
.verse-popup { padding: 1.5rem; max-width: 32rem; }
.verse-popup #versePopupContent {
    overflow-y: auto;
    max-height: calc(90vh - 6rem);  /* allow room for the Close button */
    margin-bottom: 1rem;
}
.verse-popup .verse-he {
    font-family: var(--font-hebrew);
    font-size: 1.25rem;
    line-height: 1.7;
    margin-bottom: 1rem;
}
.verse-popup .verse-en {
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Utility */
.text-muted { color: var(--text-tertiary); }
.italic { font-style: italic; }
.hidden { display: none !important; }

/* ============ Search page ============ */

.search-page { padding: 2rem 1rem; max-width: 56rem; }

.search-header { margin-bottom: 1.5rem; }
.search-title {
    margin: 0 0 1rem;
    font-size: 1.5rem;
    color: var(--text-primary);
}
.search-text-name { color: var(--accent); }
.search-text-sub  { color: var(--text-secondary); font-size: 1rem; font-weight: 400; }

.search-form { display: flex; flex-direction: column; gap: 0.75rem; }
.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font: inherit;
    font-size: 1.05rem;
}
.search-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
}
.search-controls {
    display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
}
.search-controls .checkbox-label {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.9rem; color: var(--text-secondary);
}

.search-summary {
    padding: 0.75rem 1rem;
    background: var(--bg-recessed);
    border-radius: var(--radius);
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
}

.search-group {
    border: 1px solid var(--border-default);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    overflow: hidden;
}
.search-group-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-recessed);
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: background 0.15s;
}
.search-group-header:hover {
    background: var(--accent-soft);
    color: var(--accent-on-soft);
    text-decoration: none;
}
.search-group-title { font-size: 1rem; }
.search-group-tag {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--warm-soft);
    color: var(--warm);
    padding: 0.15rem 0.5rem;
    border-radius: 0.7rem;
}

.search-result {
    display: flex; gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-subtle);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.search-result:hover {
    background: var(--bg-recessed);
    text-decoration: none;
    color: inherit;
}
.search-seg-num {
    flex: 0 0 auto;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: var(--font-ui);
    padding-top: 0.15rem;
}
.search-snippets { flex: 1; min-width: 0; }
.search-snippet {
    line-height: 1.6;
    font-family: var(--reading-font);
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}
.search-snippet.en {
    font-family: var(--font-english);
    color: var(--text-secondary);
}
mark.search-hit {
    background: var(--warm-soft);
    color: var(--warm);
    padding: 0 0.2em;
    border-radius: 2px;
    font-weight: 500;
}

.search-hint { padding: 2rem 0; text-align: center; }

/* ============ Admin tables ============ */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}
.admin-table th, .admin-table td {
    padding: 0.6rem 0.5rem;
    text-align: start;
    border-bottom: 1px solid var(--border-subtle);
    vertical-align: top;
}
.admin-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    background: var(--bg-recessed);
}
.admin-table tr:hover td { background: var(--bg-recessed); }
.admin-table tr.row-pending td {
    background: var(--warm-soft);
}
.admin-table tr.row-pending:hover td {
    background: var(--warm-soft);
    filter: brightness(0.97);
}
.admin-table .small { font-size: 0.8rem; }
.admin-table .badge {
    background: var(--accent-soft);
    color: var(--accent-on-soft);
}

/* ============ Sefaria commentaries picker ============ */
.sef-pick-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.7rem 0.9rem;
    margin-bottom: 0.4rem;
    background: var(--bg-base);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    color: var(--text-primary);
    text-align: start;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font: inherit;
}
.sef-pick-row:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.sef-pick-name {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.sef-pick-name-he {
    font-family: var(--font-hebrew);
    font-size: 0.95rem;
    color: var(--text-secondary);
}
.sef-pick-count {
    background: var(--accent-soft);
    color: var(--accent-on-soft);
    border-radius: 0.7rem;
    padding: 0.15rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 1.6rem;
    text-align: center;
}

/* ============ Sefaria slide-in panel ============ */
.sef-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 55vw;
    max-width: 720px;
    background: var(--bg-elevated);
    border-inline-start: 1px solid var(--border-strong);
    box-shadow: -4px 0 16px rgba(40, 30, 20, 0.10);
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
    z-index: 80;
    display: flex;
    flex-direction: column;
}
[dir="rtl"] .sef-panel {
    right: auto;
    left: 0;
    border-inline-start: none;
    border-inline-end: 1px solid var(--border-strong);
    transform: translateX(-100%);
    box-shadow: 4px 0 16px rgba(40, 30, 20, 0.10);
}
.sef-panel.open {
    transform: translateX(0);
}

@media (max-width: 768px) {
    .sef-panel {
        width: 100vw;
        max-width: none;
    }
}

.sef-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    background: var(--bg-recessed);
    border-bottom: 1px solid var(--border-default);
    flex-wrap: wrap;
}
.sef-panel-title {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}
.sef-panel-title #sefPanelName {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}
.sef-panel-ref {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}
.sef-panel-tools {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: nowrap;
}
.sef-lang-btn {
    background: var(--bg-base);
    border: none;
    padding: 0.25rem 0.6rem;
    font: inherit;
    font-size: 0.75rem;
    color: var(--text-primary);
    cursor: pointer;
    border-inline-end: 1px solid var(--border-strong);
}
.sef-lang-btn:last-child { border-inline-end: none; }
.sef-lang-btn.active {
    background: var(--accent);
    color: var(--text-on-accent);
}

.sef-panel-body {
    overflow-y: auto;
    flex: 1;
    padding: 1rem 1.2rem 2rem;
    -webkit-overflow-scrolling: touch;
}

.sef-seg {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}
.sef-seg:last-child { border-bottom: none; }
.sef-seg-num {
    color: var(--text-tertiary);
    font-size: 0.7rem;
    font-family: var(--font-ui);
    margin-inline-end: 0.4em;
    vertical-align: 0.15em;
}
.sef-seg-he {
    font-family: var(--font-hebrew);
    font-size: 1.05rem;
    line-height: 1.85;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}
.sef-seg-en {
    font-family: var(--font-english);
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-secondary);
}

/* Language mode visibility */
.sef-panel.sef-lang-he .sef-seg-en { display: none; }
.sef-panel.sef-lang-en .sef-seg-he { display: none; }

/* Bold first sentence emphasis (Sefaria convention preserved) */
.sef-seg-he b, .sef-seg-en b,
.sef-seg-he strong, .sef-seg-en strong {
    font-weight: 600;
    color: var(--text-primary);
}
.sef-seg-he i, .sef-seg-en i,
.sef-seg-he em, .sef-seg-en em {
    font-style: italic;
}

/* When the panel is open, narrow the main reading area on wide screens
   so the user can read both side by side. On mobile, the panel is full
   width so the underlying view is just covered. */
@media (min-width: 769px) {
    body.sef-panel-open #main-content {
        padding-right: 55vw;
        max-width: 100%;
    }
    [dir="rtl"] body.sef-panel-open #main-content {
        padding-right: 0;
        padding-left: 55vw;
    }
}

/* ============ Section banner (parasha + mitzvah label) ============ */
.section-banner {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 0.85rem;
    background: var(--accent-soft);
    color: var(--accent-on-soft);
    border-bottom: 1px solid var(--border-subtle);
    font-family: var(--font-ui);
}
.section-banner .section-name {
    font-weight: 600;
    font-size: 0.95rem;
}
.section-banner .section-display {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

/* Inline emphasis in reading text */
.reading-text b, .reading-text strong {
    font-weight: 600;
    color: var(--text-primary);
}
.reading-text i, .reading-text em {
    font-style: italic;
}

/* Bookmark label / actions */
.bookmark-label {
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-top: 0.2rem;
    font-style: italic;
}
.bookmark-actions {
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

/* Sefaria commentaries button — loading state */
.sef-btn-checking {
    opacity: 0.5;
    cursor: wait;
}
.reader-btn.hidden { display: none !important; }

/* ============ Welcome resume + My Study ============ */
.welcome-resume {
    max-width: 56rem;
    margin: 0 auto 1rem;
    padding: 0 1rem;
}
.welcome-resume-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.welcome-resume-header h2 {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.welcome-resume-more {
    font-size: 0.85rem;
    text-decoration: none;
    color: var(--accent);
}
.welcome-resume-more:hover { text-decoration: underline; }
.welcome-resume-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}
.welcome-resume-card .welcome-card-title {
    font-size: 1rem;
    margin-bottom: 0.15rem;
}

/* My Study page */
.my-study { padding: 2rem 1rem; max-width: 56rem; }
.my-study h1 { margin-top: 0; }
.my-study h2 {
    font-size: 1.05rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 1.5rem 0 0.75rem;
}
.study-resume-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.75rem;
}
.study-resume-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.study-resume-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
    text-decoration: none;
}
.study-resume-icon { font-size: 1.5rem; color: var(--warm); }
.study-resume-body { flex: 1; min-width: 0; }
.study-resume-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.1rem;
}
.study-resume-locator {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}
.study-resume-meta {
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.bookmark-book-group {
    margin-bottom: 1.5rem;
}
.bookmark-book-title {
    font-size: 0.95rem;
    color: var(--accent);
    margin: 0 0 0.4rem;
    font-weight: 600;
}

/* Inline <small> in reading text — used by Kav HaYashar for citations */
.reading-text small {
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* ============================================================
   Mobile UX (≤640px) — compact app bar + action sheets + scroll-collapse
   ONLY applies on mobile-sized screens. Desktop completely unchanged.
   ============================================================ */

/* By default (desktop), all mobile-specific elements are hidden */
.reader-mbar      { display: none; }
.m-sheet          { display: none; }
.m-sheet.open     {} /* opening handled inside @media */

/* On mobile only (≤640px so narrow desktops keep desktop chrome) */
@media (max-width: 640px) {

    /* Hide the site-wide header inside the reader to reclaim ~80px */
    body.study-page .site-header { display: none; }

    /* Hide all desktop reader chrome */
    .reader-top-desktop,
    .section-banner,
    .commentary-bar      { display: none !important; }

    /* Compact base-text-strip (Pirkei Avot) */
    .base-text-strip     { padding: 0; }
    .base-text-header    { padding: 0.35rem 0.6rem; }
    .base-text-body      { padding: 0.4rem 0.6rem 0.5rem; }

    /* ---- Mobile app bar (single 44px row) ---- */
    .reader-mbar {
        display: flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.3rem 0.5rem;
        background: var(--bg-elevated);
        border-bottom: 1px solid var(--border-default);
        position: sticky;
        top: 0;
        z-index: 50;
        min-height: 44px;
    }

    .mbar-btn {
        flex: 0 0 auto;
        background: transparent;
        border: none;
        font-size: 1.3rem;
        color: var(--text-primary);
        padding: 0.2rem 0.45rem;
        text-decoration: none;
        cursor: pointer;
        line-height: 1;
        min-height: 38px;
        min-width: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
    }
    .mbar-btn:active { background: var(--bg-recessed); }

    .mbar-title {
        flex: 1 1 auto;
        min-width: 0;
        background: transparent;
        border: 1px solid transparent;
        text-align: start;
        font: inherit;
        color: inherit;
        cursor: pointer;
        padding: 0.2rem 0.4rem;
        line-height: 1.2;
        border-radius: 4px;
        display: flex;
        align-items: center;
        gap: 0.3rem;
        white-space: nowrap;
        overflow: hidden;
    }
    .mbar-title:active { background: var(--bg-recessed); }
    .mbar-title-text {
        font-size: 0.85rem;
        font-weight: 500;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        flex: 1;
    }
    .mbar-title-caret {
        font-size: 0.65rem;
        color: var(--text-tertiary);
        flex: 0 0 auto;
    }

    .mbar-mode {
        display: inline-flex;
        align-items: center;
        border: 1px solid var(--border-strong);
        border-radius: 4px;
        overflow: hidden;
        flex: 0 0 auto;
    }
    .mbar-mode .mode-btn {
        background: var(--bg-base);
        border: none;
        padding: 0.25rem 0.45rem;
        font-size: 0.7rem;
        font-family: var(--font-ui);
        color: var(--text-primary);
        cursor: pointer;
        border-inline-end: 1px solid var(--border-strong);
        min-height: 30px;
        line-height: 1;
    }
    .mbar-mode .mode-btn:last-child { border-inline-end: none; }
    .mbar-mode .mode-btn.active {
        background: var(--accent);
        color: var(--text-on-accent);
    }

    /* ---- Mobile sheets (full-screen bottom sheets) ---- */
    .m-sheet {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(30, 25, 20, 0.5);
        z-index: 90;
        align-items: flex-end;
        justify-content: center;
    }
    .m-sheet.open {
        display: flex;
    }
    .m-sheet-inner {
        width: 100%;
        max-width: 540px;
        background: var(--bg-elevated);
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        max-height: 80vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .m-sheet-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-default);
        flex: 0 0 auto;
    }
    .m-sheet-header h3 { margin: 0; font-size: 1rem; }
    .m-sheet-body {
        padding: 0.5rem 0.5rem 1.5rem;
        overflow-y: auto;
        flex: 1 1 auto;
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    }

    .m-sheet-row { margin-bottom: 0.75rem; padding: 0 0.5rem; }
    .m-sheet-label {
        display: block;
        font-size: 0.78rem;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        margin-bottom: 0.25rem;
    }
    .m-sheet-select {
        width: 100%;
        font-size: 1rem;
        padding: 0.55rem 0.6rem;
        min-height: 44px;
    }

    .m-action-row {
        display: flex;
        align-items: center;
        gap: 0.7rem;
        width: 100%;
        padding: 0.7rem 0.6rem;
        background: transparent;
        border: none;
        text-align: start;
        font: inherit;
        color: var(--text-primary);
        cursor: pointer;
        text-decoration: none;
        min-height: 44px;
        border-radius: 6px;
        box-sizing: border-box;
    }
    .m-action-row:not(.m-action-static):hover,
    .m-action-row:not(.m-action-static):active {
        background: var(--bg-recessed);
    }
    .m-action-row[disabled] { opacity: 0.45; cursor: not-allowed; }
    .m-action-row.m-action-static { cursor: default; }
    .m-action-icon {
        font-size: 1.15rem;
        width: 1.5rem;
        text-align: center;
        flex: 0 0 auto;
    }
    .m-action-label {
        flex: 1 1 auto;
        font-size: 0.95rem;
    }
    .m-action-count {
        color: var(--text-tertiary);
        font-size: 0.8rem;
        margin-inline-start: 0.4rem;
    }
    .m-action-controls {
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        flex: 0 0 auto;
    }
    .m-action-controls .reader-btn {
        min-width: 36px;
        min-height: 36px;
    }
    .m-action-controls .reader-font-display {
        min-width: 2.2rem;
        text-align: center;
        font-variant-numeric: tabular-nums;
    }
    .m-action-divider {
        height: 1px;
        background: var(--border-subtle);
        margin: 0.4rem 0.5rem;
    }

    /* Body scroll lock when a sheet is open */
    body.m-sheet-open { overflow: hidden; }

    /* Compact bottom bar on mobile — minimize wasted real estate */
    .reader-bottom {
        padding: 0.2rem 0.3rem;
        min-height: 40px;
    }
    .bottom-btn {
        padding: 0.2rem 0.3rem;
    }
    .bottom-icon { font-size: 1.05rem; line-height: 1; }
    .bottom-label {
        font-size: 0.6rem;
        margin-top: 0.05rem;
    }

    /* Reading area: full available height */
    .reading-area { padding-bottom: 0.5rem; }
    .reader-top   { max-height: 40dvh; }
    .reader-shell { height: 100dvh; }
}

/* Mobile link-paragraphs button — active state */
@media (max-width: 640px) {
    .mbar-link {
        font-size: 1.1rem;
        opacity: 0.55;
    }
    .mbar-link.active {
        opacity: 1;
        color: var(--accent);
    }
}
