/* Scholars Gateway - Main Stylesheet
   RTL support, Hebrew/Greek font sizing, academic layout, dark mode
*/

/* ============================================================
   CSS Custom Properties (Light + Dark)
   ============================================================ */
:root {
  --color-bg: #fafaf8;
  --color-surface: #ffffff;
  --color-surface-2: #f4f3ef;
  --color-border: #d4d0c8;
  --color-text: #1a1a18;
  --color-text-muted: #5a5a52;
  --color-accent: #4a6741;       /* Scholarly green */
  --color-accent-light: #e8f0e6;
  --color-hebrew: #2c1810;       /* Dark warm for Hebrew */
  --color-greek: #1a2040;        /* Dark cool for Greek */
  --color-verse-num: #8a8070;
  --color-panel-bg: #f7f6f2;
  --color-panel-border: #e0dbd0;
  --color-link: #4a6741;
  --color-link-hover: #2e4028;
  --color-word-hover: #e8f0e6;
  --color-word-active: #c8ddc4;
  --shadow-panel: 0 1px 4px rgba(0,0,0,0.08);
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-hebrew: 'Noto Serif Hebrew', 'SBL Hebrew', 'David CLM', serif;
  --font-greek: 'Noto Serif', 'GFS Didot', 'Gentium Plus', serif;
  --font-latin: 'Noto Serif', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --text-hebrew-scale: 1.25em;
  --text-greek-scale: 1.1em;
  --radius: 4px;
  --sidebar-width: 320px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1a17;
    --color-surface: #24241f;
    --color-surface-2: #2e2e28;
    --color-border: #3a3a32;
    --color-text: #e8e8e0;
    --color-text-muted: #9a9a8a;
    --color-accent: #7aaa6a;
    --color-accent-light: #1e2e1a;
    --color-hebrew: #f0e8d8;
    --color-greek: #d8e0f0;
    --color-verse-num: #7a7268;
    --color-panel-bg: #1e1e1a;
    --color-panel-border: #38382e;
    --color-link: #7aaa6a;
    --color-link-hover: #a0cc90;
    --color-word-hover: #1e2e1a;
    --color-word-active: #2a4025;
    --shadow-panel: 0 1px 4px rgba(0,0,0,0.3);
  }
}

[data-theme="dark"] {
  --color-bg: #1a1a17;
  --color-surface: #24241f;
  --color-surface-2: #2e2e28;
  --color-border: #3a3a32;
  --color-text: #e8e8e0;
  --color-text-muted: #9a9a8a;
  --color-accent: #7aaa6a;
  --color-accent-light: #1e2e1a;
  --color-hebrew: #f0e8d8;
  --color-greek: #d8e0f0;
  --color-verse-num: #7a7268;
  --color-panel-bg: #1e1e1a;
  --color-panel-border: #38382e;
  --color-link: #7aaa6a;
  --color-link-hover: #a0cc90;
  --color-word-hover: #1e2e1a;
  --color-word-active: #2a4025;
  --shadow-panel: 0 1px 4px rgba(0,0,0,0.3);
}

/* Alpine.js: hide elements before initialization to prevent flash */
[x-cloak] { display: none !important; }

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-ui);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  color: var(--color-link-hover);
  text-decoration: underline;
}

/* ============================================================
   Navigation
   ============================================================ */
.site-nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-panel);
}

.site-nav__brand {
  font-family: var(--font-latin);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--color-accent);
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.site-nav__brand:hover {
  color: var(--color-link-hover);
  text-decoration: none;
}

.site-nav__links {
  display: flex;
  align-items: center;
  gap: 1rem;
  list-style: none;
  flex: 1;
}

.site-nav__links a {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.site-nav__links a:hover {
  color: var(--color-text);
  text-decoration: none;
}

.site-nav__search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
}

.site-nav__search input {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  color: var(--color-text);
  width: 220px;
}

.site-nav__search input:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* Hamburger button (mobile only — hidden on desktop) */
.site-nav__burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 0.45rem;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius);
  flex-shrink: 0;
  margin-left: 0.25rem;
}

.site-nav__burger:hover {
  background: var(--color-surface-2);
}

.site-nav__burger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--color-text);
  border-radius: 1px;
}

/* Mobile dropdown navigation */
.site-nav__mobile-menu {
  position: absolute;
  top: 52px;
  left: 0;
  right: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  z-index: 99;
  padding: 0.25rem 0;
}

.site-nav__mobile-menu a {
  display: block;
  padding: 0.85rem 1.5rem;
  font-size: 0.95rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-surface-2);
  text-decoration: none;
}

.site-nav__mobile-menu a:last-child {
  border-bottom: none;
}

.site-nav__mobile-menu a:hover {
  background: var(--color-accent-light);
  color: var(--color-accent);
  text-decoration: none;
}

/* ============================================================
   Layout: Two-Column Reader
   ============================================================ */
.reader-layout {
  display: grid;
  grid-template-columns: 1fr var(--sidebar-width);
  min-height: calc(100vh - 52px);
  flex: 1;
}

.reader-main {
  padding: 1.5rem 2rem;
  overflow-y: auto;
  border-right: 1px solid var(--color-border);
}

.reader-sidebar {
  background: var(--color-panel-bg);
  border-left: 1px solid var(--color-panel-border);
  position: sticky;
  top: 52px;
  height: calc(100vh - 52px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.reader-sidebar__inner {
  padding: 1.25rem;
  flex: 1;
}

.reader-sidebar__title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-panel-border);
  padding-bottom: 0.5rem;
}

/* ============================================================
   Chapter / Verse Header
   ============================================================ */
.chapter-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.chapter-header__breadcrumb {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.4rem;
}

.chapter-header__breadcrumb a {
  color: var(--color-text-muted);
}

.chapter-header__breadcrumb a:hover {
  color: var(--color-accent);
  text-decoration: none;
}

.chapter-header__breadcrumb .sep {
  margin: 0 0.3rem;
}

.chapter-header__title {
  font-family: var(--font-latin);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}

.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.875rem;
}

.chapter-nav a {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-muted);
}

.chapter-nav a:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
  text-decoration: none;
}

/* ============================================================
   Verse Display
   ============================================================ */
.verse-list {
  list-style: none;
}

.verse-row {
  display: flex;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-surface-2);
  align-items: flex-start;
  scroll-margin-top: 70px;
}

.verse-row:last-child {
  border-bottom: none;
}

.verse-row.is-active {
  background: var(--color-accent-light);
  margin: 0 -0.5rem;
  padding: 0.6rem 0.5rem;
  border-radius: var(--radius);
}

.verse-num {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-verse-num);
  min-width: 1.8rem;
  text-align: right;
  padding-top: 0.25em;
  flex-shrink: 0;
  user-select: none;
}

.verse-content {
  flex: 1;
}

.verse-text {
  margin-bottom: 0.3rem;
}

/* ── Collection markup styles ────────────────────────────────────────────────
   Applied when a collection stores HTML in full_text (has_markup = true).
   Scoped under .verse-text and .search-result__text so they only fire
   inside rendered segments, never in UI chrome.
   ──────────────────────────────────────────────────────────────────────────── */

/* Supplied / translator-inserted words (YLT <span class="additional">)
   Traditional Bible typography italicises these words. */
.verse-text .additional,
.search-result__text .additional {
  font-style: italic;
  opacity: 0.85;
}

/* Paragraph marker (YLT <span class="paragraph">&nbsp;</span>)
   Rendered as a pilcrow (¶) — the span's whitespace content is hidden and
   replaced via ::before so the marker is visible but not selectable text. */
.verse-text .paragraph,
.search-result__text .paragraph {
  font-size: 0;          /* hide &nbsp; content */
  margin: 0 0.25em;
  user-select: none;
}
.verse-text .paragraph::before,
.search-result__text .paragraph::before {
  content: '¶';
  font-size: 0.72rem;
  color: var(--color-text-muted);
  opacity: 0.6;
  vertical-align: middle;
  font-style: normal;
}

.verse-translation {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  font-family: var(--font-latin);
  line-height: 1.5;
}

/* ============================================================
   Hebrew Text
   ============================================================ */
.heb {
  font-family: var(--font-hebrew);
  font-size: var(--text-hebrew-scale);
  direction: rtl;
  unicode-bidi: embed;
  line-height: 1.8;
  color: var(--color-hebrew);
}

.heb-block {
  display: block;
  text-align: right;
  direction: rtl;
}

/* ============================================================
   Greek Text
   ============================================================ */
.grc {
  font-family: var(--font-greek);
  font-size: var(--text-greek-scale);
  direction: ltr;
  line-height: 1.7;
  color: var(--color-greek);
}

/* ============================================================
   Reader Controls Toolbar
   ============================================================ */
.reader-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.85rem;
  margin-bottom: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.8rem;
}

.rc-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.rc-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  margin-right: 0.1rem;
  user-select: none;
}

.rc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1;
  font-family: var(--font-ui);
  white-space: nowrap;
  min-width: 1.6rem;
}

.rc-btn:hover {
  background: var(--color-surface-2);
}

.rc-btn.is-active {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.rc-hl-btn.is-active {
  background: var(--hl-bg, var(--color-accent-light)) !important;
  border-color: var(--hl-color, var(--color-accent)) !important;
  color: var(--hl-color, var(--color-accent)) !important;
}

.rc-scale-val {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  min-width: 2.6rem;
  text-align: center;
  user-select: none;
}

.rc-sep {
  width: 1px;
  height: 1.2rem;
  background: var(--color-border);
  flex-shrink: 0;
}

/* ============================================================
   POS Highlighting
   ============================================================ */
.word.pos-verb    { background-color: rgba(217, 119,   6, 0.18) !important; border-radius: 2px; }
.word.pos-noun    { background-color: rgba( 37,  99, 235, 0.18) !important; border-radius: 2px; }
.word.pos-prep    { background-color: rgba(124,  58, 237, 0.18) !important; border-radius: 2px; }
.word.pos-adv     { background-color: rgba(  5, 150, 105, 0.18) !important; border-radius: 2px; }
.word.pos-adj     { background-color: rgba(220,  38,  38, 0.18) !important; border-radius: 2px; }
.word.pos-numeral { background-color: rgba(  8, 145, 178, 0.18) !important; border-radius: 2px; }

[data-theme="dark"] .word.pos-verb    { background-color: rgba(251, 191,  36, 0.22) !important; }
[data-theme="dark"] .word.pos-noun    { background-color: rgba( 96, 165, 250, 0.22) !important; }
[data-theme="dark"] .word.pos-prep    { background-color: rgba(167, 139, 250, 0.22) !important; }
[data-theme="dark"] .word.pos-adv     { background-color: rgba( 52, 211, 153, 0.22) !important; }
[data-theme="dark"] .word.pos-adj     { background-color: rgba(248, 113, 113, 0.22) !important; }
[data-theme="dark"] .word.pos-numeral { background-color: rgba( 34, 211, 238, 0.22) !important; }

/* ============================================================
   Reader Font Scale (--reader-scale set by Alpine.js)
   ============================================================ */
.reader-main .heb {
  font-size: calc(1.25em * var(--reader-scale, 1));
}

.reader-main .grc {
  font-size: calc(1.1em * var(--reader-scale, 1));
}

/* ============================================================
   Interactive Word Spans
   ============================================================ */
.word {
  cursor: pointer;
  border-radius: 2px;
  padding: 0 1px;
  transition: background-color 0.1s ease;
  display: inline;
}

.word:hover,
.word.is-hovered {
  background-color: var(--color-word-hover);
}

.word.is-active {
  background-color: var(--color-word-active);
  outline: 1px solid var(--color-accent);
}

/* Maqqef connector (U+05BE ־): inert, no hover, zero surrounding space */
.word-maqqef {
  display: inline;
  cursor: default;
  padding: 0;
  user-select: none;
}

/* HTMX loading indicator */
.htmx-indicator {
  opacity: 0;
  transition: opacity 0.15s ease;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  opacity: 1;
}

/* ============================================================
   Morphology / Parsing Panel
   ============================================================ */
.parsing-panel {
  min-height: 120px;
}

.parsing-panel__placeholder {
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-style: italic;
  text-align: center;
  padding: 2rem 0;
}

.parsing-word-form {
  font-family: var(--font-hebrew);
  font-size: 1.8em;
  direction: rtl;
  text-align: center;
  display: block;
  margin-bottom: 0.75rem;
  color: var(--color-hebrew);
  line-height: 2;
}

.parsing-word-form.grc {
  font-family: var(--font-greek);
  font-size: 1.4em;
  direction: ltr;
  text-align: center;
  color: var(--color-greek);
}

.parsing-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.82rem;
}

.parsing-label {
  color: var(--color-text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.parsing-value {
  color: var(--color-text);
  font-weight: 400;
}

.parsing-value.pos {
  font-weight: 600;
  color: var(--color-accent);
}

.parsing-section {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-panel-border);
}

.parsing-section__title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.morph-code {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--color-surface-2);
  padding: 0.1rem 0.35rem;
  border-radius: 2px;
  color: var(--color-text-muted);
}

/* ============================================================
   Lexicon Popup / Panel
   ============================================================ */
.lexicon-panel {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-panel-border);
}

.lexicon-entry__strong {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.lexicon-entry__headword {
  font-family: var(--font-hebrew);
  font-size: 1.3em;
  direction: rtl;
  display: block;
  margin-bottom: 0.25rem;
  color: var(--color-hebrew);
}

.lexicon-entry__headword.grc {
  font-family: var(--font-greek);
  font-size: 1.15em;
  direction: ltr;
  color: var(--color-greek);
}

.lexicon-entry__pos {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-style: italic;
  margin-bottom: 0.5rem;
}

.lexicon-entry__definition {
  font-size: 0.85rem;
  color: var(--color-text);
  line-height: 1.55;
}

/* ============================================================
   Browse / Book List
   ============================================================ */
.browse-layout {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

.browse-header {
  margin-bottom: 2rem;
}

.browse-header h1 {
  font-family: var(--font-latin);
  font-size: 1.75rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.testament-section {
  margin-bottom: 2.5rem;
}

.testament-section__title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 1rem;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}

.book-card {
  display: block;
  padding: 0.6rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--color-text);
  transition: background 0.1s, border-color 0.1s;
}

.book-card:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
  color: var(--color-text);
  text-decoration: none;
}

.book-card__abbr {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--color-text-muted);
  display: block;
  margin-top: 0.15rem;
}

/* ============================================================
   Chapter Index (Book detail page)
   ============================================================ */
.chapter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
}

.chapter-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--color-text);
  font-family: var(--font-mono);
}

.chapter-link:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
  text-decoration: none;
}

/* ============================================================
   Home Page
   ============================================================ */
.home-layout {
  max-width: 820px;
  margin: 2.25rem auto;
  padding: 0 1.5rem;
  flex: 1;
}

.home-hero {
  text-align: center;
  margin-bottom: 2.5rem;
}

.home-hero__title {
  font-family: var(--font-latin);
  font-size: 2.25rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.6rem;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.home-hero__sub {
  font-size: 1rem;
  color: var(--color-text-muted);
  margin-bottom: 1.75rem;
  line-height: 1.6;
}

.home-search {
  display: flex;
  gap: 0.5rem;
  max-width: 480px;
  margin: 0 auto;
}

.home-search input {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}

.home-search input:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.btn {
  font-family: var(--font-ui);
  font-size: 0.875rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.btn-primary:hover {
  background: var(--color-link-hover);
  border-color: var(--color-link-hover);
  color: #fff;
  text-decoration: none;
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-surface-2);
  text-decoration: none;
}

.home-quick-links {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
  font-size: 0.875rem;
}

/* ============================================================
   Feature Cards (Home page)
   ============================================================ */
.feature-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 2rem;
}

.feature-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1.1rem;
  border-top: 2px solid var(--color-accent);
}

.feature-card__title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--color-text);
}

.feature-card__desc {
  font-size: 0.84rem;
  color: var(--color-text-muted);
  line-height: 1.55;
}

/* ============================================================
   Home Section Label
   ============================================================ */
.home-section-label {
  font-size: 0.72rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ============================================================
   Browse Filter Buttons
   ============================================================ */
.browse-filter-btns {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

/* ============================================================
   Generic Page Title (h1 on content pages)
   ============================================================ */
.page-title {
  font-family: var(--font-latin);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  line-height: 1.3;
}

/* ============================================================
   Parallel Reader (multi-collection)
   ============================================================ */
.parallel-header,
.parallel-row {
  display: grid;
  grid-template-columns: 2rem repeat(var(--col-count, 1), 1fr);
  column-gap: 1.5rem;
  align-items: start;
}

.parallel-header {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0.5rem;
}

.col-header {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding: 0.25rem 0;
}

.parallel-row {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--color-surface-2);
  scroll-margin-top: 70px;
}

.parallel-row:last-child {
  border-bottom: none;
}

.parallel-row:hover,
.parallel-row.is-active {
  background: var(--color-accent-light);
  border-radius: var(--radius);
}

.parallel-row.is-active {
  margin: 0 -0.5rem;
  padding: 0.6rem 0.5rem;
}

.verse-cell {
  min-width: 0; /* prevent grid blowout with long RTL text */
}

.verse-missing {
  color: var(--color-text-muted);
  font-size: 0.9em;
}

/* Collection picker */
.collection-picker {
  position: relative;
  display: inline-block;
  margin-bottom: 0.5rem;
}

.picker-toggle {
  gap: 0.25rem;
}

.picker-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  min-width: 240px;
  background: var(--color-panel-bg);
  border: 1px solid var(--color-panel-border);
  border-radius: var(--radius);
  padding: 0.5rem 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

.picker-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  user-select: none;
}

.picker-option:hover {
  background: var(--color-word-hover);
}

.picker-lang-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  background: var(--color-border);
  color: var(--color-text-muted);
  font-variant: small-caps;
  flex-shrink: 0;
}

.picker-lang-badge.heb { background: #2c5a1e; color: #fff; }
.picker-lang-badge.grc { background: #1a2e5a; color: #fff; }

.picker-parsed-badge {
  margin-left: auto;
  color: var(--color-accent);
  font-size: 0.75rem;
}

@media (max-width: 900px) {
  .parallel-header,
  .parallel-row {
    grid-template-columns: 2rem 1fr;
  }
  /* Hide extra columns beyond the first.
     Row structure: verse-num (child 1), verse-cell (child 2), verse-cell (child 3)…
     :not(:nth-child(2)) hides children at position 3+ only, leaving child 2 visible. */
  .parallel-header .col-header:not(:nth-child(2)),
  .parallel-row .verse-cell:not(:nth-child(2)) {
    display: none;
  }
}

/* ============================================================
   Comparison View
   ============================================================ */
.compare-layout {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  min-height: calc(100vh - 52px);
  gap: 0;
}

.compare-column {
  padding: 1.5rem;
  border-right: 1px solid var(--color-border);
}

.compare-column:last-child {
  border-right: none;
}

.compare-column__header {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 1rem;
}

/* ============================================================
   Verse Detail Page
   ============================================================ */
.verse-detail-layout {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

.verse-detail__text {
  font-family: var(--font-hebrew);
  font-size: 2em;
  direction: rtl;
  text-align: right;
  line-height: 2.2;
  color: var(--color-hebrew);
  margin: 1rem 0 1.5rem;
  padding: 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.verse-detail__words-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

.verse-detail__words-table th {
  text-align: left;
  padding: 0.4rem 0.75rem;
  border-bottom: 2px solid var(--color-border);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 600;
}

.verse-detail__words-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--color-surface-2);
  vertical-align: top;
}

.verse-detail__words-table tr:hover td {
  background: var(--color-accent-light);
}

/* ============================================================
   Search Results
   ============================================================ */
.search-layout {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.search-form input {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 1rem;
  padding: 0.6rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}

.search-form input:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

.search-result {
  display: flex;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-surface-2);
  align-items: flex-start;
}

.search-result__meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex-shrink: 0;
  gap: 0.2rem;
  padding-top: 0.15rem;
}

.search-result__ref {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-accent);
  white-space: nowrap;
}

.search-result__collection {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  opacity: 0.75;
}

.search-result__text {
  flex: 1;
  font-size: 1em;
  line-height: 1.8;
}

.search-result__text--rtl {
  font-family: var(--font-hebrew);
  font-size: 1.1em;
  color: var(--color-hebrew);
}

.search-pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.25rem 0 0.5rem;
  flex-wrap: wrap;
}

.pagination__btn {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-accent);
  text-decoration: none;
}

.pagination__btn--disabled {
  color: var(--color-text-muted);
  opacity: 0.4;
  cursor: default;
}

.pagination__pages {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.pagination__page {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.3rem 0.55rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--color-text);
}

.pagination__page:hover {
  background: var(--color-surface-2);
}

.pagination__page--current {
  background: var(--color-accent);
  color: var(--color-bg);
  font-weight: 600;
}

.pagination__ellipsis {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  padding: 0 0.2rem;
}

mark {
  background: #f0e040;
  border-radius: 2px;
  padding: 0 1px;
}

[data-theme="dark"] mark {
  background: #6a5a00;
}

/* ============================================================
   Loading / Spinner
   ============================================================ */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 1rem 1.5rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-footer a {
  color: var(--color-text-muted);
}

/* ============================================================
   Utilities
   ============================================================ */
.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;
}

.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }

/* Small button variant */
.btn-sm {
  font-size: 0.75rem;
  padding: 0.3rem 0.65rem;
}

/* Section label (h2 variant used in book/verse-detail pages) */
.section-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
}

/* Horizontally scrollable table wrapper for narrow screens */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1.5rem;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 900px) {
  .reader-layout {
    grid-template-columns: 1fr;
  }
  .reader-sidebar {
    position: static;
    height: auto;
    border-left: none;
    border-top: 1px solid var(--color-border);
  }
  .compare-layout {
    grid-template-columns: 1fr;
  }
  .site-nav__links {
    display: none;
  }
  /* Show hamburger on tablet/mobile */
  .site-nav__burger {
    display: flex;
  }
  /* Chapter links: larger touch targets on tablet/mobile */
  .chapter-link {
    width: 2.75rem;
    height: 2.75rem;
  }
}

@media (max-width: 600px) {
  .reader-main {
    padding: 1rem;
  }
  .home-search {
    flex-direction: column;
  }
  .browse-layout,
  .verse-detail-layout,
  .search-layout {
    padding: 1rem;
  }
  .feature-grid {
    grid-template-columns: 1fr;
  }
  :root {
    --sidebar-width: 100%;
  }

  /* Nav: hide search text input on small phones, keep icon button as search link */
  .site-nav__search input {
    display: none;
  }

  /* Reader controls: bigger touch targets */
  .rc-btn {
    min-height: 2.25rem;
    padding: 0.4rem 0.65rem;
  }

  /* Collection picker: constrain panel to viewport width */
  .picker-panel {
    width: min(300px, calc(100vw - 2rem));
    min-width: 0;
  }

  /* Hebrew text: slightly smaller on mobile so lines don't overflow */
  .reader-main .heb {
    font-size: calc(1.1em * var(--reader-scale, 1));
  }

  /* Home layout: reduce top margin */
  .home-layout {
    margin-top: 1.5rem;
  }

  /* Footer: stack items */
  .site-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 1rem;
  }
}

/* ============================================================
   Extra-small screens (≤480px) — typical phone portrait
   ============================================================ */
@media (max-width: 480px) {
  /* Search results: stack ref/text vertically instead of side-by-side */
  .search-result {
    flex-direction: column;
    gap: 0.35rem;
  }

  .search-result__meta {
    flex-direction: row;
    align-items: baseline;
    gap: 0.5rem;
  }

  /* Book grid: allow slightly narrower cards on very small screens */
  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }

  /* Home hero: tighten heading for narrow screens */
  .home-hero__title {
    font-size: 1.85rem;
  }

  /* Browse filter buttons: always stack */
  .browse-filter-btns {
    flex-direction: column;
  }
}

/* ============================================================
   Print Stylesheet
   ============================================================ */
@media print {
  .site-nav,
  .reader-sidebar,
  .reader-controls,
  .chapter-nav,
  .htmx-indicator,
  .site-footer {
    display: none !important;
  }

  .reader-layout {
    display: block;
  }

  .reader-main {
    padding: 0;
    border: none;
  }

  body {
    font-size: 11pt;
    color: #000;
    background: #fff;
  }

  .heb {
    color: #000;
    font-size: 1.3em;
  }

  .verse-row {
    page-break-inside: avoid;
    border-bottom: 1px solid #ccc;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  .verse-num {
    color: #666;
  }
}
