/* ============ Tokens ============ */
:root {
  color-scheme: light dark;
  --bg:      light-dark(#f3f0e6, #0c1210);
  --surface: light-dark(#ffffff, #151d1a);
  --paper:   light-dark(#fffbf1, #121a17);
  --ink:     light-dark(#15201b, #e9f0eb);
  --muted:   light-dark(#66736b, #8da096);
  --line:    light-dark(#e4decc, #24302b);
  --chip:    light-dark(#e9e4d3, #1f2a25);
  --primary: light-dark(#0b6b57, #3bb890);
  --on-primary: light-dark(#ffffff, #06241c);
  --gold:    light-dark(#a47e22, #d4b25e);
  --hero-a:  light-dark(#0c7a63, #145a4b);
  --hero-b:  light-dark(#064a3d, #0a3a30);
  --shadow-c: light-dark(rgb(40 50 40 / .13), rgb(0 0 0 / .5));

  --ui: "Cairo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --quran: "Amiri Quran", "Scheherazade New", "Traditional Arabic", serif;
  --fs: 1.75rem;           /* Quran text size (user adjustable) */
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }
@media (min-width: 700px) { :root { --fs: 2rem; } }

/* ============ Base ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--ui); line-height: 1.6; min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
}
body.noscroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
[hidden] { display: none !important; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.lead { margin: 18px 4px 10px; font-size: .9rem; }
svg { flex: none; }

/* ============ App bar ============ */
.appbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.5) blur(16px); backdrop-filter: saturate(1.5) blur(16px);
  border-bottom: 1px solid var(--line);
  transition: transform .28s ease;
}
.appbar-in {
  max-width: 760px; margin: 0 auto; height: 56px; padding: 0 8px;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
}
.titles { text-align: center; min-width: 0; }
.titles h1 { margin: 0; font-size: 1.08rem; font-weight: 700; line-height: 1.25; }
.titles .sub {
  margin: 1px 0 0; font-size: .74rem; color: var(--muted); line-height: 1.3;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.slot { display: flex; justify-content: center; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 12px;
  background: transparent; color: var(--ink); cursor: pointer;
}
.icon-btn:active { background: var(--chip); }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.aa { font-size: 1.05rem; font-weight: 700; color: var(--primary); }
.progress { position: absolute; inset-inline: 0; bottom: -1px; height: 3px; }
.progress i { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 0 2px 2px 0; transition: width .15s linear; }

/* ============ Bottom tab bar ============ */
.tabbar {
  position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 640px;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: saturate(1.5) blur(16px); backdrop-filter: saturate(1.5) blur(16px);
  border-top: 1px solid var(--line);
  transition: transform .28s ease;
}
.tab {
  height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px; color: var(--muted); font-size: .72rem; font-weight: 600;
}
.tab .ic { display: grid; place-items: center; width: 52px; height: 30px; border-radius: 15px; transition: background .2s; }
.tab svg { width: 23px; height: 23px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--primary); }
.tab.on .ic { background: color-mix(in srgb, var(--primary) 17%, transparent); }
.tab:active .ic { background: var(--chip); }
@media (min-width: 700px) {
  .tabbar { bottom: 14px; border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 10px 30px var(--shadow-c); }
  body { padding-bottom: calc(var(--tabbar-h) + 36px); }
}
body.hide-bars .appbar { transform: translateY(-100%); }
body.hide-bars .tabbar { transform: translateY(110%); }

/* ============ Shared components ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 0 22px;
  border-radius: 14px; background: var(--primary); color: var(--on-primary); font-weight: 700; margin-top: 14px;
}
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px;
  background: var(--chip); border-radius: 13px;
}
.seg > * {
  border: 0; background: transparent; color: var(--muted); font-size: .92rem; font-weight: 700;
  min-height: 40px; padding: 0 12px; border-radius: 10px; text-align: center; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.seg > .on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 5px var(--shadow-c); }

.bismillah { font-family: var(--quran); font-size: calc(var(--fs) * 1.05); text-align: center; margin: 6px 0 12px; color: var(--gold); line-height: 1.8; }

.list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
@media (min-width: 640px) { .list { grid-template-columns: 1fr 1fr; } }
.row, .card {
  display: flex; align-items: center; gap: 14px; padding: 11px 14px; min-height: 68px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  transition: transform .1s, border-color .2s;
}
.row:active, .card:active { transform: scale(.985); border-color: var(--primary); }
.grow { flex: 1; min-width: 0; }
.row .name { display: block; font-family: var(--quran); font-size: 1.35rem; line-height: 1.7; }
.row .meta { display: block; font-size: .78rem; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.row .en { font-size: .76rem; color: var(--muted); direction: ltr; font-family: system-ui, sans-serif; white-space: nowrap; }

/* 8‑point star badge (two rotated squares) */
.badge { position: relative; flex: none; width: 44px; height: 44px; display: grid; place-items: center; }
.badge::before, .badge::after { content: ""; position: absolute; inset: 7px; border: 1.5px solid var(--gold); border-radius: 4px; }
.badge::after { transform: rotate(45deg); }
.badge b { position: relative; font-size: .88rem; font-weight: 700; color: var(--ink); }

.searchbox { position: relative; }
.searchbox svg { position: absolute; inset-inline-start: 16px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2; stroke-linecap: round; }
.searchbox input {
  width: 100%; height: 52px; padding-inline: 48px 16px; font: inherit; font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; outline: none;
}
.searchbox input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.searchbox.small { margin-top: 12px; }
.searchbox.small input { height: 46px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 9px 16px; background: var(--chip); border-radius: 999px; font-weight: 600; font-size: .92rem; }
.chip:active { background: color-mix(in srgb, var(--primary) 20%, var(--chip)); }

.card { display: block; padding: 14px 16px; }
.card .ref { display: block; font-size: .8rem; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
.card .verse { display: block; font-family: var(--quran); font-size: 1.5rem; line-height: 2.1; }

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; stroke: var(--gold); fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 8px; }
.empty p { margin: 4px 0; }

.footer { text-align: center; padding: 28px 8px 8px; font-size: .78rem; color: var(--muted); }
.footer a { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; }

/* ============ Home ============ */
.hero-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 16px; padding: 18px 20px;
  border-radius: 22px; color: #fff; box-shadow: 0 10px 28px var(--shadow-c);
  background:
    radial-gradient(circle at 12% 15%, rgb(255 255 255 / .14), transparent 45%),
    linear-gradient(135deg, var(--hero-a), var(--hero-b));
}
.hero-card .k { font-size: .78rem; opacity: .85; }
.hero-card .t { font-family: var(--quran); font-size: 1.7rem; line-height: 1.7; }
.hero-card .s { font-size: .8rem; opacity: .85; margin-top: 2px; }
.hero-card .go { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: rgb(255 255 255 / .18); }
.hero-card .go svg { width: 22px; height: 22px; stroke: #fff; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* ============ Reader ============ */
.modes { margin-bottom: 12px; }
.mushaf {
  background: var(--paper); margin-inline: -16px; padding: 20px 18px 26px;
  border-block: 1px solid var(--line);
}
@media (min-width: 640px) {
  .mushaf { margin-inline: 0; padding: 30px 34px; border: 1px solid var(--line); border-radius: 22px; }
}
.surah-banner {
  margin: 4px auto 14px; padding: 12px 16px 12px; text-align: center;
  font-family: var(--quran); font-size: calc(var(--fs) * .9); line-height: 1.6; color: var(--gold);
  border: 1.5px solid var(--gold); border-radius: 16px;
  background: linear-gradient(color-mix(in srgb, var(--gold) 12%, transparent), transparent);
  box-shadow: inset 0 0 0 4px var(--paper), inset 0 0 0 5px color-mix(in srgb, var(--gold) 45%, transparent);
}
.surah-banner small { display: block; font-family: var(--ui); font-size: .74rem; color: var(--muted); margin-top: 4px; line-height: 1.4; }
.sura + .sura { margin-top: 22px; }
.ayahs {
  margin: 0; font-family: var(--quran); font-size: var(--fs); line-height: 2.35;
  text-align: justify; text-justify: inter-word; text-wrap: pretty;
}
.ayah {
  cursor: pointer; border-radius: 8px; scroll-margin-top: 90px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone; transition: background .2s;
}
.ayah.active, .ayah:target { background: color-mix(in srgb, var(--gold) 30%, transparent); }
.ayah .end { color: var(--gold); font-size: .72em; margin-inline: .2em; white-space: nowrap; }
.ayah.bm .end { background: var(--gold); color: var(--paper); border-radius: 999px; padding: 0 .3em; }
.page-no { text-align: center; margin-top: 16px; color: var(--gold); font-family: var(--quran); font-size: 1.15rem; }

.pager { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-top: 16px; }
.pbtn {
  display: flex; flex-direction: column; justify-content: center; min-height: 58px; padding: 8px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
}
.pbtn small { color: var(--muted); font-size: .72rem; }
.pbtn b { font-size: .92rem; line-height: 1.3; }
.pbtn.next { text-align: end; }
.pbtn:active { border-color: var(--primary); }
.goto input {
  width: 74px; height: 46px; text-align: center; font: inherit; font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
.goto input:focus { border-color: var(--primary); }

/* ============ Bottom sheets ============ */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / .5); opacity: 0; pointer-events: none; transition: opacity .25s; }
.backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px;
  max-height: 86dvh; overflow: auto; padding: 10px 20px calc(20px + var(--safe-b));
  background: var(--surface); border-radius: 26px 26px 0 0; box-shadow: 0 -12px 40px var(--shadow-c);
  transform: translateY(105%); visibility: hidden;
  transition: transform .32s cubic-bezier(.2, .8, .2, 1), visibility 0s .32s;
}
.sheet.open { transform: none; visibility: visible; transition-delay: 0s; }
.grab { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { margin: 0 0 12px; font-size: 1.05rem; }
.sheet .ayah-text {
  font-family: var(--quran); font-size: 1.5rem; line-height: 2.1; text-align: justify;
  max-height: 32dvh; overflow: auto; padding: 8px 14px; margin-bottom: 16px; background: var(--bg); border-radius: 16px;
}
#fs-preview { font-size: var(--fs); text-align: center; }
.lbl { display: block; margin: 14px 2px 8px; font-size: .85rem; font-weight: 700; color: var(--muted); }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input { flex: 1; height: 32px; accent-color: var(--primary); }
.a-s { font-size: .9rem; font-weight: 700; } .a-l { font-size: 1.5rem; font-weight: 700; }
.actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
.act {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 80px; padding: 12px 6px; border: 0; border-radius: 16px; cursor: pointer;
  background: var(--chip); color: var(--ink); font-size: .82rem; font-weight: 700;
}
.act svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.act:active { transform: scale(.97); }
.act.on { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }
.act.on svg { fill: currentColor; }

.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  translate: -50% 20px; opacity: 0; pointer-events: none; padding: 10px 20px; border-radius: 999px;
  background: #1b2420; color: #fff; font-size: .9rem; font-weight: 600; white-space: nowrap;
  transition: opacity .2s, translate .2s;
}
.toast.show { opacity: 1; translate: -50% 0; }

/* ============ Bookmarks ============ */
.card.bmrow { display: flex; align-items: flex-start; gap: 8px; padding-inline-end: 6px; }
.bmrow .ref { display: block; font-size: .8rem; font-weight: 700; color: var(--primary); }
.bmrow .snip {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-family: var(--quran); font-size: 1.25rem; line-height: 2;
}

@media (max-width: 380px) { .titles h1 { font-size: 1rem; } }
@media (prefers-reduced-motion: reduce) { * { transition-duration: 0s !important; scroll-behavior: auto !important; } }

/* ============ Menu + Adhkar ============ */
button.tab { background: none; border: 0; font-family: inherit; cursor: pointer; }
.menu-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.menu-list .row { min-height: 60px; background: var(--bg); }
.mname { font-weight: 700; font-size: 1rem; }
.ico { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, transparent); }
.ico svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.group-title { margin: 22px 4px 0; font-size: .9rem; color: var(--muted); font-weight: 700; }
.dname { font-family: var(--ui) !important; font-size: 1.02rem !important; font-weight: 700; line-height: 1.5 !important; }
.credit { margin: 22px 8px 0; text-align: center; font-size: .78rem; color: var(--muted); }

.tip { margin: 10px 4px 0; font-size: .82rem; color: var(--muted); }
.adhkar { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 12px; }
.dhikr {
  position: relative; padding: 16px 16px 10px; cursor: pointer; user-select: none; -webkit-user-select: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  transition: transform .1s, background .2s, border-color .2s; outline: none;
}
.dhikr:active { transform: scale(.992); }
.dhikr:focus-visible { border-color: var(--primary); }
.dtext { font-family: var(--quran); font-size: calc(var(--fs) * .82); line-height: 2.2; text-align: justify; text-justify: inter-word; }
.devening { margin-top: 10px; padding: 8px 12px; border-radius: 12px; background: color-mix(in srgb, var(--gold) 13%, transparent); font-family: var(--quran); font-size: calc(var(--fs) * .78); line-height: 2.1; }
.devening .tag { display: block; font-family: var(--ui); font-size: .72rem; font-weight: 700; color: var(--gold); }
.devening p { margin: 0; }
#adhkar:not([data-time="evening"]) .devening { display: none; }
.dfoot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); min-height: 44px; }
.dcount { font-weight: 700; color: var(--primary); }
.dcount .of { color: var(--muted); font-weight: 600; font-size: .85rem; }
.undo { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--chip); color: var(--ink); font-size: 1.3rem; line-height: 1; cursor: pointer; visibility: hidden; }
.dhikr.started .undo { visibility: visible; }
.dhikr.done { background: color-mix(in srgb, var(--primary) 9%, var(--surface)); border-color: color-mix(in srgb, var(--primary) 45%, var(--line)); }
.dhikr.done .dtext { opacity: .62; }
.dhikr.done .dcount::after { content: " ✓"; }
#dh-reset { background: var(--chip); color: var(--ink); margin-top: 20px; }

/* ============ Install / offline ============ */
.install-card { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; padding: 12px 14px; background: var(--surface); border: 1px dashed var(--primary); border-radius: 18px; }
.install-card b { display: block; font-size: .95rem; line-height: 1.4; }
.install-card .meta { display: block; font-size: .76rem; color: var(--muted); line-height: 1.4; }
.btn.sm { min-height: 38px; padding: 0 16px; margin: 0; font-size: .9rem; border: 0; cursor: pointer; }
.set-actions { display: grid; gap: 8px; }
.wide { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 14px; border: 0; border-radius: 14px; background: var(--chip); color: var(--ink); font-size: .9rem; font-weight: 700; cursor: pointer; }
.wide svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wide:disabled { opacity: .7; }
.steps { margin: 0 0 14px; padding-inline-start: 22px; line-height: 2; }
.kbd { display: inline-block; padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }

/* ============ Book mode (page turning) ============ */
body.book .mushaf, body.book .pager { display: none; }
.book-stage {
  position: relative; height: var(--stage-h, 600px); margin: 10px auto 0;
  width: min(100%, calc(var(--stage-h, 600px) * .74));
  perspective: 1700px; perspective-origin: 100% 50%;
  touch-action: pan-y; user-select: none; -webkit-user-select: none;
}
/* a few page edges peeking out on the left = thickness of the book */
.book-stage::before, .book-stage::after {
  content: ""; position: absolute; top: 5px; bottom: 5px; right: 3px; left: -5px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 14px 4px 4px 14px;
}
.book-stage::after { top: 2.5px; bottom: 2.5px; left: -2.5px; }
.bpage {
  position: absolute; inset: 0; z-index: 2; display: flex; flex-direction: column;
  overflow-y: auto; overscroll-behavior: contain; padding: 12px 12px 8px;
  background: linear-gradient(to left, rgb(0 0 0 / .08), transparent 26px), var(--paper);  /* spine shadow on the right */
  border: 1px solid var(--line); border-radius: 14px 4px 4px 14px;
  box-shadow: 0 8px 24px var(--shadow-c);
  transform-origin: 100% 50%; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  will-change: transform; cursor: grab;
}
.bpage.next { z-index: 1; }
.bpage.prev { z-index: 3; }
.bcontent { margin-block: auto; }
.bcontent .ayahs { line-height: 1.95; }
.bcontent .surah-banner { margin-bottom: 8px; }
.bcontent .bismillah { margin: 2px 0 4px; }
.bcontent .page-no { margin-top: 8px; font-size: 1rem; }
.bshade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; border-radius: inherit; }
.book-ctrl {
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; justify-items: center;
  max-width: 420px; margin: 6px auto 0; font-size: .82rem; font-weight: 600; color: var(--muted);
}
.book-ctrl .icon-btn:disabled { opacity: .3; }
@media (min-width: 640px) { .bpage { padding: 22px 26px 12px; } }
.bk-mid { display: flex; align-items: center; gap: 6px; }
.bk-no { min-width: 72px; text-align: center; }
.bk-fs, .bk-fit {
  height: 36px; min-width: 40px; padding: 0 10px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--chip); color: var(--ink); font: inherit; font-size: .9rem; font-weight: 700;
}
.bk-fit { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); font-size: .8rem; }
.bk-fs:disabled { opacity: .35; }
.bmore {
  position: absolute; z-index: 4; left: 50%; bottom: 8px; translate: -50% 0; width: 34px; height: 34px;
  display: grid; place-items: center; border-radius: 50%; pointer-events: none;
  background: var(--surface); box-shadow: 0 2px 10px var(--shadow-c); color: var(--primary);
  opacity: 0; transition: opacity .2s;
}
.bmore svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.book-stage.more .bmore { opacity: .92; animation: bmore 1.6s ease-in-out infinite; }
@keyframes bmore { 50% { translate: -50% 4px; } }
