/* ==========================================================================
   שם משמואל — מהדורת עיון אינטראקטיבית
   Authentic Hebrew Sefer Typography (Frank Ruhl Libre + David Libre)
   & Warm Piotrków Parchment / Beit Midrash Night Theme
   ========================================================================== */

:root {
  --font-makor: "Frank Ruhl Libre", "Times New Roman", serif;
  --font-biur: "David Libre", Georgia, serif;
  --font-ui: "Heebo", system-ui, -apple-system, sans-serif;

  --scale: 1;

  /* Light Theme: Warm Piotrków Cream Parchment */
  --bg-canvas: #f6f1e7;
  --bg-sheet: #fffdf9;
  --bg-raised: #f9f5ec;
  --bg-sunken: #efe8da;
  --bg-accent-wash: #fbf3df;
  --bg-navy-wash: #eef2f8;

  --ink-primary: #1a1714;
  --ink-secondary: #3d3730;
  --ink-muted: #6b6155;
  --ink-faint: #938778;

  --brand-navy: #1b365d;
  --brand-navy-strong: #122644;
  --brand-gold: #9a6f1e;
  --brand-gold-soft: #d9b872;
  --accent-emerald: #1e6b4b;

  --border-subtle: #e5dccb;
  --border-strong: #cbbda5;
  --border-sefer-frame: #b8a688;

  --shadow-sheet: 0 6px 28px rgba(36, 27, 14, 0.07), 0 1px 3px rgba(36, 27, 14, 0.05);
  --shadow-drawer: 8px 0 32px rgba(20, 16, 10, 0.18);

  /* Stream colors */
  --stream-sochatchov: #1b365d;
  --stream-kotzk: #6b3fa0;
  --stream-izhbitz: #0f6e66;
  --stream-maharal: #8c5319;
  --stream-classic: #2f5d3a;
  --stream-kabbalah: #7a2e4d;
}

[data-theme="dark"] {
  --bg-canvas: #131210;
  --bg-sheet: #1b1916;
  --bg-raised: #23201c;
  --bg-sunken: #171512;
  --bg-accent-wash: #2b2416;
  --bg-navy-wash: #1b2433;

  --ink-primary: #efe8dc;
  --ink-secondary: #d4cbbd;
  --ink-muted: #9e9486;
  --ink-faint: #736a5e;

  --brand-navy: #7ca6e8;
  --brand-navy-strong: #a3c2f5;
  --brand-gold: #deb359;
  --brand-gold-soft: #6b5322;
  --accent-emerald: #52b788;

  --border-subtle: #2e2a24;
  --border-strong: #453f36;
  --border-sefer-frame: #574e41;

  --shadow-sheet: 0 8px 32px rgba(0, 0, 0, 0.45);
  --shadow-drawer: 8px 0 36px rgba(0, 0, 0, 0.65);

  --stream-sochatchov: #7ca6e8;
  --stream-kotzk: #b794f4;
  --stream-izhbitz: #4fd1c5;
  --stream-maharal: #f6ad55;
  --stream-classic: #68d391;
  --stream-kabbalah: #f687b3;
}

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

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-family: var(--font-ui);
  direction: rtl;
  text-align: start;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

button,
a,
.rt-abbr,
.cit-phrase,
.kushya-card,
.heara-item,
.pathway-step {
  touch-action: manipulation;
  -webkit-tap-highlight-color: color-mix(in srgb, var(--brand-navy) 14%, transparent);
}

/* Explicit Left-to-Right styling for all English-labeled UI elements */
[dir="ltr"] {
  direction: ltr;
  text-align: left;
  unicode-bidi: isolate;
}

[dir="rtl"] {
  direction: rtl;
  text-align: right;
  unicode-bidi: isolate;
}

button[dir="ltr"].axis-tab,
button[dir="ltr"].pill-filter,
button[dir="ltr"].subtab-btn,
button[dir="ltr"].study-mode-btn,
button[dir="ltr"].icon-btn,
button[dir="ltr"].lang-btn,
.brand-emblem[dir="ltr"],
.loading-state,
.loading-state[dir="ltr"],
.index-hero[dir="ltr"],
.index-hero h2[dir="ltr"],
.index-hero p[dir="ltr"],
.iyunim-box-header[dir="ltr"],
.sefer-divider-heading[dir="ltr"],
.kinyan-veil-box[dir="ltr"] {
  text-align: center;
}

input[dir="ltr"] {
  text-align: left;
}

.card-label-head {
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--brand-navy);
  margin-bottom: 0.22rem;
}

.bridge-card .card-label-head {
  color: var(--stream-izhbitz);
}

.avodah-card .card-label-head {
  color: var(--accent-emerald);
}

.chip-meta-en {
  font-family: var(--font-ui);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--brand-navy);
  margin-bottom: 0.14rem;
}

/* Top Navigation Bar */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--bg-sheet) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}

.top-bar-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 0.55rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.brand-emblem {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 6px;
  border: 1.5px solid var(--brand-gold);
  background: var(--bg-accent-wash);
  color: var(--brand-navy);
  font-family: var(--font-makor);
  font-weight: 700;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-main {
  margin: 0;
  font-family: var(--font-makor);
  font-size: 1.35rem;
  font-weight: 900;
  line-height: 1.1;
  color: var(--ink-primary);
  letter-spacing: 0.01em;
}

.brand-sub {
  display: block;
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.main-tabs {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-sunken);
  padding: 0.25rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.main-tab {
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-family: var(--font-ui);
  font-size: 0.84rem;
  font-weight: 500;
  padding: 0.42rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.main-tab:hover {
  color: var(--ink-primary);
  background: color-mix(in srgb, var(--bg-sheet) 55%, transparent);
}

.main-tab.active {
  background: var(--bg-sheet);
  color: var(--brand-navy);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.trust-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.32rem 0.7rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent-emerald) 35%, var(--border-subtle));
  background: color-mix(in srgb, var(--accent-emerald) 8%, var(--bg-sheet));
  color: var(--accent-emerald);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.trust-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-emerald);
}

.icon-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-sheet);
  color: var(--ink-secondary);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.34rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink-primary);
}

.icon-btn.active {
  border-color: var(--brand-navy);
  color: var(--brand-navy);
  background: var(--bg-navy-wash);
  font-weight: 600;
}

.font-controls {
  display: flex;
  gap: 0.2rem;
}

.lang-segmented {
  display: inline-flex;
  align-items: center;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.14rem;
  gap: 0.12rem;
}

.lang-btn {
  border: none;
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.48rem;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1.1;
  transition: all 0.15s ease;
}

.lang-btn:hover {
  color: var(--ink-primary);
}

.lang-btn.active {
  background: var(--brand-navy);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .lang-btn.active {
  color: #111;
}

.mobile-only {
  display: none;
}

/* Workspace Views */
.workspace {
  max-width: 1560px;
  margin: 0 auto;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

#view-reader.active {
  display: grid;
  grid-template-columns: 350px minmax(0, 1fr);
  align-items: start;
  min-height: calc(100vh - 60px);
}

/* Multi-Axis ToC Sidebar */
.toc-sidebar {
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border-left: 1px solid var(--border-subtle);
  overscroll-behavior: contain;
}

.toc-mobile-bar {
  display: none;
}

.toc-mobile-title {
  font-family: var(--font-makor);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.toc-header {
  padding: 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-sheet);
}

.toc-search-input,
.wide-search {
  width: 100%;
  padding: 0.52rem 0.75rem;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-family: var(--font-ui);
  font-size: 0.84rem;
}

.toc-search-input:focus,
.wide-search:focus {
  outline: 2px solid var(--brand-navy);
  border-color: transparent;
}

.toc-axis-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.25rem;
  margin-top: 0.65rem;
}

.axis-tab {
  border: 1px solid var(--border-subtle);
  background: var(--bg-raised);
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: 0.71rem;
  font-weight: 500;
  padding: 0.34rem 0.2rem;
  border-radius: 5px;
  cursor: pointer;
  text-align: center;
}

.axis-tab.active {
  background: var(--brand-navy);
  color: #fff;
  border-color: var(--brand-navy);
  font-weight: 600;
}

[data-theme="dark"] .axis-tab.active {
  color: #111;
}

.toc-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  overscroll-behavior: contain;
}

.toc-section-block {
  margin-bottom: 0.9rem;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-sheet);
  overflow: hidden;
}

.toc-section-header {
  width: 100%;
  border: none;
  background: var(--bg-sunken);
  color: var(--ink-primary);
  padding: 0.6rem 0.8rem;
  font-family: var(--font-makor);
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.toc-count-badge {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink-muted);
  background: var(--bg-sheet);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
}

.toc-year-group {
  border-top: 1px solid var(--border-subtle);
}

.toc-year-title {
  padding: 0.4rem 0.8rem;
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--brand-gold);
  background: color-mix(in srgb, var(--bg-accent-wash) 55%, var(--bg-sheet));
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.era-tag {
  font-size: 0.66rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.toc-maamar-btn {
  width: 100%;
  border: none;
  border-top: 1px solid color-mix(in srgb, var(--border-subtle) 60%, transparent);
  background: transparent;
  padding: 0.58rem 0.85rem;
  text-align: right;
  cursor: pointer;
  display: block;
  transition: background 0.12s ease;
}

.toc-maamar-btn:hover {
  background: var(--bg-raised);
}

.toc-maamar-btn.active {
  background: var(--bg-navy-wash);
  border-right: 3.5px solid var(--brand-navy);
}

.toc-maamar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-bottom: 0.2rem;
}

.toc-occ-pill {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--brand-navy);
  background: color-mix(in srgb, var(--brand-navy) 10%, transparent);
  padding: 0.08rem 0.42rem;
  border-radius: 4px;
}

.toc-meta-mini {
  font-family: var(--font-ui);
  font-size: 0.67rem;
  color: var(--ink-faint);
}

.toc-maamar-header {
  font-family: var(--font-makor);
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink-primary);
  line-height: 1.35;
}

.toc-maamar-dh {
  font-family: var(--font-biur);
  font-size: 0.78rem;
  color: var(--ink-muted);
  margin-top: 0.18rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reader Stage & Classic Sefer Sheet */
.reader-stage {
  padding: 1.25rem 1.75rem 4rem;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
}

.study-controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.mode-segmented {
  display: inline-flex;
  background: var(--bg-sunken);
  padding: 0.22rem;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.study-mode-btn {
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.38rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
}

.study-mode-btn.active {
  background: var(--bg-sheet);
  color: var(--brand-navy);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.subtle-btn {
  border: 1px solid var(--border-subtle);
  background: var(--bg-sheet);
  color: var(--ink-secondary);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  padding: 0.38rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

.subtle-btn:hover {
  border-color: var(--border-strong);
  color: var(--ink-primary);
}

/* The Sefer Page Sheet */
.sefer-sheet {
  background: var(--bg-sheet);
  border: 1px solid var(--border-sefer-frame);
  border-radius: 4px;
  box-shadow: var(--shadow-sheet);
  padding: 2.25rem 2.6rem 2.75rem;
  position: relative;
}

.sefer-sheet::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid color-mix(in srgb, var(--border-sefer-frame) 45%, transparent);
  pointer-events: none;
  border-radius: 2px;
}

/* Running Folio Head (Modeled on Noam Elimelech / Kedushat Levi page) */
.running-folio-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  border-bottom: 1.5px solid var(--ink-primary);
  padding-bottom: 0.45rem;
  margin-bottom: 1.4rem;
  font-family: var(--font-makor);
  font-size: 0.9rem;
  color: var(--ink-secondary);
}

.folio-center-title {
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--ink-primary);
}

.maamar-title-banner {
  text-align: center;
  margin-bottom: 1.6rem;
  padding: 0 1rem;
}

.maamar-occasion-chips {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.occ-chip {
  font-family: var(--font-ui);
  font-size: 0.73rem;
  font-weight: 600;
  padding: 0.16rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-accent-wash);
  color: var(--brand-gold);
  border: 1px solid color-mix(in srgb, var(--brand-gold) 35%, transparent);
}

.occ-chip.era {
  background: var(--bg-navy-wash);
  color: var(--brand-navy);
  border-color: color-mix(in srgb, var(--brand-navy) 28%, transparent);
}

.maamar-display-title {
  margin: 0;
  font-family: var(--font-makor);
  font-size: calc(1.65rem * var(--scale));
  font-weight: 900;
  line-height: 1.3;
  color: var(--ink-primary);
}

.maamar-display-subtitle {
  margin: 0.4rem 0 0;
  font-family: var(--font-biur);
  font-size: calc(1.05rem * var(--scale));
  color: var(--ink-muted);
}

/* Part 1: Mavo LaMaamar + Logic Subway Map */
.mavo-box {
  border: 1px solid var(--border-strong);
  background: var(--bg-raised);
  padding: 1.15rem 1.35rem;
  margin-bottom: 1.85rem;
  border-radius: 3px;
}

.mavo-box-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.45rem;
  margin-bottom: 0.75rem;
}

.mavo-box-title {
  font-family: var(--font-makor);
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--brand-navy);
}

.mavo-anchor-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-sheet);
  color: var(--brand-gold);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  cursor: pointer;
}

.mavo-summary-text {
  font-family: var(--font-biur);
  font-size: calc(1.04rem * var(--scale));
  line-height: 1.72;
  color: var(--ink-secondary);
  margin: 0 0 0.9rem;
}

.mahalach-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.kushya-rail {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.kushya-card {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  background: var(--bg-sheet);
  border: 1px solid var(--border-subtle);
  border-right: 3px solid var(--brand-gold);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.kushya-card:hover {
  border-color: var(--brand-gold);
}

.kushya-badge {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--brand-gold);
  white-space: nowrap;
}

.kushya-text {
  font-family: var(--font-biur);
  font-size: calc(0.96rem * var(--scale));
  line-height: 1.5;
  color: var(--ink-primary);
  flex: 1;
}

.kushya-jump-hint {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.yesod-card,
.bridge-card,
.avodah-card {
  padding: 0.6rem 0.85rem;
  border-radius: 4px;
  background: var(--bg-sheet);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-biur);
  font-size: calc(0.97rem * var(--scale));
  line-height: 1.6;
}

.yesod-card {
  border-right: 3px solid var(--brand-navy);
}

.yesod-card[dir="ltr"] {
  border-right: 1px solid var(--border-subtle);
  border-left: 3px solid var(--brand-navy);
}

.bridge-card {
  border-right: 3px solid var(--stream-izhbitz);
  background: color-mix(in srgb, var(--stream-izhbitz) 5%, var(--bg-sheet));
}

.avodah-card {
  border-right: 3px solid var(--accent-emerald);
}

.avodah-card[dir="ltr"] {
  border-right: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent-emerald);
}

.card-inline-label {
  font-family: var(--font-ui);
  font-size: 0.73rem;
  font-weight: 700;
  margin-left: 0.45rem;
  color: var(--brand-navy);
}

.bridge-card .card-inline-label {
  color: var(--stream-izhbitz);
}

.avodah-card .card-inline-label {
  color: var(--accent-emerald);
}

/* Kinyan Veil Button */
.kinyan-veil-box {
  text-align: center;
  padding: 0.9rem;
  border: 1px dashed var(--brand-gold);
  background: var(--bg-accent-wash);
  border-radius: 6px;
  margin: 0.6rem 0;
}

.kinyan-reveal-btn {
  border: 1px solid var(--brand-navy);
  background: var(--brand-navy);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.4rem 0.95rem;
  border-radius: 6px;
  cursor: pointer;
}

[data-theme="dark"] .kinyan-reveal-btn {
  color: #111;
}

/* Parts 2 & 3: Lockstep Segments (Pointed Makor + Threaded/Paired Biur) */
.segments-stream {
  display: flex;
  flex-direction: column;
  gap: 1.45rem;
}

.segment-block {
  padding: 0.85rem 0 1.15rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.25s ease;
}

.segment-block.highlighted-kushya {
  background: var(--bg-accent-wash);
  padding-inline: 0.85rem;
  border-radius: 6px;
}

.segment-block.highlighted-tirutz {
  background: color-mix(in srgb, var(--accent-emerald) 9%, var(--bg-sheet));
  padding-inline: 0.85rem;
  border-radius: 6px;
}

.segment-gutter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.45rem;
}

.seg-num-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.seg-gematria {
  font-family: var(--font-makor);
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--brand-navy);
}

.seg-role-tag {
  font-size: 0.68rem;
  padding: 0.08rem 0.45rem;
  border-radius: 4px;
  background: var(--bg-sunken);
  color: var(--ink-secondary);
  font-weight: 600;
}

/* Authentic Sefer Inset Makor Block (13.5pt Frank Ruehl equivalent, set in from both margins!) */
.makor-passage {
  font-family: var(--font-makor);
  font-size: calc(1.32rem * var(--scale));
  font-weight: 500;
  line-height: 1.95;
  color: var(--ink-primary);
  padding-inline: 1.35rem;
  margin: 0;
  text-align: justify;
}

.segment-block.is-year-header .makor-passage {
  font-size: calc(1.08rem * var(--scale));
  font-weight: 700;
  text-align: center;
  color: var(--brand-navy);
  padding-inline: 0;
}

/* Inline Rashei Tevos Tooltip */
.rt-abbr {
  text-decoration: underline dotted color-mix(in srgb, var(--brand-gold) 65%, transparent);
  text-underline-offset: 4px;
  cursor: help;
  position: relative;
}

.rt-abbr.rt-active {
  background: color-mix(in srgb, var(--brand-gold) 18%, transparent);
  border-radius: 3px;
}

@media (hover: hover) {
  .rt-abbr:not(.rt-active):hover::after {
    content: attr(data-expanded);
    position: absolute;
    bottom: 100%;
    right: 50%;
    transform: translateX(50%);
    background: var(--ink-primary);
    color: var(--bg-sheet);
    font-family: var(--font-ui);
    font-size: 0.74rem;
    font-weight: 500;
    padding: 0.25rem 0.55rem;
    border-radius: 5px;
    direction: rtl;
    unicode-bidi: plaintext;
    white-space: nowrap;
    z-index: 25;
    pointer-events: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
  }
}

.rt-popover {
  position: fixed;
  z-index: 80;
  max-width: min(320px, calc(100vw - 24px));
  background: var(--ink-primary);
  color: var(--bg-sheet);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
  line-height: 1.45;
  pointer-events: none;
  unicode-bidi: plaintext;
}

/* Underlined Cited Phrase */
.cit-phrase {
  text-decoration-line: underline;
  text-decoration-style: solid;
  text-decoration-color: color-mix(in srgb, var(--brand-navy) 46%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.32em;
  text-decoration-skip-ink: none;
  cursor: pointer;
  border-radius: 2px;
  transition: background-color 0.14s ease, text-decoration-color 0.14s ease;
}

.cit-phrase.cit-phrase-unconfirmed {
  text-decoration-style: dashed;
  text-decoration-color: color-mix(in srgb, var(--brand-gold) 68%, transparent);
}

.cit-phrase:hover,
.cit-phrase.cit-hover {
  background-color: color-mix(in srgb, var(--brand-navy) 10%, transparent);
  text-decoration-color: var(--brand-navy);
  text-decoration-thickness: 2px;
}

.cit-phrase.cit-phrase-unconfirmed:hover,
.cit-phrase.cit-phrase-unconfirmed.cit-hover {
  background-color: color-mix(in srgb, var(--brand-gold) 14%, transparent);
  text-decoration-color: var(--brand-gold);
}

.cit-phrase .rt-abbr {
  text-underline-offset: 0.16em;
}

/* Inline Citation Superscript */
.cit-sup {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--brand-navy);
  background: var(--bg-navy-wash);
  border: 1px solid color-mix(in srgb, var(--brand-navy) 30%, transparent);
  border-radius: 4px;
  padding: 0.02rem 0.32rem;
  margin-inline: 0.15rem;
  vertical-align: super;
  cursor: pointer;
  line-height: 1;
}

.cit-sup:hover,
.cit-sup.cit-hover {
  background: var(--brand-navy);
  color: #fff;
}

[data-theme="dark"] .cit-sup:hover,
[data-theme="dark"] .cit-sup.cit-hover {
  color: #111;
}

/* Biur Section Directly Under Rule (10.5pt David equivalent, full width!) */
.biur-passage-wrap {
  margin-top: 0.75rem;
  padding-top: 0.7rem;
  border-top: 1px solid color-mix(in srgb, var(--border-strong) 55%, transparent);
}

.biur-passage {
  margin: 0;
  font-family: var(--font-biur);
  font-size: calc(1.06rem * var(--scale));
  line-height: 1.78;
  color: var(--ink-secondary);
  text-align: justify;
}

.biur-dh-bold,
.woven-bold {
  font-family: var(--font-makor);
  font-weight: 700;
  color: var(--ink-primary);
}

.kinyan-prompt-banner {
  margin-top: 0.7rem;
  padding: 0.65rem 0.9rem;
  border-radius: 5px;
  background: var(--bg-accent-wash);
  border-right: 3px solid var(--brand-gold);
  font-family: var(--font-biur);
  font-size: calc(0.98rem * var(--scale));
  color: var(--ink-primary);
}

/* Part 4: Two-Column He'arot & Marei Mekomos */
.hearot-section {
  margin-top: 2rem;
}

.sefer-divider-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-family: var(--font-makor);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-secondary);
  margin-bottom: 0.85rem;
}

.sefer-divider-heading::before,
.sefer-divider-heading::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-strong);
}

.hearot-two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem 1.4rem;
}

.heara-item {
  font-family: var(--font-biur);
  font-size: calc(0.94rem * var(--scale));
  line-height: 1.55;
  padding: 0.45rem 0.65rem;
  border-radius: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.heara-item:hover {
  border-color: var(--brand-navy);
}

.heara-num {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.76rem;
  color: var(--brand-navy);
  margin-inline-end: 0.25rem;
}

.heara-ref {
  font-weight: 700;
  color: var(--ink-primary);
}

.badge-verified {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  color: var(--accent-emerald);
  margin-inline-start: 0.25rem;
}

.badge-unconfirmed {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--brand-gold);
  margin-inline-start: 0.25rem;
}

/* Part 5: Boxed Iyunim & Chassidic Parallels */
.iyunim-box {
  margin-top: 2rem;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  overflow: hidden;
}

.iyunim-box-header {
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border-strong);
  padding: 0.5rem 1rem;
  text-align: center;
  font-family: var(--font-makor);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.iyun-card {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-sheet);
}

.iyun-card:last-child {
  border-bottom: none;
}

.iyun-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.stream-pill {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.14rem 0.55rem;
  border-radius: 999px;
  border: 1px solid currentColor;
}

.stream-sochatchov_avnei_nezer { color: var(--stream-sochatchov); }
.stream-kotzk_gur_peshischa { color: var(--stream-kotzk); }
.stream-izhbitz_radzin_lublin { color: var(--stream-izhbitz); }
.stream-maharal { color: var(--stream-maharal); }
.stream-classic_chassidus { color: var(--stream-classic); }
.stream-kabbalah_rishonim { color: var(--stream-kabbalah); }

.iyun-question {
  font-family: var(--font-makor);
  font-size: calc(1.02rem * var(--scale));
  font-weight: 700;
  color: var(--brand-navy);
  margin: 0.25rem 0 0.45rem;
}

.iyun-quote {
  margin: 0.5rem 0;
  padding: 0.55rem 0.85rem;
  background: var(--bg-raised);
  border-right: 3px solid var(--border-strong);
  font-family: var(--font-makor);
  font-size: calc(0.98rem * var(--scale));
  line-height: 1.65;
  color: var(--ink-primary);
}

.iyun-body {
  margin: 0.45rem 0 0;
  font-family: var(--font-biur);
  font-size: calc(1rem * var(--scale));
  line-height: 1.7;
  color: var(--ink-secondary);
}

.iyun-actions {
  margin-top: 0.6rem;
  display: flex;
  gap: 0.6rem;
  align-items: center;
  font-family: var(--font-ui);
  font-size: 0.74rem;
}

.ext-link {
  color: var(--brand-navy);
  text-decoration: none;
  font-weight: 600;
}

.ext-link:hover {
  text-decoration: underline;
}

/* Maamar Footer Navigation & Theme Links */
.maamar-footer-nav {
  margin-top: 2.25rem;
  padding-top: 1.2rem;
  border-top: 1.5px solid var(--border-strong);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

/* Index Pages (Topics, Sources, Themes) */
.index-page-container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.index-hero {
  text-align: center;
  max-width: 780px;
  margin: 0 auto 2rem;
}

.index-hero h2 {
  font-family: var(--font-makor);
  font-size: 2rem;
  margin: 0 0 0.45rem;
}

.index-hero p {
  color: var(--ink-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin: 0 0 1.2rem;
}

.index-subtabs,
.filter-pills {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.subtab-btn,
.pill-filter {
  border: 1px solid var(--border-strong);
  background: var(--bg-sheet);
  color: var(--ink-secondary);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
}

.subtab-btn.active,
.pill-filter.active {
  background: var(--brand-navy);
  color: #fff;
  border-color: var(--brand-navy);
}

[data-theme="dark"] .subtab-btn.active,
[data-theme="dark"] .pill-filter.active {
  color: #111;
}

.index-card {
  background: var(--bg-sheet);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 1.15rem 1.35rem;
  margin-bottom: 0.9rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

.index-card h3 {
  margin: 0 0 0.35rem;
  font-family: var(--font-makor);
  font-size: 1.25rem;
  color: var(--ink-primary);
}

.glossary-def {
  font-family: var(--font-biur);
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--ink-secondary);
  margin: 0 0 0.75rem;
}

.locus-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.locus-chip {
  border: 1px solid var(--border-subtle);
  background: var(--bg-raised);
  color: var(--brand-navy);
  padding: 0.32rem 0.68rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  text-align: right;
}

.locus-chip:hover {
  border-color: var(--brand-navy);
  background: var(--bg-navy-wash);
}

/* Themes Grid */
.themes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 1.4rem;
}

.theme-constellation-card {
  background: var(--bg-sheet);
  border: 1px solid var(--border-sefer-frame);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: var(--shadow-sheet);
}

.pathway-steps {
  margin-top: 1rem;
  border-right: 2px solid var(--brand-gold);
  padding-right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.pathway-step {
  background: var(--bg-raised);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  cursor: pointer;
}

.pathway-step:hover {
  border-color: var(--brand-navy);
}

/* Slide-Over Drawer & Modal */
.toc-backdrop,
.drawer-backdrop,
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 8, 0.45);
  z-index: 60;
}

.source-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(460px, 92vw);
  background: var(--bg-sheet);
  border-right: 1px solid var(--border-strong);
  box-shadow: var(--shadow-drawer);
  z-index: 70;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}

.drawer-header,
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-header h3,
.modal-header h3 {
  margin: 0;
  font-family: var(--font-makor);
  font-size: 1.2rem;
}

.drawer-body,
.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  font-family: var(--font-biur);
  line-height: 1.7;
  overscroll-behavior: contain;
}

.modal-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background: var(--bg-sheet);
  border: 1px solid var(--border-sefer-frame);
  border-radius: 10px;
  max-width: 680px;
  width: 100%;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sheet);
}

.hidden {
  display: none !important;
}

mark.diyuk-mark {
  background: color-mix(in srgb, var(--brand-gold) 28%, transparent);
  color: inherit;
  padding: 0 0.2rem;
  border-radius: 3px;
}

/* Diplomatic-Reversible Paragraph Splits & Lockstep Sub-Segments */
.sub-segments-list {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.sub-segment-block {
  padding-top: 0.35rem;
}

.sub-segment-block + .sub-segment-block {
  border-top: 1px dashed var(--border-subtle);
  padding-top: 0.9rem;
}

.sub-seg-head {
  display: flex;
  align-items: center;
  margin-bottom: 0.28rem;
  padding-inline: 1.35rem;
}

.sub-seg-pill {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--brand-gold);
  background: var(--bg-accent-wash);
  border: 1px solid color-mix(in srgb, var(--brand-gold) 30%, transparent);
  border-radius: 4px;
  padding: 0.04rem 0.42rem;
}

.makor-passage.sub-makor-para + .makor-passage.sub-makor-para {
  margin-top: 0.72rem;
  padding-top: 0.65rem;
  border-top: 1px dashed color-mix(in srgb, var(--border-subtle) 75%, transparent);
}

@media (max-width: 980px) {
  .sub-seg-head {
    padding-inline: 0.25rem;
  }
}

/* Responsive & Print */
@media (max-width: 980px) {
  #view-reader.active {
    grid-template-columns: 1fr;
  }
  .mobile-only {
    display: inline-flex;
  }
  .toc-mobile-bar.mobile-only {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.65rem;
  }
  .top-bar-inner {
    padding: 0.45rem 0.75rem;
    gap: 0.45rem;
  }
  .main-tabs {
    order: 3;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .main-tabs::-webkit-scrollbar {
    display: none;
  }
  .main-tab {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 0.38rem 0.72rem;
  }
  .toc-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100dvh;
    width: min(350px, 88vw);
    z-index: 65;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateX(105%);
    transition: transform 0.2s ease;
  }
  .toc-sidebar.open {
    transform: translateX(0);
    box-shadow: -8px 0 32px rgba(20, 16, 10, 0.22);
  }
  .reader-stage {
    padding: 0.9rem 0.85rem calc(3rem + env(safe-area-inset-bottom));
  }
  .source-drawer {
    height: 100dvh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .hearot-two-col,
  .themes-grid {
    grid-template-columns: 1fr;
  }
  .sefer-sheet {
    padding: 1.4rem 1.2rem;
  }
  .makor-passage {
    padding-inline: 0.25rem;
  }
}

@media (max-width: 640px) {
  .brand-sub {
    display: none;
  }
  .brand-emblem {
    width: 1.9rem;
    height: 1.9rem;
    font-size: 0.88rem;
  }
  .brand-main {
    font-size: 1.08rem;
  }
  .top-bar-inner {
    padding: 0.38rem 0.65rem;
    gap: 0.35rem 0.5rem;
  }
  .toolbar-actions {
    flex: 1;
    min-width: 0;
    justify-content: flex-end;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    gap: 0.3rem;
  }
  .toolbar-actions::-webkit-scrollbar {
    display: none;
  }
  #trust-pill-text {
    display: none;
  }
  .trust-pill {
    padding: 0.38rem 0.5rem;
    flex-shrink: 0;
  }
  .icon-btn {
    padding: 0.32rem 0.5rem;
    font-size: 0.75rem;
    min-height: 34px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .lang-segmented,
  .font-controls {
    flex-shrink: 0;
  }
  .main-tabs {
    padding: 0.18rem;
    gap: 0.2rem;
  }
  .main-tab {
    padding: 0.34rem 0.62rem;
    font-size: 0.78rem;
  }
  .mode-segmented {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  .study-mode-btn {
    padding: 0.42rem 0.3rem;
    font-size: 0.74rem;
    text-align: center;
  }
  .reader-quick-actions {
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }
  .sefer-sheet {
    padding: 1.15rem 0.9rem 1.75rem;
  }
  .running-folio-head {
    font-size: 0.78rem;
    gap: 0.35rem;
    flex-wrap: wrap;
  }
  .makor-passage {
    font-size: calc(1.22rem * var(--scale));
    line-height: 1.88;
    text-align: start;
    padding-inline: 0.15rem;
  }
  .biur-passage {
    text-align: start;
  }
  .kushya-card {
    flex-wrap: wrap;
    gap: 0.35rem 0.5rem;
  }
  .maamar-footer-nav {
    flex-direction: column;
    gap: 0.6rem;
  }
  .maamar-footer-nav .subtle-btn {
    width: 100%;
  }
  .index-page-container {
    padding: 1.25rem 0.85rem 3rem;
  }
  .index-hero h2 {
    font-size: 1.48rem;
  }
  .modal-card {
    max-height: 90dvh;
  }
}

@media print {
  .no-print {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
  }
  .reader-stage {
    padding: 0;
    max-width: 100%;
  }
  .sefer-sheet {
    box-shadow: none;
    border: none;
    padding: 0.5cm;
  }
}
