/* The reader (design.md 4, 7.3, 7.4, 7.5). Plain CSS on the design tokens; logical properties only, so RTL mirrors itself. */
/* Gentium second: Latin letters and digits inside Arabic/Persian text stay in the reading serif, not the UI sans. */
:root { --read-size: 19px; --font-naskh: "Noto Naskh Arabic", "Gentium Book Plus", "Segoe UI", "Traditional Arabic", "Geeza Pro", serif; }
@media (max-width: 767px) { :root { --read-size: 18px; } }

.reader { max-inline-size: 68ch; font-family: var(--font-read); font-size: var(--read-size); line-height: 1.65; color: var(--ink); }
.reader a { color: var(--link); text-decoration: underline; text-underline-offset: 3px; }

/* Running head: author at the start, title at the end, hairline below. */
.running-head { position: sticky; inset-block-start: 0; z-index: 1; display: flex; justify-content: space-between; gap: 1rem; padding-block: .75rem .5rem;
  background: var(--page); border-block-end: 1px solid var(--rule); font-size: 15px; line-height: 20px; font-style: italic; color: var(--ink-2); }
.running-head span { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Title block: first screen only. */
.book-head { margin-block: 3rem 2.5rem; text-align: center; }
.book-author { font: 600 13px/16px var(--font-ui); font-variant-caps: all-small-caps; letter-spacing: .14em; text-transform: none; color: var(--ink-2); margin: 0; }
.book-head h1 { font-size: 34px; line-height: 1.15; font-weight: 400; margin: .5rem 0 .75rem; }
.book-meta { font: 13px/18px var(--font-ui); color: var(--ink-2); margin: 0; }
.book-actions { margin-block-start: .75rem; display: flex; justify-content: center; gap: .5rem; font-family: var(--font-ui); }

/* Text. Paragraphs run on as the index stores them; one line between. */
.reader article { overflow-wrap: anywhere; }
.reader article p { margin-block: 0 1lh; text-wrap: pretty; }
.book-head h1, .toc h1, .toc h2, .toc h3 { text-wrap: balance; }
.reader article .RTL { direction: rtl; }
.reader article p.num { text-align: center; margin-block: 1.5lh .25lh; font-size: 15px; line-height: 20px; letter-spacing: .2em; color: var(--ink-2); }
/* Script faces apply to the text and to the title and running head, which carry the book's lang too. */
.reader :is([lang="ar"], [lang="fa"]) { font-family: var(--font-naskh); }
.reader article:is([lang="ar"], [lang="fa"]) { font-size: calc(var(--read-size) * 1.15); line-height: 1.9; }
.book-head h1:is([lang="ar"], [lang="fa"]) { line-height: 1.5; } /* Naskh's tall marks need more than 1.15 when a title wraps */
.reader:has(article[lang="ja"]), .reader:has(article[lang="zh-Hans"]), .reader:has(article[lang="zh-Hant"]), .reader:has(article[lang="ko"]) { max-inline-size: 38em; }
.reader [lang="ja"] { font-family: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif; }
.reader [lang="zh-Hans"] { font-family: "Songti SC", "SimSun", "Noto Serif SC", serif; }
.reader [lang="zh-Hant"] { font-family: "PMingLiU", "Noto Serif TC", serif; }
.reader [lang="ko"] { font-family: "Batang", "Noto Serif KR", serif; }
/* These scripts have no true italic; slanting them is a fake. The running head sets them upright. */
.running-head :is([lang="ar"], [lang="fa"], [lang="ja"], [lang="zh-Hans"], [lang="zh-Hant"], [lang="ko"]) { font-style: normal; }
.reader article[lang="ja"], .reader article[lang="zh-Hans"], .reader article[lang="zh-Hant"], .reader article[lang="ko"] { line-height: 1.9; text-align: justify; line-break: strict; }

/* End of book. */
.book-end { margin-block: 3rem 2rem; font: 15px/1.6 var(--font-ui); color: var(--ink-2); text-align: center; }
.end-rule { display: flex; align-items: center; gap: 1rem; margin: 0 0 1.25rem; }
.end-rule::before, .end-rule::after { content: ""; flex: 1; border-block-start: 1px solid var(--rule); }
.more-by { margin: .5rem 0; }
.more-by > span { margin-inline-end: .5rem; }
.more-by a + a::before { content: " · "; color: var(--ink-2); text-decoration: none; display: inline-block; }

/* Full table of contents: crawlable plain HTML, two columns from xl. */
.toc { font-family: var(--font-ui); }
.toc h1 { font-weight: 400; } /* page titles are regular, as the book title is */
.toc h2 { font-size: 1rem; font-weight: 600; margin: 1.5rem 0 .25rem; color: var(--ink); break-after: avoid; }
.toc h3 { font-size: .875rem; font-weight: 600; margin: .75rem 0 .125rem; color: var(--ink-2); break-after: avoid; }
.toc ul { margin: 0; padding: 0; list-style: none; }
.toc li { font-size: .875rem; line-height: 1.5; padding-block: 1px; text-wrap: pretty; }
.toc a { color: var(--link); text-decoration: underline; text-underline-offset: 3px; }
.toc-group { break-inside: auto; }
@media (min-width: 1280px) { .toc-body { column-count: 2; column-gap: 3rem; } }

@media print { .running-head, .book-actions { display: none; } .reader { max-inline-size: none; } }
