/* libible — plain reading layout. System fonts only, no JS, and no colour
   except red letters for the words of Jesus.
   Phones (and print) get one scrolling column; desktop screens get the
   paged layout at the end of this file. */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: #fff;
  color: #000;
  font-family: "Times New Roman", Times, Georgia, serif;
  font-size: 1.4rem;
  line-height: 1.5;
}

a {
  color: inherit;
}

/* ---------- Page frame ---------- */

main {
  max-width: 110rem;
  margin: 0 auto;
  padding: 1.5rem 11vw 4rem;
}

.book-title {
  margin: 0 0 1.5rem;
  font-size: 1.6rem;
  font-weight: bold;
  line-height: 1.2;
}

/* ---------- Chapter text ---------- */

/* One scrolling column by default; the paged layout adds columns. */
.chapter {
  column-gap: 3rem;
}

/* Superscriptions (\d), speakers (\sp) and other one-line blocks keep a
   blank line after them. */
.chapter p {
  margin: 0 0 1.5em;
}

/* Prose paragraphs run on with no gap; each new paragraph is indented
   instead. The first paragraph of a chapter, or one after poetry or a
   heading, starts flush. Continuations (\m, \mi, \nb: text resuming after
   poetry) and list items (\li) are never indented. */
.chapter .p {
  margin: 0;
}

.chapter .p + .p:not(.m, .mi, .nb, .li1, .li2, .li3, .li4) {
  text-indent: 1.5em;
}

/* Poetry, headings and superscriptions that follow prose get a blank line
   above them. */
.chapter .p + :not(.p) {
  margin-top: 1.5em;
}

/* Poetry: \q1/\q2 lines in a line group, hanging indents. */
.chapter .lg {
  margin: 0 0 1.5em;
}

.chapter .l {
  display: block;
  padding-left: 2em;
  text-indent: -2em;
}

.chapter .l.q2 {
  text-indent: -1em;
}

.chapter .l.q3 {
  text-indent: 0;
}

.chapter .d,
.chapter .sp {
  font-style: italic;
}

.chapter h2.s {
  margin: 0 0 0.75em;
  font-size: 1em;
  font-weight: bold;
  break-after: avoid;
}

.nd,
.sc {
  font-variant: small-caps;
}

/* Red letters: words of Jesus, tagged \wj in the WEB USFM. Footnote and
   cross-reference markers inside them (and their hover previews) stay black. */
.wj {
  color: #b00;
}

.wj .note {
  color: #000;
}

/* A verse jumped to by link (#vN) gets a light yellow background. Chapter
   pages extend it to the rest of a verse split over several lines with a
   small <style> block of their own. */
:root {
  --target-bg: #fff3a0;
}

.chapter .verse:target {
  background: var(--target-bg);
}

/* A credit jumped to from a popover's "Source:" line is highlighted the same way. */
.credit-part:target {
  background: var(--target-bg);
}

@media (max-width: 768px) {
  body {
    font-size: 1.25rem;
  }

  main {
    padding: 1rem 1rem 3rem;
  }
}

/* ---------- Inline markers (verse numbers, footnotes) ---------- */

.vn,
.mark {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0.3em 0.15em;
  cursor: pointer;
  /* Raise without growing the line box. */
  font-size: 0.6em;
  line-height: 1;
  position: relative;
  top: -0.55em;
}

.vn {
  font-weight: bold;
  padding-right: 0.3em;
}

.mark.fn {
  font-style: italic;
}

/* Commentary marker ("K" for Kretzmann) at the first verse of each unit. */
.mark.comm {
  font-weight: bold;
}

/* Phones: each marker gets an invisible hit area of at least 24 x 24px
   (WCAG 2.5.8 target size) from an absolutely positioned ::before, so the
   letter, the line height and the text flow stay as they are. Neighbouring
   areas must not overlap, so an area grows to one side: leftwards (over the
   space or word before it) by default, rightwards for .tap-r. build.py sets
   .tap-r on the last of a run of markers at most three characters apart
   ("1" + "K", "4" + note "b", a note letter at a verse's end + the next verse
   number, notes on two words either side of "of") and on a K; a
   marker in the middle of a run (.tap-mid) is centred and given margins to
   make room for its area; a verse number between a note letter and its K
   (.tap-gap) only needs a little room on its left. */
@media (max-width: 768px) {
  .vn::before,
  .mark::before {
    content: "";
    position: absolute;
    top: 50%;
    right: 0;
    width: 24px;
    min-width: 100%;
    height: 24px;
    margin-top: -12px;
  }

  .tap-r::before {
    right: auto;
    left: 0;
  }

  .tap-mid {
    margin: 0 9px;
  }

  .tap-mid::before {
    right: auto;
    left: 50%;
    margin-left: -12px;
  }

  .tap-gap {
    margin-left: 8px;
  }
}

/* A button that reads as a link (commentary entries in verse popovers). */
button.link {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  cursor: pointer;
}

.pop-comm .comm-section {
  font-weight: bold;
}

.pop-comm .subject {
  font-style: italic;
}

/* Between two comments on one verse ("V.5a." / "V.5b.") in one popover. */
.pop-comm .comm-sep {
  margin: 1rem 0;
  border: 0;
  border-top: 1px solid currentColor;
}

/* ---------- Associative readings (dist/readings/) ---------- */

.reading-source {
  margin: -0.5rem 0 1.5rem;
  font-size: 0.9rem;
}

.reading-source .src-label {
  margin-left: 0;
  margin-right: 0.35em;
}

.reading-scope,
.reading-note {
  font-size: 0.9rem;
}

/* Reading pages use the chapter pages' paged layout (<article class="chapter
   prose">). Their paragraphs are prose with a gap between them, not verse
   paragraphs, and headings stay with the text after them. */
.prose > p {
  margin: 0 0 1em;
}

.prose :is(h1, h2, h3, h4, h5, h6) {
  break-after: avoid;
}

.prose > :first-child {
  margin-top: 0;
}

/* ---------- Desktop hover preview (CSS only) ---------- */

.note {
  position: relative;
}

.preview {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .note:hover > .preview,
  .note:has(> button:focus-visible) > .preview {
    display: block;
    position: absolute;
    z-index: 1;
    bottom: 1.4em;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: 22rem;
    padding: 0.5rem 0.75rem;
    background: #fff;
    border: 1px solid #000;
    font-size: 1.05rem;
    font-style: normal;
    font-weight: normal;
    line-height: 1.4;
    text-align: left;
    text-indent: 0;
    pointer-events: none;
  }

  /* Verse numbers often start a line at the column's left edge, where a
     centred preview would be cut off; open those to the right instead. */
  .vn-note:hover > .preview,
  .vn-note:has(> button:focus-visible) > .preview {
    left: 0;
    transform: none;
  }

  /* Once a popover is open, the preview is redundant. */
  body:has(:popover-open) .preview {
    display: none !important;
  }
}

/* Where anchor positioning works, the preview is fixed-positioned against
   its own .note instead: it escapes the paged text window (whose scrolling
   clips anything absolutely positioned inside it), draws over the title and
   margins, and stays on screen. It sits above the marker, flips below it
   when there's no room above, and is shifted sideways to stay within the
   window. Verse-number previews open to the right, as above.
   The Firefox/Safari rotation trick (end of file) puts the text inside
   transforms, which trap fixed elements; it switches this back off. */
@supports (anchor-name: --a) and (anchor-scope: all) {
  @media (hover: hover) and (pointer: fine) {
    .note {
      anchor-name: --note;
      anchor-scope: --note;
    }

    .note:hover > .preview,
    .note:has(> button:focus-visible) > .preview {
      position: fixed;
      inset: auto;
      transform: none;
      margin: 0 0 0.3rem;
      max-width: min(22rem, calc(100vw - 1rem));
      z-index: 10;
      position-anchor: --note;
      position-area: top;
      position-try-fallbacks: flip-block;
    }

    .vn-note:hover > .preview,
    .vn-note:has(> button:focus-visible) > .preview {
      position-area: top span-right;
    }
  }
}

/* ---------- Popovers ---------- */

.pop {
  /* UA default centres the popover in the viewport; we just size and frame it. */
  max-width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1rem 1.25rem;
  background: #fff;
  color: #000;
  border: 1px solid #000;
  font-size: 1.1rem;
  line-height: 1.45;
}

.pop::backdrop {
  background: transparent;
}

.pop > :last-child {
  margin-bottom: 0;
}

.pop-ref {
  margin: 0 2rem 0.75rem 0;
  font-weight: bold;
}

.pop .share {
  margin: -0.5rem 0 0.75rem;
  font-size: 0.9em;
}

.pop h2 {
  margin: 1rem 0 0.25rem;
  font-size: 1em;
  font-weight: bold;
}

.pop ol,
.pop ul {
  margin: 0;
  padding-left: 1.5em;
}

.pop ul.plain {
  list-style: none;
  padding-left: 0;
}

.pop .credit {
  margin-top: 1rem;
  font-size: 0.9em;
}

/* Source tag on notes taken from another edition ("Geneva 1561/62"). */
.src-label {
  display: inline-block;
  margin-left: 0.35em;
  padding: 0 0.3em;
  border: 1px solid currentColor;
  font-size: 0.7em;
  font-style: normal;
  letter-spacing: 0.04em;
  line-height: 1.4;
  text-transform: uppercase;
  vertical-align: 0.1em;
  white-space: nowrap;
}

.close {
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  min-width: 2.75rem;
  min-height: 2.75rem;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

/* On small screens show popovers as a sheet along the bottom edge. */
@media (max-width: 768px) {
  .pop {
    inset: auto 0 0 0;
    margin: 0;
    width: 100%;
    max-width: none;
    max-height: 70vh;
    border-width: 1px 0 0;
  }
}

/* The popover's "Source:" link scrolls to the credit in the footer. On small
   screens the sheet covers up to the bottom 70vh, so while a credit is
   targeted the page gets that much room below it: the jump can then bring
   the credit to the top of the screen, clear of the sheet. */
@media (max-width: 768px) {
  body:has(.credit-part:target) {
    padding-bottom: 70vh;
  }
}

/* Fallback: browsers without popover support show the notes inline at the
   end of the chapter. Where popovers work, that heading is hidden. */
@supports selector(:popover-open) {
  .notes-heading {
    display: none;
  }
}

.notes {
  margin-top: 1.5rem;
}

/* ---------- <details> inline-expand variant ---------- */

details.inline {
  display: inline;
}

details.inline > summary {
  display: inline;
  list-style: none;
  cursor: pointer;
  font-size: 0.6em;
  font-style: italic;
  position: relative;
  top: -0.55em;
  padding: 0.3em 0.15em;
}

details.inline > summary::-webkit-details-marker {
  display: none;
}

details.inline > .inline-note {
  display: block;
  margin: 0.25em 0 0.5em 1.5em;
  font-size: 0.8em;
  line-height: 1.4;
}

/* ---------- Contents page ---------- */

.testament {
  margin: 2rem 0 0;
  font-size: 1em;
  font-weight: bold;
}

.testament + ul {
  margin-top: 0.5rem;
}

/* ---------- Footer / chapter navigation ---------- */

.site-footer {
  margin-top: 3rem;
  font-size: 0.9rem;
}

/* Previous chapter | Contents | next chapter. The outer columns share the
   leftover space equally so "Contents" stays centred. */
.chapter-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 1.1rem;
}

.chapter-nav > :last-child {
  justify-self: end;
  text-align: right;
}

.chapter-nav a {
  display: inline-block;
  padding: 0.5rem 0; /* 44px-ish touch target */
}

/* Phones: previous | next on one row, Contents centred below, so long names
   like "1 Thessalonians" have room. */
@media (max-width: 768px) {
  .chapter-nav {
    grid-template-columns: 1fr 1fr;
    row-gap: 0;
  }

  .chapter-nav > :nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
  }
}

/* ---------- Paged layout (desktop) ----------
   On screens at least 769px wide and 32rem tall, the chapter gets a fixed
   height and two columns, and overflows sideways into extra columns: one
   screen of text at a time. Phones, landscape phones, short windows and
   print keep the single scrolling column above. Multicol breaks between
   lines, so no line is ever cut in half.

   Only chapter and reading pages (<main class="reader">) are paged; the
   contents pages share the stylesheet and are left alone. Keep the three media queries
   below in sync. */

@media screen and (min-width: 769px) and (min-height: 32rem) {
  /* Peek: the text window reaches --bleed into the right margin, and the
     chapter's right padding (--peek) keeps the columns at their normal
     width. The next column starts one gap after the padding begins, so a
     sliver of it shows at the edge as a cue that the text continues. */
  .reader {
    --peek: min(7.5rem, 10vw);
    --bleed: var(--peek);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: 0.5rem;
  }

  .reader > .book-title {
    flex: none;
    margin-bottom: 1rem;
  }

  /* A reading's link up to its document, above the title. */
  .reader > p {
    flex: none;
    margin: 0 0 0.5rem;
  }

  /* .pager is the flexible slot; the chapter fills it. */
  .reader > .pager {
    flex: 1 1 0;
    min-height: 0;
    margin-right: calc(-1 * var(--bleed));
    position: relative;
    container-type: size;
  }

  .reader .pager-rot {
    height: 100%;
  }

  .reader .chapter {
    columns: 2;
    height: 100%;
    padding-right: var(--peek);
    column-fill: auto;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: auto; /* keep a full, visible scrollbar */
  }

  /* Snap to column starts where the ::column pseudo-element exists
     (Chromium); elsewhere the rule is ignored and scrolling is free. */
  .reader .chapter::column {
    scroll-snap-align: start;
  }

  .reader > .chapter-nav {
    flex: none;
    margin-top: 0.25rem;
  }

  /* Credits take a short fixed row under the nav; the pager keeps the rest. */
  .reader > .site-footer {
    flex: none;
    margin-top: 0.25rem;
    font-size: 0.7rem;
    line-height: 1.3;
  }

  .reader > .site-footer p {
    margin: 0;
  }
}

/* The "Credits" link in the footer is only for short windows (below). */
.credits-link {
  display: none;
}

/* Short desktop windows (paged, under ~700px tall): the credits would take a
   quarter of the height and leave few lines per column, so they are clamped
   to one line with a "Credits" link after it. The link targets the footer
   (#credits), and :target shows the credits in full; no script needed. A
   popover's "Source:" link (#credit-kretzmann) unclamps them as well. */
@media screen and (min-width: 769px) and (min-height: 32rem) and (max-height: 700px) {
  .reader > .site-footer:has(.credits-link):not(:target, :has(:target)) {
    display: flex;
    gap: 0.75em;
  }

  .reader > .site-footer:has(.credits-link):not(:target, :has(:target)) p {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .reader > .site-footer:has(.credits-link):not(:target, :has(:target)) .credits-link {
    display: inline;
    flex: none;
  }
}

/* Page-turn buttons. CSS scroll buttons (::scroll-button, Chromium 135+)
   scroll the chapter one screen at a time and disable themselves at either
   end. Browsers without support get the rotation trick below. */
@media screen and (min-width: 769px) and (min-height: 32rem) {
  .reader .chapter {
    anchor-name: --chapter;
  }

  .reader .chapter::scroll-button(*) {
    position: fixed;
    position-anchor: --chapter;
    position-area: block-start span-inline-start; /* above the columns, right-aligned */
    margin-bottom: 0.5rem;
    width: 2.75rem;
    height: 2.75rem;
    font: inherit;
    font-size: 1.3rem;
    line-height: 1;
    color: #000;
    background: #fff;
    border: 1px solid #000;
    cursor: pointer;
  }

  .reader .chapter::scroll-button(inline-start) {
    content: "\2190" / "Previous page";
    margin-right: 3.25rem; /* sits left of the next button */
  }

  .reader .chapter::scroll-button(inline-end) {
    content: "\2192" / "Next page";
  }

  .reader .chapter::scroll-button(*):disabled {
    opacity: 0.25;
    cursor: default;
  }
}

/* Wheel paging for browsers without ::scroll-button (Firefox, Safari).
   The scroller (.pager-rot) is rotated -90deg and the chapter rotated back
   +90deg, so the page looks identical but its sideways overflow becomes
   vertical scrolling: the mouse wheel, Space and PageDown turn pages.
   Fine pointer only, since on touch screens swipe direction would be
   rotated too; tablets swipe sideways instead. */
@supports not selector(::scroll-button(*)) {
  @media screen and (min-width: 769px) and (min-height: 32rem) and (hover: hover) and (pointer: fine) {
    /* direction: rtl puts the vertical scrollbar on the scroller's left
       edge, which the -90deg rotation turns into the bottom edge. */
    .reader .pager-rot {
      position: absolute;
      top: 0;
      left: 0;
      width: 100cqh;   /* pre-rotation: width = visible height */
      height: 100cqw;  /*               height = visible width */
      direction: rtl;
      overflow-x: hidden;
      overflow-y: auto;
      scrollbar-width: auto;
      transform-origin: 0 0;
      transform: translateY(100cqh) rotate(-90deg);
    }

    /* In rtl the chapter's box is right-aligned in the scroller, so rotate
       about its top-right corner and shift it back by its own width. Its
       height leaves room for the scrollbar along the bottom. */
    .reader .chapter {
      direction: ltr;
      width: 100cqw;
      height: calc(100cqh - 1.25rem);
      overflow: visible;
      scroll-snap-type: none;
      transform-origin: top right;
      transform: translateY(100cqw) rotate(90deg);
    }

    /* Inside the transforms, fixed-position previews can't escape the text
       window and anchoring misplaces them past the first column, so the
       previews go back to plain absolute positioning (they can be cut off
       at the window's edges). */
    .reader .note {
      anchor-name: none;
    }

    .reader .note:hover > .preview,
    .reader .note:has(> button:focus-visible) > .preview {
      position: absolute;
      position-area: none;
      position-try-fallbacks: none;
      inset: auto auto 1.4em 50%;
      transform: translateX(-50%);
      margin: 0;
    }

    .reader .vn-note:hover > .preview,
    .reader .vn-note:has(> button:focus-visible) > .preview {
      left: 0;
      transform: none;
    }
  }
}

/* ---------- Paragraph-numbered readings (Book of Concord) ----------
   Triglot paragraph numbers sit in the text like verse numbers; each is a
   link to itself (#p21) so it can be copied or followed. */

.paras p {
  margin: 0 0 0.75em;
}

.paras h2.part {
  margin: 2.5rem 0 1rem;
  font-size: 1.15em;
}

.paras h3,
.paras h4,
.paras h5,
.paras h6 {
  margin: 1.5em 0 0.5em;
  font-size: 1em;
}

.paras h4,
.paras h5,
.paras h6 {
  font-style: italic;
  font-weight: normal;
}

.pn {
  display: inline-block;
  padding: 0.3em 0.15em 0.3em 0;
  font-size: 0.6em;
  font-weight: bold;
  line-height: 1;
  vertical-align: 0.6em;
  text-decoration: none;
}

.pn:target {
  background: var(--target-bg);
}

ul.toc {
  padding-left: 1.2em;
}

ul.toc li {
  margin: 0.2em 0;
}

ul.toc ul {
  padding-left: 1.2em;
  font-size: 0.9em;
}

/* Origin and purpose of a translation, on its contents page. */
.tr-about {
  max-width: 40em;
}

.tr-about p {
  margin: 0 0 0.75em;
}

.tr-about .legend {
  font-size: 0.9em;
}

/* A note shown on a reading set's contents page (e.g. on canonicity). */
.reading-notice {
  max-width: 40em;
  margin: 1rem 0 1.5rem;
  padding: 0.25rem 1rem;
  border-left: 3px solid currentColor;
}

.reading-notice p {
  margin: 0.5em 0;
}

/* Lines of verse (1 Enoch), and the Ethiopic/Greek column labels. */
.paras p.lg {
  padding-left: 1.5em;
}

.paras p.col-label {
  margin: 1em 0 0.25em;
  font-size: 0.8em;
  font-variant: small-caps;
  letter-spacing: 0.04em;
}

.paras p.col-g {
  padding-left: 1em;
  border-left: 1px solid currentColor;
}

.chapter-links {
  font-size: 0.9em;
  line-height: 1.9;
}

/* Charles's critical brackets (⌈ ⌉ 〈 〉): not in every text font. */
.sign {
  font-family: "Segoe UI Symbol", "Cambria Math", "STIX Two Math", "STIX Two Text",
    "Apple Symbols", "DejaVu Sans", "Noto Sans Math", "Noto Sans Symbols", serif;
  font-style: normal;
}

.paras p.col-label sup {
  font-variant: normal;
  text-transform: none;
}
