/* ============ Темы ============ */
:root {
  --bg: #f6f3ec;
  --card: #ffffff;
  --text: #222b26;
  --muted: #75807a;
  --accent: #2f6f5e;
  --accent-2: #c9a24b;
  --accent-soft: rgba(47, 111, 94, 0.12);
  --border: #e8e2d6;
  --chip: #f1ece1;
  --shadow: 0 6px 24px rgba(30, 45, 38, 0.08);
  --ar-size: 28px;
  --ru-size: 14.5px;
}
html[data-theme="dark"] {
  --bg: #101614;
  --card: #18211e;
  --text: #e9e7de;
  --muted: #9aa8a0;
  --accent: #83c9b2;
  --accent-2: #d4b169;
  --accent-soft: rgba(131, 201, 178, 0.14);
  --border: #27332d;
  --chip: #1f2a25;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

/* Шрифты для арабского текста */
html[data-arfont="naskh"] { --ar-family: "Noto Naskh Arabic", "Amiri", serif; }
html[data-arfont="simple"] { --ar-family: "Segoe UI", "Arial", "Noto Naskh Arabic", sans-serif; }
html[data-arfont="mushaf"] { --ar-family: "Scheherazade New", "Amiri", serif; }
html[data-arfont="classic"] { --ar-family: "Amiri", "Scheherazade New", serif; }
:root { --ar-family: "Amiri", "Scheherazade New", "Noto Naskh Arabic", serif; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.25s ease, color 0.25s ease;
}

/* ============ Шапка ============ */
#topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.4px;
  color: var(--accent);
  white-space: nowrap;
}
.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #ffffff;
  color: #d12622;
  font-size: 17px;
  font-weight: 900;
  line-height: 1;
  border: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}
html[data-theme="dark"] .logo {
  background: #000000;
  color: #ff2d2d;
  border-color: rgba(255, 255, 255, 0.14);
}
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.hidden { display: none; }

/* ============ Основная область ============ */
#view {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 14px calc(40px + env(safe-area-inset-bottom, 0px));
}

/* Главная */
.date-line { color: var(--muted); font-size: 14px; margin: 4px 2px 14px; }
.verse-block {
  text-align: center;
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px 18px 16px;
  margin-bottom: 18px;
}
.verse-block .ar { margin: 0 0 8px; text-align: center; font-size: calc(var(--ar-size) + 6px); }
.verse-ru { color: var(--muted); font-size: 13.5px; margin: 0; line-height: 1.5; }

/* Горизонтальные плитки разделов (друг над другом) */
.tiles { display: flex; flex-direction: column; gap: 12px; }
.tile {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: transform 0.14s ease;
}
.tile:active { transform: scale(0.98); }
.tile-emoji {
  font-size: 30px;
  flex-shrink: 0;
  width: 54px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 15px;
}
.tile-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tile-title { font-weight: 700; font-size: 16px; }
.tile-sub { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.tile-count {
  align-self: flex-start;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ============ Карточки зикра ============ */
.sec-head { display: flex; align-items: center; gap: 12px; margin: 2px 0 16px; }
.sec-head .back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 18px;
  text-decoration: none;
}
.sec-head h2 { margin: 0; font-size: 20px; }
.sec-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px 16px 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chip {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 11px;
  border-radius: 999px;
}
.card-title { margin: 10px 0 6px; font-size: 15.5px; font-weight: 700; color: var(--accent-2); }
.blk + .blk { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.blk-name {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  direction: rtl;
  text-align: right;
}
.ar {
  direction: rtl;
  font-family: var(--ar-family);
  font-size: var(--ar-size);
  line-height: 1.95;
  text-align: right;
  margin: 8px 0 12px;
  word-spacing: 2px;
  white-space: pre-line;
}
.ar.small { font-size: calc(var(--ar-size) - 6px); line-height: 2.1; }
.ru { font-size: var(--ru-size); line-height: 1.6; margin: 0 0 10px; color: var(--text); white-space: pre-line; }
.ru.small { font-size: calc(var(--ru-size) - 1px); line-height: 1.75; }
.audio-btn {
  display: inline-block;
  border: 1.5px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.audio-btn:active { transform: scale(0.97); }
.audio-btn.playing { background: var(--accent); color: #fff; }
.card-foot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.src {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--chip);
  border-radius: 999px;
  padding: 4px 11px;
}
.note { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px; }
.note summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  list-style: none;
}
.note summary::after { content: " ▾"; }
.note[open] summary::after { content: " ▴"; }
.note p { font-size: 13.5px; line-height: 1.55; color: var(--muted); margin: 8px 0 2px; }

/* Кнопки действий карточки: счётчик справа от "Слушать" */
.card-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

/* Круглый счётчик повторов — большой, для удобного нажатия */
.counter {
  --p: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
  background:
    radial-gradient(closest-side, var(--card) 76%, transparent 77% 100%),
    conic-gradient(var(--accent) calc(var(--p) * 1%), var(--accent-soft) 0);
  cursor: pointer;
  border: none;
  padding: 0;
  transition: transform 0.1s ease;
}
.counter:active { transform: scale(0.9); }
.counter.done { --p: 100%; }
.counter.done .counter-num { color: var(--accent); }
.counter-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}
.counter-num small { font-size: 13px; font-weight: 700; color: var(--muted); margin-left: 2px; }

/* Кнопки увеличения/уменьшения текста в настройках */
.size-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.size-btn {
  border: 1px solid var(--border);
  background: var(--chip);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  border-radius: 10px;
  min-width: 44px;
  height: 36px;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.size-btn:active { transform: scale(0.94); }
.size-label { flex: 1; font-size: 13px; font-weight: 600; color: var(--muted); }
.size-val { font-size: 13px; font-weight: 700; min-width: 34px; text-align: right; color: var(--accent); }

/* ============ Модальное окно настроек ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-back {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 13, 0.5);
  animation: fadeIn 0.2s ease;
}
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: sheetUp 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close {
  border: none;
  background: var(--chip);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 11px;
  font-size: 15px;
  cursor: pointer;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 10px; font-size: 15px; }
.panel p, .panel li { font-size: 13.5px; color: var(--muted); line-height: 1.6; }
.seg { display: flex; gap: 6px; background: var(--chip); border-radius: 12px; padding: 4px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 40%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  padding: 9px 4px;
  border-radius: 9px;
  cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

/* Переключатели */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
}
.switch-row + .switch-row { border-top: 1px dashed var(--border); }
.switch-row .sw-label { font-size: 14px; font-weight: 600; }
.switch-row .sw-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 999px;
  border: none;
  background: var(--chip);
  cursor: pointer;
  transition: background 0.2s ease;
  padding: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }

@media (min-width: 560px) {
  #view { padding-left: 20px; padding-right: 20px; }
}
