/* books.css — what only the book viewers have: page sections, OCR block types and positions,
   the scan toggle, "not transcribed" pages and one-page-per-sheet printing. Everything shared is
   in base.css. */
body.book {
  --sidebar-w: 300px;
  --content-max: 1100px;
  --fs-urdu: 22px;
  --fs-arabic: 22px;
  --fs-persian: 21px;
  --fs-latin-block: 16px;
  --fs-trans: 15px;
}
.book .main { padding: var(--space-6) 48px; }
.book .aligned { gap: 14px var(--space-6); margin-top: 18px; }
.book .aligned .trans-cell.empty { font-size: var(--fs-m); padding-top: var(--space-1); }

.page { padding: 28px var(--space-6); margin-bottom: var(--space-6); scroll-margin-top: var(--space-4); }
.page-header { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-3); }
.page-header h2 { margin: 0; font-size: 22px; color: var(--accent-2); display: flex; align-items: baseline; gap: var(--space-3); }
.page-header h2 .ur { font-weight: 500; font-size: 22px; line-height: 1.9; }  /* dir="rtl" header: Urdu on the right */
.page-header h2 .en { font-size: var(--fs-m); font-weight: 600; color: var(--fg-2); letter-spacing: 0.03em; }
.page.missing { border-color: var(--red); border-style: dashed; }
.missing-banner { margin-bottom: var(--space-3); }
.missing-note { color: var(--fg-2); text-align: center; margin: var(--space-4) 0; }
.missing-note [lang="ur"] { display: block; font-family: var(--font-ur); font-size: 17px; line-height: 2; }
.missing-note [lang="en"] { display: block; font-size: var(--fs-m); }
.missing-error { opacity: 0.75; }
.sb-num { font-weight: 500; }
.sb-item { font-size: 13px; }
.sb-item.missing .sb-num { color: var(--red); }

/* Printed vs PDF numbering: the PDF page is a quiet hint where they differ. */
.pdf-num { font: 11px var(--font-mono); color: var(--fg-2); border: 1px solid var(--border); border-radius: var(--radius-s); padding: 1px 6px; }
.page.front .page-header h2 { color: var(--fg-2); }

/* ─── Book head + contents (main column) and the contents rail ─────────────────────────────────
   One tree markup for both (book.html `entry`): a number column (masala / surah number, Western digits), the Urdu
   title in Nastaliq with its English below; no page numbers or dot leaders (the page is the row's tooltip). */
.book-head { text-align: center; margin: 0 auto var(--space-5); }
.book-head h1 { margin: 0; font-weight: 400; }
.book-head h1 .ur { display: block; font-size: var(--fs-ur-h1); font-weight: 600; color: var(--accent-2); line-height: var(--lh-ur-tight); }
.book-head h1 .en { display: block; font-size: var(--fs-h3); color: var(--fg-2); letter-spacing: 0.03em; }
.book-by { margin: var(--space-2) 0 0; color: var(--fg-2); font-size: var(--fs-small); }
.book-by [lang="ur"] { font-size: var(--fs-ur-caption); }

.book-toc { padding: var(--space-4) var(--space-6); margin-bottom: var(--space-6); }
.book-toc > summary { cursor: pointer; display: flex; align-items: baseline; gap: var(--space-3); color: var(--accent-2); }
.book-toc > summary .ur { font-size: var(--fs-ur-h3); font-weight: 600; }
.book-toc > summary .en { font-size: var(--fs-small); font-weight: 600; color: var(--fg-2); text-transform: uppercase; letter-spacing: 0.06em; }
.toc-main { columns: 2 380px; column-gap: var(--space-6); margin-top: var(--space-3); }
.toc-sec { break-inside: avoid-column; margin-bottom: var(--space-2); }
.toc-items { list-style: none; margin: 0; padding: 0; }
.toc-row, .rail-link {
  display: grid; grid-template-columns: 2.2em minmax(0, 1fr); column-gap: var(--space-2); align-items: baseline;
  padding: 3px var(--space-2); border-radius: var(--radius-s); text-decoration: none; color: inherit;
  border-inline-start: 3px solid transparent;
}
a.toc-row:hover, a.rail-link:hover { background: var(--bg-3); }
.toc-num { grid-column: 1; font-size: var(--fs-caption); font-weight: 600; color: var(--fg-2); text-align: center; font-variant-numeric: tabular-nums; }
.toc-t { grid-column: 2; display: flex; flex-direction: column; min-width: 0; }
.toc-ur { font-family: var(--font-ur); font-size: var(--fs-ur-small); line-height: 1.95; color: var(--fg); }
.toc-en { font-size: var(--fs-caption); line-height: 1.4; color: var(--fg-2); text-align: left; padding-bottom: 3px; }
.lvl-0 > .toc-t .toc-ur { font-weight: 600; color: var(--accent-2); }
.lvl-0.k-front > .toc-t .toc-ur, .lvl-0.k-front > .toc-t .toc-ur { font-weight: 500; color: var(--fg); }
.toc-items .toc-row, .toc-items .rail-link { padding-inline-start: var(--space-4); }
.toc-nolink { opacity: 0.6; }

/* The rail */
body.book .sidebar.book-rail { gap: var(--space-2); }
.rail-title { margin: var(--space-1) 0 0; text-align: center; font-weight: 400; }
.rail-title .ur { display: block; font-size: var(--fs-ur-h3); font-weight: 600; color: var(--accent-2); line-height: var(--lh-ur-tight); }
.rail-title .en { display: block; font-size: var(--fs-caption); color: var(--fg-2); text-transform: uppercase; letter-spacing: 0.08em; }
.rail-list { padding-top: var(--space-2); }
.goto { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); font-size: var(--fs-caption); color: var(--fg-2); }
.goto [lang="ur"] { font-size: var(--fs-ur-caption); }
.goto input { width: 5em; font: var(--fs-small) var(--font-en); text-align: center; padding: 3px 6px; color: var(--fg);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-s); }
.rail-h { margin: 0 0 var(--space-1); font-size: var(--fs-caption); color: var(--fg-2); text-transform: uppercase; letter-spacing: 0.06em; text-align: right; }
.rail-h [lang="ur"] { font-size: var(--fs-ur-caption); text-transform: none; }
.rail-tree .toc-ur { font-size: 15.5px; line-height: 1.9; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rail-tree .toc-en { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rail-head { display: flex; align-items: center; gap: 2px; }
.rail-head > .rail-link { flex: 1 1 auto; }
.rail-tog { flex: 0 0 auto; width: 26px; height: 26px; padding: 0; border: 0; border-radius: var(--radius-s); background: none;
  color: var(--fg-2); cursor: pointer; font: 16px/1 var(--font-en); }
.rail-tog::before { content: "‹"; display: inline-block; transition: transform var(--dur); }
.rail-sec.open .rail-tog::before { transform: rotate(-90deg); }
.rail-tog:hover { background: var(--bg-3); color: var(--accent); }
.rail-link.current { background: var(--bg-3); border-inline-start-color: var(--accent); }
.rail-link.current .toc-ur { color: var(--accent-2); font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .rail-tog::before { transition: none; } }
/* landing highlight after a contents / go-to jump */
.page.flash { animation: page-flash 1.2s ease-out; }
@keyframes page-flash { from { box-shadow: 0 0 0 3px var(--accent), var(--shadow); } to { box-shadow: var(--shadow); } }
@media (prefers-reduced-motion: reduce) { .page.flash { animation: none; } }

/* Page footer: confidence, flags, reading order, notes, scan — below the text. */
.page-footer {
  margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: var(--space-3);
}
.footer-meta { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.scan-toggle img {
  display: block; max-width: 100%; height: auto; margin-top: var(--space-2);
  border: 1px solid var(--border); border-radius: var(--radius-s); background: #fff;
}

/* ─── The original column, set like the printed page ─────────────────────────────────────────
   Urdu in Nastaliq, Arabic (whole blocks and inline quotations) in Naskh as the book prints it; justified
   with an even, generous leading. The OCR's printed line ends (`.nl-mark`, see inline.py) are hidden so
   a paragraph flows and justifies; `.nl-end` (sentence-final line ends, and every line of poetry, headings
   and short-line blocks) stays a hard break. On wide screens the column is a sheet of paper: each row's
   cell carries the sheet's sides, the first and last its top and bottom, so the rows stay level with
   the English. */
body.book {
  --font-ar-book: 'Amiri', 'Noto Naskh Arabic', serif;
  --fs-urdu: 21px;   --lh-urdu: 2.25;
  --fs-arabic: 22px; --lh-arabic: 2;
  --fs-persian: 21px;
  --sheet-bg: color-mix(in srgb, var(--bg-3) 40%, var(--bg-2));
  --sheet-pad: 30px;
}
.book .orig-cell .block[dir="rtl"] {
  text-align: justify; text-align-last: start; word-spacing: 0.06em; hyphens: none;
}
.book .orig-cell .block[dir="rtl"] p { margin: 0; }
.book .orig-cell .block:last-child { margin-bottom: 0; }
.book .orig-cell .block.script-arabic { font-family: var(--font-ar-book); font-weight: 500; word-spacing: 0; }
.book .orig-cell :is(.inline-arabic, .semantic-quran, .semantic-hadith, .semantic-dua) {
  font-family: var(--font-ar-book); font-weight: 500;
}
.book .orig-cell .script-urdu :is(.inline-arabic, .semantic-quran, .semantic-hadith, .semantic-dua) { font-size: 0.98em; }
/* Inline runs in another face must not stretch the Nastaliq line box: keep the leading even. */
.book .orig-cell :is(.inline-arabic, .inline-persian, .inline-urdu, .semantic-quran, .semantic-hadith,
  .semantic-dua, .semantic-quran_translation, .semantic-hadith_translation, .ref) { line-height: 1; }
/* Quotations as printed: no box, the Quran a quiet green, its reference a small superscript. */
.book .orig-cell :is(.semantic-quran, .semantic-hadith) { background: none; border: 0; padding: 0; border-radius: 0; }
.book .orig-cell .semantic-dua { background: none; padding: 0; }
.book .orig-cell .semantic-quran .ref, .book .orig-cell .semantic-hadith .ref { font-weight: 500; opacity: 0.8; }

/* Printed line ends: hidden (the space before each keeps the words apart); `nl-end` is a hard break. */
.book .orig-cell .nl-mark { display: none; }
.book .orig-cell .nl-mark.nl-end { display: block; height: 0; overflow: hidden; }
/* Proofreading toggle (sidebar): show where each printed line ended. */
.book.show-breaks .orig-cell .nl-mark { display: inline; color: var(--accent); font-size: 0.75em; margin-inline-end: 0.3em; }
.book.show-breaks .orig-cell .nl-mark.nl-end { height: auto; overflow: visible; }
.book.show-breaks .orig-cell .nl-mark.nl-end::after { content: "\A"; white-space: pre; }
.sb-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-2); margin: 6px 0 2px; cursor: pointer; }
.sb-toggle .nl-sample { color: var(--accent); }

/* Headings centred, as printed. */
.book .orig-cell .block-heading { text-align: center !important; text-align-last: center !important; }
.book .block-heading h4 { margin: 0; color: var(--accent-2); font-size: 1.3em; font-weight: 600; line-height: inherit; }
.book .block-heading.script-arabic h4 { font-weight: 700; }
/* Quotations indented from the start edge (Fatawa), or centred (Khulasa's du'as and ayat). */
.book .orig-cell .block-quote {
  margin: 0 0 var(--space-3); margin-inline-start: 1.6em; padding: 0;
  background: none; border: 0; border-radius: 0;
}
.book .orig-cell .block-quote[dir="ltr"] { border: 0; }
.book [data-book="khulasa-tafseer"] .orig-cell .block-quote.block { margin-inline-start: 0; text-align: center; text-align-last: center; }
/* Poetry: centred lines (each misra a hard break). */
.book .block-poetry pre { font-family: inherit; font-size: inherit; line-height: inherit; white-space: normal; margin: 0; text-align: center; text-align-last: center; }
.book .orig-cell .block-calligraphy { text-align: center !important; text-align-last: center !important; }
.block-calligraphy .calligraphy { font-size: 1.35em; color: var(--accent-2); font-weight: 600; }
/* Footnotes: smaller, under a hairline; Nastaliq has no italic, so no slant. */
.book .orig-cell :is(.block-footnote, .block-margin_note) {
  font-size: 16px; line-height: 2.1; color: var(--fg-2);
  border-top: 1px solid var(--rule); padding-top: var(--space-1); margin-top: var(--space-1);
}
.book .orig-cell :is(.block-footnote, .block-margin_note) em { font-style: normal; }
.book .orig-cell .block-footnote + .block-footnote,
.book .row:has(.block-footnote) + .row .block-footnote { border-top: 0; margin-top: 0; padding-top: 0; }
.block-margin_note, .block-footnote { font-size: 13px; color: var(--fg-2); }
.pos-overflow_margin { background: var(--warn-bg); padding: var(--space-1) var(--space-2); border-radius: var(--radius-s); }
.pos-top, .pos-bottom, .pos-left, .pos-right { font-size: 0.95em; }

/* Page furniture (running header, page number, catchword): small and centred like the printed head,
   ruled off from the text by a hairline (`furniture-head` / `furniture-foot` rows, see body.py). */
.book .orig-cell :is(.block-page_number, .block-page_header, .block-catchword) {
  font-size: 14px; line-height: 1.8; color: var(--fg-2); text-align: center !important; text-align-last: center !important;
  margin-bottom: 0;
}
.book .orig-cell :is(.block-page_number, .block-page_header, .block-catchword).script-urdu { font-size: 16px; line-height: 2.1; }
.book .orig-cell :is(.block-page_number, .block-page_header, .block-catchword).script-arabic { font-size: 16px; line-height: 2; }
.book .orig-cell :is(.block-page_number, .block-page_header, .block-catchword) code { font: inherit; color: inherit; background: none; padding: 0; }
.book .orig-cell .block-page_number.script-english { font-family: var(--font-en); font-size: 15px; }
.book .orig-cell :is(.block-page_header, .block-catchword).pos-right { text-align: right !important; text-align-last: right !important; }
.book .orig-cell :is(.block-page_header, .block-catchword).pos-left { text-align: left !important; text-align-last: left !important; }
.book .aligned .row:is(.furniture-head, .furniture-foot) > * { padding-top: 2px; padding-bottom: 2px; }
.book .aligned .row:is(.furniture-head, .furniture-foot) > .trans-cell { color: var(--fg-2); }
.book .aligned .row:is(.furniture-head, .furniture-foot) > .trans-cell p { font-size: 13px; margin: 0; }
.book .aligned .row.furniture-head + .row:not(.furniture-head) > .orig-cell,
.book .aligned .row:not(.furniture-foot) + .row.furniture-foot > .orig-cell { position: relative; }
.book .aligned .row.furniture-head + .row:not(.furniture-head) > .orig-cell::before,
.book .aligned .row:not(.furniture-foot) + .row.furniture-foot > .orig-cell::before {
  content: ""; position: absolute; top: 0; inset-inline: var(--sheet-pad); border-top: 1px solid var(--fg-2); opacity: 0.45;
}
.book .aligned .row.furniture-head + .row:not(.furniture-head) > * { padding-top: var(--space-4); }

/* Alignment labels ("↳ blocks 3"): kept for proofreading, shown only when the English is hovered. */
.book .aligned .trans-cell { position: relative; }
.book .aligned .trans-refs {
  position: absolute; top: 0; right: 0; opacity: 0; pointer-events: none; transition: opacity 0.15s;
}
.book .aligned .trans-cell:hover .trans-refs { opacity: 0.75; }
.book .aligned .trans-cell p { line-height: 1.7; }

/* Wide screens: rows touch (padding instead of the grid gap) so the original column reads as one sheet. */
@media screen and (min-width: 1101px) {
  .book .aligned { row-gap: 0; }
  .book .aligned .trans-cell { padding: 12px 0 14px; }
  .book .aligned .orig-cell {
    padding: 12px var(--sheet-pad) 14px; border-bottom: 0;
    background: var(--sheet-bg); border-inline: 1px solid var(--border);
  }
  .book .aligned > .orig-col-header + .row > .orig-cell {
    border-top: 1px solid var(--border); border-radius: var(--radius-m) var(--radius-m) 0 0; padding-top: 22px;
  }
  .book .aligned > .orig-col-header + .row > .trans-cell { padding-top: 22px; }
  .book .aligned > .row:last-child > .orig-cell {
    border-bottom: 1px solid var(--border); border-radius: 0 0 var(--radius-m) var(--radius-m); padding-bottom: 24px;
  }
  .book .aligned > .orig-col-header + .row:last-child > .orig-cell { border-radius: var(--radius-m); }
  .book .aligned .orig-col-header { padding-inline-end: var(--sheet-pad); border-bottom: 0; }
  .book .aligned .trans-col-header { border-bottom: 0; }
}

/* ─── فہرست pages: a two-language contents table (tocpage.py) ──────────────────────────────
   Same columns as the study view (English left, Urdu right on the sheet); each side reads
   `no. · title ····· page`. The OCR rows of the page stay in the `.toc-ocr` disclosure below. */
.toc-page-title { margin: var(--space-2) 0 0; text-align: center; color: var(--accent-2); font-weight: 600; display: flex; justify-content: center; align-items: baseline; gap: var(--space-3); }
.toc-page-title [lang="ur"] { font-family: var(--font-ur); font-size: 26px; line-height: 2; }
.toc-page-title .en { font-size: var(--fs-m); color: var(--fg-2); letter-spacing: 0.04em; }
.toc-page { display: grid; grid-template-columns: 1fr 1.1fr; column-gap: var(--space-6); margin-top: 18px; }
.tp-row { display: contents; color: inherit; text-decoration: none; }
.tp-en, .tp-ur { padding: 2px 0; min-width: 0; }
.tp-in { display: flex; align-items: baseline; gap: 10px; }
.tp-en { font-size: 14px; line-height: 1.55; padding-top: 6px; padding-bottom: 6px; }
.tp-ur { font-family: var(--font-ur); font-size: 18px; line-height: 2.1; }
.tp-no { flex: 0 0 2em; color: var(--fg-2); font: 13px var(--font-en); font-variant-numeric: tabular-nums; }
.tp-title { flex: 0 1 auto; min-width: 0; }
.tp-head .tp-title { flex: 1 1 auto; }
.tp-lead { flex: 1 1 1.5em; min-width: 1.5em; height: 0; border-bottom: 2px dotted var(--fg-2); opacity: 0.45; }
.tp-pg { flex: 0 0 auto; min-width: 2.2em; text-align: end; font: 600 13px var(--font-en); color: var(--accent-2); font-variant-numeric: tabular-nums; }
.tp-head > div { font: 600 11px var(--font-en); letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-2); padding-top: 0; padding-bottom: 6px; border-bottom: 1px solid var(--rule); }
.tp-head .tp-ur { font: 500 14px var(--font-ur); line-height: 2.2; letter-spacing: 0; text-transform: none; }
.tp-head .tp-pg, .tp-head .tp-no { font: inherit; color: inherit; }
.tp-group > div { padding-top: var(--space-3); }
.tp-group .tp-title { font-weight: 600; color: var(--accent-2); }
.tp-group .tp-ur .tp-title { font-weight: 600; font-size: 19px; }
a.tp-row:hover > div { background: var(--bg-3); }
a.tp-row:hover .tp-title { text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 4px; }
.toc-ocr { margin-top: var(--space-5); }
@media screen and (min-width: 1101px) {
  .tp-ur { background: var(--sheet-bg); border-inline: 1px solid var(--border); padding-inline: var(--sheet-pad); }
  .tp-head > .tp-ur { border-top: 1px solid var(--border); border-radius: var(--radius-m) var(--radius-m) 0 0; padding-top: 10px; }
  .toc-page > .tp-row:last-child > .tp-ur { border-bottom: 1px solid var(--border); border-radius: 0 0 var(--radius-m) var(--radius-m); padding-bottom: 14px; }
  .tp-head > .tp-ur { border-bottom-color: var(--rule); }
}
@media screen and (max-width: 1100px) {
  .toc-page { display: block; }
  .tp-row { display: flex; flex-direction: column; padding: 4px 0; border-bottom: 1px dashed var(--rule); }
  .tp-row > .tp-ur { order: -1; }
  /* the English title under the Urdu, right-aligned (RTL list); number, leader and page are the Urdu's */
  .tp-row > .tp-en { padding-top: 0; color: var(--fg-2); text-align: left; font-size: 13px; }
  .tp-row > .tp-en .tp-in { justify-content: flex-end; padding-inline-end: calc(2em + 10px); }
  .tp-en :is(.tp-no, .tp-lead, .tp-pg) { display: none; }
  .tp-head > .tp-en { display: none; }
  .tp-head > div { border-bottom: 0; }
}

/* Narrow screens: the page list goes above the book (not after ~600 pages), kept short. */
@media screen and (max-width: 1100px) {
  .book .sidebar { order: -1; border-top: none; border-bottom: 1px solid var(--border); }
  .book .sb-list { max-height: 30vh; }
}
@media (max-width: 720px) {
  .book .main { padding: var(--space-3) var(--space-2); }
  .page { padding: var(--space-4); margin-bottom: var(--space-4); }
  body.book { --fs-urdu: 19px; --fs-arabic: 20px; --lh-urdu: 2.2; --sheet-pad: 0px; }
  .book .orig-cell .block-quote { margin-inline-start: 0.8em; }
}

@media print {
  body.book { font-size: 10.5pt; }
  .page { break-inside: avoid; page-break-inside: avoid; break-after: page; page-break-after: always; }
  .page:last-of-type { break-after: auto; page-break-after: auto; }
  .page-header { border-bottom: 1px solid #888; padding-bottom: 6pt; margin-bottom: 8pt; }
  .page-header h2 { font-size: 15pt; }
  .page-footer { margin-top: 10pt; }
  .scan-toggle { display: none !important; }
  .book-toc { break-after: page; }
  .book .block-heading h4 { font-size: 1.25em; }
  .block-calligraphy .calligraphy { font-size: 20pt; }
  /* Nastaliq needs more leading than base.css's print default */
  .book .orig-cell :is(.script-urdu, .script-persian, .block.script-mixed[dir="rtl"]) { font-size: 13.5pt; line-height: 2.15; }
  .book .orig-cell .script-arabic { font-size: 14pt; line-height: 1.9; }
  .book .orig-cell :is(.block-footnote, .block-margin_note) { font-size: 11pt; line-height: 2; }
  .book .orig-cell :is(.block-page_number, .block-page_header, .block-catchword) { font-size: 10pt; line-height: 1.8; }
  .book .trans-refs, .sb-toggle, .toc-ocr { display: none !important; }
  .toc-page { grid-template-columns: 1fr 1.05fr; column-gap: 22pt; }
  .tp-ur { font-size: 12.5pt; line-height: 2; } .tp-en { font-size: 9.5pt; }
  /* a hairline between the two columns: the gap alone is not enough on paper */
  .aligned {
    background-image: linear-gradient(to bottom, #999 0, #999 100%) !important;
    background-repeat: no-repeat !important;
    background-position: calc(50% - 11pt) 18pt !important;
    background-size: 0.4pt calc(100% - 36pt) !important;
  }
}

/* Under the mode bar (base.css .mode-bar): the sticky rail and page anchors sit below it. */
body.book.has-modebar .sidebar { top: calc(var(--header-offset, 0px) + var(--modebar-h)); height: calc(100vh - var(--header-offset, 0px) - var(--modebar-h)); }
body.book.has-modebar .page { scroll-margin-top: calc(var(--modebar-h) + var(--space-4)); }
body.book.has-modebar .book-toc { scroll-margin-top: var(--modebar-h); }
