/* ============ Раздел «Хифз» ============
   Поверх app.css: темы, панели, листы настроек и рамка суры берутся оттуда. */
:root { --hz-dock-h: 62px; }
body.hz { --hz-now: rgba(22, 106, 79, .24); }
body.hz[data-theme="turquoise"] { --hz-now: rgba(14, 124, 134, .24); }
body.hz[data-theme="dark"] { --hz-now: rgba(86, 196, 156, .26); }
body.hz { background: var(--page); }

/* верхняя панель: назад · заголовок · издание */
.hz-bar { gap: 6px; }
.hz-bar a.icon-btn { text-decoration: none; }
.hz-chip {
  flex: 0 0 auto; max-width: 42vw; margin-inline-end: 4px;
  padding: 6px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 650;
  color: var(--accent); border: 1px solid var(--accent); background: var(--page);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hz-chip:active { background: var(--sel); }

/* область страницы: между панелью и плеером */
.hz-reader {
  position: fixed; left: 0; right: 0; overflow: hidden;
  top: calc(var(--bar-h) + env(safe-area-inset-top));
  bottom: calc(var(--hz-dock-h) + env(safe-area-inset-bottom));
}
.hz-slot {
  position: absolute; inset: 0; display: flex; justify-content: center; align-items: center;
  overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; will-change: transform;
}
#hzNext { transform: translateX(-100%); }
#hzPrev { transform: translateX(100%); }
.hz-reader.animating .hz-slot { transition: transform .28s cubic-bezier(.25,.8,.35,1); }
.hz-slot > .hz-page { margin: auto; flex: 0 0 auto; }

/* страница: без рамки и тени, как лист мусхафа на весь экран */
.hz-page {
  direction: rtl; user-select: none; -webkit-user-select: none;
  padding: 0 calc(var(--fs, 24px) * var(--side, .3));
}
.hz-ph, .hz-pf {
  direction: ltr; display: flex; align-items: center; justify-content: space-between;
  font: 12.5px/1.2 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--muted);
}
.hz-ph { height: 28px; padding: 0 2px; }
.hz-ph .hz-juz { text-align: end; }
html[dir="rtl"] .hz-ph, html[dir="rtl"] .hz-pf { direction: rtl; }
.hz-pf { height: 34px; justify-content: center; gap: 14px; }
.hz-pnum { font-variant-numeric: tabular-nums; }
.hz-learn {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  font-size: 12px; color: var(--muted); border: 1px solid var(--line);
}
.hz-learn svg { width: 14px; height: 14px; }
.hz-learn.on { color: var(--accent); border-color: var(--accent); background: var(--sel); }
.hz-learn.on svg { fill: var(--accent); }

.hz-line {
  display: flex; direction: rtl; align-items: center; white-space: nowrap;
  height: calc(var(--fs) * var(--lh, 1.62));
  font-family: var(--pf); font-size: var(--fs); color: var(--ink);
  column-gap: calc(var(--fs) * var(--gap, .2));
}
.hz-line.j { justify-content: space-between; }
.hz-line.c { justify-content: center; }
.hz-line span { display: inline-block; flex-shrink: 0; border-radius: .14em; transition: background .15s; }
.hz-line.w span[data-vk] { cursor: pointer; }
.hz-line.h { justify-content: center; }
.hz-line.h .surah-frame { height: 82%; }
.hz-line.b { justify-content: center; }
.hz-line.b .btext { font-family: "UthmanicHafs", serif; font-size: calc(var(--fs) * .9); line-height: 1; }
.hz-page.ornate .hz-line { justify-content: center; }
.hz-page.ornate { padding-block: calc(var(--fs) * .4); }

/* Отметки (с 1.26.0): золотая полоса — только то, что выбрано сейчас (аят под меню, начало отрезка);
   заливка — читаемый аят; выбранный отрезок — «фокус»: всё вне него бледное.
   Границы полос считает applyMarks() по словам строки (--sl/--sw, --pl/--pw). */
.hz-line.w { position: relative; }
.hz-line.w > span { position: relative; z-index: 1; }
.hz-line.w::before, .hz-line.w::after {
  content: ""; position: absolute; top: 10%; bottom: 10%; border-radius: .22em; z-index: 0; display: none;
}
.hz-line.w::before { left: var(--sl, 0); width: var(--sw, 0); background: var(--ayah-selected); }
.hz-line.w::after { left: var(--pl, 0); width: var(--pw, 0); background: var(--hz-now); top: 8%; bottom: 8%; }
.hz-line.w.has-sel::before, .hz-line.w.has-play::after { display: block; }
.hz-line.b.hz-now .btext { background: var(--hz-now); border-radius: .14em; }
.hz-page.focus .hz-line.w > span[data-vk]:not(.hz-in),
.hz-page.focus .hz-line.b:not(.hz-in),
.hz-page.focus .hz-line.h:not(.hz-in) { opacity: .28; }
.hz-page.focus .hz-line.w > span.hz-sel { opacity: 1; }
.hz-line.w > span[data-vk], .hz-line.b, .hz-line.h { transition: opacity .2s; }

/* ошибка загрузки */
.hz-error {
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%); z-index: 15;
  width: min(86vw, 360px); text-align: center; background: var(--bg); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px 16px; box-shadow: 0 6px 24px var(--shadow);
  font-size: 14px; line-height: 1.45;
}
.hz-error[hidden] { display: none; }
.hz-error p { margin-bottom: 12px; }

/* кнопки */
.hz-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 12px;
  background: var(--accent); color: #f6f3ea; font-size: 14px; font-weight: 650;
}
.hz-btn-soft { background: var(--page); color: var(--ink); border: 1px solid var(--line); font-weight: 600; }

/* плеер повтора внизу */
.hz-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--hz-dock-h) + env(safe-area-inset-bottom));
  padding: 0 max(10px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(10px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 8px;
  background: var(--bar); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.hz-play {
  width: 46px; height: 46px; flex: 0 0 auto; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: #f6f3ea;
}
.hz-play svg { width: 22px; height: 22px; }
.hz-play .i-play { fill: currentColor; stroke: none; }
.hz-play .i-pause { display: none; stroke-width: 2.6; }
body.hz-playing .hz-play .i-play { display: none; }
body.hz-playing .hz-play .i-pause { display: block; }
.hz-bar-listen, .hz-bar-test { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; }
.hz-bar-listen[hidden], .hz-bar-test[hidden] { display: none; }
.hz-skip { width: 36px; display: none; }
.hz-skip svg .fill { fill: currentColor; stroke: none; }
body.hz-active .hz-skip { display: grid; }
.hz-dock-main {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  text-align: start; padding: 4px 2px;
}
.hz-range-row { display: flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; }
.hz-range { font-size: 14px; font-weight: 650; min-width: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: start; color: var(--ink); }
.hz-reset { width: 22px; height: 22px; flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; background: var(--line); color: var(--ink); }
.hz-reset svg { width: 12px; height: 12px; stroke-width: 2.4; }
.hz-reset[hidden] { display: none; }
.hz-times {
  flex: 0 0 auto; min-width: 44px; height: 34px; padding: 0 8px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--page); color: var(--ink); font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
body.hz-active .hz-times { display: none; }
body.hz-active #hzTune { display: none; } /* во время чтения место — подписи; настройки открываются касанием подписи */
.hz-bar-test .hz-tb { flex: 1; min-height: 40px; padding: 7px 6px; }
.hz-bar-test .hz-tb-more { flex: 0 0 48px; font-size: 18px; line-height: 1; }
.hz-counter { font-size: 12px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hz-stop[hidden] { display: none; }

/* листы настроек */
.hz-sheet { z-index: 33; max-height: 88vh; overflow-y: auto; }
.hz-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; }
.hz-row .set-label { display: flex; flex-direction: column; gap: 2px; }
.hz-sub { font-size: 11.5px; font-weight: 400; color: var(--muted); }
.hz-range-pick { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.hz-vk { min-width: 54px; text-align: center; padding: 6px 8px; border-radius: 10px; background: var(--page); border: 1px solid var(--line); font-weight: 650; }
.hz-dash { color: var(--muted); }
.hz-quick { display: flex; gap: 8px; flex-wrap: wrap; padding: 2px 0 4px; }
.hz-quick .hz-btn { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.hz-step { display: flex; align-items: center; gap: 8px; }
.hz-step output { min-width: 38px; text-align: center; font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.hz-switch {
  width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: 0 0 auto;
  transition: background .2s;
}
.hz-switch span { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--page); box-shadow: 0 1px 3px var(--shadow); transition: transform .2s; }
.hz-switch[aria-checked="true"] { background: var(--accent); }
.hz-switch[aria-checked="true"] span { transform: translateX(20px); }
.hz-select {
  max-width: 62%; padding: 8px 10px; border-radius: 10px; font: inherit; font-size: 14px;
  color: var(--ink); background: var(--page); border: 1px solid var(--line);
}

/* выбор издания */
.hz-ed-lead { font-size: 14px; line-height: 1.45; margin-bottom: 10px; }
.hz-ed {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%;
  text-align: start; padding: 12px 14px; margin-bottom: 8px; border-radius: 14px;
  background: var(--page); border: 1.5px solid var(--line);
}
.hz-ed strong { font-size: 15px; }
.hz-ed span { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.hz-ed.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.hz-ed.active strong { color: var(--accent); }

body.hz .toast { bottom: calc(var(--hz-dock-h) + env(safe-area-inset-bottom) + 14px); white-space: normal; text-align: center; max-width: 88vw; }

/* ============ Этап 2: проверка себя, ошибки, план, карта, методики ============ */

/* Проверка: слова скрыты (знаки конца аята видны — по ним держится место на странице) */
body.hz-test .hz-line.w > span[data-vk]:not([data-end]):not(.shown) { color: transparent; }
body.hz-test .hz-line.w > span[data-vk]:not([data-end]):not(.shown)::after {
  content: ""; position: absolute; left: 8%; right: 8%; bottom: 22%; height: .07em; border-radius: .05em;
  background: var(--muted); opacity: .45;
}
body.hz-test .hz-line.w > span.shown { animation: hzshow .25s ease-out; }
@keyframes hzshow { from { opacity: 0; } to { opacity: 1; } }

/* отметка ошибки — красная черта под словом, только в проверке (вне её страница чистая) */
.hz-line.w > span.err::before {
  content: ""; position: absolute; left: 6%; right: 6%; bottom: 6%; height: .09em; border-radius: .05em;
  background: #c0392b; z-index: 2;
}
body[data-theme="dark"] .hz-line.w > span.err::before { background: #e5675a; }
body:not(.hz-test) .hz-line.w > span.err::before { display: none; }
body.hz-errmode .hz-line.w > span[data-vk] { cursor: crosshair; }

.hz-tb {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 600;
  background: var(--page); border: 1px solid var(--line); color: var(--ink); white-space: nowrap;
}
.hz-tb[aria-pressed="true"] { background: var(--accent); color: #f6f3ea; border-color: var(--accent); }
.hz-tb-err[aria-pressed="true"] { background: #b03a2e; border-color: #b03a2e; }

/* План */
.hz-plan { max-height: 92vh; min-height: 60vh; }
.hz-tabs { margin: 2px 0 12px; }
.hz-tabs .seg-btn { flex: 1; }
.hz-panel[hidden] { display: none; }
.hz-sum { font-size: 13px; color: var(--muted); margin: 0 0 10px; line-height: 1.45; }
.hz-sum b { color: var(--ink); }
.hz-task {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px;
  padding: 11px 12px; margin-bottom: 8px; border-radius: 14px; background: var(--page); border: 1px solid var(--line);
}
.hz-task.done { opacity: .62; }
.hz-task-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.hz-task-what { font-size: 15px; font-weight: 650; margin-top: 2px; }
.hz-task-note { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.hz-task .hz-btn { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.hz-check {
  width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--line); display: grid; place-items: center;
  color: transparent; background: var(--bg);
}
.hz-check svg { width: 18px; height: 18px; stroke-width: 2.4; }
.hz-task.done .hz-check { background: var(--accent); border-color: var(--accent); color: #f6f3ea; }
.hz-empty { font-size: 14px; line-height: 1.5; padding: 6px 2px 12px; }

/* Карта: 30 джузов по строке, страницы — клетки */
.hz-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.hz-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: -1px; margin-inline-end: 4px; }
.hz-juz-row { display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 6px; margin-bottom: 4px; direction: ltr; }
.hz-juz-n { font-size: 11px; color: var(--muted); text-align: end; font-variant-numeric: tabular-nums; }
.hz-cells { display: flex; flex-direction: row-reverse; gap: 2px; }
.hz-cell {
  flex: 1 1 0; min-width: 0; height: 16px; border-radius: 3px; background: var(--line); position: relative;
}
.hz-cell.learn, .hz-legend .learn { background: #d9a441; }
.hz-cell.done, .hz-legend .done { background: var(--accent); }
.hz-cell.due { box-shadow: inset 0 0 0 2px var(--gold); }
.hz-cell.err::after { content: ""; position: absolute; top: 2px; right: 2px; width: 5px; height: 5px; border-radius: 50%; background: #c0392b; }
.hz-cell.cur { outline: 2px solid var(--ink); outline-offset: 1px; }
.hz-legend .none { background: var(--line); }
.hz-legend .due { background: var(--page); box-shadow: inset 0 0 0 2px var(--gold); }

/* Методика */
.hz-method {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; width: 100%; text-align: start;
  padding: 11px 13px; margin-bottom: 8px; border-radius: 14px; background: var(--page); border: 1.5px solid var(--line);
}
.hz-method strong { font-size: 14.5px; }
.hz-method span { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.hz-method.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.hz-method.active strong { color: var(--accent); }
.hz-sub-title { font-size: 13px; font-weight: 650; color: var(--muted); margin: 14px 0 4px; }
.hz-data { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.hz-data .hz-btn { min-height: 36px; font-size: 13px; }
.hz-danger { color: #b03a2e; border-color: rgba(176, 58, 46, .45); }

/* правки этапа 2 */
.hz-bar .bar-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hzPlanBtn { position: relative; }
#hzPlanBtn.pending::after {
  content: ""; position: absolute; top: 9px; right: 8px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 2px var(--bar);
}
body.hz-test .hz-line.w::before { display: none; }


/* ============ Простой «Хифз» (1.26.0): меню аята, подсказка, «⋯», поиск ============ */

/* меню аята — над плеером; если аят внизу, меню встаёт под шапку */
.hz-amenu {
  position: fixed; z-index: 30;
  left: max(10px, calc(50% - 260px)); right: max(10px, calc(50% - 260px));
  bottom: calc(var(--hz-dock-h) + env(safe-area-inset-bottom) + 10px);
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 28px var(--shadow);
  padding: 12px;
}
.hz-amenu.top { bottom: auto; top: calc(var(--bar-h) + env(safe-area-inset-top) + 8px); }
.hz-amenu[hidden] { display: none; }
.hz-amenu-title { font-size: 14px; font-weight: 650; margin: 0 2px 10px; }
.hz-amenu-acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hz-amenu-acts .hz-btn { min-height: 44px; padding: 8px 10px; font-size: 13.5px; }

/* подсказка поверх шапки: страница под ней не сдвигается */
.hz-banner {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--bar-h); z-index: 3;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: #2b2a26; color: #f6f3ea; font-size: 14px; font-weight: 600;
}
.hz-banner[hidden] { display: none; }
.hz-banner span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hz-banner-btn { flex: 0 0 auto; color: #e9c46a; font-size: 14px; font-weight: 700; padding: 8px 4px; }
body.hz-errmode .hz-banner { background: #8e2f25; }
body.hz-errmode .hz-banner-btn { color: #fff; }

/* «⋯» в проверке */
.hz-more {
  position: fixed; z-index: 31; right: max(10px, env(safe-area-inset-right));
  bottom: calc(var(--hz-dock-h) + env(safe-area-inset-bottom) + 8px); min-width: 220px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 28px var(--shadow); padding: 6px;
}
.hz-more[hidden] { display: none; }
.hz-more-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px; border-radius: 10px; font-size: 14px; text-align: start; color: var(--ink); }
.hz-more-item:active { background: var(--sel); }
.hz-more-item[aria-checked="true"]::after { content: "✓"; margin-inline-start: auto; color: var(--accent); font-weight: 700; }

/* повтор: готовые значения */
.hz-row-col { flex-direction: column; align-items: stretch; gap: 6px; }
.hz-chips .seg-btn { flex: 1; padding: 7px 0; font-variant-numeric: tabular-nums; }

/* поиск */
/* Поиск — панель сверху, сразу на своём месте (без выезда снизу): иначе поле получает фокус за краем экрана,
   iPhone сдвигает страницу к нему, и после анимации поле оказывается выше экрана (замечание Камиля 17.10).
   Высоту по видимой области над клавиатурой задаёт fitSearch(). */
.sheet.hz-search {
  top: 0; bottom: auto; border-radius: 0 0 18px 18px; transform: none; opacity: 0; transition: opacity .16s;
  padding: calc(10px + env(safe-area-inset-top)) 16px 14px; max-height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  box-shadow: 0 6px 30px var(--shadow);
}
.sheet.hz-search.open { opacity: 1; }
.sheet.hz-search:not(.open) { pointer-events: none; }
.hz-search .sheet-grip { display: none; }
.hz-search-row { display: flex; align-items: center; gap: 10px; }
.hz-search-row .hz-search-field { flex: 1; min-width: 0; }
.hz-search-close { flex: 0 0 auto; color: var(--accent); font-size: 15px; font-weight: 600; padding: 8px 2px; }
.hz-search-field { display: flex; align-items: center; gap: 8px; border: 1.5px solid var(--accent); border-radius: 12px; padding: 0 12px; background: var(--page); }
.hz-search-field svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--muted); stroke-width: 1.9; }
.hz-search-field input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 16px; padding: 11px 0; color: var(--ink); outline: none; }
.hz-res {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: start;
  padding: 11px 12px; margin-bottom: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--page); color: var(--ink);
}
.hz-res b { font-size: 14.5px; }
.hz-res small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.hz-res .go { flex: 0 0 auto; font-size: 12.5px; font-weight: 650; color: var(--accent); }
.hz-juz-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.hz-juz-grid button { padding: 8px 0; border-radius: 9px; border: 1px solid var(--line); background: var(--page); color: var(--ink); font-size: 13.5px; font-variant-numeric: tabular-nums; }
.hz-juz-grid button.cur { border-color: var(--accent); color: var(--accent); font-weight: 700; }
