/* Siddur — calm, reverent, mobile-first. Nusach Edot HaMizrach (Sephardi).
   Two themes (parchment day / quiet night); auto follows the device. */

:root {
  --maxw: 40rem;
  --he-scale: 1; /* set by the size control */

  /* day (parchment) */
  --bg: #f1e9d6;
  --bg-grad: radial-gradient(120% 80% at 50% -10%, #f7f1e2 0%, #efe6d1 55%, #e9dfc6 100%);
  --surface: #fcf8ee;
  --surface-2: #f6efdf;
  --ink: #2c2620;
  --muted: #6d6555;
  --faint: #948a76;
  --gold: #8a6a2c;
  --rule: rgba(70, 58, 35, 0.14);
  --shadow: 0 1px 2px rgba(60, 48, 28, 0.06), 0 8px 26px rgba(60, 48, 28, 0.08);
  --accent: #7c5e26;
}

:root[data-theme="dark"],
body[data-theme="dark"] {
  --bg: #131009;
  --bg-grad: radial-gradient(130% 80% at 50% -10%, #201a10 0%, #17130c 60%, #100d07 100%);
  --surface: #1e1810;
  --surface-2: #241d13;
  --ink: #ece2cd;
  --muted: #a2967d;
  --faint: #786d58;
  --gold: #c7a55e;
  --rule: rgba(199, 165, 94, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
  --accent: #c7a55e;
}

@media (prefers-color-scheme: dark) {
  body[data-theme="auto"] {
    --bg: #131009;
    --bg-grad: radial-gradient(130% 80% at 50% -10%, #201a10 0%, #17130c 60%, #100d07 100%);
    --surface: #1e1810;
    --surface-2: #241d13;
    --ink: #ece2cd;
    --muted: #a2967d;
    --faint: #786d58;
    --gold: #c7a55e;
    --rule: rgba(199, 165, 94, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.45);
    --accent: #c7a55e;
  }
}

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

body {
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--ink);
  font-family: "Spectral", Georgia, "Times New Roman", serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
  padding-top: env(safe-area-inset-top);
}
.topbar__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px 10px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand__he {
  font-family: "Frank Ruhl Libre", "SBL Hebrew", "David", serif;
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: 0.5px;
}
.brand__meta {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}
.iconbtn {
  appearance: none;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--muted);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.iconbtn:active { transform: scale(0.94); }

.partnav {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  gap: 8px;
  padding: 0 14px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.partnav::-webkit-scrollbar { display: none; }
.partnav button {
  appearance: none;
  white-space: nowrap;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 7px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s;
}
.partnav button.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 500;
}

/* ---------- reader ---------- */
.reader {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 8px 20px 28vh;
}
.part-head {
  text-align: center;
  padding: 26px 0 14px;
}
.part-head__now {
  display: inline-block;
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--accent);
  padding: 3px 12px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.part-head__he {
  font-family: "Frank Ruhl Libre", serif;
  font-size: 2rem;
  font-weight: 500;
  margin: 0;
  color: var(--ink);
}
.part-head__en { color: var(--faint); font-size: 0.9rem; margin-top: 4px; letter-spacing: 0.04em; }

.section { margin-top: 30px; scroll-margin-top: 116px; }
.section__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding-bottom: 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}
.section__no {
  font-size: 0.78rem;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.section__he {
  font-family: "Frank Ruhl Libre", serif;
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--ink);
  margin-inline-start: auto;
  direction: rtl;
}
.section__en { font-size: 0.86rem; color: var(--muted); letter-spacing: 0.02em; }
.section__note { font-size: 0.82rem; color: var(--faint); font-style: italic; margin: 2px 0 0; }

.block { padding: 14px 0; border-bottom: 1px solid color-mix(in srgb, var(--rule) 55%, transparent); }
.block:last-child { border-bottom: 0; }
.block__label {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--gold);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.block__instruction {
  font-size: 0.82rem;
  color: var(--faint);
  font-style: italic;
  margin-bottom: 8px;
}
.he {
  direction: rtl;
  text-align: right;
  font-family: "Frank Ruhl Libre", "SBL Hebrew", "Times New Roman", serif;
  font-size: calc(1.5rem * var(--he-scale));
  line-height: 2.05;
  color: var(--ink);
  font-weight: 500;
  margin: 0;
}
.tr {
  color: var(--muted);
  font-style: italic;
  font-size: 1rem;
  line-height: 1.65;
  margin: 10px 0 0;
}
.en {
  color: var(--faint);
  font-size: 0.92rem;
  line-height: 1.6;
  margin: 9px 0 0;
}
body.hide-tr .tr { display: none; }
body.hide-en .en { display: none; }

/* quiet, whispered lines (e.g. Baruch shem) */
.block--whisper .he { font-size: calc(1.2rem * var(--he-scale)); color: var(--muted); }

/* ---------- settings sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 15, 8, 0.5);
  z-index: 30;
  animation: fade 0.2s ease;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 31;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  padding: 10px 22px calc(26px + env(safe-area-inset-bottom));
  animation: rise 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet__handle { width: 40px; height: 4px; border-radius: 999px; background: var(--rule); margin: 6px auto 14px; }
.sheet__title { font-family: "Frank Ruhl Libre", serif; font-weight: 500; font-size: 1.1rem; margin: 0 0 8px; }
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--rule);
}
.row--stack { flex-direction: column; align-items: stretch; gap: 10px; }
.row__label { font-size: 0.98rem; color: var(--ink); }
.sheet__note { font-size: 0.78rem; color: var(--faint); margin-top: 16px; line-height: 1.5; }

.toggle {
  appearance: none; border: 0; cursor: pointer;
  width: 50px; height: 30px; border-radius: 999px;
  background: var(--rule); position: relative; transition: background 0.18s;
}
.toggle span {
  position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,0.25);
  transition: transform 0.18s;
}
.toggle[aria-checked="true"] { background: var(--accent); }
.toggle[aria-checked="true"] span { transform: translateX(20px); }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; appearance: none; cursor: pointer;
  border: 1px solid var(--rule); background: transparent; color: var(--muted);
  border-radius: 10px; padding: 9px 4px; font: inherit; transition: all 0.15s;
}
.seg button.is-on { background: var(--accent); border-color: var(--accent); color: var(--bg); }
#sizeSeg button[data-size="s"] { font-size: 0.8rem; }
#sizeSeg button[data-size="m"] { font-size: 1rem; }
#sizeSeg button[data-size="l"] { font-size: 1.2rem; }
#sizeSeg button[data-size="xl"] { font-size: 1.45rem; }

@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 560px) {
  .reader { padding-left: 8px; padding-right: 8px; }
}
