:root {
  --bg: #F7F3EA;
  --surface: #FFFDF8;
  --ink: #1F1B14;
  --ink-soft: #3A342A;
  --muted: #7A7162;
  --line: #E6DECD;
  --accent: #2F6B45;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3EEE5;
  --gold: #A87A22;
  --guide: rgba(168, 122, 34, 0.10);
  --guide-edge: rgba(168, 122, 34, 0.35);
  --shadow: 0 10px 30px rgba(40, 30, 10, 0.12), 0 2px 6px rgba(40, 30, 10, 0.08);

  --text-size: 28px;
  --serif: "Frank Ruhl Libre", "David Libre", "Times New Roman", serif;
  --sans: "Assistant", "Segoe UI", system-ui, sans-serif;
  --dock-h: 84px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130F;
    --surface: #1D1B16;
    --ink: #EFE8DA;
    --ink-soft: #D8D0C0;
    --muted: #A1978A;
    --line: #34302A;
    --accent: #86C79C;
    --accent-ink: #0F1A12;
    --accent-soft: #1F3326;
    --gold: #DDB564;
    --guide: rgba(221, 181, 100, 0.08);
    --guide-edge: rgba(221, 181, 100, 0.30);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14130F;
  --surface: #1D1B16;
  --ink: #EFE8DA;
  --ink-soft: #D8D0C0;
  --muted: #A1978A;
  --line: #34302A;
  --accent: #86C79C;
  --accent-ink: #0F1A12;
  --accent-soft: #1F3326;
  --gold: #DDB564;
  --guide: rgba(221, 181, 100, 0.08);
  --guide-edge: rgba(221, 181, 100, 0.30);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ── התקדמות ── */
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 30; pointer-events: none; }
.progress-bar { height: 100%; width: 0; background: var(--gold); transition: width .15s linear; }

/* ── כותרת ── */
.hero {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 20px) 16px 8px;
  text-align: center;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 15px; letter-spacing: .02em; color: var(--muted);
}
.brand img { border-radius: 8px; }
.today { margin: 18px 0 4px; font-size: 15px; font-weight: 600; color: var(--accent); }
.piyut-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(34px, 9vw, 52px);
  line-height: 1.25;
  color: var(--ink);
}
.heb-date { margin: 6px 0 20px; color: var(--muted); font-size: 15px; }

.segmented {
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  max-width: 100%;
}
.segmented button {
  border: 0; background: transparent; cursor: pointer;
  min-height: 44px; padding: 0 18px; border-radius: 999px;
  font-weight: 600; font-size: 16px; color: var(--muted);
  white-space: nowrap;
  transition: background .2s, color .2s;
}
.segmented button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); }
.segmented button:active { transform: scale(.96); }
@media (max-width: 420px) {
  #nusachPicker button { padding: 0 12px; font-size: 15px; }
}
.segmented.small button { min-height: 36px; padding: 0 12px; font-size: 14px; }

.days {
  display: flex; gap: 6px;
  max-width: 520px;
  margin: 18px auto 0;
  padding-top: 6px;
}
.day {
  flex: 1 1 0;
  min-width: 0;
  min-height: 58px;
  padding: 8px 2px 7px;
  justify-content: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  position: relative;
  transition: border-color .2s, background .2s;
}
.day b { font-family: var(--serif); font-size: 19px; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.day small { font-size: 12px; color: var(--muted); white-space: nowrap; }
@media (max-width: 360px) { .day b { font-size: 16px; } .day small { font-size: 11px; } }
.day:active { transform: scale(.95); }
.day[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); border-width: 2px; }
.day[aria-selected="true"] b { color: var(--accent); }
.day.is-today::after {
  content: "היום";
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  font-size: 10px; font-weight: 700; line-height: 1;
  padding: 3px 6px; border-radius: 999px;
  background: var(--gold); color: var(--surface);
}
.notice {
  margin: 14px auto 0; max-width: 520px;
  padding: 10px 14px; border-radius: 12px;
  background: var(--surface); border: 1px dashed var(--line);
  color: var(--ink-soft); font-size: 14px; line-height: 1.5;
}

/* ── טקסט התפילה ── */
.reader {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 20px calc(var(--dock-h) + 45vh);
  font-family: var(--serif);
  font-size: var(--text-size);
  line-height: 1.9;
  color: var(--ink);
  cursor: default;
}
.reader p { margin: 0 0 .55em; }
.reader .txt { text-align: start; }
.reader .refrain {
  text-align: center;
  font-weight: 700;
  color: var(--accent);
  margin: .7em 0;
}
.reader .note {
  font-family: var(--sans);
  font-size: max(15px, .56em);
  line-height: 1.55;
  color: var(--muted);
  text-align: center;
  margin: 1.1em 0 .8em;
}
.reader .sec {
  font-family: var(--sans);
  font-size: max(15px, .58em);
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--gold);
  text-align: center;
  margin: 2em 0 .6em;
  display: flex; align-items: center; gap: 14px;
  scroll-margin-top: 30vh;
}
.reader .sec::before, .reader .sec::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.reader .piyut { text-align: start; margin: .4em 0 .8em; }
.reader .st { display: inline; }
.reader .st + .st::before { content: " "; }
.reader .ac { color: var(--gold); font-weight: 700; }
.reader small { font-size: .72em; color: var(--muted); }
.reader small.xs { font-size: .5em; }
.reader .end {
  font-family: var(--sans);
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  margin-top: 3em;
  padding-top: 1.5em;
  border-top: 1px solid var(--line);
}
.reader .end strong { display: block; font-size: 17px; color: var(--ink-soft); margin-bottom: 6px; }
.reader .end .credit {
  margin: 22px 0 0;
  font-family: var(--serif);
  font-size: 17px;
  color: var(--gold);
}

/* ── קו מיקוד ── */
.guide {
  position: fixed; left: 0; right: 0;
  top: 34vh; height: calc(var(--text-size) * 2.1);
  transform: translateY(-50%);
  background: var(--guide);
  border-top: 1px solid var(--guide-edge);
  border-bottom: 1px solid var(--guide-edge);
  pointer-events: none;
  z-index: 5;
}

.tap-flash {
  position: fixed; top: 50%; left: 50%;
  width: 84px; height: 84px; margin: -42px 0 0 -42px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--ink) 70%, transparent);
  opacity: 0; pointer-events: none; z-index: 40;
  display: grid; place-items: center;
}
.tap-flash svg { width: 38px; height: 38px; fill: var(--bg); }
.tap-flash.show { animation: flash .7s ease-out; }
@keyframes flash {
  0% { opacity: 0; transform: scale(.8); }
  20% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.1); }
}

/* ── סרגל שליטה ── */
.dock {
  position: fixed;
  left: 50%; bottom: calc(env(safe-area-inset-bottom) + 10px);
  transform: translateX(-50%);
  width: min(520px, calc(100% - 20px));
  height: var(--dock-h);
  padding: 0 8px;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: center; gap: 6px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
  z-index: 20;
}
.ctl { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.ctl-row {
  display: flex; align-items: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2px;
}
.ctl-cap { font-size: 11px; font-weight: 600; color: var(--muted); line-height: 1.2; white-space: nowrap; }
.step {
  width: 44px; height: 44px;
  border: 0; border-radius: 13px;
  background: transparent; cursor: pointer;
  display: grid; place-items: center;
  color: var(--ink);
  transition: background .12s, transform .12s;
}
.step svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.step:active:not(:disabled) { background: var(--accent-soft); transform: scale(.92); }
.step:disabled { color: var(--line); cursor: default; }
.glyph { font-family: var(--serif); font-weight: 700; line-height: 1; }
.glyph.big { font-size: 24px; }
.glyph.small { font-size: 15px; }
#speedValue {
  min-width: 30px; text-align: center;
  font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums;
}

.play {
  width: 64px; height: 64px; flex: 0 0 auto;
  border: 0; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform .12s, background .2s;
}
.play:active { transform: scale(.93); }
.play svg { width: 26px; height: 26px; fill: currentColor; }
.play-cap { font-size: 10px; font-weight: 700; line-height: 1; }
.play .i-pause { display: none; }
.play[aria-pressed="true"] { background: var(--gold); box-shadow: 0 6px 16px color-mix(in srgb, var(--gold) 40%, transparent); }
.play[aria-pressed="true"] .i-play { display: none; }
.play[aria-pressed="true"] .i-pause { display: block; }

.more {
  width: 40px; height: 56px;
  border: 0; border-radius: 14px;
  background: transparent; cursor: pointer;
  display: grid; place-items: center;
  color: var(--muted);
}
.more svg { width: 22px; height: 22px; fill: currentColor; }
.more:active { background: var(--accent-soft); }

.toast {
  position: fixed; left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + var(--dock-h) + 22px);
  transform: translateX(-50%);
  padding: 9px 16px; border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: 15px; font-weight: 600; white-space: nowrap;
  z-index: 21; pointer-events: none;
  animation: toast 1.6s ease forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 8px); }
  12%, 80% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; }
}

button { touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@media (max-width: 360px) {
  .step { width: 40px; }
  .play { width: 58px; height: 58px; }
}

/* ── גיליון אפשרויות ── */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.28); z-index: 24; }
.sheet {
  position: fixed; left: 50%; bottom: 0;
  transform: translateX(-50%);
  width: min(560px, 100%);
  max-height: 80vh; overflow-y: auto;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 20px);
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow);
  z-index: 25;
  animation: up .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes up { from { transform: translate(-50%, 30px); opacity: 0; } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 0; border-bottom: 1px solid var(--line);
  font-size: 16px;
}
.switch {
  appearance: none; -webkit-appearance: none;
  width: 46px; height: 28px; border-radius: 999px;
  background: var(--line); position: relative; cursor: pointer; flex: 0 0 auto;
  transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: right .2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { right: 21px; }
.sheet-actions { display: flex; gap: 10px; padding: 16px 0 6px; }
.btn {
  flex: 1; padding: 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg);
  font-weight: 600; cursor: pointer;
}
.sections-title { margin: 14px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.sections-list { display: flex; flex-wrap: wrap; gap: 8px; }
.sections-list button {
  padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 14px; cursor: pointer;
}
.shortcuts { margin: 16px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

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