:root {
  --bg: #f6f1e7;
  --surface: #fffcf6;
  --ink: #2a2520;
  --muted: #6f6458;
  --line: #e3d9c8;
  --accent: #8a2433;
  --accent-bg: #80202c;
  --on-accent: #fffaf2;
  --hl: #f2dc9b;
  --learn: #d9ead0;
  /* reading view: the page itself is papyrus */
  --vellum: #f2e5c8;
  --mottle: rgba(186, 142, 78, .17);
  --sheen: rgba(255, 249, 233, .6);
  --known: #d3bd94;
  --fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.42 .78' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .29 0 0 0 0 .12 0 0 0 .11 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --en: #5e554b;
  --shadow: 0 -6px 28px rgba(60, 40, 20, .16);
  --fs: 19px;
  --serif: "Gentium Book Plus", "Noto Serif", "Times New Roman", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --gutter: 16px;
  --side: min(380px, 45vw);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1714;
    --surface: #24201c;
    --ink: #e9e2d6;
    --muted: #a09585;
    --line: #3a342d;
    --accent: #e3929c;
    --accent-bg: #7c2430;
    --hl: #5c4b1f;
    --learn: #2f4a2d;
    /* candlelit: umber papyrus, warm ink */
    --vellum: #2a2119;
    --mottle: rgba(0, 0, 0, .26);
    --sheen: rgba(255, 196, 120, .05);
    --known: #54473a;
    --fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.42 .78' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .95 0 0 0 0 .82 0 0 0 0 .62 0 0 0 .045 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
    --en: #b6ac9e;
    --shadow: 0 -6px 28px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 var(--serif);
  overflow-wrap: break-word;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus, #sheet:focus { outline: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* header */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.icon, .icon-spacer {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  cursor: pointer;
}
.icon.aa { font: 600 17px var(--serif); }
.bar-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-align: center;
  font: 600 1.05rem/44px var(--serif);
}
.brand { font-size: 1.3rem; letter-spacing: .04em; }
.title-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 44px;
  padding: 0 4px;
  border: 0;
  border-radius: 10px;
  background: none;
  cursor: pointer;
}
.title-btn .t { overflow: hidden; text-overflow: ellipsis; }
.title-btn .caret { flex: none; width: 18px; height: 18px; color: var(--muted); }
.title-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }

.panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: min(60vh, 520px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px max(var(--gutter), env(safe-area-inset-right)) 16px max(var(--gutter), env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .12);
}
.panel-head { margin: 0 0 8px; font: 600 .8rem var(--sans); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; max-width: 40rem; margin: 0 auto; }
.grid a {
  display: grid;
  place-items: center;
  min-height: 44px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font: 500 15px var(--sans);
  text-decoration: none;
}
.grid a.cur { background: var(--accent-bg); color: var(--on-accent); }
.settings { left: auto; width: min(100%, 340px); border-left: 1px solid var(--line); border-bottom-left-radius: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; font: 15px var(--sans); }
.row + .row { border-top: 1px solid var(--line); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper output { min-width: 2.2em; text-align: center; font-variant-numeric: tabular-nums; }
.stepper .btn { min-width: 48px; padding: 0 10px; border-color: var(--muted); }
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 50px;
  height: 30px;
  margin: 0;
  border-radius: 15px;
  background: var(--line);
  cursor: pointer;
  transition: background .15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform .15s;
}
.switch:not(:checked) { box-shadow: inset 0 0 0 1.5px var(--muted); }
.switch:checked { background: var(--accent-bg); }
.switch:checked::after { transform: translateX(20px); }

/* pages */
main {
  display: block;
  padding: 0 max(var(--gutter), env(safe-area-inset-right)) env(safe-area-inset-bottom) max(var(--gutter), env(safe-area-inset-left));
}
.page { max-width: 40rem; margin: 0 auto; padding-bottom: 32px; }
.status { text-align: center; color: var(--muted); margin: 3em 0; }
.intro { color: var(--muted); font-style: italic; text-align: center; margin: 20px 0; }
.section { font: 600 .8rem var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 28px 0 10px; }
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card {
  display: block;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}
.card-title { display: block; font-size: 1.25rem; line-height: 1.3; }
.card-sub { display: block; margin-top: 4px; font: .85rem/1.4 var(--sans); color: var(--muted); }
.continue { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--on-accent); }
.continue .card-sub, .continue .eyebrow { color: var(--on-accent); opacity: .8; }
.eyebrow { display: block; margin-bottom: 2px; font: 600 .72rem var(--sans); text-transform: uppercase; letter-spacing: .08em; }
.foot { text-align: center; margin: 32px 0 0; }
.foot a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; font: .95rem var(--sans); }

.group { font: 600 .78rem var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin: 28px 0 4px; }
.books { list-style: none; margin: 0; padding: 0; }
.books a {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 48px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}
.bk-title { flex: 1 1 auto; font-size: 1.08rem; overflow-wrap: normal; }
.bk-en { flex: 0 1 auto; font: .82rem var(--sans); color: var(--muted); text-align: right; overflow-wrap: normal; }
.bk-ch { flex: none; min-width: 2.2em; text-align: right; font: .82rem var(--sans); color: var(--muted); font-variant-numeric: tabular-nums; }
@media (min-width: 720px) {
  .books { columns: 2; column-gap: 32px; }
  .books li { break-inside: avoid; }
}

.dl { margin: 8px 0 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-family: var(--sans); }
.dl:empty { display: none; }
.dl p { margin: 0; }
.dl-label { font-size: .9rem; margin-bottom: 8px !important; }
.dl progress { width: 100%; height: 8px; accent-color: var(--accent-bg); }
.dl-done { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: .95rem; }
.dl-done svg { color: #3f8a4f; }
.error-text { color: var(--accent); font-size: .9rem; margin-bottom: 10px !important; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.2 var(--sans);
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { width: 100%; background: var(--accent-bg); border-color: var(--accent-bg); color: var(--on-accent); }
.error { margin: 2em 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); font-family: var(--sans); }
.error p { margin: 0 0 12px; }

.prose p { margin: 1em 0; }
.sources { list-style: none; margin: 0; padding: 0; }
.sources li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.sources p { margin: 4px 0 0; font-size: .92rem; }
.lic { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 6px; background: var(--line); font: .75rem/1.6 var(--sans); }
.url { overflow-wrap: anywhere; font-family: var(--sans); font-size: .8rem !important; }

/* reader */
.text {
  max-width: 38em;
  margin: 0 auto;
  padding-bottom: 24px;
  font-size: var(--fs);
  line-height: 1.6;
  touch-action: manipulation;
}
body.reading {
  background-color: var(--vellum);
  /* fibre grain, then mottling and sheen repeating at unrelated periods so long chapters show no tile */
  background-image: var(--fibre),
    radial-gradient(55% 32% at 16% 24%, var(--mottle), transparent 70%),
    radial-gradient(48% 28% at 84% 66%, var(--mottle), transparent 70%),
    radial-gradient(70% 40% at 52% 42%, var(--sheen), transparent 72%);
  background-size: 220px 220px, 100% 937px, 100% 1381px, 100% 1123px;
}
.ch-head { margin: 1.1em 0 .9em; text-align: center; font-weight: normal; line-height: 1.2; }
.ch-book { display: block; font-size: .85rem; letter-spacing: .08em; color: var(--muted); }
.ch-book:lang(la) { font-size: .8rem; letter-spacing: .14em; text-transform: uppercase; }
.ch-num { display: block; margin-top: .1em; font-size: 2.2rem; color: var(--accent); }
.v { margin: 0 0 .5em; }
.text:not(.no-en) .v { margin-bottom: .95em; }
.vn {
  margin-right: .15em;
  font: 600 .6em var(--sans);
  color: var(--accent);
  vertical-align: .45em;
  line-height: 0;
  user-select: none;
  -webkit-user-select: none;
}
.sv { font-size: .62em; font-style: italic; color: var(--muted); line-height: 0; margin: 0 .12em; user-select: none; -webkit-user-select: none; }
.w { cursor: pointer; border-radius: 3px; padding: .17em 0; }
/* vocabulary marks: new words stay plain, learning words are tinted, known words get an underline a shade off the
   leaf; the selection highlight still wins */
.w.st1 { background: var(--learn); box-shadow: 0 0 0 2px var(--learn); }
.w.st2 { text-decoration-line: underline; text-decoration-color: var(--known); text-decoration-thickness: .14em;
  text-underline-offset: .22em; text-decoration-skip-ink: none; }
.w.sel { background: var(--hl); box-shadow: 0 0 0 2px var(--hl); }
@media (hover: hover) {
  .w:hover { text-decoration: underline dotted var(--muted); text-underline-offset: .22em; }
  .icon:hover, .title-btn:hover { background: var(--line); }
  .card:hover, .btn:hover { border-color: var(--muted); }
  .books a:hover .bk-title { color: var(--accent); }
}
.en { display: block; margin-top: .2em; font-size: .8em; line-height: 1.5; color: var(--en); }
/* English as the main text: English runs on from the verse number at reading size, the original follows below,
   smaller but still large enough to tap; with English hidden the original is back at full size */
.text:not(.no-en) .en-first .en { display: inline; margin: 0; font-size: 1em; line-height: inherit; color: var(--ink); }
.text:not(.no-en) .en-first .orig { display: block; margin-top: .25em; font-size: .85em; line-height: 1.55; color: var(--en); }
.en-note { margin: 0 0 1.2em; padding: .6em .9em; border-left: 3px solid var(--line); font-size: .78em; font-style: italic; color: var(--muted); }
.no-en .en, .no-en .en-note { display: none; }
.chnav { display: flex; justify-content: space-between; gap: 12px; margin: 2em 0 1em; font-size: 1rem; }
.chnav .btn { flex: 0 1 auto; min-width: 0; max-width: 48%; }
.chnav .btn[rel="next"] { margin-left: auto; }
body.sheet-open main { padding-bottom: 58vh; }

/* lookup sheet */
#sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  max-width: 44rem;
  max-height: 55vh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-top { display: flex; align-items: center; gap: 6px; padding: 10px max(8px, env(safe-area-inset-right)) 6px max(14px, env(safe-area-inset-left)); }
#search { flex: 1; min-width: 0; }
#q {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--muted);
  border-radius: 10px;
  background: var(--bg);
  font: 16px var(--sans);
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px max(18px, env(safe-area-inset-right)) 18px max(18px, env(safe-area-inset-left));
}
.lk-head { margin: 6px 0 0; font-size: 1.45rem; line-height: 1.3; }
.lk-tr { margin-left: .35em; font: italic .7em var(--serif); color: var(--muted); }
.lk-gloss { margin: 2px 0 0; font-style: italic; color: var(--muted); }
.lk-also { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 10px 0 0; font: .85rem var(--sans); color: var(--muted); }
.chip { min-height: 44px; padding: 0 12px; border: 1px solid var(--muted); border-radius: 22px; background: var(--bg); color: var(--ink); font: 600 1rem var(--serif); cursor: pointer; }
.entry { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.entry-h { margin: 0 0 4px; font: inherit; }
.entry summary { display: flex; align-items: baseline; gap: 8px; min-height: 44px; padding: 8px 0; cursor: pointer; list-style: none; }
.entry summary > .hw { flex: none; }
.entry summary > .src { flex: 1; min-width: 0; }
.entry summary::-webkit-details-marker { display: none; }
.entry summary::before { content: "▸"; color: var(--muted); font-size: .8em; transition: transform .15s; }
.entry[open] summary::before { transform: rotate(90deg); }
.hw { font-weight: 700; font-size: 1.12rem; }
.src { display: block; margin-top: 1px; font: max(.75rem, calc(var(--fs) * .63))/1.3 var(--sans); color: var(--muted); }
.def { font-size: max(.98rem, calc(var(--fs) * .82)); line-height: 1.55; overflow-wrap: anywhere; }
.def .sense { margin: .35em 0; }
.def .sense[data-level="2"] { margin-left: 1em; }
.def .sense[data-level="3"] { margin-left: 2em; }
.def .sense[data-level="4"], .def .sense[data-level="5"] { margin-left: 3em; }

@media (min-width: 900px), (orientation: landscape) and (max-height: 500px) {
  #sheet {
    top: 0;
    left: auto;
    width: var(--side);
    max-width: none;
    max-height: none;
    border: 0;
    border-left: 1px solid var(--line);
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
    box-shadow: none;
  }
  body.sheet-open { padding-right: var(--side); }
  body.sheet-open main { padding-bottom: env(safe-area-inset-bottom); }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 30;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 6px 6px 16px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--bg);
  font: 15px var(--sans);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast .btn { min-height: 40px; background: var(--bg); color: var(--ink); border: 0; }

/* vocabulary */
.marks { display: flex; gap: 6px; margin: 12px 0 2px; }
.mark, .seg button { flex: 1; min-height: 44px; border: 1px solid var(--muted); border-radius: 10px; background: var(--bg); color: var(--ink); font: 600 .9rem var(--sans); cursor: pointer; }
.mark[aria-pressed="true"], .seg button[aria-pressed="true"] { background: var(--accent-bg); border-color: var(--accent-bg); color: var(--on-accent); }
.words { list-style: none; margin: 0; padding: 0; }
.words li { display: flex; align-items: center; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.wl-word { flex: none; min-height: 44px; padding: 0; border: 0; background: none; color: var(--accent); font: 600 1.1rem var(--serif); cursor: pointer; text-align: left; }
.wl-gloss { flex: 1; min-width: 0; color: var(--muted); font: .9rem/1.35 var(--sans); }
.wl-known { flex: none; margin-left: auto; }
.tools { display: grid; gap: 10px; }
.file { position: relative; overflow: hidden; }
.file input { position: absolute; inset: 0; width: 100%; opacity: 0; cursor: pointer; }
.file:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.words-msg { min-height: 1.4em; font: .95rem var(--sans); }
.seg { display: flex; gap: 6px; }
.seg button { padding: 0 14px; }
