:root {
  --paper: #fbf7ef;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #6b6f7a;
  --line: #e6dfd0;
  --navy: #1d3a6b;
  --navy-deep: #152b50;
  --gold: #b8893a;
  --gold-soft: #f3e7cf;
  --ok: #2e7d4f;
  --ok-soft: #e3f3e8;
  --danger: #a33b2e;
  --he-font: "Frank Ruhl Libre", "Noto Serif Hebrew", "David", "Times New Roman", serif;
  --en-font: "Source Serif 4", Georgia, "Times New Roman", serif;
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --size: 1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 6px 20px rgba(20, 30, 50, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15181f;
    --card: #1d222b;
    --ink: #ece7dc;
    --muted: #9aa0ad;
    --line: #2d3340;
    --navy: #8fb0e6;
    --navy-deep: #0f1a2e;
    --gold: #d6a957;
    --gold-soft: #2c261a;
    --ok: #6fcf97;
    --ok-soft: #1d2f26;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui-font);
  line-height: 1.5;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--navy); }
button { font: inherit; cursor: pointer; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--navy-deep);
  color: #fbf7ef;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  font-family: var(--he-font); font-weight: 700; font-size: 1.35rem;
  background: var(--gold); color: #1a1a1a; padding: 2px 10px; border-radius: 8px; line-height: 1.3;
}
.brand .name { font-weight: 700; letter-spacing: .02em; font-size: 1.15rem; }
.datebar { display: flex; align-items: center; justify-content: center; gap: 4px; min-width: 0; position: relative; }
.date-btn {
  background: transparent; color: inherit; border: 1px solid rgba(255,255,255,.18);
  border-radius: 10px; padding: 4px 14px; display: flex; flex-direction: column; align-items: center; min-width: 0;
}
.date-btn .heb { font-family: var(--he-font); font-size: 1.2rem; font-weight: 500; line-height: 1.2; }
.date-btn .sub { font-size: .78rem; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
#datePick { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; left: 50%; top: 100%; }
.icon-btn {
  background: transparent; color: inherit; border: 0; border-radius: 10px;
  width: 38px; height: 38px; font-size: 1.5rem; line-height: 1; display: inline-grid; place-items: center;
}
.icon-btn:hover { background: rgba(255,255,255,.1); }
.tools { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
.pill {
  background: rgba(255,255,255,.1); color: inherit; border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px; padding: 5px 12px; font-size: .85rem; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.pill:hover { background: rgba(255,255,255,.18); }
.pill.toggle input { accent-color: var(--gold); margin: 0; }

/* ---------- tabs ---------- */
.tabs {
  position: sticky; top: var(--header-h, 62px); z-index: 19;
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 0 10px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 0 0 auto; padding: 12px 14px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .92rem;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a.active { color: var(--navy); border-bottom-color: var(--gold); }
.tabs a .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-left: 6px; vertical-align: middle; }

/* ---------- content ---------- */
.view { max-width: 1040px; margin: 0 auto; padding: 18px 16px 40px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
}
.card-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; margin-bottom: 8px; }
.card-head h2 { margin: 0; font-size: 1.35rem; font-weight: 700; line-height: 1.25; }
.card-head h2 .he-title { font-family: var(--he-font); color: var(--gold); margin-left: 8px; font-weight: 500; }
.card-head .portion { color: var(--muted); font-size: .95rem; margin-top: 2px; }
.card-head .portion b { color: var(--ink); font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 7px 14px; font-size: .88rem; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.done { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.btn.small { padding: 4px 10px; font-size: .8rem; }
.sources { font-size: .78rem; color: var(--muted); margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 10px; }

.notice { background: var(--gold-soft); border-radius: 10px; padding: 10px 14px; font-size: .9rem; margin: 8px 0 14px; }
.error { background: #fdecea; color: var(--danger); border-radius: 10px; padding: 12px 14px; margin: 8px 0; }
@media (prefers-color-scheme: dark) { .error { background: #3a1f1c; color: #f3a79b; } }
.loading { color: var(--muted); padding: 24px 0; text-align: center; }
.loading::before { content: ""; display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--gold); border-radius: 50%; margin-right: 8px; vertical-align: -4px; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- text ---------- */
.text { margin-top: 10px; }
.unit-h {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin: 26px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--gold-soft);
  font-size: 1.05rem;
}
.unit-h:first-child { margin-top: 6px; }
.unit-h .he { font-family: var(--he-font); font-size: 1.25rem; direction: rtl; }
.unit-h .en { color: var(--muted); font-weight: 600; }
.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 28px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.seg:last-child { border-bottom: 0; }
.seg .he { direction: rtl; text-align: right; font-family: var(--he-font); font-size: calc(1.3rem * var(--size)); line-height: 1.75; order: 2; }
.seg .en { font-family: var(--en-font); font-size: calc(1.02rem * var(--size)); line-height: 1.65; order: 1; }
.seg .n { font-family: var(--ui-font); font-size: .7em; color: var(--gold); font-weight: 700; margin: 0 .4em; vertical-align: .35em; user-select: none; }
.seg .he .n { margin: 0 0 0 .4em; }
.seg .en .n { margin: 0 .4em 0 0; }
.seg .he .big, .seg .he big { font-size: 1.2em; }
.seg small { font-size: .8em; color: var(--muted); }
.seg .mediumGrey { color: var(--muted); }
.seg .poetry { display: block; }
.seg .indentAll { padding-left: 1.2em; }
.footnote-marker { color: var(--gold); font-size: .7em; }
.footnote { display: none; }
body.show-footnotes .footnote { display: inline; color: var(--muted); font-size: .85em; font-style: italic; }
body.show-footnotes .footnote::before { content: " ["; }
body.show-footnotes .footnote::after { content: "] "; }
body:not(.show-footnotes) .footnote-marker { display: none; }

body.display-he .seg { grid-template-columns: 1fr; }
body.display-he .seg .en, body.display-he .unit-h .en { display: none; }
body.display-en .seg { grid-template-columns: 1fr; }
body.display-en .seg .he, body.display-en .unit-h .he { display: none; }

/* rashi */
.rashi { grid-column: 1 / -1; margin: 2px 0 4px; border-left: 3px solid var(--gold-soft); padding-left: 12px; }
.rashi summary { cursor: pointer; color: var(--muted); font-size: .85rem; font-weight: 600; list-style: none; }
.rashi summary::-webkit-details-marker { display: none; }
.rashi summary::before { content: "▸ "; color: var(--gold); }
.rashi[open] summary::before { content: "▾ "; }
.rashi .seg { border-bottom: 1px dotted var(--line); padding: 7px 0; }
.rashi .seg .he { font-size: calc(1.12rem * var(--size)); }
.rashi .seg .en { font-size: calc(.95rem * var(--size)); }
.rashi .seg b { color: var(--navy); }

/* ---------- today overview ---------- */
.hero { text-align: center; padding: 10px 0 6px; }
.hero .heb { font-family: var(--he-font); font-size: 2rem; font-weight: 500; line-height: 1.2; }
.hero .sub { color: var(--muted); }
.streak { display: inline-flex; gap: 14px; margin-top: 10px; background: var(--gold-soft); border-radius: 999px; padding: 6px 16px; font-size: .9rem; }
.streak b { color: var(--navy); }
.list { display: grid; gap: 10px; margin-top: 14px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: inherit;
  box-shadow: var(--shadow);
}
.item:hover { border-color: var(--gold); }
.item .chk {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 1rem; color: transparent;
}
.item.done .chk { background: var(--ok); border-color: var(--ok); color: #fff; }
.item .t { font-weight: 700; }
.item .t .he-title { font-family: var(--he-font); color: var(--gold); margin-left: 6px; font-weight: 500; }
.item .p { color: var(--muted); font-size: .9rem; }
.item .go { color: var(--muted); font-size: 1.3rem; }

/* ---------- settings ---------- */
.settings { border: 0; border-radius: 16px; padding: 0; width: min(520px, 92vw); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.settings::backdrop { background: rgba(10, 15, 30, .55); }
.settings form { padding: 20px 22px; }
.settings h2 { margin: 0 0 10px; }
.settings fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 12px; padding: 8px 14px 10px; }
.settings legend { font-weight: 700; font-size: .85rem; color: var(--muted); padding: 0 6px; }
.settings label { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: .95rem; }
.settings input[type=range] { width: 100%; }
.settings input[type=number] { width: 90px; margin-left: auto; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--ink); }
.settings .row { display: flex; justify-content: flex-end; }
.settings .primary { background: var(--navy); color: #fff; border: 0; border-radius: 999px; padding: 8px 18px; font-weight: 600; }

.foot { max-width: 1040px; margin: 0 auto; padding: 0 16px 30px; color: var(--muted); font-size: .78rem; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .top { grid-template-columns: 1fr auto; gap: 8px 10px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .brand { order: 1; }
  .tools { order: 2; }
  .datebar { order: 3; grid-column: 1 / -1; }
  .brand .name { display: none; }
  .pill.toggle span { font-size: .8rem; }
  .seg { grid-template-columns: 1fr; gap: 6px; }
  .seg .he { order: 1; }
  .seg .en { order: 2; }
  .card { padding: 14px; }
  .hero .heb { font-size: 1.7rem; }
}
