/* ==========================================================================
 * BROWSER-SUPPORT CONTRACT
 * Floor: full fidelity on Chrome/WebView 69+ and iOS Safari 12.2+ — the
 * audience includes old Android WebViews. Therefore:
 *   - Logical LONGHANDS only (padding-inline-start: Chrome 69). The logical
 *     SHORTHANDS (margin-block:, inset:, …) are Chrome 87+ — banned.
 *   - Every logical `inset-*` or `float: inline-*` declaration needs a
 *     PHYSICAL fallback earlier in the same block (top/left/float:left…);
 *     without it, fixed panels render in-flow on older engines — unusable.
 *   - No :has(), @container, :is()/:where(), text-wrap, aspect-ratio, or
 *     math functions (clamp/min/max) — all above the floor.
 *   - Ignorable single-declaration enhancements ARE permitted where their
 *     absence degrades gracefully: accent-color, color-scheme, and flex
 *     `gap` (Chrome 84; header spacing collapses below that — crowded, not
 *     broken).
 * The test suite enforces a curated deny-list of these (test-styles.mjs,
 * "compatibility floor") — curated, NOT exhaustive: this comment is the
 * contract. package.json carries a `browserslist` field for future tooling.
 * ==========================================================================
 *
 * app.css — the entire visual layer. No framework, no icon font, no images.
 *
 * Themes are CSS custom properties on <html data-theme="...">. The red-letter
 * color is defined per theme because a brick red that sits well on warm paper
 * vibrates on a near-black ground; night gets a lighter rose instead.
 * Measured contrast against each theme's own background:
 *   paper  text 13.39:1  red #8e2f21 7.30:1  verse-nums #706452 5.18:1
 *   sepia  text 10.46:1  red #84291c 7.14:1  verse-nums #6d5f47 4.89:1
 *   night  text 11.98:1  red #e39a8e 7.96:1  verse-nums #98907f 5.69:1
 * All ≥ 4.5:1 (WCAG AA for normal text).
 */

:root {
  /* System stacks only: a CJK or Arabic webfont is megabytes and this site
   * may get exactly one chance to load. */
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
           "Songti SC", SimSun, "Noto Naskh Arabic", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC",
          "Microsoft YaHei", sans-serif;
  --measure: 68ch;      /* cap the line length for readability */
  --scale: 1;           /* user text-size control multiplies this */
}

html[data-theme="paper"] {
  --bg: #f7f2e8; --bg-raised: #efe8d9; --fg: #2c2620;
  --muted: #706452; --rule: #d8cfbd; --accent: #8e2f21;
  --wj: #8e2f21; --focus: #4a5f8a; --sel: #e6d9ba;
  color-scheme: light;
}
html[data-theme="sepia"] {
  --bg: #efe3cc; --bg-raised: #e6d7b9; --fg: #382e20;
  --muted: #6d5f47; --rule: #cfbf9e; --accent: #84291c;
  --wj: #84291c; --focus: #43597f; --sel: #dcc99d;
  color-scheme: light;
}
html[data-theme="night"] {
  --bg: #191613; --bg-raised: #241f1a; --fg: #d9d2c4;
  --muted: #98907f; --rule: #3a332b; --accent: #e39a8e;
  --wj: #e39a8e; --focus: #9db4dd; --sel: #3d3527;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  font-size: 100%; /* inherit the user's browser setting — never override it */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ------------------------------------------------------------ chrome */

header.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-block-end: 1px solid var(--rule);
}

header.bar .site-name {
  font-family: var(--serif);
  font-variant-caps: small-caps;
  letter-spacing: 0.06em;
  font-size: 1.05rem;
  text-decoration: none;
  color: var(--fg);
  margin-inline-end: auto;
}

select, button, input[type="search"], input[type="range"] {
  font: inherit; /* inherits 1rem = 16px: also prevents iOS zoom-on-focus */
  color: var(--fg);
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.45rem 0.6rem;
  max-inline-size: 11rem;
  /* 44px touch target (2.75rem at default size) — thumbs, not cursors. */
  min-block-size: 2.75rem;
}
button { cursor: pointer; }
button:hover, select:hover { border-color: var(--muted); }
button.quiet { background: none; border-color: transparent; color: var(--muted); }
button.quiet:hover { color: var(--fg); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------ reading view */

main {
  max-inline-size: var(--measure);
  margin-inline-start: auto; margin-inline-end: auto;
  padding: 1.25rem 1.25rem 5rem;
  /* Nothing may force horizontal scroll: break CIDs, URLs, any long token. */
  overflow-wrap: break-word;
}

/* Parallel view: two independent columns, each with its own lang/dir. */
main.parallel {
  max-inline-size: calc(var(--measure) * 2 + 3rem);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2.5rem;
}
@media (max-width: 52rem) {
  main.parallel { grid-template-columns: 1fr; gap: 0; }
  /* Stacked columns need identification: a sticky label naming the
   * translation rides under the header while its column scrolls. */
  main.parallel .col-label { display: block; }
}
.col-label {
  display: none; /* only shown when parallel stacks (media rule above) */
  position: sticky;
  top: 3.4rem; /* clears the sticky header bar */
  z-index: 5;
  background: var(--bg);
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding-block-start: 0.2rem; padding-block-end: 0.2rem;
  border-block-end: 1px solid var(--rule);
}

.running-head {
  font-family: var(--serif);
  font-variant-caps: small-caps;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
  margin-block-start: 0.5rem; margin-block-end: 0;
}

.chapter-num {
  font-family: var(--serif);
  text-align: center;
  font-size: 2.2rem;
  font-weight: 400;
  color: var(--muted);
  margin-block-start: 0.25rem; margin-block-end: 1rem;
}

.scripture {
  font-family: var(--serif);
  font-size: calc(1.125rem * var(--scale));
  line-height: 1.8;
}
/* Per-script metrics, keyed off data-script (derived by the build from each
 * translation's language; the config's optional "script" field overrides).
 * Keying on the WRITING SYSTEM means Persian gets Arabic-script metrics and
 * Japanese would get CJK metrics without anyone editing this file. To add a
 * script with its own needs, add one block here — everything else (drop-cap
 * gating, digit forms) lives beside the script table in app.js/build. */
.scripture[data-script="cjk"] { line-height: 1.9; }
.scripture[data-script="arabic"] { line-height: 1.9; font-size: calc(1.25rem * var(--scale)); }

.scripture p { margin-block-start: 0; margin-block-end: 0.9em; text-align: start; }
.scripture p.m { text-indent: 0; }

/* Indented prose (\pi1/\pi2): genealogies, embedded letters, quoted decrees.
   Logical properties so the indent mirrors correctly in RTL. */
.scripture .pi1 { padding-inline-start: 1.75em; }
.scripture .pi2 { padding-inline-start: 3.5em; }

/* Poetry: indentation encodes the \q level preserved by the pipeline.
 * A hanging indent keeps wrapped lines visually inside their level. */
.scripture .q1, .scripture .q2, .scripture .q3, .scripture .q4 {
  margin-block-start: 0; margin-block-end: 0;
  padding-inline-start: 3.5em;
  text-indent: -2em;
}
.scripture .q2 { padding-inline-start: 5em; }
.scripture .q3 { padding-inline-start: 6.5em; }
.scripture .q4 { padding-inline-start: 8em; }
.scripture .q1:last-child, .scripture .q2:last-child { margin-block-end: 0.9em; }

.scripture .d {
  font-style: italic;
  color: var(--muted);
  margin-block-start: 0; margin-block-end: 1em;
}

.scripture h2, .scripture h3 {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  margin-block-start: 1.6em; margin-block-end: 0.6em;
}
.scripture h3 { font-style: italic; font-weight: 400; color: var(--muted); }

.scripture .blank { block-size: 0.9em; }

/* Drop cap on the chapter opening. A real element (built by the renderer),
 * not ::first-letter: the pseudo-element matched the verse-number <sup>
 * digit, and it cannot be language-gated per column or verified by tests.
 * The renderer applies it only to scripts with a drop-cap tradition and
 * suppresses it for cursive and CJK scripts (see NO_DROP_CAP in app.js). */
.scripture .dropcap {
  float: left;                 /* fallback: engines without flow-relative float */
  float: inline-start;
  font-size: 3.1em;
  line-height: 0.82;
  padding-inline-end: 0.08em;
  padding-block-start: 0.04em;
  font-weight: 500;
}
/* No RTL flip needed: the drop-cap scripts (Latin, Cyrillic, Greek) are all
 * LTR, so the physical float:left fallback is always correct where it fires. */

sup.v {
  font-size: 0.62em;
  font-family: var(--sans);
  color: var(--muted);
  font-weight: 400;
  margin-inline-end: 0.15em;
  user-select: none;
  line-height: 0;
}

.nd { font-variant-caps: small-caps; letter-spacing: 0.03em; }

/* Red letter is decoration: nothing but color changes, and the whole class
 * disappears when the toggle is off, so meaning never depends on it. */
html[data-red="on"] .wj { color: var(--wj); }

/* Verse selection for copying */
span.verse { cursor: pointer; }
span.verse.selected { background: var(--sel); border-radius: 2px; }

.copybar {
  position: fixed;
  bottom: 1rem; left: 50%;       /* fallback: inset-* logical is Chrome 87+ */
  inset-block-end: 1rem;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  max-inline-size: calc(100vw - 1.5rem);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  align-items: center;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  font-size: 0.9rem;
}
html[dir="rtl"] .copybar { left: auto; right: 50%; transform: translateX(50%); }

/* Chapter pager */
nav.pager {
  display: flex;
  justify-content: space-between;
  margin-block-start: 2rem;
  font-family: var(--sans);
}
nav.pager a {
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-block-size: 2.75rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
}
nav.pager a:hover { color: var(--fg); border-color: var(--muted); }

/* The one permitted ornament: a small inline-SVG fleuron divider (< 2 KB). */
.divider {
  display: flex;
  justify-content: center;
  margin-block-start: 1.6rem; margin-block-end: 1.6rem;
  color: var(--muted);
}
.divider svg { inline-size: 4.5rem; block-size: auto; }

/* ------------------------------------------------------------ panels */

.panel {
  max-inline-size: var(--measure);
  margin-inline-start: auto; margin-inline-end: auto;
  padding: 1.5rem 1.25rem 4rem;
}
.panel h1 { font-family: var(--serif); font-variant-caps: small-caps; font-weight: 500; letter-spacing: 0.04em; }
.panel h2 { font-family: var(--serif); font-weight: 500; margin-block-start: 2rem; }
.panel a { color: var(--accent); }
.panel code, .panel pre {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.9em;
  overflow-wrap: anywhere;
}
.panel pre { padding: 0.75rem; overflow-x: auto; }

/* Settings */
.settings {
  display: none;
  position: fixed;
  top: 3.2rem; right: 0.75rem;   /* fallback: inset-* logical is Chrome 87+ */
  inset-block-start: 3.2rem;
  inset-inline-end: 0.75rem;
  max-block-size: calc(100vh - 4.5rem);
  overflow-y: auto;
  z-index: 20;
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 1rem;
  min-inline-size: 15rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}
html[dir="rtl"] .settings { right: auto; left: 0.75rem; inset-inline-end: 0.75rem; }
.settings.open { display: block; }
.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block-start: 0.6rem; margin-block-end: 0.6rem; }
.settings label { font-size: 0.9rem; }
.settings .hint { font-size: 0.8rem; color: var(--muted); margin-block-start: 0.5rem; margin-block-end: 0; }

progress { inline-size: 100%; accent-color: var(--accent); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Search */
.search-form { display: flex; gap: 0.5rem; margin-block-end: 1rem; }
.search-form input { flex: 1; max-inline-size: none; }
.result { margin-block-start: 1rem; margin-block-end: 1rem; }
.result a.ref { font-family: var(--sans); font-size: 0.85rem; color: var(--accent); text-decoration: none; }
.result .snippet { font-family: var(--serif); }
.result mark { background: var(--sel); color: inherit; border-radius: 2px; padding-inline-start: 1px; padding-inline-end: 1px; }
.search-status { color: var(--muted); font-size: 0.9rem; }
.scope-note {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.8rem;
  text-align: center;
  margin-block-start: 1.4rem; margin-block-end: 0.4rem;
  letter-spacing: 0.04em;
}

/* QR code (share page) — drawn as a table of cells, no canvas needed */
.qr { margin-block-start: 1rem; margin-block-end: 1rem; }
.qr td { inline-size: 4px; block-size: 4px; padding: 0; }
.qr td.on { background: var(--fg); }
.qr table { border-collapse: collapse; background: var(--bg); padding: 8px; border: 8px solid var(--bg); }

.notice { color: var(--muted); font-size: 0.9rem; }

/* Welcome (language picker): the one screen navigated natively by every
 * reader — large targets, each row in its own script and direction. */
.welcome h1 { font-size: 1.05rem; text-align: center; letter-spacing: 0; }
.lang-list { display: flex; flex-direction: column; gap: 0.6rem; margin-block-start: 1.2rem; margin-block-end: 1.2rem; }
.lang-choice {
  font-family: var(--serif);
  font-size: 1.25rem;
  padding: 0.8rem 1rem;
  max-inline-size: none;
  text-align: start;
}
.lang-choice.suggested { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Primary actions under the pager: visible, never loud. */
nav.actions {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-block-start: 1.2rem;
  font-family: var(--sans);
  font-size: 0.9rem;
}
nav.actions a {
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-block-size: 2.75rem;
  padding: 0.4rem 0.6rem;
}
nav.actions a:hover { color: var(--fg); }

button.gear svg { display: block; }

/* Update notice: slim bar at the bottom edge. main reserves 5rem of bottom
 * padding precisely so fixed bottom chrome never covers scripture; this bar
 * lives in that space. When the copybar is also visible it steps up above
 * the notice rather than overlapping it. */
.update-notice {
  position: fixed;
  bottom: 0; left: 0; right: 0;   /* fallback: inset-* logical is Chrome 87+ */
  inset-block-end: 0;
  inset-inline-start: 0; inset-inline-end: 0;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: var(--bg-raised);
  border-block-start: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: 0.9rem;
}
html.has-update .copybar {
  bottom: 4rem;                    /* fallback */
  inset-block-end: 4rem;
}

@media (prefers-reduced-motion: no-preference) {
  .settings.open { animation: fadein 120ms ease-out; }
  @keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }
}

@media print {
  header.bar, nav.pager, .copybar, .settings { display: none; }
}

/* ------------------------------------------------- narrow phones (≤480px) */
/* Indent scale: a 5–8em indent that reads well at 900px wastes a third of a
 * 360px screen; poetry levels stay distinguishable at ~0.75em steps. The
 * drop cap shrinks so it doesn't swallow the first line at phone measure. */
@media (max-width: 30rem) {
  main { padding: 1rem 0.9rem 5rem; }
  .scripture .q1, .scripture .q2, .scripture .q3, .scripture .q4 {
    padding-inline-start: 1.5em;
    text-indent: -1em;
  }
  .scripture .q2 { padding-inline-start: 2.25em; }
  .scripture .q3 { padding-inline-start: 3em; }
  .scripture .q4 { padding-inline-start: 3.75em; }
  .scripture .pi1 { padding-inline-start: 1.25em; }
  .scripture .pi2 { padding-inline-start: 2.5em; }
  .scripture .dropcap { font-size: 2.5em; }
  .chapter-num { font-size: 1.8rem; }
  .settings {
    left: 0.6rem; right: 0.6rem;             /* full-width bottom-sheet style */
    inset-inline-start: 0.6rem; inset-inline-end: 0.6rem;
    min-inline-size: 0;
  }
  html[dir="rtl"] .settings { left: 0.6rem; right: 0.6rem; }
  .search-form { flex-wrap: wrap; }
}
