:root {
  --bg: #f7f4ed;
  --panel: #fffdf8;
  --ink: #23201b;
  --ink-soft: #6b6459;
  --rule: #ddd6c7;
  --accent: #7a5c2e;
  --accent-soft: #f0e7d5;
  --shadow: 0 1px 2px rgba(60, 50, 30, .06), 0 8px 24px rgba(60, 50, 30, .05);

  /* Serifs that place nikud cleanly. A generic sans drops or collides with the marks. */
  --hebrew: 'Frank Ruhl Libre', 'Noto Serif Hebrew', 'David Libre', 'Times New Roman', serif;
  --english: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --panel: #201d19;
    --ink: #ece6da;
    --ink-soft: #9c9384;
    --rule: #3a352d;
    --accent: #d3b078;
    --accent-soft: #2e2820;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-text-size-adjust: 100%;
}

#app { max-width: 46rem; margin: 0 auto; padding: 1.5rem 1.15rem 5rem; }

/* ---------- header ---------- */

header { text-align: center; padding: 1rem 0 1.75rem; }

.brand {
  font-family: var(--hebrew);
  font-size: 1.9rem;
  font-weight: 500;
  letter-spacing: .01em;
  margin: 0;
}

.brand-sub {
  margin: .35rem 0 0;
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--ink-soft);
}

/* ---------- date navigation ---------- */

.nav {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: .85rem;
  margin-bottom: 1.5rem;
}

.nav-row { display: flex; align-items: center; gap: .55rem; }
.nav-row + .nav-row {
  margin-top: .7rem;
  padding-top: .7rem;
  border-top: 1px solid var(--rule);
}

.nav-mid { flex: 1; min-width: 0; text-align: center; }
.civil-date { font-weight: 600; font-size: 1rem; }

.hebrew-date {
  font-family: var(--hebrew);
  font-size: 1.1rem;
  color: var(--ink-soft);
  margin-top: .1rem;
  direction: rtl;
}

.today-flag {
  display: inline-block;
  margin-top: .3rem;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 99px;
  padding: .12rem .55rem;
}

/* ---------- controls ---------- */

button, select, input[type=date] {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: .42rem .6rem;
  cursor: pointer;
}

button:hover:not(:disabled), select:hover, input[type=date]:hover { border-color: var(--accent); }
button:disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.arrow { font-size: 1.1rem; line-height: 1; padding: .45rem .75rem; flex: none; }

.pickers { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; justify-content: center; }
.pickers select { padding: .35rem .45rem; font-size: .88rem; }
.pickers input[type=date] { font-size: .88rem; }

.picker-group { display: flex; gap: .3rem; align-items: center; }
.picker-label {
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-soft);
  margin-inline-end: .1rem;
}

.linkish {
  background: none;
  border: none;
  padding: .2rem .3rem;
  color: var(--accent);
  text-decoration: underline;
  font-size: .82rem;
}

/* ---------- portion heading ---------- */

.portion-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.portion-title { margin: 0; font-size: 1.15rem; font-weight: 600; }
.portion-sub { margin: .2rem 0 0; font-size: .85rem; color: var(--ink-soft); }

.toggle {
  display: flex;
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  flex: none;
}
.toggle button { border: none; border-radius: 0; padding: .35rem .8rem; font-size: .85rem; background: transparent; }
.toggle button.on { background: var(--accent); color: var(--panel); }
.toggle button:disabled { opacity: .3; }

/* ---------- the text ---------- */

.sheet {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1.75rem 1.6rem;
}

.seg { margin: 0 0 1.35rem; }
.seg:last-child { margin-bottom: 0; }

/* The text is fully vocalized, so line-height has to leave room for the nikud. */
.text-he {
  direction: rtl;
  text-align: justify;
  font-family: var(--hebrew);
  font-size: 1.32rem;
  line-height: 1.95;
  font-weight: 400;
}

.text-en {
  direction: ltr;
  text-align: justify;
  /* Justified English without hyphenation opens rivers at this measure. Hebrew is not
     hyphenated -- browsers justify it on the word spaces instead. */
  hyphens: auto;
  font-family: var(--english);
  font-size: 1.15rem;
  line-height: 1.72;
}

/* The last line of a justified paragraph should not be stretched. */
.text-he, .text-en { text-align-last: auto; }

.incipit {
  font-family: var(--hebrew);
  direction: rtl;
  text-align: right;
  font-size: .95rem;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
  padding-bottom: .7rem;
  margin-bottom: 1.2rem;
}

/* ---------- states ---------- */

.note, .error { border-radius: 10px; padding: .8rem 1rem; font-size: .88rem; line-height: 1.5; }
.note { background: var(--accent-soft); color: var(--ink); margin-bottom: 1.1rem; }
.error { background: var(--panel); border: 1px solid var(--rule); box-shadow: var(--shadow); }
.error h2 { margin: 0 0 .4rem; font-size: 1rem; }

a { color: var(--accent); }

.skeleton { animation: pulse 1.4s ease-in-out infinite; }
.skeleton div { height: .95rem; border-radius: 4px; background: var(--rule); margin-bottom: .75rem; }

/* Ragged widths for the loading placeholder. Classes rather than style attributes so the
   CSP can refuse inline styles outright. */
.skeleton .w96 { width: 96%; }
.skeleton .w94 { width: 94%; }
.skeleton .w92 { width: 92%; }
.skeleton .w88 { width: 88%; }
.skeleton .w70 { width: 70%; }
.skeleton .w60 { width: 60%; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .45 } }

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

.boot { text-align: center; color: var(--ink-soft); padding: 3rem 1rem; font-size: .9rem; }

/* ---------- footer ---------- */

footer {
  margin-top: 2rem;
  text-align: center;
  font-size: .78rem;
  line-height: 1.7;
  color: var(--ink-soft);
}
footer a { color: inherit; }

/* Hebrew citations carry gematriya numerals, so the line needs the Hebrew face. */
.source[lang="he"] { font-family: var(--hebrew); font-size: .92rem; }

/* ---------- narrow screens ---------- */

@media (max-width: 34rem) {
  #app { padding: 1rem .8rem 4rem; }
  .sheet { padding: 1.3rem 1.05rem; }
  .text-he { font-size: 1.22rem; }
  .text-en { font-size: 1.06rem; }
  .brand { font-size: 1.6rem; }
}
