/* Hebrew typography.
 *
 * This site carries a lot of Hebrew, in three different shapes, and they do not
 * want the same treatment:
 *
 *   unpointed rabbinic prose   the Igros Kodesh letters, Tanya, most of it
 *   pointed text (nikud)       verses, tefilá, anything meant to be read aloud
 *   Rashi script               commentary, when it is set the traditional way
 *
 * Pointed text is the one that breaks naively. Vowel points and cantillation
 * marks hang below and above the letter, so a font without proper mark
 * positioning stacks them on top of each other, and a normal line-height
 * collides the marks of one line with the letters of the next.
 *
 * Font choice follows what the Hebrew-web projects settled on. Frank Ruhl is the
 * classic Israeli printed-sefer face and is what the volumes look like, so it
 * leads for unpointed prose. Noto Serif Hebrew leads for pointed text because
 * Noto is built for full Unicode mark positioning. Behind both sit the Culmus
 * and SIL family names, which cost nothing and are picked up automatically by
 * readers who already have them installed, which serious Hebrew readers often do.
 *
 * See Sefaria's font notes and Aharon Varady's browser tests for the background:
 *   https://github.com/Sefaria/Sefaria-Project/tree/master/static/fonts/Taamey-Frank
 *   https://aharon.varady.net/browser-test/how-to.html
 */

/* ---- stacks ------------------------------------------------------------- */

:root {
  /* unpointed: the printed sefer look */
  --he-serif:
    'Frank Ruhl Libre', 'Taamey Frank CLM', 'Frank Ruehl CLM', 'David Libre',
    'Taamey David CLM', 'Narkisim', 'Times New Roman', serif;

  /* pointed: chosen for mark positioning, not for looks */
  --he-nikud:
    'Noto Serif Hebrew', 'Taamey Frank CLM', 'Keter YG', 'Shofar',
    'Ezra SIL SR', 'Ezra SIL', 'SBL Hebrew', 'Cardo', 'David Libre', serif;

  --he-sans:
    'Noto Sans Hebrew', 'Heebo', 'Assistant', 'Arial Hebrew', Arial, sans-serif;

  --he-rashi: 'Noto Rashi Hebrew', 'Keter Aram Tsova', var(--he-serif);
}

/* ---- inline Hebrew inside a Portuguese line ----------------------------- */

/* Use this, or <bdi>, for ANY Hebrew that shares a line with Latin text.
 *
 * An RTL run dropped into an LTR line reorders the neutral characters around it,
 * so digits, parentheses and punctuation next to the Hebrew migrate to the wrong
 * side. A citation reading "carta ב'תכג (2423) · 22 de Shevat" renders as
 * "carta 22 · (2423) · ב'תכג de Shevat" without isolation. It is not a font
 * problem and it does not show up until real Hebrew meets real numbers. */
.he,
bdi.he {
  unicode-bidi: isolate;
  font-family: var(--he-serif);
  font-size: 1.06em; /* Hebrew reads small next to Latin at the same size */
}

/* ---- block Hebrew ------------------------------------------------------- */

.he-block,
[lang="he"]:not(.he),
[lang="yi"] {
  direction: rtl;
  text-align: right;
  font-family: var(--he-serif);
  font-size: 1.08em;
  line-height: 1.95;
}

/* Marks need vertical room. Without it the nikud of one line touches the
 * letters of the line above, which is the usual reason pointed text looks
 * cramped and slightly broken on the web. */
.he-nikud {
  font-family: var(--he-nikud);
  line-height: 2.25;
  font-size: 1.12em;
}

.he-rashi {
  font-family: var(--he-rashi);
  line-height: 2;
}

.he-sans {
  font-family: var(--he-sans);
}

/* Hebrew has no case and no italic tradition. Faux-italic slants the letters
 * into something that is simply wrong, and uppercase does nothing. */
.he, .he-block, [lang="he"], [lang="yi"] {
  font-style: normal;
  text-transform: none;
  font-synthesis: none;
}

.he-block em, .he-block i, [lang="he"] em, [lang="he"] i {
  font-style: normal;
  font-weight: 500;
}

/* ---- direction-aware spacing -------------------------------------------- */

/* Logical properties so a block flips correctly when it is RTL instead of
 * needing a mirrored copy of every rule. */
.he-block blockquote,
.he-block .quote {
  border-inline-start: 3px solid var(--line, #e2ddd0);
  border-inline-end: 0;
  padding-inline-start: 16px;
  padding-inline-end: 0;
  margin-inline: 0;
}

.he-block ul,
.he-block ol {
  padding-inline-start: 1.4em;
  padding-inline-end: 0;
}

/* ---- punctuation -------------------------------------------------------- */

/* Hebrew abbreviations use geresh ׳ and gershayim ״, not the ASCII quote. They
 * are letters' worth of meaning, so never let a "smart quotes" pass touch text
 * inside these blocks. */
.he-block, .he {
  quotes: none;
}

/* ---- when the whole interface is in Hebrew ------------------------------ */

html[lang="he"] {
  direction: rtl;
}

html[lang="he"] body {
  font-family: var(--he-sans);
}

/* Latin sitting inside a Hebrew page needs the same isolation in reverse. */
html[lang="he"] .lat {
  unicode-bidi: isolate;
  direction: ltr;
  font-family: Inter, system-ui, sans-serif;
}
