/* ---------- fonts ---------- */
@font-face { font-family: 'Frank Ruhl Libre'; src: url(fonts/frl-400.woff2) format('woff2'); font-weight: 400; font-display: block; }
@font-face { font-family: 'Frank Ruhl Libre'; src: url(fonts/frl-700.woff2) format('woff2'); font-weight: 700; font-display: block; }
@font-face { font-family: 'Frank Ruhl Libre'; src: url(fonts/frl-900.woff2) format('woff2'); font-weight: 900; font-display: swap; }
@font-face { font-family: 'Birkon Shva Na'; src: url(fonts/frl-sn-400.woff2) format('woff2'); font-weight: 400; font-display: block; }
@font-face { font-family: 'Birkon Shva Na'; src: url(fonts/frl-sn-700.woff2) format('woff2'); font-weight: 700; font-display: block; }
@font-face { font-family: 'Assistant'; src: url(fonts/assistant.woff2) format('woff2'); font-weight: 200 800; font-display: swap; }

/* ---------- tokens ---------- */
:root {
  --paper: #F7F6F1;
  --surface: #FFFFFF;
  --insert: #EAEFF6;
  --ink: #1A2131;
  --muted: #5F6779;
  --tekhelet: #1F3A68;
  --wheat: #B0832B;
  --line: #D8DDE6;
  --shadow: 31 58 104;

  --scale: 1;
  --text: calc(clamp(21px, 0.75vw + 16px, 26px) * var(--scale));   /* a little larger on tablets and desktops */
  --gutter: 16px;
  --measure: 40rem;
  --r-card: 16px;
  --r-box: 14px;

  --serif: 'Frank Ruhl Libre', 'Times New Roman', serif;
  --sans: 'Assistant', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --spring: cubic-bezier(.2, .9, .25, 1.15);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --paper: #0E131D; --surface: #151C29; --insert: #18223A; --ink: #E9E6DD; --muted: #9AA3B5;
  --tekhelet: #9DB9EC; --wheat: #D9B260; --line: #27324A; --shadow: 0 0 0;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0E131D; --surface: #151C29; --insert: #18223A; --ink: #E9E6DD; --muted: #9AA3B5;
    --tekhelet: #9DB9EC; --wheat: #D9B260; --line: #27324A; --shadow: 0 0 0;
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--paper); color: var(--ink);
  font-family: var(--sans); -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2.5px solid var(--wheat); outline-offset: 3px; border-radius: 8px; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  min-height: calc(56px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
body[data-view="home"] .bar { border-bottom-color: transparent; }
.bar { transition: transform .35s var(--spring); }
body.bar-tucked .bar { transform: translateY(-100%); }
.progress {
  position: absolute; inset-inline: 0; bottom: -1px; height: 2px; background: var(--wheat);
  transform: scaleX(0); transform-origin: right; opacity: .85; pointer-events: none;
}
body[data-view="home"] .progress { opacity: 0; }
.bar-title {
  grid-column: 2; margin: 0; text-align: center;
  font: 700 19px/1 var(--serif); color: var(--tekhelet); letter-spacing: -0.01em;
}
#back { grid-column: 1; }
#settingsBtn { grid-column: 3; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 12px; cursor: pointer; color: var(--tekhelet);
  transition: transform .25s var(--spring), opacity .2s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:hover { opacity: .75; }
.icon-btn:active { transform: scale(.9); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.aa { display: flex; align-items: baseline; gap: 1px; font-family: var(--serif); font-weight: 700; line-height: 1; }
.aa-big { font-size: 22px; }
.aa-small { font-size: 14px; }

/* ---------- settings sheet ---------- */
.settings {
  position: fixed; z-index: 30; inset-inline: var(--gutter); top: calc(60px + env(safe-area-inset-top));
  max-width: 380px; margin-inline-start: auto;
  background: var(--surface); border-radius: var(--r-card); padding: 6px 16px;
  box-shadow: 0 1px 2px rgb(var(--shadow) / .08), 0 12px 32px -8px rgb(var(--shadow) / .22), 0 0 0 1px rgb(var(--shadow) / .06);
  animation: drop .3s var(--spring);
}
@keyframes drop { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; }
.settings-row + .settings-row { border-top: 1px solid var(--line); }
.settings-label { font-size: 15px; font-weight: 600; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper output { min-width: 3.4em; text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.step, .seg button {
  min-width: 40px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--paper);
  cursor: pointer; font-size: 17px; font-weight: 600; transition: transform .2s var(--spring), background-color .2s;
}
.step:hover, .seg button:hover { background: var(--insert); }
.step:active, .seg button:active { transform: scale(.94); }
.seg { display: flex; gap: 4px; }
.seg button { font-size: 14px; padding: 0 10px; }
.seg button[aria-checked="true"] { background: var(--tekhelet); border-color: var(--tekhelet); color: var(--paper); }

/* ---------- home ---------- */
main { outline: none; }
.home { max-width: 34rem; margin: 0 auto; padding: 8px var(--gutter) 40px; }
.mast { text-align: center; padding: 28px 0 26px; }
.mast-name {
  margin: 0; font: 900 clamp(64px, 22vw, 96px)/1 var(--serif); color: var(--tekhelet); letter-spacing: -0.03em;
}
.mast-rule { display: block; width: 200px; height: 16px; margin: 18px auto 0; }
.mast-rule path { stroke: var(--wheat); stroke-width: 1.2; fill: none; }
.mast-rule .ear { fill: var(--wheat); stroke: none; }

.list { display: grid; gap: 12px; }
.card {
  position: relative; display: grid; gap: 4px; text-decoration: none;
  padding: 20px 22px 20px 52px; border-radius: var(--r-card); background: var(--surface);
  box-shadow: 0 1px 1px rgb(var(--shadow) / .05), 0 6px 18px -10px rgb(var(--shadow) / .28), 0 0 0 1px rgb(var(--shadow) / .06);
  transition: transform .35s var(--spring), box-shadow .3s;
  -webkit-tap-highlight-color: transparent;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 2px 2px rgb(var(--shadow) / .05), 0 14px 28px -12px rgb(var(--shadow) / .34), 0 0 0 1px rgb(var(--shadow) / .08); }
.card:active { transform: scale(.985); }
.card-title { font: 700 26px/1.25 var(--serif); color: var(--ink); letter-spacing: -0.01em; }
.card-sub { font-size: 15px; color: var(--muted); }
.card-chip {
  justify-self: start; margin-top: 6px; padding: 3px 10px; border-radius: 99px;
  background: color-mix(in srgb, var(--wheat) 16%, transparent); color: color-mix(in srgb, var(--wheat) 75%, var(--ink));
  font-size: 14px; font-weight: 700;
}
.chev { position: absolute; left: 18px; top: 50%; width: 22px; height: 22px; translate: 0 -50%; fill: none; stroke: var(--wheat); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.hint {
  position: relative; margin-top: 22px; padding: 14px 16px 14px 44px; border-radius: var(--r-box);
  background: var(--insert); font-size: 15px; line-height: 1.6; color: var(--ink);
}
.hint p { margin: 0; }
.hint-close { position: absolute; left: 8px; top: 8px; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; color: var(--muted); }
.hint-close:hover { background: color-mix(in srgb, var(--line) 50%, transparent); }
.hint-close:active { transform: scale(.9); }

/* ---------- nusach ribbon ---------- */
.ribbon-wrap { position: relative; z-index: 10; display: flex; justify-content: center; pointer-events: none; }
.ribbon { display: flex; gap: 6px; pointer-events: auto; padding: 0 0 4px; }
.ribbon button {
  position: relative; border: 0; cursor: pointer; background: transparent;
  padding: 7px 16px 13px; font: 700 16px/1 var(--sans); color: var(--muted);
  transition: transform .35s var(--spring), color .2s;
  -webkit-tap-highlight-color: transparent;
}
.ribbon button::before {
  content: ''; position: absolute; inset: 0; z-index: -1; background: var(--tekhelet);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 7px), 0 100%);
  transform: scaleY(0); transform-origin: top; opacity: 0;
  transition: transform .4s var(--spring), opacity .2s;
  box-shadow: 0 6px 14px -6px rgb(var(--shadow) / .5);
}
.ribbon button[aria-checked="true"] { color: var(--paper); transform: translateY(0); }
.ribbon button[aria-checked="true"]::before { transform: scaleY(1); opacity: 1; }
.ribbon button:not([aria-checked="true"]):hover { color: var(--tekhelet); }
.ribbon button:active { transform: translateY(2px); }

/* ---------- reading text ---------- */
.text {
  max-width: var(--measure); margin: 0 auto; padding: 12px var(--gutter) 72px;
  font-family: var(--serif); font-size: var(--text); line-height: 1.95; color: var(--ink);
  font-feature-settings: 'kern';
  animation: settle .45s var(--spring) both;
}
@keyframes settle { from { opacity: 0; transform: translateY(6px); } }
.text p { margin: 0 0 .9em; text-align: start; hyphens: none; text-wrap: pretty; }
.text .sn { font-family: 'Birkon Shva Na', var(--serif); }
.text .sm { font-size: .7em; color: var(--muted); line-height: 1; }
.text .sm.en, .text .en { font-family: var(--sans); }
.text .en { font-size: .72em; color: var(--muted); }
.text .lg { font-size: 1.1em; }
.text .b { font-weight: 700; }
.text p.ltr { text-align: left; text-align-last: auto; font-family: var(--sans); font-size: .76em; line-height: 1.6; color: var(--ink); }
.text p.ltr .en, .text p.ltr .sm { font-size: 1em; color: inherit; }
.text p.ltr [dir="rtl"] { font-family: var(--serif); font-size: 1.15em; }

.title {
  margin: 10px 0 22px; text-align: center; font-weight: 900; font-size: 1.15em; line-height: 1.4; color: var(--tekhelet);
  letter-spacing: -0.02em;
}
.title::after { content: ''; display: block; width: 56px; height: 2px; margin: 10px auto 0; background: var(--wheat); border-radius: 2px; }

.box {
  margin: 1.2em 0 1.4em; padding: .9em 1em .2em; border-radius: var(--r-box); background: var(--insert);
  box-shadow: inset 0 0 0 1px rgb(var(--shadow) / .06);
}
.box-h {
  margin: 0 0 .5em; font: 700 calc(15px * var(--scale))/1.4 var(--sans); color: var(--tekhelet); letter-spacing: .01em;
}
.box-h .en, .box-h .sm { font-size: 1em; color: inherit; font-family: var(--sans); }
.box-h .b { font-weight: 700; }

.box.fold { padding: 0; transition: box-shadow .2s; }
.box.fold > summary {
  list-style: none; cursor: pointer; margin: 0; padding: .85em 1em;
  display: flex; align-items: center; justify-content: space-between; gap: .6em;
  border-radius: var(--r-box); -webkit-tap-highlight-color: transparent;
}
.box.fold > summary::-webkit-details-marker { display: none; }
.box.fold > summary:hover { background: color-mix(in srgb, var(--tekhelet) 6%, transparent); }
.box.fold > summary:active .fold-chev { transform: scale(.85); }
.box.fold[open] > summary .fold-chev { transform: rotate(180deg); }
.box.fold > summary:focus-visible { outline-offset: -2px; }
.fold-chev {
  flex: none; width: 1.25em; height: 1.25em; fill: none; stroke: var(--wheat); stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round; transition: transform .35s var(--spring);
}
.fold-body { padding: 0 1em .2em; animation: settle .35s var(--spring) both; }

.rows { margin: 0 0 .9em; display: grid; gap: .1em; }
.rows > div { display: grid; grid-template-columns: max-content 1fr; gap: .6em; align-items: baseline; }
.rows dt { font-family: var(--sans); font-size: .7em; font-weight: 700; color: var(--muted); }
.rows dt .en, .rows dt .sm { font-size: 1em; }
.rows dd { margin: 0; }

.table { overflow-x: auto; margin: 1em 0 1.2em; border-radius: var(--r-box); box-shadow: 0 0 0 1px var(--line); background: var(--surface); }
.table table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table th, .table td { padding: .55em .5em; text-align: center; vertical-align: middle; border-inline-start: 1px solid var(--line); }
.table th:first-child, .table td:first-child { border-inline-start: 0; }
.table th { font-family: var(--sans); font-size: .62em; font-weight: 700; color: var(--tekhelet); line-height: 1.4; border-bottom: 1px solid var(--line); }
.table th .sm, .table th .b { font-size: 1em; color: inherit; }
.table td { line-height: 1.7; font-size: .92em; }

.omer { list-style: none; margin: 0 0 1em; padding: 0; display: grid; gap: .15em; }
.omer li { position: relative; padding: .35em .6em; border-radius: 12px; }
.omer li:nth-child(7n) { margin-bottom: .5em; }
.omer .num { font-family: var(--sans); font-weight: 700; color: var(--wheat); }
.omer li.today {
  background: color-mix(in srgb, var(--wheat) 14%, transparent);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--wheat) 55%, transparent);
  scroll-margin: 120px;
}
.today-chip {
  float: left; margin: .25em 0 0 0; padding: 2px 9px; border-radius: 99px; background: var(--wheat); color: var(--paper);
  font: 700 calc(12px * var(--scale))/1.5 var(--sans);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
