/* ============================================
   Analyzing Islam
   Reader page — dedicated reading experience
   Black background, white text, serif display headers.
   ============================================ */

.reader-layout {
  display: grid;
  grid-template-columns: var(--reader-toc-w, 260px) 10px minmax(0, 1fr);
  gap: 0;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 32px;
}

/* Draggable handle between the sticky TOC and the reading column.
   The 10px column is the visible + hittable zone; ::before paints the
   divider line (always subtle, bold accent on hover/drag); ::after
   extends the click target slightly beyond the column so small cursor
   misses still grab the handle. */
.reader-layout > .splitter {
  position: sticky;
  top: 90px;
  align-self: start;
  height: calc(100vh - 90px);
  cursor: col-resize;
  user-select: none;
  touch-action: none;
  z-index: 2;
}
.reader-layout > .splitter::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: var(--border);
  pointer-events: none;
  transition: background 0.15s, width 0.15s;
}
.reader-layout > .splitter:hover::before,
.reader-layout > .splitter:focus-visible::before,
.reader-layout > .splitter.is-dragging::before {
  background: var(--accent);
  width: 3px;
}
.reader-layout > .splitter:focus-visible { outline: none; }

/* --- Collapse + expand arrow for the reader TOC splitter --------------- */
/* When collapsed, the TOC column is 0px and the splitter shows a visible
   arrow button so the user can expand the list back to its default width. */
.reader-layout > .splitter .splitter-expand {
  display: none;
  position: absolute;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 44px;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  font: inherit;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  z-index: 3;
}
.reader-layout > .splitter .splitter-expand svg {
  display: block;
}
.reader-layout > .splitter.is-collapsed .splitter-expand {
  display: flex;
}
.reader-layout > .splitter .splitter-expand:hover,
.reader-layout > .splitter .splitter-expand:focus-visible {
  background: var(--panel-2);
  color: var(--accent);
  border-color: var(--accent);
  outline: none;
}

/* When collapsed the handle widens slightly and drops its line — the
   arrow button is now the visual anchor. */
.reader-layout > .splitter.is-collapsed::before {
  background: transparent;
}

/* When the splitter is collapsed, fully hide the TOC — without this the
   grid column is 0 px but the sidebar's horizontal padding still paints
   a ~40 px ghost strip where the chapter list used to be. :has() lets
   the TOC react to its sibling splitter's state without any JS. */
.reader-layout:has(> .splitter[data-splitter-key="reader-toc"].is-collapsed) > .reader-toc {
  padding-left: 0;
  padding-right: 0;
  visibility: hidden;
  /* Width was already 0 via the CSS var, but border/outline wouldn't be,
     so force it home for browsers that relax grid clamping under padding. */
  width: 0;
  min-width: 0;
}

/* ===== Table of Contents (sticky sidebar) ===== */
.reader-toc {
  position: sticky;
  top: 90px;
  align-self: start;
  height: calc(100vh - 90px);
  overflow-y: auto;
  /* Clip horizontal overflow so a collapsed TOC (column width 0) doesn't
     let its contents spill into the reader column. Left padding is >= the
     negative margin that external readers (tanakh, enoch, mishnah, talmud,
     etc.) apply to their .toc-section labels (currently -12px). */
  overflow-x: hidden;
  padding: 32px 24px 32px 16px;
  /* Divider line moved to the adjacent .splitter so the visual line and
     the draggable zone are in the same place. */
  font-size: 13px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
  box-sizing: border-box;
}

.reader-toc::-webkit-scrollbar { width: 6px; }
.reader-toc::-webkit-scrollbar-thumb { background: var(--border-hover); }
.reader-toc::-webkit-scrollbar-track { background: transparent; }

.reader-toc-header {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  margin-bottom: 16px;
  font-weight: 600;
  padding: 0 8px;
}

/* Floating verse-search box injected by reader-search.js. Lives at the
   top of .reader-toc (or at the top of the reading column when no TOC
   is present). Accepts casual refs — "John 3:16", "Bukhari 2749", … */
.reader-search-wrap {
  padding: 0 8px 14px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.reader-search-bar {
  position: relative;
  display: flex;
}

.reader-search-input {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 36px 8px 10px;
  font-size: 12px;
  font-family: var(--sans);
  border-radius: var(--radius-lg);
}
.reader-search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg);
}
.reader-search-input::placeholder {
  color: var(--text-dim);
}

.reader-search-btn {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 34px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.reader-search-btn:hover,
.reader-search-btn:focus { color: var(--accent); outline: none; }

.reader-search-hint {
  margin-top: 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  color: var(--text-dim);
}
.reader-search-hint--ok   { color: var(--accent); }
.reader-search-hint--miss { color: var(--moderate); }

/* Result picker shown on multi-page index pages (Interlinear Bible,
   Ibn Kathir) — each row links to the specific sub-page + anchor. */
.reader-search-results {
  margin-top: 8px;
  padding: 2px 4px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
}
.reader-search-results[hidden] { display: none; }
.reader-search-results-header {
  padding: 8px 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.reader-search-result {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
}
.reader-search-result:last-child { border-bottom: none; }
.reader-search-result:hover,
.reader-search-result:focus {
  background: var(--panel-2);
  color: var(--accent);
  outline: none;
}
.reader-search-result-ref {
  display: block;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 4px;
}
.reader-search-result-snippet {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}
.reader-search-result mark {
  background: rgba(122, 162, 247, 0.25);
  color: var(--text);
  padding: 0 2px;
}

.reader-toc ol {
  list-style: none;
  padding: 0;
  margin: 0;
}

.reader-toc li {
  margin: 0;
}

.reader-toc a {
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  gap: 10px;
  padding: 5px 10px;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  border-left: 2px solid transparent;
}

.reader-toc a:hover {
  color: var(--text);
  background: var(--panel);
  border-left-color: var(--border-hover);
  text-decoration: none;
}

.reader-toc a.active {
  color: var(--text);
  background: var(--panel);
  border-left-color: var(--accent);
}

.reader-toc .toc-num {
  flex: 0 0 24px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
  font-weight: 600;
}

.reader-toc .toc-name {
  flex: 1;
  font-family: var(--serif);
  font-style: italic;
}

/* ===== Main reading column ===== */
.reader-main {
  padding: 40px 0 80px 48px;
  max-width: 720px;
}

.reader-hero {
  padding: 40px 0 56px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 56px;
}

.reader-meta {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 16px;
}

.reader-hero h1 {
  font-family: var(--serif);
  font-size: clamp(56px, 7vw, 84px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 0 0 24px;
  color: var(--text);
}

.reader-intro {
  font-size: 15px;
  color: var(--text-muted);
  margin: 0 0 28px;
  max-width: 560px;
  line-height: 1.65;
}

.reader-cta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ===== Sūrah block ===== */
.surah {
  margin-bottom: 96px;
  scroll-margin-top: 80px;
  /* Skip rendering off-screen sūrahs to keep splitter drags and scroll
     smooth on long readers (Quran = 114 sūrahs × many verses). */
  content-visibility: auto;
  contain-intrinsic-size: 1px 1200px;
}

.surah-header {
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.surah-number {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 8px;
}

.surah h2 {
  font-family: var(--serif);
  font-size: clamp(36px, 4.5vw, 52px);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.surah-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 500;
}

.surah-bismillah {
  font-family: var(--serif);
  font-style: italic;
  color: var(--accent);
  font-size: 17px;
  letter-spacing: 0.01em;
  margin-top: 18px;
  padding: 0;
}

/* ===== Verses ===== */
.verses {
  list-style: none;
  padding: 0;
  margin: 0;
}

.verses li {
  display: grid;
  grid-template-columns: 36px 1fr;
  column-gap: 20px;
  row-gap: 10px;
  padding: 10px 0;
  margin: 0;
  line-height: 1.8;
  scroll-margin-top: 80px;
  border: none;
  background: transparent;
}

.verses li:target {
  background: rgba(122, 162, 247, 0.08);
  padding-left: 12px;
  border-left: 2px solid var(--accent);
  margin-left: -14px;
}

.verse-number {
  grid-column: 1;
  grid-row: 1 / span 2;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  padding-top: 6px;
  text-align: right;
  user-select: none;
  letter-spacing: 0.04em;
}

.verse-text {
  grid-column: 2;
  grid-row: 1;
  color: var(--text);
  font-size: 16px;
  font-family: var(--sans);
  line-height: 1.8;
}

.verse-arabic {
  grid-column: 2;
  grid-row: 2;
  direction: rtl;
  text-align: right;
  font-family: "Amiri", "Scheherazade New", "Noto Naskh Arabic", serif;
  font-size: 21px;
  line-height: 2.1;
  color: var(--text-dim);
}

.reader-footer {
  margin-top: 80px;
  padding: 32px 0 0;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.7;
}

.reader-footer p { margin: 0; }

/* ==========================================================
   Hadith reader — different structure from the Quran.
   ========================================================== */

.hadith-book {
  margin-bottom: 96px;
  scroll-margin-top: 80px;
  content-visibility: auto;
  contain-intrinsic-size: 1px 1600px;
}

.hadith-book-header {
  margin-bottom: 40px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.hadith-book-number {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 8px;
}

.hadith-book h2 {
  font-family: var(--serif);
  font-size: clamp(32px, 4vw, 44px);
  margin: 0 0 8px;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
}

.hadith-book-subtitle {
  color: var(--text-muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 500;
}

.hadith-book-arabic {
  font-family: "Amiri", "Scheherazade New", "Noto Naskh Arabic", "Traditional Arabic", "Simplified Arabic", serif;
  font-size: 28px;
  color: var(--accent);
  margin: 6px 0 14px;
  line-height: 1.3;
  direction: rtl;
  unicode-bidi: isolate;
}

.hadith-book-body {
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.hadith {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  scroll-margin-top: 80px;
}

.hadith:first-child {
  border-top: none;
  padding-top: 0;
}

.hadith-header {
  margin-bottom: 12px;
}

.hadith-ref {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.hadith-body {
  color: var(--text);
  font-size: 16px;
  line-height: 1.8;
}

.hadith-narrator {
  font-family: var(--serif);
  font-style: italic;
  color: var(--accent);
  font-size: 15px;
  margin-bottom: 12px;
  letter-spacing: 0.01em;
}

.hadith-body p {
  margin: 0 0 12px;
  color: var(--text);
}

.hadith-body p:last-child {
  margin-bottom: 0;
}

/* Arabic text rendered under the English translation — muted, RTL, spacious. */
.hadith-body p.hadith-arabic {
  direction: rtl;
  text-align: right;
  font-family: "Amiri", "Scheherazade New", "Noto Naskh Arabic", serif;
  font-size: 19px;
  line-height: 2.1;
  color: var(--text-dim);
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.hadith:target {
  background: rgba(122, 162, 247, 0.05);
  margin-left: -16px;
  padding-left: 16px;
  border-left: 2px solid var(--accent);
}

/* ==========================================================
   PDF-embed reader — for sources where OCR quality makes
   native HTML rendering unusable (Abu Dawud, Tirmidhi, Nasa'i,
   Ibn Majah — all scanned Darussalam editions).
   ========================================================== */

.pdf-reader-layout {
  max-width: 1600px;
  margin: 0 auto;
  padding: 32px 32px 0;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 72px);
}

.pdf-reader-header {
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  flex-wrap: wrap;
}

.pdf-reader-meta {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 10px;
}

.pdf-reader-header h1 {
  font-family: var(--serif);
  font-size: clamp(30px, 4vw, 44px);
  margin: 0;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.pdf-reader-header p {
  color: var(--text-muted);
  margin: 8px 0 0;
  font-size: 14px;
  max-width: 560px;
}

.pdf-reader-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.pdf-reader-frame {
  flex: 1;
  border: 1px solid var(--border);
  background: #2b2b2b;
  width: 100%;
  min-height: 1100px;
  margin-bottom: 32px;
}

.pdf-reader-note {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}

.pdf-reader-note strong {
  color: var(--text);
}

/* Mobile fallback: large button shown instead of the iframe. */
.pdf-reader-mobile-open {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  min-height: 260px;
  padding: 48px 24px;
  margin-bottom: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}

.pdf-reader-mobile-open:hover,
.pdf-reader-mobile-open:active {
  background: #1a1a1a;
  border-color: var(--accent);
  text-decoration: none;
  color: var(--text);
}

.pdf-reader-mobile-open-icon {
  font-size: 48px;
  line-height: 1;
}

.pdf-reader-mobile-open-label {
  font-family: var(--sans);
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
}

.pdf-reader-mobile-open-hint {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 420px;
  line-height: 1.5;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .reader-layout {
    grid-template-columns: 1fr;
    padding: 0 20px;
  }
  .reader-layout > .splitter {
    display: none;
  }
  .reader-toc {
    position: static;
    height: auto;
    max-height: 280px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    /* Horizontal padding here absorbs the negative margin-left used by
       .toc-section labels on external-source readers; without it, "INFANCY
       GOSPEL OF JAMES" and similar section labels would clip off the
       left edge on phones. */
    padding: 20px 16px;
    overflow-x: hidden;
  }
  .reader-main {
    padding: 24px 0 60px;
  }
  .reader-hero h1 {
    font-size: clamp(40px, 11vw, 64px);
  }
  .surah h2 {
    font-size: clamp(28px, 7vw, 40px);
  }
}

/* External link affordance on per-hadith reference labels. Rendered via
   ::after (generated content) so it is NOT a DOM text node and does not
   shift saved-highlight character offsets inside an article. */
.hadith-ref a { text-decoration: none; }

/* Previous / Next pager — flex so the two controls sit at opposite ends with a
   clear gap between them (otherwise "Previous" and "Next" render merged). */
.reader-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.reader-pager-prev,
.reader-pager-next {
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}
.reader-pager-next { margin-left: auto; }
.reader-pager-prev:hover,
.reader-pager-next:hover { text-decoration: underline; }
.reader-pager-prev.is-disabled,
.reader-pager-next.is-disabled {
  color: var(--muted);
  opacity: 0.5;
  pointer-events: none;
}
.hadith-ref a::after { content: " 97"; font-size: 0.85em; opacity: 0.7; }
