/* Rozvržení: horní lišta s odkazem a výběrem kapitoly; pod ní sloupce překladů (řádek = verš) a vpravo komentář k vybranému verši.
   Barvy: papír a tisková čerň, rubrikační červeň pro čísla veršů a nadpisy perikop jako v liturgických tiscích. */
:root {
  --paper: #f8f8f6;
  --panel: #ffffff;
  --ink: #1c1d21;
  --muted: #646873;
  --rule: #e0dfda;
  --rubric: #a1271f;
  --jesus: #b0261c;
  --sel: #f4e7b5;
  --active: #a1271f;
  --text: "Literata", "Georgia", "Times New Roman", serif;
  --ui: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --bar-h: 3.5rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16171b; --panel: #1d1f24; --ink: #e7e5e0; --muted: #9b9fa9; --rule: #2e3138;
    --rubric: #e27a6f; --jesus: #ef8a7c; --sel: #3f3720; --active: #e27a6f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16171b; --panel: #1d1f24; --ink: #e7e5e0; --muted: #9b9fa9; --rule: #2e3138;
  --rubric: #e27a6f; --jesus: #ef8a7c; --sel: #3f3720; --active: #e27a6f; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.5 var(--ui);
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--active); outline-offset: 2px; }

/* ---------- lišta ---------- */
.bar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem 1rem;
  padding: .55rem 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
}
.brand {
  font: 600 1.15rem/1 var(--text);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: .01em;
}
.brand span { color: var(--rubric); font-style: italic; font-weight: 400; }
.ref { display: flex; flex: 1 1 14rem; max-width: 22rem; }
.ref input {
  flex: 1; min-width: 0;
  padding: .4rem .6rem;
  border: 1px solid var(--rule); border-right: 0; border-radius: 4px 0 0 4px;
  background: var(--paper);
}
.ref input[aria-invalid="true"] { border-color: var(--rubric); }
.ref button, .chap button, .cols-btn, .selbar button {
  padding: .4rem .7rem;
  border: 1px solid var(--rule);
  background: var(--panel);
  cursor: pointer;
}
.ref button { border-radius: 0 4px 4px 0; }
.chap { display: flex; align-items: center; gap: .25rem; }
.chap select { padding: .35rem .3rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--panel); }
.chap button { border-radius: 4px; padding-inline: .6rem; }
.chap button:disabled { opacity: .35; cursor: default; }
.cols-btn { margin-left: auto; border-radius: 4px; font-weight: 500; }
.cols-btn[aria-expanded="true"] { border-color: var(--active); color: var(--active); }

/* ---------- panel sloupců ---------- */
.cols-panel {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + var(--bar-h));
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
  gap: 1rem 2rem;
  padding: 1rem 16px 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 8px 20px -16px rgba(0, 0, 0, .35);
}
.cols-group h2 {
  margin: 0 0 .2rem;
  font: 600 .75rem/1.2 var(--ui);
  text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.cols-group ul { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .35rem; }
.cols-group li { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; }
.cols-group li .hint { flex-basis: 100%; margin: 0 0 0 1.6rem; }
.hint { margin: 0; font-size: .82rem; color: var(--muted); }
small { font-size: .72rem; color: var(--muted); font-weight: 400; }
.move { margin-left: auto; display: flex; gap: .2rem; }
.move button { border: 1px solid var(--rule); background: var(--paper); border-radius: 3px; padding: 0 .4rem; cursor: pointer; }
.move button:disabled { opacity: .3; cursor: default; }

/* ---------- kapitola ---------- */
main { padding: 1.5rem 16px 6rem; max-width: 92rem; margin: 0 auto; }
.chapter-head { margin: 0 0 1.25rem; }
.book-title {
  margin: 0;
  font: 500 .78rem/1.3 var(--ui); text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
}
h1 { margin: .15rem 0 0; font: 600 clamp(1.8rem, 4vw, 2.6rem)/1.1 var(--text); text-wrap: balance; }
h1 span { color: var(--rubric); }
.intro { max-width: 46rem; margin: 0 0 1.5rem; font: 400 .95rem/1.65 var(--text); }
.intro summary { cursor: pointer; font: 500 .9rem/1.4 var(--ui); color: var(--rubric); }
.intro p { margin: .6rem 0 0; }

.layer-note { margin: 0 0 1rem; max-width: 46rem; font-size: .85rem; color: var(--muted); }
.reader { display: grid; gap: 2rem; align-items: start; }
.reader.with-comments { grid-template-columns: minmax(0, 1fr) minmax(16rem, 25rem); }
.grid-wrap { min-width: 0; }
.grid { --n: 1; max-width: calc(var(--n) * 38rem); }
.colhead, .vrow {
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  gap: 0 2rem;
}
.colhead {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + var(--bar-h));
  z-index: 5;
  padding: .45rem .6rem;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  font: 600 .74rem/1.3 var(--ui); text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
}
.pericope {
  margin: 1.6rem 0 .4rem;
  padding: 0 .6rem;
  font: 600 .8rem/1.35 var(--ui);
  font-variant: small-caps;
  letter-spacing: .06em;
  text-transform: lowercase;
  color: var(--rubric);
  text-wrap: balance;
}
.pericope + .pericope { margin-top: 0; }
.vrow {
  padding: .3rem .6rem;
  border-left: 2px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font: 400 1.06rem/1.68 var(--text);
}
.vrow:hover { background: color-mix(in srgb, var(--sel) 45%, transparent); }
.vrow.sel { background: var(--sel); }
.vrow.active { border-left-color: var(--active); }
.cell { min-width: 0; overflow-wrap: anywhere; }
.cell[lang="la"] { font-style: italic; }
.vn {
  margin-right: .3rem;
  font: 600 .66rem/1 var(--ui);
  color: var(--rubric);
  vertical-align: .45em;
  font-variant-numeric: tabular-nums;
}
.vrow.has-c .cell:first-child .vn { text-decoration: underline dotted; text-underline-offset: 2px; }
.nm { font: 600 .7em/1 var(--ui); color: var(--rubric); padding-left: .05em; }
.j { color: var(--jesus); }
.no-red .j { color: inherit; }
.n { color: var(--muted); }
.missing { font: italic .85rem var(--ui); color: var(--muted); }

/* ---------- komentáře ---------- */
.comments {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + var(--bar-h) + .5rem);
  max-height: calc(100vh - var(--bar-h) - 1.5rem);
  overflow: auto;
  padding: 0 1rem 1rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font: 400 .93rem/1.62 var(--text);
}
.c-head {
  position: sticky; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 -1rem; padding: .6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  font: 600 .95rem/1.2 var(--ui);
}
.c-copy { display: none; padding: .25rem .6rem; border: 1px solid var(--rule); border-radius: 4px; background: var(--paper); font: 500 .8rem var(--ui); cursor: pointer; }
.c-close { display: none; border: 0; background: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); }
.c-layer h3 {
  margin: 1rem 0 .3rem;
  font: 600 .72rem/1.3 var(--ui); text-transform: uppercase; letter-spacing: .08em; color: var(--rubric);
}
.c-layer p { margin: .35rem 0; }
.c-layer h4 { margin: .8rem 0 .2rem; font: 600 .9rem/1.3 var(--text); }
.c-layer .none { color: var(--muted); font: italic .85rem var(--ui); }

.pager { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; margin-top: 2.5rem; max-width: 60rem; }
.pager a, .notice a { color: var(--rubric); font-weight: 500; text-decoration: none; }
.pager a:hover, .notice a:hover { text-decoration: underline; }
.notice { max-width: 40rem; font-size: 1.05rem; }

/* předvykreslená stránka, než se načte aplikace */
.static-chapter { max-width: 40rem; font: 400 1.06rem/1.68 var(--text); }
.static-chapter h3 { font: 600 .8rem var(--ui); color: var(--rubric); font-variant: small-caps; margin: 1.5rem 0 .3rem; }
.static-chapter sup { color: var(--rubric); font: 600 .66rem var(--ui); }
.static-intro { font-size: .95rem; color: var(--muted); }

/* ---------- výběr veršů ---------- */
.selbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
  z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem;
  max-width: calc(100% - 32px);
  padding: .5rem .6rem .5rem 1rem;
  background: var(--ink); color: var(--paper);
  border-radius: 6px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5);
  font-size: .9rem;
}
#sel-ref { font-weight: 600; }
#sel-url { font: .85rem ui-monospace, "SFMono-Regular", Menlo, monospace; opacity: .8; overflow-wrap: anywhere; }
.selbar button { border-color: transparent; border-radius: 4px; background: var(--paper); color: var(--ink); font-weight: 500; }
#sel-clear { background: none; color: var(--paper); font-size: 1.2rem; line-height: 1; padding: .2rem .4rem; }

/* ---------- telefon ---------- */
@media (max-width: 760px) {
  :root { --bar-h: 6rem; }
  .brand { order: 0; }
  .chap { order: 1; margin-left: auto; }
  .ref { order: 2; flex: 1 1 12rem; min-width: 0; max-width: none; }
  .ref input { width: 100%; }
  .cols-btn { order: 3; margin-left: 0; }
  .reader.with-comments { grid-template-columns: minmax(0, 1fr); }
  .grid-wrap { overflow-x: auto; scroll-snap-type: x mandatory; margin-inline: -16px; padding-inline: 16px; scroll-padding-inline: 16px; }
  .grid { width: calc(var(--n) * 84vw); max-width: none; }
  .grid[style="--n:1"] { width: auto; }
  .colhead, .vrow { gap: 0 1.2rem; }
  .cell, .colhead > div { scroll-snap-align: start; }
  .colhead { position: static; }
  .comments {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 55vh;
    border-radius: 10px 10px 0 0;
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 1rem);
    transform: translateY(105%);
    transition: transform .2s ease;
    z-index: 25;
    box-shadow: 0 -10px 30px -12px rgba(0, 0, 0, .4);
  }
  .reader.c-open .comments { transform: none; }
  .c-close, .c-copy { display: block; }
  .c-tools { display: flex; align-items: center; gap: .5rem; }
  body.sheet-open .selbar { display: none; }
  #sel-url { display: none; }
  .selbar { left: 16px; right: 16px; transform: none; justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) { .comments { transition: none; } }
