/* Heilig.OTF = the main text face.  Heilig-ls ("Heilig-ls-Bold.ttf") = the lighter face the sefer uses for
   emphasized words, so <b> in the text switches to it instead of getting heavier. */
@font-face {
  font-family: "Heilig";
  src: url("/fonts/Heilig.otf") format("opentype");
  font-display: swap;
}
@font-face {
  font-family: "Heilig LS";
  src: url("/fonts/Heilig-Bold.ttf") format("truetype");
  font-display: swap;
}

:root {
  --bg: #faf7f0;
  --paper: #fffdf8;
  --fg: #1f1c17;
  --muted: #6f675a;
  --accent: #7a4b12;
  --accent-soft: #f1e6d3;
  --rule: #e3d9c6;
  --mark: #fbe39a;
  --shadow: 0 1px 2px rgb(60 40 10 / .06), 0 4px 16px rgb(60 40 10 / .06);
  --text-size: 22px;
  --font: "Heilig", "Times New Roman", serif;
  --font-em: "Heilig LS", "Heilig", serif;
  --ui: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --paper: #1f1c18;
    --fg: #ebe5d8;
    --muted: #a69d8c;
    --accent: #e0aa60;
    --accent-soft: #3a2f20;
    --rule: #36312a;
    --mark: #6b5418;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 16px rgb(0 0 0 / .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--ui);
}
a { color: inherit; }
main { outline: none; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.top-inner {
  max-width: 1040px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: baseline; gap: 10px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.brand-he { font-family: var(--font); font-size: 28px; }
.brand-en { font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.search { flex: 1; display: flex; max-width: 480px; margin-inline-start: auto; }
.search input {
  flex: 1; min-width: 0;
  font: 16px var(--ui); padding: 9px 14px;
  border: 1px solid var(--rule); border-inline-end: 0;
  border-radius: 8px 0 0 8px;
  background: var(--paper); color: var(--fg);
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.search button {
  border: 1px solid var(--rule); border-radius: 0 8px 8px 0;
  background: var(--accent); color: var(--paper);
  padding: 0 14px; cursor: pointer; display: grid; place-items: center;
}

/* ---------- shared ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 28px 16px 80px; }
.crumbs { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { text-decoration: none; color: var(--accent); }
.crumbs a:hover { text-decoration: underline; }
h1.page-title { font-family: var(--ui); font-weight: 700; font-size: 34px; letter-spacing: -.01em; margin: 0 0 4px; color: var(--accent); }
.sub { color: var(--muted); margin: 0 0 24px; }
h2.group { font-family: var(--ui); font-size: 20px; font-weight: 700; margin: 36px 0 12px; color: var(--fg); }
.loading, .empty, .error { color: var(--muted); padding: 40px 0; text-align: center; }
.error { color: #b3261e; }

/* volumes grid */
.vol-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
.vol {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px 8px; border-radius: 10px; text-decoration: none;
  background: var(--paper); border: 1px solid var(--rule); box-shadow: var(--shadow);
  transition: transform .12s, border-color .12s;
}
.vol:hover { transform: translateY(-2px); border-color: var(--accent); }
.vol b { font-family: var(--font); font-weight: 400; font-synthesis: none; font-size: 32px; color: var(--accent); line-height: 1.1; }
.vol i { font-style: normal; font-family: var(--font); font-size: 17px; color: var(--fg); margin-top: 2px; }
.vol span { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* parsha chips */
.chumash { margin-bottom: 18px; }
.chumash h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 15px; text-decoration: none;
  padding: 4px 12px; border-radius: 999px;
  background: var(--paper); border: 1px solid var(--rule);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip small { font-family: var(--ui); font-size: 11px; color: var(--muted); margin-inline-start: 4px; }

/* sicha list */
.list { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
.list li + li { border-top: 1px solid var(--rule); }
.list a {
  display: flex; align-items: baseline; gap: 12px;
  padding: 12px 16px; text-decoration: none;
}
.list a:hover { background: var(--accent-soft); }
.list .t { font-size: 21px; flex: 0 1 auto; }
.list .en { font-size: 14px; color: var(--muted); flex: 1; }
.list .m { font-size: 13px; color: var(--muted); white-space: nowrap; margin-inline-start: auto; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); margin-inline-start: 6px; vertical-align: 2px; }

/* ---------- reader ---------- */
.reader { max-width: 760px; margin: 0 auto; padding: 28px 16px 120px; }
.sicha-head { text-align: center; padding-bottom: 18px; margin-bottom: 8px; border-bottom: 2px solid var(--rule); }
.sicha-head .book { color: var(--muted); font-size: 15px; letter-spacing: .02em; }
.sicha-head .book a { color: var(--accent); text-decoration: none; }
.sicha-head h1 { font-family: var(--font); font-weight: 400; font-synthesis: none; font-size: 46px; color: var(--accent); margin: 4px 0 2px; }
.sicha-head .meta { color: var(--muted); font-size: 14px; }

.toolbar { display: flex; justify-content: center; gap: 6px; margin: 14px 0 6px; }
.toolbar button {
  font: 14px var(--ui); padding: 5px 11px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--rule); background: var(--paper); color: var(--fg);
}
.toolbar button:hover { border-color: var(--accent); }

.text { font-family: var(--font); font-size: var(--text-size); line-height: 1.75; }
.text p { margin: 0 0 .75em; text-align: justify; text-justify: inter-word; hyphens: none; }
.text b, .notes b, .fn-sheet-body b { font-family: var(--font-em); font-weight: 400; }
.text, .notes, .fn-sheet-body, .brand, h1, h2 { font-synthesis: none; }
.text h2.sec {
  font-family: var(--font); font-weight: 400; font-size: 1.35em; color: var(--accent);
  text-align: center; margin: 1.4em 0 .3em;
}
.text p.src { text-align: center; color: var(--muted); font-size: .85em; margin-top: 2em; }
.text p.flash { animation: flash 2.4s ease-out; border-radius: 4px; }
@keyframes flash { 0%, 40% { background: var(--mark); } 100% { background: transparent; } }

.page-mark {
  display: inline-block; font: 12px var(--ui); color: var(--muted);
  border: 1px solid var(--rule); border-radius: 4px; padding: 0 5px; margin-inline-end: 6px;
  vertical-align: 3px; user-select: none;
}

sup.fn {
  font-family: var(--ui); font-size: .55em; line-height: 0; vertical-align: .9em;
  color: var(--accent); cursor: pointer; padding: 0 2px; font-weight: 600;
}
sup.fn:hover, sup.fn.active { background: var(--accent-soft); border-radius: 3px; }

/* footnotes at the end */
.notes { margin-top: 48px; border-top: 2px solid var(--rule); padding-top: 8px; }
.notes h2 { font-family: var(--ui); font-weight: 700; font-size: 20px; text-align: center; color: var(--accent); margin: 10px 0 16px; }
.notes ol { list-style: none; margin: 0; padding: 0; font-family: var(--font); font-size: calc(var(--text-size) * .76); line-height: 1.65; }
.notes li { margin: 0 0 .6em; padding: 2px 6px; border-radius: 4px; text-align: justify; }
.notes li:target, .notes li.flash { background: var(--accent-soft); }
.notes .num { font-weight: 400; color: var(--accent); text-decoration: none; margin-inline-end: 4px; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 48px; }
.pager a {
  flex: 1; text-decoration: none; padding: 12px 16px; border-radius: 10px;
  background: var(--paper); border: 1px solid var(--rule);
}
.pager a:hover { border-color: var(--accent); }
.pager small { display: block; font-size: 12px; color: var(--muted); }

.pager .next { text-align: end; }
.pager .he { font-size: 20px; }

/* footnote sheet */
.fn-sheet {
  position: fixed; z-index: 20; inset-inline: 0; bottom: 0;
  max-width: 760px; margin: 0 auto;
  background: var(--paper); border: 1px solid var(--rule); border-bottom: 0;
  border-radius: 14px 14px 0 0; box-shadow: 0 -8px 30px rgb(0 0 0 / .15);
  max-height: 45vh; display: flex; flex-direction: column;
}
.fn-sheet[hidden] { display: none; }
.fn-sheet-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px 6px; border-bottom: 1px solid var(--rule); }
.fn-sheet-num { font-weight: 700; color: var(--accent); font-size: 15px; }
.fn-sheet-jump { font-size: 13px; color: var(--muted); }
.fn-sheet-close { margin-inline-start: auto; border: 0; background: none; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px; }
.fn-sheet-body { overflow: auto; padding: 10px 18px 18px; font-family: var(--font); font-size: calc(var(--text-size) * .82); line-height: 1.65; text-align: justify; }

/* search results */
.results { list-style: none; margin: 0; padding: 0; }
.results li { background: var(--paper); border: 1px solid var(--rule); border-radius: 10px; margin-bottom: 10px; }
.results a { display: block; padding: 12px 16px; text-decoration: none; }
.results a:hover { border-color: var(--accent); background: var(--accent-soft); }
.results .head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 4px; }
.results .head .he { font-size: 20px; color: var(--accent); }
.results .m { font-size: 12px; color: var(--muted); }
.results .snip { font-family: var(--font); font-size: 18px; line-height: 1.6; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
.more { display: block; margin: 16px auto; font: 15px var(--ui); padding: 9px 20px; border-radius: 8px; border: 1px solid var(--rule); background: var(--paper); color: var(--fg); cursor: pointer; }
.hint { font-size: 14px; color: var(--muted); margin: -12px 0 20px; }
.hint summary { cursor: pointer; color: var(--accent); }
.help { font-size: 15px; line-height: 1.7; color: var(--muted); padding-inline-start: 20px; max-width: 720px; }
.help .he { font-size: 18px; color: var(--fg); }

@media (max-width: 600px) {
  .top-inner { gap: 10px; }
  .brand { font-size: 22px; }
  h1.page-title { font-size: 32px; }
  .sicha-head h1 { font-size: 36px; }
  :root { --text-size: 20px; }
  .pager { flex-direction: column; }
}

/* ---------- English interface around Hebrew text ---------- */
.he, .he-sub, [dir="rtl"] { unicode-bidi: isolate; }
.he { font-family: var(--font); font-synthesis: none; }
.chip .he { margin-inline-start: 4px; color: var(--muted); }
.he-sub { font-family: var(--font); font-weight: 400; color: var(--muted); font-size: .8em; margin-inline-start: 10px; }
.en-title { font-size: 16px; color: var(--fg); margin-bottom: 2px; }
.tip { text-align: center; font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.text p.empty { font-family: var(--ui); font-size: 16px; text-align: center; }
.error a { color: var(--accent); display: inline-block; margin-top: 10px; }
.fn-sheet-head { direction: ltr; }
@media (max-width: 600px) {
  .brand-en { display: none; }
  .list a { flex-wrap: wrap; }
  .list .en { flex-basis: 100%; order: 3; }
}
