/*
 * Reading column: the book-like centre pane. Depends on tokens.css.
 *
 *  <article class="reader">
 *    <header class="reader-head">            kicker, display title, meta, pill row
 *    <h2 class="divider"><span>…</span></h2>  tracked caps date/section between rules
 *    <section class="article">
 *      <header class="article-head">          article title + small pills (Listen, Cite, Link)
 *      <div class="prose">…</div>             body text; safe for arbitrary legacy HTML
 *
 * Text size, leading and font follow the reader settings through --reading-size,
 * --reading-leading and --font-reading (tokens.css).
 */

.reader {
  max-width: calc(var(--measure) + 2 * var(--pane-pad-x));
  margin: 0 auto;
  padding: 67px var(--pane-pad-x) 112px;
}

/* ---------------------------------------------------------------------------------------- */
/* Head of a volume / book / section                                                         */
/* ---------------------------------------------------------------------------------------- */
.reader-head { text-align: center; }
.reader-head .kicker { line-height: 16px; }

.display-title {
  margin-top: 14px;
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: -0.005em;
  color: var(--text-title);
  font-variant-numeric: lining-nums;
  text-wrap: balance;
}
.reader-head .meta-caps { margin-top: 14px; line-height: 16px; }
.reader-head .pill-row { margin-top: 23px; }

/* ---------------------------------------------------------------------------------------- */
/* Divider: thin rules either side of a tracked caps heading (dates, parts)                  */
/* ---------------------------------------------------------------------------------------- */
.divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 72px 0 0;
  font-family: var(--font-ui);
  font-size: var(--fs-divider);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: var(--tracking-divider);
  text-transform: uppercase;
  text-align: center;
  color: var(--accent);
  font-variant-numeric: lining-nums tabular-nums;
}
.divider::before,
.divider::after {
  content: "";
  flex: 0 0 40px;
  height: 1px;
  background: var(--border);
}
/* The trailing letter-space would push the text off centre. */
.divider > span { margin-right: calc(-1 * var(--tracking-divider)); }
.divider-sm { --fs-divider: 13px; margin-top: 48px; }
.divider-sm::before, .divider-sm::after { flex-basis: 28px; }

/* ---------------------------------------------------------------------------------------- */
/* Article                                                                                   */
/* ---------------------------------------------------------------------------------------- */
.article { scroll-margin-top: 24px; }
.reader-head + .article { margin-top: 72px; }
.divider + .article { margin-top: 84px; }
.divider-sm + .article { margin-top: 56px; }   /* a smaller divider sits closer to its text */
.article + .article { margin-top: 104px; }
.article + .divider { margin-top: 112px; }

.article-head { text-align: center; }
.article-title {
  font-family: var(--font-display);
  font-size: var(--fs-article-title);
  font-weight: 400;
  line-height: 1.15;
  color: var(--text-title);
  text-wrap: balance;
}
.article-head .pill-row { margin-top: 8px; gap: 6px; }
.article-byline {
  margin-top: 10px;
  font-family: var(--font-reading);
  font-size: var(--fs-lg);
  font-style: italic;
  color: var(--text-muted);
}
.article-head + .prose { margin-top: 92px; }

/* ---------------------------------------------------------------------------------------- */
/* Prose                                                                                     */
/* ---------------------------------------------------------------------------------------- */
.prose {
  font-family: var(--font-reading);
  font-size: var(--reading-size);
  line-height: var(--reading-leading);
  color: var(--text);
  text-align: left;
  hyphens: auto;
  -webkit-hyphens: auto;
  hyphenate-limit-chars: 6 3 3;
  overflow-wrap: break-word;
  font-variant-ligatures: common-ligatures;
  font-kerning: normal;
}
.prose > * + * { margin-top: 0; }
.prose p { margin: 0 0 var(--para-space); }
.prose > :last-child { margin-bottom: 0; }

.prose h1, .prose h2, .prose h3, .prose h4, .prose h5, .prose h6 {
  margin: 1.6em 0 .55em;
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.25;
  color: var(--text-title);
  hyphens: manual;
  text-wrap: balance;
}
.prose h1 { font-size: 1.6em; font-weight: 400; }
.prose h2 { font-size: 1.4em; font-weight: 400; }
.prose h3 { font-size: 1.2em; }
.prose h4 { font-size: 1.05em; }
.prose h5, .prose h6 { font-size: 1em; font-style: italic; font-weight: 400; }
.prose > :first-child { margin-top: 0; }

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .16em;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  overflow-wrap: anywhere;
}
.prose a:hover { text-decoration-color: currentColor; }

.prose strong, .prose b { font-weight: 600; }
.prose em, .prose i, .prose cite { font-style: italic; }
.prose small { font-size: .85em; }
.prose sup, .prose sub { font-size: .7em; line-height: 0; }
.prose u { text-decoration-thickness: 1px; text-underline-offset: .16em; }

.prose blockquote {
  margin: 1.3em 0;
  padding: 0 0 0 1.2em;
  border-left: 2px solid var(--rule);
  color: var(--text);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose ul, .prose ol { margin: 0 0 var(--para-space); padding-left: 1.3em; }
.prose li { padding-left: .15em; }
.prose li + li { margin-top: .3em; }
.prose li > ul, .prose li > ol { margin: .3em 0 0; }
.prose ul > li::marker { color: var(--text-muted); }
.prose ol > li::marker { color: var(--text-muted); font-variant-numeric: lining-nums; font-size: .9em; }

.prose hr {
  width: 96px;
  height: 1px;
  margin: 2.2em auto;
  border: 0;
  background: var(--rule);
}

.prose pre, .prose code, .prose kbd, .prose samp { font-family: var(--font-mono); font-size: .82em; }
.prose pre {
  margin: 1.2em 0;
  padding: 1em 1.1em;
  overflow-x: auto;
  line-height: 1.5;
  background: var(--hover-bg);
  border-radius: var(--radius-sm);
  hyphens: none;
}

/* Media and embeds from legacy HTML: never wider than the column. */
.prose img, .prose svg, .prose video, .prose canvas {
  max-width: 100% !important;
  height: auto !important;
}
.prose img { margin: 1.4em auto; border-radius: 2px; }
.prose p > img:only-child { margin: .2em auto; }
.prose iframe, .prose embed, .prose object, .prose video {
  display: block;
  width: 100% !important;
  max-width: 100%;
  margin: 1.4em 0;
  border: 0;
}
.prose iframe, .prose embed, .prose object {
  height: auto !important;
  aspect-ratio: 16 / 9;
}
.prose figure { margin: 1.6em 0; }
.prose figure img { margin: 0 auto; }
.prose figcaption, .prose caption {
  margin-top: .7em;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  line-height: 1.45;
  text-align: center;
  color: var(--text-muted);
}

/* Tables scroll inside the column instead of widening it. */
.prose table {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 1.4em 0;
  overflow-x: auto;
  font-size: .86em;
  line-height: 1.45;
  border-collapse: collapse;
  hyphens: none;
}
.prose th, .prose td {
  padding: .45em .8em;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.prose th { font-weight: 600; color: var(--text-title); border-bottom-color: var(--rule); }
.prose table[border] td, .prose table[border] th { border: 1px solid var(--border); }

/* Legacy presentational HTML: keep the structure, drop sizes and faces that fight the theme. */
.prose font { font-family: inherit; font-size: inherit; }
.prose center { text-align: center; }
:root[data-theme="dark"] .prose font[color],
:root[data-theme="dark"] .prose [style*="color"] { color: inherit !important; }
:root[data-theme="dark"] .prose [style*="background"],
:root[data-theme="dark"] .prose [bgcolor] { background: transparent !important; }

/* ---------------------------------------------------------------------------------------- */
/* Sanskrit: Devanagari blocks, transliteration, script choice                                */
/* ---------------------------------------------------------------------------------------- */
/* Devanagari needs more room between lines (matras above and below): 1.8 at the normal setting,
   still following the line-spacing setting. Tiro has one weight, so bold is never faked. */
.deva,
.prose :lang(sa),
.prose :lang(hi) {
  font-family: var(--font-deva);
  line-height: calc(var(--reading-leading) * 1.108);
  hyphens: manual;
  font-synthesis-weight: none;
}
.deva { font-size: 1.04em; }
.iast { font-family: var(--font-reading); hyphens: manual; }

/* A verse: lines kept, slightly inset. Its leading follows the setting (see .deva above). */
.verse {
  margin: 1.2em 0;
  padding-left: 1.4em;
  white-space: pre-line;
  hyphens: manual;
}
.verse + .verse { margin-top: .6em; }

/* Tracked capitals are a Latin device. In Indic scripts letter-spacing pulls conjuncts apart, and
   the 10.5–12px caps sizes are too small to read, so these components drop the tracking there.
   (Mark IAST text lang="sa-Latn" if it should keep the caps style.) */
:is(.toc-heading, .kicker, .meta-caps, .divider):is(:lang(sa), :lang(hi), :lang(mr), :lang(ne), :lang(bn), :lang(gu), :lang(pa), :lang(or), :lang(ta), :lang(te), :lang(kn), :lang(ml)):not(:lang(sa-Latn)) {
  --tracking-divider: 0;
  letter-spacing: 0;
  text-transform: none;
  font-synthesis-weight: none;   /* Tiro Devanagari has one weight: never smear a fake bold */
}
/* A Devanagari section heading in the TOC: the Devanagari face at its own weight, a step larger
   than the items (their hierarchy comes from size and colour, not a faux bold). */
.toc-heading:is(:lang(sa), :lang(hi), :lang(mr), :lang(ne)):not(:lang(sa-Latn)) {
  font-family: var(--font-deva);
  font-size: var(--fs-snippet);
  font-weight: 400;
  line-height: 21px;
  color: var(--text-caps);
}
.toc-heading:is(:lang(bn), :lang(gu), :lang(pa), :lang(or), :lang(ta), :lang(te), :lang(kn), :lang(ml)) {
  font-size: var(--fs-ui);
  line-height: 19px;
}

/* Elements that exist in both scripts carry .script-deva / .script-iast; the reader setting
   (html[data-script]) picks which show. Single-script text has neither class and always shows. */
:root[data-script="deva"] .script-iast,
:root[data-script="iast"] .script-deva { display: none; }

/* IAST is Latin: the reading face and leading, also inside a lang="sa" section (:lang(sa) matches
   sa-Latn too, so this follows the Devanagari rule above). */
.prose :lang(sa-Latn),
.article-title:lang(sa-Latn), .article-title :lang(sa-Latn) {
  font-family: var(--font-reading);
  line-height: var(--reading-leading);
  font-synthesis-weight: auto;
}

/* A book's Devanagari written twice inside one block (Views/Design/Reader):
     <p class="verse">[page mark]<span class="script-deva">…</span><span class="script-iast" lang="sa-Latn">…</span></p>
   The page marks stay outside both spans, so the reader's markers never hide. With both scripts
   showing, the IAST sits under its Devanagari, a step smaller and quieter; alone, it is the text. */
:root[data-script="both"] span.script-iast {
  display: block;
  margin-top: .25em;
  font-size: .9em;
  color: var(--text-sidebar);
}
:root[data-script="both"] .article-title span.script-iast {
  margin-top: .4em;
  font-size: .5em;
  letter-spacing: .01em;
}
.article-title .script-iast { line-height: 1.2; }
/* IAST alone: the block's own line box (its strut) is still the Devanagari face's, so it takes the
   reading face and leading too, or the Latin lines would sit 1.8 apart. */
:root[data-script="iast"] .prose :is(p, li, h1, h2, h3, h4):has(> span.script-iast) {
  font-family: var(--font-reading);
  line-height: var(--reading-leading);
}

/* ---------------------------------------------------------------------------------------- */
/* Scanned-book text (OCR, Utils/OcrText): where each page starts, with its folio            */
/*                                                                                            */
/*  <article class="reader book-text">  …                                                     */
/*    <span class="page-mark" id="page-3" data-page="2" role="doc-pagebreak" aria-label="Page 2"> */
/*      <span class="folio" aria-hidden="true" data-find-ignore><span>2</span></span></span>  */
/*                                                                                            */
/* The mark is inline, so a paragraph that runs over a page break stays one paragraph. Its    */
/* folio sits in the column's left margin on the line where the page starts ("·" for an       */
/* unnumbered page), on the same baseline as the text; on phones it becomes a small inline   */
/* tag. The mark is reader.js's [data-page] marker and the target of the TOC's page links.    */
/* ---------------------------------------------------------------------------------------- */
.book-text { position: relative; }

.page-mark { scroll-margin-top: var(--sp-6); }
.page-mark:focus { outline: none; }   /* focused after TOC navigation (tabindex=-1), never ringed */

.folio {
  position: absolute;              /* top: auto keeps it on the mark's line */
  right: calc(100% - var(--pane-pad-x) + 16px);
  font-style: normal;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  text-indent: 0;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
/* With the folio, a short dashed rule between it and the text marks where the page starts (as
   the reference does): the folio alone, especially "·", reads as a speck. */
.folio::after {
  content: "";
  position: absolute;
  left: calc(100% + 9px);
  top: 50%;
  height: 1.15em;
  border-left: 1px dashed var(--rule);
  transform: translateY(-50%);
}
.folio > span {
  font-family: var(--font-ui);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: .02em;
}
/* Devanagari folios (१, २ …) need the Devanagari face and a larger size to read as numbers. */
.folio:is(:lang(sa), :lang(hi), :lang(mr), :lang(ne)) > span {
  font-family: var(--font-deva);
  font-size: var(--fs-md);
  font-weight: 400;
}

/* Verses in a book's text are centred as printed, under their centred speaker lines. */
.book-text .verse { padding-left: 0; text-align: center; }

/* Title pages and other front matter: lines as printed, centred, a step smaller than the text
   (they are mostly set in capitals). */
.text-lines {
  font-size: .84em;
  line-height: calc(var(--reading-leading) * 1.046);   /* 1.7 at the normal line spacing */
  letter-spacing: .03em;
  text-align: center;
  hyphens: manual;
  -webkit-hyphens: manual;
  text-wrap: balance;
}
/* "संजय उवाच": the speaker of the verses that follow. */
.speaker {
  text-align: center;
  font-size: .94em;
  color: var(--text-title);
}
.prose .speaker { margin: 1.5em 0 .6em; }
.prose > .speaker:first-child { margin-top: 0; }
.page-empty { font-style: italic; color: var(--text-muted); }

@media (max-width: 767.98px) {
  .folio { position: static; }
  .folio::after { content: none; }
  .folio > span {
    display: inline-block;
    margin: 0 .2em;
    padding: 0 .4em;
    font-size: var(--fs-2xs);
    line-height: 1.6;
    vertical-align: .12em;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
  }
  /* Inline, a tag would push a centred heading off centre (and the heading marks the page). */
  .page-mark[aria-label="Unnumbered page"] .folio,
  .page-mark[aria-label="Title page"] .folio,
  :is(.divider, .article-title) .folio { display: none; }
}

/* ---------------------------------------------------------------------------------------- */
/* Search / find highlights                                                                  */
/* ---------------------------------------------------------------------------------------- */
mark {
  padding: .04em .12em;
  margin: 0 -.12em;
  color: var(--mark-fg);
  background: var(--mark-bg);
  border-radius: 2px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
mark.is-current, mark[aria-current] {
  background: var(--mark-current-bg);
  color: var(--mark-current-fg);
}

/* ---------------------------------------------------------------------------------------- */
/* Non-reader pages (home, search, account): a plain centred column                          */
/* ---------------------------------------------------------------------------------------- */
.page {
  max-width: calc(880px + 2 * var(--pane-pad-x));
  margin: 0 auto;
  padding: 56px var(--pane-pad-x) 32px;
}
.page-narrow { max-width: calc(var(--measure) + 2 * var(--pane-pad-x)); }
.page-head { margin-bottom: 32px; }
.page-head .kicker { margin-bottom: 12px; }
.page-title {
  font-family: var(--font-display);
  font-size: var(--fs-h2);
  font-weight: 400;
  line-height: 1.2;
  color: var(--text-title);
}
.page-lede { margin-top: 10px; font-size: var(--fs-md); color: var(--text-muted); max-width: 60ch; }

@media (max-width: 767.98px) {
  .reader { padding-top: 40px; padding-bottom: 80px; }
  .display-title { margin-top: 14px; }
  .divider { margin-top: 56px; gap: 12px; }
  .divider::before, .divider::after { flex-basis: 24px; }
  .reader-head + .article, .divider + .article { margin-top: 52px; }
  .divider-sm + .article { margin-top: 36px; }
  .article + .article, .article + .divider { margin-top: 72px; }
  .article-head + .prose { margin-top: 44px; }
  .page { padding-top: 32px; }
}
