:root {
  --green: #123d2f;
  --green-2: #1d5a45;
  --gold: #c9a45c;
  --paper: #fbf7ec;
  --ink: #1c1a16;
  --muted: #6f6a5e;
  --line: #e6dfcc;
  --sheet: #fffdf7;
  --hl: #f3e3b3;
  --page-bg: #fdfbf3;
  --bar-bg: rgba(18, 61, 47, .96);
  --bar-ink: #f6f0de;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
body.night {
  --paper: #121412;
  --ink: #e9e4d6;
  --muted: #a39e90;
  --line: #2a2e2a;
  --sheet: #1a1d1a;
  --hl: #4a3f1f;
  --page-bg: #0e0f0e;
  --bar-bg: rgba(12, 20, 16, .96);
  color-scheme: dark;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--page-bg);
  color: var(--ink);
  font-family: "Noto Kufi Arabic", system-ui, sans-serif;
  font-size: 15px;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

/* ---------- Pager ---------- */
#pager {
  position: fixed; inset: 0;
  display: flex;
  overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
#pager::-webkit-scrollbar { display: none; }
.slide {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  padding: calc(var(--safe-t) + 4px) 4px calc(var(--safe-b) + 4px);
}
.slide img {
  -webkit-touch-callout: none;
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  user-select: none; -webkit-user-drag: none;
  opacity: 0; transition: opacity .2s;
}
.slide img.ok { opacity: 1; }
.slide .ph {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); font-size: 14px; pointer-events: none;
}
.slide .ph b { font-family: Amiri, serif; font-size: 40px; color: var(--gold); font-weight: 400; }
.slide.loaded .ph { display: none; }
.slide .ph .err { pointer-events: auto; color: var(--green-2); text-decoration: underline; }
body.night .slide img { filter: invert(1) hue-rotate(180deg) brightness(.88) contrast(.95); }
/* مصحف التجويد: لا نعكس الألوان حتى تبقى دلالة أحكام التجويد صحيحة */
body.night.src-tajweed .slide img { filter: brightness(.78) contrast(1.05); }
body.night.src-color .slide img { filter: invert(.92) hue-rotate(180deg) brightness(.9) sepia(.15); }

/* أزرار التقليب: تظهر فقط مع الفأرة */
.nav { display: none; }
@media (hover: hover) and (pointer: fine) {
  .nav {
    display: grid; place-items: center;
    position: fixed; top: 50%; z-index: 5; transform: translateY(-50%);
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--bar-bg); color: var(--bar-ink);
    opacity: .55; transition: opacity .2s;
  }
  .nav:hover { opacity: 1; }
  .nav.next { left: 24px; }
  .nav.prev { right: 24px; }
  .nav svg { width: 26px; height: 26px; }
}

/* ---------- Bars ---------- */
.bar {
  position: fixed; left: 0; right: 0; z-index: 10;
  background: var(--bar-bg); color: var(--bar-ink);
  backdrop-filter: blur(8px);
  transition: transform .22s ease, opacity .22s;
}
#topbar {
  top: 0;
  padding: calc(var(--safe-t) + 8px) 14px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid rgba(201, 164, 92, .35);
}
#topbar.hidden { transform: translateY(-100%); opacity: 0; pointer-events: none; }
#topbar .info { min-width: 0; }
#topbar .surah { font-family: Amiri, serif; font-size: 22px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar .meta { font-size: 12px; opacity: .8; }
.actions { display: flex; gap: 2px; }
.icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; }
.icon:active { background: rgba(255, 255, 255, .12); }
#btnBookmark.on svg { fill: var(--gold); stroke: var(--gold); }

#player {
  bottom: 0;
  padding: 8px 14px calc(var(--safe-b) + 10px);
  border-top: 1px solid rgba(201, 164, 92, .35);
}
#player.hidden { transform: translateY(100%); opacity: 0; pointer-events: none; }
#player .reciter {
  display: block; width: 100%; text-align: center;
  font-size: 12px; opacity: .85; padding: 2px 0 6px;
}
#player .reciter::after { content: " ▾"; opacity: .6; }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.play {
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--gold); color: var(--green);
  display: grid; place-items: center;
}
.play svg { width: 26px; height: 26px; }
.play .i-pause { display: none; }
.play.playing .i-play { display: none; }
.play.playing .i-pause { display: block; }
.play.loading { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.psurah {
  font-family: Amiri, serif; font-size: 19px; font-weight: 700;
  min-width: 92px; text-align: right;
}
.speed {
  min-width: 52px; font-size: 13px; text-align: left;
  font-variant-numeric: tabular-nums; direction: ltr;
}
.progress { display: flex; align-items: center; gap: 8px; font-size: 11px; opacity: .85; margin-top: 4px; font-variant-numeric: tabular-nums; }
.progress span { direction: ltr; min-width: 34px; text-align: center; }
.progress input { flex: 1; accent-color: var(--gold); }

/* ---------- Sheets ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .35);
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-height: 78vh; height: 78vh;
  background: var(--sheet); color: var(--ink);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  transform: translateY(105%);
  transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
}
.sheet.tall { height: 88vh; max-height: 88vh; }
.sheet.on { transform: none; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 6px; flex: none; }
.sheet-title { margin: 4px 16px 8px; font-size: 16px; font-weight: 600; }

.tabs { display: flex; gap: 6px; padding: 4px 16px 8px; flex: none; }
.tabs button {
  flex: 1; padding: 8px 0; border-radius: 10px;
  background: transparent; border: 1px solid var(--line); font-size: 14px;
}
.tabs button.on { background: var(--green); border-color: var(--green); color: var(--bar-ink); }
body.night .tabs button.on { background: var(--green-2); }

.goto { display: flex; gap: 8px; padding: 0 16px 8px; flex: none; }
.goto input, .searchbox input, .settings input[type=url], .settings select {
  flex: 1; width: 100%;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--paper);
  outline: none;
}
.goto input:focus, .searchbox input:focus { border-color: var(--gold); }
.goto button, .dl button {
  padding: 0 16px; border-radius: 10px;
  background: var(--green); color: var(--bar-ink); font-size: 14px;
}
body.night .goto button, body.night .dl button { background: var(--green-2); }
.searchbox { padding: 0 16px 6px; flex: none; }
.qinfo { padding: 2px 18px 8px; font-size: 12px; color: var(--muted); flex: none; }

.list { overflow-y: auto; flex: 1; padding: 0 8px 16px; -webkit-overflow-scrolling: touch; }
.item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: right;
  padding: 10px 10px; border-bottom: 1px solid var(--line);
}
.item:active { background: var(--hl); }
.item.current { background: color-mix(in srgb, var(--hl) 55%, transparent); }
.num {
  flex: none; width: 34px; height: 34px;
  display: grid; place-items: center;
  font-size: 12px; color: var(--green-2);
  border: 1.5px solid var(--gold); border-radius: 50% 50% 50% 50% / 42% 42% 58% 58%;
  transform: rotate(45deg);
}
.num > span { transform: rotate(-45deg); }
body.night .num { color: var(--gold); }
.item .main { flex: 1; min-width: 0; }
.item .name { font-family: Amiri, serif; font-size: 19px; font-weight: 700; line-height: 1.3; }
.item .sub { font-size: 12px; color: var(--muted); }
.item .end { font-size: 12px; color: var(--muted); flex: none; }
.item .del { color: var(--muted); padding: 6px; }

.results .item { display: block; }
.results .ref { font-size: 12px; color: var(--green-2); margin-bottom: 2px; }
body.night .results .ref { color: var(--gold); }
.results .txt { font-family: Amiri, serif; font-size: 20px; line-height: 1.9; }
.results mark { background: var(--hl); color: inherit; border-radius: 4px; padding: 0 2px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }

.reciter-item .name { font-family: inherit; font-size: 15px; font-weight: 600; }
.reciter-item.sel .name::before { content: "● "; color: var(--gold); }

/* ---------- Settings ---------- */
.settings { overflow-y: auto; padding: 0 16px 20px; flex: 1; }
.settings .row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.settings .row.col { flex-direction: column; align-items: stretch; }
.settings select { flex: 0 1 60%; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0; }
.dl { display: flex; gap: 8px; }
.dl button { flex: 1; padding: 10px 0; }
.dl button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.settings progress { width: 100%; accent-color: var(--gold); }
.switch {
  appearance: none; width: 44px; height: 26px; border-radius: 13px;
  background: var(--line); position: relative; flex: none; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.switch:checked { background: var(--green-2); }
.switch:checked::after { transform: translateX(-18px); }
.about { padding: 14px 0; font-size: 13px; color: var(--muted); }
.about summary { cursor: pointer; color: var(--ink); }
.about a { color: var(--green-2); }
body.night .about a { color: var(--gold); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 140px); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0;
  background: rgba(20, 20, 20, .9); color: #fff;
  padding: 10px 16px; border-radius: 20px; font-size: 13px;
  transition: .25s; pointer-events: none; max-width: 86vw; text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 900px) {
  .sheet { left: 50%; right: auto; width: 520px; transform: translate(-50%, 105%); }
  .sheet.on { transform: translate(-50%, 0); }
}

/* الشاشات الواسعة: تجميع أزرار المشغل في الوسط */
@media (min-width: 760px) {
  #player > * { max-width: 620px; margin-left: auto; margin-right: auto; }
}

/* شارات القراء */
.tag {
  display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 8px;
  font-size: 10.5px; border: 1px solid var(--gold); color: var(--green-2);
}
.tag.srv { background: var(--green-2); border-color: var(--green-2); color: #fff; }
body.night .tag { color: var(--gold); }
body.night .tag.srv { color: #fff; }
.psurah { white-space: nowrap; }

/* حلقة الآية */
.ayring {
  position: absolute; pointer-events: none; border-radius: 50%;
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 4px rgba(201, 164, 92, .28), 0 0 14px rgba(201, 164, 92, .55);
  transition: left .25s, top .25s;
}
.ayring.sel { border-color: #d0662b; box-shadow: 0 0 0 4px rgba(208, 102, 43, .25), 0 0 16px rgba(208, 102, 43, .55); animation: ringpulse 1.2s ease-in-out infinite; }
@keyframes ringpulse { 50% { transform: scale(1.12); } }

/* شريط الآية المختارة */
.ayahbar {
  position: fixed; left: 10px; right: 10px; z-index: 15;
  display: flex; align-items: center; gap: 2px;
  padding: 8px 8px 8px 12px; border-radius: 16px;
  background: var(--sheet); color: var(--ink);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .22);
  transform: translateY(20px); opacity: 0; pointer-events: none; transition: .2s;
}
.ayahbar.on { transform: none; opacity: 1; pointer-events: auto; }
.abref { flex: 1; min-width: 0; font-family: Amiri, serif; font-size: 17px; font-weight: 700; padding-inline-start: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.abplay { display: flex; align-items: center; gap: 4px; padding: 9px 12px; border-radius: 12px; background: var(--green); color: var(--bar-ink); font-size: 14px; white-space: nowrap; }
body.night .abplay { background: var(--green-2); }
.abplay svg { width: 18px; height: 18px; }
@media (min-width: 760px) { .ayahbar { left: 50%; right: auto; width: 520px; transform: translate(-50%, 20px); } .ayahbar.on { transform: translate(-50%, 0); } }

.ayahbar .icon { width: 38px; height: 38px; flex: none; }

/* تظليل الآية المتلوّة */
.ayhl { position: absolute; pointer-events: none; overflow: visible; }
.ayhl path {
  fill: rgba(214, 170, 72, .30); stroke: rgba(190, 140, 40, .55); stroke-width: 2;
  stroke-linejoin: round; mix-blend-mode: multiply;
}
body.night .ayhl path { fill: rgba(214, 170, 72, .22); mix-blend-mode: normal; }
