:root {
  --bg: #fbf8f2;
  --paper: #fffdf8;
  --ink: #2a2622;
  --muted: #8a8177;
  --faint: #e7e0d4;
  --accent: #8a5a2b;
  --he-font: "Noto Serif Hebrew", "SBL Hebrew", "Times New Roman", serif;
  --en-font: "EB Garamond", Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --paper: #221f1b;
    --ink: #ece5d8;
    --muted: #9a9083;
    --faint: #3a352f;
    --accent: #d6a46c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--en-font);
  font-size: 19px;
  line-height: 1.55;
}
a { color: var(--accent); }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--faint);
}
.nav {
  width: 28px; height: 28px; flex: none;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
  font: 22px/1 var(--en-font); cursor: pointer;
  opacity: .55; transition: opacity .15s, background .15s;
}
.nav:hover, .nav:focus-visible { opacity: 1; background: var(--faint); }

.toggles { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.toggles label { cursor: pointer; }
.toggles input { position: absolute; opacity: 0; pointer-events: none; }
.toggles span {
  display: inline-block; padding: 3px 12px;
  border: 1px solid var(--faint); border-radius: 999px;
  font-size: 14px; color: var(--muted);
  transition: all .15s; user-select: none;
}
.toggles input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.toggles input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggles span:lang(he), .toggles label:first-child span { font-family: var(--he-font); }

/* ---------- page ---------- */
main { max-width: 1040px; margin: 0 auto; padding: 0 16px 48px; }
.title { text-align: center; padding: 36px 0 12px; }
.title .date { margin: 0; color: var(--muted); font-size: 15px; }
.title h1 { font-family: var(--he-font); font-weight: 600; font-size: 44px; margin: 10px 0 0; line-height: 1.3; }
.title h2 { font-weight: 500; font-size: 26px; margin: 0; letter-spacing: .02em; }
.title .refs { color: var(--muted); font-size: 15px; margin: 6px 0 0; }
.today {
  margin-top: 10px; border: 1px solid var(--faint); background: none; color: var(--accent);
  font: 14px var(--en-font); padding: 3px 12px; border-radius: 999px; cursor: pointer;
}

.status { text-align: center; color: var(--muted); padding: 48px 0; }
.status.error { color: #b4442c; }

h2.part {
  text-align: center; font-weight: 500; font-size: 15px; letter-spacing: .25em;
  text-transform: uppercase; color: var(--accent);
  margin: 48px 0 0; display: flex; align-items: center; gap: 16px;
}
h2.part::before, h2.part::after { content: ""; flex: 1; border-top: 1px solid var(--faint); }

.section-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin: 32px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--faint);
}
.section-head h3 { margin: 0; font-weight: 600; font-size: 20px; }
.section-head h3:empty { display: none; }
.section-head .he-label { font-family: var(--he-font); color: var(--muted); font-size: 18px; }
.section-head .ref { margin-left: auto; color: var(--muted); font-size: 14px; }

/* ---------- verses ---------- */
.verse {
  display: grid;
  grid-template-columns: 2.6em 1fr;
  gap: 0 14px;
  padding: 7px 0;
}
.verse .num {
  grid-row: 1 / span 2;
  color: var(--muted); font-size: 12px; padding-top: .55em;
  font-variant-numeric: tabular-nums; text-align: right;
}
.verse p { margin: 0; }
.he { font-family: var(--he-font); font-size: 25px; line-height: 1.8; text-align: right; }
.tr { font-style: italic; color: var(--ink); opacity: .78; font-size: 17px; line-height: 1.5; }
.en { font-size: 19px; }

body:not(.show-he) .he,
body:not(.show-tr) .tr,
body:not(.show-en) .en { display: none; }
body:not(.show-he):not(.show-tr) .orig { display: none; }

/* transliteration under Hebrew reads as a gloss */
body.show-he .tr { margin-top: 2px; }
body.show-he.show-tr.show-en:not(.paired) .en,
body.show-en .orig + .en { margin-top: 6px; }

/* siddur layout: English on the left page, Hebrew on the right */
@media (min-width: 760px) {
  body.paired .verse {
    grid-template-columns: 2.6em 1fr 1fr;
    gap: 0 28px;
    padding: 10px 0;
    border-bottom: 1px dotted var(--faint);
  }
  body.paired .verse .num { grid-row: 1; }
  body.paired .orig { grid-column: 3; grid-row: 1; }
  body.paired .en { grid-column: 2; grid-row: 1; margin-top: 0; padding-top: .35em; }
  body.paired.show-he .en { padding-top: .45em; }
  body.paired:not(.show-he) .tr { font-size: 18px; padding-top: .35em; }
}

/* single-language reading flows like a book */
body.show-he:not(.show-tr):not(.show-en) main { max-width: 760px; }
body.show-en:not(.show-he):not(.show-tr) main,
body.show-tr:not(.show-he):not(.show-en) main { max-width: 720px; }
body.show-he:not(.show-tr):not(.show-en) .verse { grid-template-columns: 1fr 2.6em; }
body.show-he:not(.show-tr):not(.show-en) .verse .num { grid-column: 2; text-align: left; }
body.show-he:not(.show-tr):not(.show-en) .orig { grid-column: 1; grid-row: 1; }

footer {
  text-align: center; color: var(--muted); font-size: 13px;
  padding: 24px 16px 40px; border-top: 1px solid var(--faint);
  line-height: 1.5;
}
footer p { max-width: 720px; margin: 0 auto 8px; }

@media (max-width: 520px) {
  body { font-size: 18px; }
  .toggles span { padding: 3px 9px; font-size: 13px; }
  .title h1 { font-size: 36px; }
  .he { font-size: 23px; }
  .verse { grid-template-columns: 2em 1fr; gap: 0 10px; }
}
