/* Chitas and Rambam. Phone first; wider screens and print further down. */
@font-face { font-family: "Frank Ruhl Libre"; src: url(fonts/FrankRuhlLibre-400.woff2) format("woff2"); font-weight: 400; font-display: block; }
@font-face { font-family: "Frank Ruhl Libre"; src: url(fonts/FrankRuhlLibre-500.woff2) format("woff2"); font-weight: 500; font-display: block; }
@font-face { font-family: "Frank Ruhl Libre"; src: url(fonts/FrankRuhlLibre-700.woff2) format("woff2"); font-weight: 700; font-display: block; }
@font-face { font-family: "Noto Rashi Hebrew"; src: url(fonts/NotoRashiHebrew-400.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Source Serif"; src: url(fonts/SourceSerif4-Caption-400.woff2) format("woff2"); font-weight: 400; font-display: block; }
@font-face { font-family: "Source Serif"; src: url(fonts/SourceSerif4-Caption-600.woff2) format("woff2"); font-weight: 600; font-display: block; }
@font-face { font-family: "Source Serif Text"; src: url(fonts/SourceSerif4-Text-400.woff2) format("woff2"); font-weight: 400; font-display: block; }
@font-face { font-family: "Source Serif Text"; src: url(fonts/SourceSerif4-Text-600.woff2) format("woff2"); font-weight: 600; font-display: block; }
@font-face { font-family: "Source Serif Text"; src: url(fonts/SourceSerif4-Italic-400.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: block; }

:root {
  --scale: 1;
  --he: "Frank Ruhl Libre", "Taamey Frank CLM", "SBL Hebrew", "Times New Roman", serif;
  --rashi-font: var(--he);
  --en: "Source Serif", Georgia, "Times New Roman", serif;
  --en-text: "Source Serif Text", Georgia, "Times New Roman", serif;

  --bg: #fbfaf6; --ink: #1c1915; --gloss: #5c574e; --muted: #6f695e; --faint: #9b9488; --rule: #e4dfd4; --rule-strong: #cfc8b9;
  --accent: #8b2e1f; --accent-soft: #f3e9e3; --press: #f0ece3;

  --he-size: calc(1.5rem * var(--scale));
  --en-size: calc(0.8rem * var(--scale));
  --rashi-he: calc(1.2rem * var(--scale));
  --rashi-en: calc(0.95rem * var(--scale));
  --rambam-he: calc(1.38rem * var(--scale));
  --chunk-min: 4.6rem;
  --measure: 40rem;
  --pad: 1.15rem;
  --head-h: 6rem;
}
html[data-theme="dark"] {
  --bg: #161513; --ink: #ebe5d9; --gloss: #aea698; --muted: #a39b8d; --faint: #7d766b; --rule: #2d2a25; --rule-strong: #403b34;
  --accent: #dc9a83; --accent-soft: #2a201c; --press: #22201c;
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #161513; --ink: #ebe5d9; --gloss: #aea698; --muted: #a39b8d; --faint: #7d766b; --rule: #2d2a25; --rule-strong: #403b34;
    --accent: #dc9a83; --accent-soft: #2a201c; --press: #22201c;
  }
}
html[data-rashifont="script"] { --rashi-font: "Noto Rashi Hebrew", var(--he); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: var(--head-h); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--en); font-size: 1rem; line-height: 1.5;
  font-kerning: normal; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[lang="he"] { font-family: var(--he); }
.skip { position: absolute; left: -999px; top: 0; background: var(--bg); padding: .6rem 1rem; z-index: 30; }
.skip:focus { left: .5rem; }

/* ---------- masthead ---------- */
.masthead { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--rule); padding-top: env(safe-area-inset-top); }
.bar { display: grid; grid-template-columns: 2.75rem 1fr 2.75rem; align-items: center; max-width: 52rem; margin: 0 auto; padding: 0 .25rem; height: 3.25rem; }
.daypick { grid-column: 2; display: flex; align-items: center; justify-content: center; min-width: 0; }
.nav-btn { width: 2.75rem; height: 2.75rem; display: grid; place-items: center; color: var(--ink); flex: none; border-radius: 2px; }
.nav-btn svg { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn:disabled { color: var(--rule-strong); }
.nav-btn:not(:disabled):active, .date-btn:active { background: var(--press); }
.aa { grid-column: 3; font-family: var(--en-text); font-size: 1.05rem; letter-spacing: .01em; }
.date-btn { flex: 1 1 auto; min-width: 0; height: 2.75rem; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; padding: 0 .25rem; border-radius: 2px; }
.date-en { font-size: .9rem; font-weight: 600; letter-spacing: .005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.date-he { font-size: .92rem; color: var(--muted); }

.tabs { display: flex; justify-content: center; gap: 0; max-width: 52rem; margin: 0 auto; }
.tab { flex: 1 1 0; max-width: 12rem; height: 2.75rem; display: flex; align-items: center; justify-content: center; gap: .45rem; color: var(--muted);
  position: relative; font-size: .88rem; letter-spacing: .02em; }
.tab-he { font-size: 1.12rem; font-weight: 500; }
.tab[aria-pressed="true"] { color: var(--ink); }
.tab[aria-pressed="true"]::after { content: ""; position: absolute; left: 22%; right: 22%; bottom: -1px; height: 2px; background: var(--accent); }

/* ---------- page ---------- */
main { display: block; max-width: calc(var(--measure) + 2 * var(--pad)); margin: 0 auto; padding: 0 var(--pad) 2rem; min-height: 100vh; outline: none; }
html:not(.ready) main { visibility: hidden; }
html[data-tab="chumash"] .part.rambam, html[data-tab="rambam"] .part.chumash { display: none; }

.away { margin: 1rem 0 0; font-size: .85rem; color: var(--muted); text-align: center; }
.linkish { color: var(--accent); text-decoration: underline; text-underline-offset: .18em; text-decoration-thickness: 1px; min-height: 2.75rem; padding: 0 .25rem; }

.part-head { text-align: center; padding: 2rem 0 1.5rem; border-bottom: 1px solid var(--rule); margin-bottom: .5rem; }
.dayline { margin: 0 0 1.35rem; display: flex; flex-direction: column; gap: .1rem; }
.dl-he { font-size: 1rem; color: var(--muted); }
.dl-en { font-size: .78rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.kicker-he { margin: 0 0 .2rem; font-size: 1.02rem; color: var(--muted); }
.title { margin: 0; font-weight: 700; font-size: calc(2.15rem * var(--scale)); line-height: 1.15; letter-spacing: 0; }
.subtitle { margin: .3rem 0 0; font-size: calc(1.3rem * var(--scale)); color: var(--accent); font-weight: 500; }
.en-title { margin: .7rem auto 0; font-size: .95rem; color: var(--ink); max-width: 30rem; font-family: var(--en-text); }
.jump { display: flex; justify-content: center; gap: .25rem; margin-top: 1rem; direction: rtl; flex-wrap: wrap; }
.jump a { min-height: 2.75rem; min-width: 2.75rem; padding: 0 .75rem; display: inline-flex; align-items: center; font-size: 1.05rem; color: var(--ink);
  text-decoration: underline; text-decoration-color: var(--rule-strong); text-underline-offset: .3em; text-decoration-thickness: 1px; }
.jump a:hover { text-decoration-color: var(--accent); }

/* pasuk and halachah */
.pasuk, .halacha { position: relative; padding: 1.1rem 0 1.15rem; border-bottom: 1px solid var(--rule); }
.pasuk:last-child, .perek .halacha:last-child { border-bottom: 0; }
.num { display: flex; justify-content: flex-start; align-items: baseline; gap: .5rem; flex-direction: row-reverse; margin-bottom: .2rem; line-height: 1; }
.num-he { font-size: 1.08rem; font-weight: 700; color: var(--accent); }
.num-en { font-size: .7rem; color: var(--faint); letter-spacing: .03em; font-variant-numeric: tabular-nums; }

/* interlinear lines: Hebrew chunk on top, English under it, as wide as the Hebrew */
.il { text-align: right; line-height: 1; }
.ch { display: inline-block; vertical-align: top; text-align: center; min-width: max(var(--chunk-min), calc(var(--en-size) * var(--lw, 0) * .54)); margin: 0 0 .7rem .62rem; }
.ch .h { display: block; white-space: nowrap; font-family: var(--he); font-size: var(--he-size); line-height: 1.4; font-weight: 400; color: var(--ink); }
.ch .e { display: block; width: 0; min-width: 100%; margin-top: .05rem; font-family: var(--en); font-size: var(--en-size); line-height: 1.28; color: var(--gloss);
  hyphens: manual; overflow-wrap: normal; }
.rambam-il .ch .h { font-size: var(--rambam-he); }
.ch.long { display: block; min-width: 0; margin-left: 0; }
.ch.long .h { white-space: normal; line-height: 1.55; }
.ch.long .e { width: auto; text-align: left; margin-top: .25rem; }
.ch.cite .h { font-size: calc(var(--he-size) * .62); color: var(--muted); }
.rambam-il .ch.cite .h { font-size: calc(var(--rambam-he) * .66); }
.ch.cite .e { font-size: calc(var(--en-size) * .92); color: var(--muted); }

/* Rashi */
.rashi { margin: .55rem 0 0; padding: .55rem .9rem .1rem 0; border-right: 1px solid var(--rule-strong); }
.rashi + .rashi { margin-top: .5rem; }
.rashi-he { margin: 0; font-family: var(--rashi-font); font-size: var(--rashi-he); line-height: 1.62; text-align: right; }
.rashi-he .dh-he { font-weight: 700; font-family: var(--he); }
html[data-rashifont="script"] .rashi-he .dh-he { font-family: var(--he); }
.rashi-he .cite { font-size: .72em; color: var(--muted); }
.rashi-en { margin: .4rem 0 .5rem; font-family: var(--en-text); font-size: var(--rashi-en); line-height: 1.55; color: var(--ink); text-align: left; max-width: 36rem; margin-left: auto; }
.rashi-en .dh-en { font-style: italic; }
.r-il .ch .h { font-family: var(--rashi-font); font-size: var(--rashi-he); }
.r-il .ch.dh .h { font-weight: 700; font-family: var(--he); }
.r-il .ch .e { font-size: calc(var(--en-size) * .95); }
.r-il .ch { min-width: max(var(--chunk-min), calc(var(--en-size) * .95 * var(--lw, 0) * .54)); }
.r-il .ch.cite .h { font-size: calc(var(--rashi-he) * .7); }
.r-il { padding-top: .1rem; }
html[data-rashi="flow"] .r-inter, html[data-rashi="inter"] .r-flow { display: none; }
html[data-rambam="flow"] .m-inter, html[data-rambam="inter"] .m-flow { display: none; }
.rambam-he { margin: 0; font-family: var(--he); font-size: calc(var(--he-size) * .86); line-height: 1.7; text-align: right; }
.rambam-he .cite { font-size: .72em; color: var(--muted); }
.rambam-en { margin: .5rem 0 .2rem; font-family: var(--en-text); font-size: calc(var(--en-size) * 1.08); line-height: 1.6; color: var(--ink); text-align: left; max-width: 38rem; margin-left: auto; }

/* perek dividers */
.perek-mark { display: flex; align-items: baseline; justify-content: center; gap: .6rem; margin: 1.6rem 0 .3rem; color: var(--muted); font-size: 1.05rem; }
.perek-mark .pm-en { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
.perek { padding-top: .5rem; }
.perek-head { margin: 1.6rem 0 .1rem; text-align: center; font-weight: 400; display: flex; flex-direction: column; align-items: center; gap: .1rem; }
.perek-head .ph-he { font-size: calc(1.55rem * var(--scale)); font-weight: 700; }
.perek-head .ph-en { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.perek-head::after { content: ""; width: 2.5rem; height: 1px; background: var(--accent); margin-top: .6rem; }

.pending { margin: .2rem 0 .3rem; font-size: .82rem; color: var(--muted); font-style: italic; font-family: var(--en-text); text-align: left; }

.nhe { font-size: 1.05rem; color: var(--ink); }
.nhe-in { font-size: 1.05em; }

/* day navigation at the end */
.daynav { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: 2.5rem 0 0; padding-top: 1.25rem; border-top: 1px solid var(--rule); }
.dn { display: flex; flex-direction: column; gap: .1rem; padding: .7rem .2rem; min-height: 3.5rem; text-align: left; }
.dn.next { text-align: right; grid-column: 2; }
.dn-l { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.dn-d { font-size: 1rem; color: var(--ink); }
.dn.prev .dn-d::before { content: "‹ "; color: var(--muted); }
.dn.next .dn-d::after { content: " ›"; color: var(--muted); }

.colophon { max-width: calc(var(--measure) + 2 * var(--pad)); margin: 0 auto; padding: 1.5rem var(--pad) calc(2.5rem + env(safe-area-inset-bottom)); font-size: .78rem; line-height: 1.5; color: var(--muted); border-top: 1px solid var(--rule); }
.colophon p { margin: 0 0 .5rem; }

/* ---------- sheets (date picker, settings) ---------- */
.sheet { border: 0; padding: 0 0 calc(1rem + env(safe-area-inset-bottom)); margin: auto 0 0; width: 100%; max-width: 100%; max-height: 88vh; background: var(--bg); color: var(--ink);
  border-top: 1px solid var(--rule-strong); box-shadow: 0 -8px 30px rgba(0,0,0,.12); }
.sheet::backdrop { background: rgba(20, 17, 12, .38); }
.sheet[open] { animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(12px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: .4rem .35rem 0 var(--pad); }
.sheet-head h2 { margin: 0; font-size: 1.05rem; font-weight: 600; letter-spacing: .01em; }
.close { width: 2.75rem; height: 2.75rem; display: grid; place-items: center; }
.close svg { width: 1.2rem; height: 1.2rem; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; }
.sheet-sub { margin: 0 var(--pad) .5rem; font-size: .82rem; color: var(--muted); }
.days { list-style: none; margin: 0; padding: 0; }
.day { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem var(--pad); min-height: 3.6rem; text-align: left; border-top: 1px solid var(--rule); position: relative; }
.day[aria-current="date"] { background: var(--press); }
.day[aria-current="date"]::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.day-l, .day-r { display: flex; flex-direction: column; gap: .1rem; }
.day-r { align-items: flex-end; text-align: right; }
.day-name { font-size: 1rem; font-weight: 600; }
.today-tag { margin-left: .5rem; font-size: .7rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--accent); }
.day-date, .day-rm { font-size: .8rem; color: var(--muted); }
.day-he { font-size: 1.05rem; }
.opt { padding: .7rem var(--pad); border-top: 1px solid var(--rule); }
.opt-l { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .45rem; letter-spacing: .02em; }
.seg { display: flex; border: 1px solid var(--rule-strong); border-radius: 3px; overflow: hidden; }
.seg button { flex: 1 1 0; min-height: 2.75rem; padding: .3rem .4rem; font-size: .88rem; line-height: 1.2; color: var(--ink); }
.seg button + button { border-left: 1px solid var(--rule-strong); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg button:disabled { color: var(--faint); }
.seg .size-now { font-variant-numeric: tabular-nums; color: var(--muted); cursor: default; }
.seg .size-now:disabled { color: var(--muted); }
.a-s { font-size: .85rem; } .a-l { font-size: 1.25rem; }
.opt-foot { margin: .2rem var(--pad) .2rem; font-size: .78rem; color: var(--muted); }

/* ---------- tablet ---------- */
@media (min-width: 700px) {
  :root { --he-size: calc(1.8rem * var(--scale)); --en-size: calc(.86rem * var(--scale)); --rashi-he: calc(1.35rem * var(--scale)); --rashi-en: calc(1.02rem * var(--scale));
          --rambam-he: calc(1.6rem * var(--scale)); --chunk-min: 5.4rem; --pad: 2rem; --measure: 44rem; }
  .bar { padding: 0 .75rem; }
  .date-btn { flex: 0 1 auto; min-width: 15rem; flex-direction: row; gap: .75rem; }
  .date-en { font-size: .95rem; }
  .date-he { font-size: 1rem; }
  .part-head { padding: 2.75rem 0 2rem; }
  .title { font-size: calc(2.7rem * var(--scale)); }
  .ch { margin-left: .85rem; margin-bottom: .85rem; }
  /* verse numbers sit in the right margin, like a printed Chumash */
  .pasuk, .halacha { padding-right: 3rem; }
  .num { position: absolute; right: 0; top: 1.45rem; flex-direction: column; align-items: center; gap: .3rem; width: 2.2rem; }
  .num-he { font-size: 1.2rem; }
  .sheet { width: 26rem; max-width: calc(100vw - 2rem); margin: auto; border: 1px solid var(--rule-strong); max-height: 80vh; box-shadow: 0 12px 40px rgba(0,0,0,.18); }
}
/* ---------- desktop ---------- */
@media (min-width: 1100px) {
  :root { --he-size: calc(2rem * var(--scale)); --en-size: calc(.9rem * var(--scale)); --rashi-he: calc(1.45rem * var(--scale)); --rashi-en: calc(1.06rem * var(--scale));
          --rambam-he: calc(1.8rem * var(--scale)); --chunk-min: 5.8rem; --measure: 50rem; }
  .pasuk, .halacha { padding-right: 3.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (hover: hover) {
  .nav-btn:not(:disabled):hover, .date-btn:hover, .tab:hover, .day:hover, .dn:hover, .close:hover { background: var(--press); }
  .seg button:not([aria-pressed="true"]):not(:disabled):hover { background: var(--press); }
}

/* ---------- print (US Letter) ---------- */
@page { size: Letter; margin: .6in .6in .7in; }
@media print {
  :root, html[data-theme] { --bg: #fff; --ink: #000; --gloss: #3d3a35; --muted: #55514a; --faint: #77736b; --rule: #d8d3c8; --rule-strong: #bdb6a8; --accent: #7a2618;
    --he-size: 17pt; --en-size: 7.6pt; --rashi-he: 12.5pt; --rashi-en: 9pt; --rambam-he: 15pt; --chunk-min: 50pt; --scale: 1; }
  html, body { background: #fff !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .masthead, .daynav, .away, .skip, .jump, dialog { display: none !important; }
  html[data-tab] .part.chumash, html[data-tab] .part.rambam { display: block !important; }
  main { max-width: none; padding: 0; min-height: 0; }
  .part.rambam { break-before: page; }
  .part-head { padding: 0 0 12pt; }
  .title { font-size: 24pt; }
  .subtitle { font-size: 14pt; }
  .en-title { font-size: 10pt; }
    .dl-en { font-size: 7.5pt; }
  .pasuk, .halacha { padding: 7pt 26pt 8pt 0; break-inside: auto; }
  .num { position: absolute; right: 0; top: 9pt; flex-direction: column; align-items: center; gap: 2pt; width: 18pt; }
  .num-he { font-size: 11pt; }
  .num-en { font-size: 6pt; }
  .ch { break-inside: avoid; margin: 0 0 5pt 6pt; }
  .rashi { break-inside: avoid; padding-right: 8pt; }
  .rashi-en { font-size: 9pt; max-width: none; }
  .perek-head { break-after: avoid; margin-top: 12pt; }
  .perek-mark { break-after: avoid; }
  .colophon { border: 0; padding: 14pt 0 0; font-size: 7.5pt; break-inside: avoid; }
}
