/* ============================================================
   Halaka — Qur'an reader & memorization companion
   Design language: warm parchment / deep emerald night,
   gold ornament, frosted glass surfaces.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --radius: 18px;
  --radius-sm: 12px;
  --radius-lg: 26px;
  --maxw: 820px;
  --topbar-h: clamp(52px, 13vw, 64px);
  --band: clamp(11px, 3.2vw, 17px);   /* gilt frame band thickness — scales down on small screens */
  --font-ui: "Amiri", ui-serif, Georgia, "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --font-quran: "Amiri Quran", "Amiri", "Scheherazade New", "Geeza Pro", "Noto Naskh Arabic", serif;
  --font-ar: "Amiri", "Geeza Pro", "Noto Naskh Arabic", serif;
  --arabic-size: 2.05rem; /* adjustable via settings */
}

/* NIGHT (default) — deep emerald charcoal, warm gold */
html[data-theme="night"] {
  --bg-0: #0b0f0d;
  --bg-1: #0f1512;
  --bg-2: #141b17;
  --ink: #ece5d4;
  --ink-soft: #b8b3a2;
  --ink-faint: #7d7a6d;
  --gold: #d9b968;
  --gold-soft: #b89a4f;
  --emerald: #4bb897;
  --emerald-deep: #2f8f74;
  --line: rgba(217, 185, 104, 0.16);
  --glass-bg: rgba(20, 27, 23, 0.62);
  --glass-brd: rgba(217, 185, 104, 0.20);
  --glass-hi: rgba(255, 255, 255, 0.06);
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.75);
  --scrim: rgba(4, 7, 6, 0.55);
  --glow-a: rgba(43, 122, 100, 0.35);
  --glow-b: rgba(150, 116, 47, 0.22);
  color-scheme: dark;
}

/* DAY — parchment, ink, deep emerald */
html[data-theme="day"] {
  --bg-0: #efe7d4;
  --bg-1: #f6efdd;
  --bg-2: #fbf6e9;
  --ink: #2a2116;
  --ink-soft: #6a5f4c;
  --ink-faint: #9c917a;
  --gold: #9c7a24;
  --gold-soft: #b08f3a;
  --emerald: #1c6f59;
  --emerald-deep: #14513f;
  --line: rgba(120, 92, 30, 0.20);
  --glass-bg: rgba(251, 246, 233, 0.66);
  --glass-brd: rgba(120, 92, 30, 0.22);
  --glass-hi: rgba(255, 255, 255, 0.55);
  --shadow: 0 18px 44px -22px rgba(70, 52, 20, 0.45);
  --scrim: rgba(60, 45, 20, 0.28);
  --glow-a: rgba(28, 111, 89, 0.20);
  --glow-b: rgba(156, 122, 36, 0.18);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-1);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background 0.6s var(--ease), color 0.6s var(--ease);
}
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
button { font-family: inherit; color: inherit; cursor: pointer; }
::selection { background: color-mix(in srgb, var(--gold) 42%, transparent); }

/* ---------- Backdrop ---------- */
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; background:
    radial-gradient(120% 100% at 50% -10%, var(--bg-2), var(--bg-1) 45%, var(--bg-0)); }
.backdrop-glow { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.9; }
.glow-a { width: 60vw; height: 60vw; top: -20vw; left: -10vw; background: var(--glow-a); }
.glow-b { width: 55vw; height: 55vw; bottom: -25vw; right: -12vw; background: var(--glow-b); }
.backdrop-pattern {
  position: absolute; inset: 0; opacity: 0.05; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'><g fill='none' stroke='%23d9b968' stroke-width='1'><path d='M60 6l14 24 28 4-20 20 5 28-27-13-27 13 5-28-20-20 28-4z'/><circle cx='60' cy='60' r='40'/></g></svg>");
  background-size: 220px 220px;
}

/* ---------- Glass surfaces ---------- */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  backdrop-filter: blur(22px) saturate(1.4);
  border: 1px solid var(--glass-brd);
  box-shadow: var(--shadow), inset 0 1px 0 var(--glass-hi);
}
.glass-soft {
  background: color-mix(in srgb, var(--glass-bg) 70%, transparent);
  border: 1px solid var(--line);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 14px; padding-top: env(safe-area-inset-top);
  border-left: 0; border-right: 0; border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}
.wordmark { display: flex; flex-direction: column; align-items: center; line-height: 1; padding: 0 4px; user-select: none; }
.wm-ar { font-family: var(--font-ar); font-size: 1.35rem; color: var(--gold); font-weight: 700; }
.wm-en { font-size: 0.58rem; letter-spacing: 0.32em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; padding-left: 0.32em; }

.icon-btn {
  display: grid; place-items: center;
  width: 42px; height: 42px; border-radius: 12px;
  background: transparent; border: 1px solid transparent; color: var(--ink-soft);
  transition: all 0.25s var(--ease);
}
.icon-btn:hover { color: var(--ink); background: var(--glass-hi); border-color: var(--line); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.sm { width: 36px; height: 36px; }
.icon-btn.active { color: var(--bg-1); background: var(--gold); border-color: transparent; }

.surah-pill {
  display: flex; align-items: center; gap: 10px;
  margin: 0; padding: 5px 14px 5px 6px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--glass-hi);
  max-width: min(56vw, 340px); transition: all 0.2s var(--ease);
}
.surah-pill:hover { border-color: var(--gold-soft); }
.surah-pill:active { transform: scale(0.98); }
.sp-num {
  display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px;
  border-radius: 50%; font-family: var(--font-ar); font-weight: 700; font-size: 0.9rem;
  color: var(--bg-1); background: linear-gradient(145deg, var(--gold), var(--gold-soft));
}
.sp-text { display: flex; flex-direction: column; line-height: 1.12; overflow: hidden; text-align: start; }
.sp-ar { font-family: var(--font-ar); font-size: 1.02rem; font-weight: 700; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-name { font-size: 0.6rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-caret { width: 16px; height: 16px; color: var(--ink-faint); flex: none; }
.topbar-actions { display: flex; align-items: center; gap: 2px; }

/* theme icon swap */
.ic-sun { display: none; }
html[data-theme="day"] .ic-moon { display: none; }
html[data-theme="day"] .ic-sun { display: block; }

/* Tajwīd colouring is paused (needs the v4 font, whose line metrics differ from the
   authentic v2 layout). The palette machinery in mushaf.js stays dormant for later. */

/* ---------- Reader ---------- */
.reader { position: relative; min-height: calc(100vh - var(--topbar-h)); }
.reader-inner { max-width: var(--maxw); margin: 0 auto; padding: 26px 20px 40vh; }

.loader { text-align: center; padding: 22vh 0; color: var(--ink-faint); }
.loader-ornament {
  width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--gold);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Surah header */
.surah-header { text-align: center; margin: 8px 0 26px; }
.sh-frame {
  position: relative; display: inline-flex; flex-direction: column; align-items: center;
  padding: 26px 46px; border-radius: var(--radius-lg);
  background: linear-gradient(160deg, color-mix(in srgb, var(--gold) 12%, transparent), transparent 60%);
  border: 1px solid var(--line);
}
.sh-frame::before, .sh-frame::after {
  content: ""; position: absolute; width: 30px; height: 30px; border: 2px solid var(--gold-soft); opacity: 0.6;
}
.sh-frame::before { top: 8px; left: 8px; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.sh-frame::after { bottom: 8px; right: 8px; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }
.sh-index { font-size: 0.66rem; letter-spacing: 0.34em; text-transform: uppercase; color: var(--gold-soft); }
.sh-name-ar { font-family: var(--font-ar); font-weight: 700; font-size: 2.6rem; color: var(--ink); margin: 6px 0 2px; line-height: 1; }
.sh-name-en { font-size: 1.02rem; font-weight: 600; letter-spacing: 0.02em; }
.sh-meta { display: flex; gap: 14px; justify-content: center; margin-top: 10px; font-size: 0.74rem; color: var(--ink-faint); }
.sh-meta span { display: inline-flex; align-items: center; gap: 5px; }
.sh-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--gold-soft); }

/* Basmala ornament */
.basmala {
  text-align: center; font-family: var(--font-quran); font-size: 1.7rem; color: var(--gold);
  margin: 6px auto 30px; padding: 14px 0; position: relative; line-height: 2;
}
.basmala::before, .basmala::after {
  content: "۞"; color: var(--gold-soft); opacity: 0.55; font-size: 1.1rem; margin: 0 12px; vertical-align: middle;
}

/* ---------- Muṣḥaf: continuous flowing text ---------- */
.mushaf {
  direction: rtl; text-align: center;
  font-family: var(--font-quran); font-size: var(--arabic-size); line-height: 2.45;
  color: var(--ink); word-spacing: 0.05em; padding: 2px 2px 6px;
  -webkit-user-select: none; user-select: none;
}
/* each verse is an inline wrapper so highlights & flags flow across lines */
.v { border-radius: 8px; transition: background 0.3s var(--ease); scroll-margin-top: calc(var(--topbar-h) + 24px); box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.v.flash { background: color-mix(in srgb, var(--gold) 22%, transparent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 18%, transparent); }
.v.playing { background: color-mix(in srgb, var(--emerald) 15%, transparent); }
.v.review-flag { background: color-mix(in srgb, var(--gold) 11%, transparent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 12%, transparent); }

.word { padding: 0 0.02em; border-radius: 6px; transition: background 0.15s ease, color 0.15s ease; }
body.annotate-mode .word:hover { background: var(--glass-hi); }
/* word highlight — colour comes from inline --hl */
.word.marked { background: color-mix(in srgb, var(--hl, var(--gold)) 32%, transparent); box-shadow: 0 2px 0 color-mix(in srgb, var(--hl, var(--gold)) 60%, transparent); }

/* ayah-end number — a clear gold roundel with the verse number */
.ayah-num {
  position: relative; display: inline-grid; place-items: center; vertical-align: middle;
  width: 1.55em; height: 1.55em; margin: 0 0.28em; font-family: var(--font-ar);
  font-size: 0.5em; font-weight: 700; line-height: 1; color: var(--gold); cursor: pointer;
  border: 1.6px solid var(--gold-soft); border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--gold) 16%, transparent), color-mix(in srgb, var(--gold) 4%, transparent));
  box-shadow: 0 1px 3px rgba(0,0,0,0.25), inset 0 0 0 2.4px color-mix(in srgb, var(--bg-1) 55%, transparent);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.ayah-num:hover { transform: scale(1.12); }
.ayah-num.bookmarked { color: var(--bg-1); border-color: var(--gold); background: radial-gradient(circle, var(--gold), var(--gold-soft)); box-shadow: 0 0 10px color-mix(in srgb, var(--gold) 55%, transparent); }
.ayah-num.has-note::after { content: ""; position: absolute; top: -2px; inset-inline-start: -2px; width: 7px; height: 7px; border-radius: 50%; background: var(--emerald); box-shadow: 0 0 0 2px var(--bg-1); }
.sajda-mark { font-size: 0.62em; color: var(--emerald); margin: 0 0.15em; }

/* ---------- Freehand ink overlay ---------- */
.ink { position: absolute; top: 0; left: 0; width: 100%; z-index: 6; pointer-events: none; overflow: visible; }
.ink.active { pointer-events: auto; touch-action: none; }
body.annotate-mode .reader-inner { position: relative; }

/* end-of-surah ornament + nav */
.surah-nav { display: flex; justify-content: space-between; gap: 12px; margin-top: 34px; }
.surah-nav button {
  flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 14px 18px; border-radius: var(--radius-sm);
  background: var(--glass-hi); border: 1px solid var(--line); color: var(--ink); transition: all 0.25s var(--ease);
}
.surah-nav button:hover { border-color: var(--glass-brd); transform: translateY(-2px); }
.surah-nav button:disabled { opacity: 0.35; pointer-events: none; }
.sn-dir { font-size: 0.64rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--ink-faint); }
.sn-name { font-weight: 600; }
.surah-nav .next { text-align: right; align-items: flex-end; }

/* reading progress */
.progressbar { position: fixed; left: 0; right: 0; top: calc(var(--topbar-h) - 2px); height: 2px; z-index: 39; background: transparent; pointer-events: none; }
.progressbar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--emerald), var(--gold)); transition: width 0.1s linear; }

/* ---------- Scrim + drawers ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: var(--scrim); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); animation: fade 0.3s var(--ease); }
@keyframes fade { from { opacity: 0; } }
.drawer {
  /* full-cover: an opened section covers the muṣḥaf completely (the Qur'an stays home) */
  position: fixed; inset: 0; z-index: 120; width: 100%; max-width: 100%;
  display: flex; flex-direction: column; padding: 0; border-radius: 0;
  padding-top: env(safe-area-inset-top); background: var(--bg-1);
}
.drawer-left { left: 0; border-radius: 0; border-left: 0; animation: slideL 0.34s var(--ease); }
.drawer-right { right: 0; border-radius: 0; border-right: 0; animation: slideR 0.34s var(--ease); }
.drawer-head h2 { max-width: none; }
.surah-list, .bookmark-list, .settings-body, .search-results { max-width: 640px; margin-left: auto; margin-right: auto; width: 100%; }
@keyframes slideL { from { transform: translateX(-102%); } }
@keyframes slideR { from { transform: translateX(102%); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-family: var(--font-ar); font-size: 1.15rem; font-weight: 700; color: var(--gold); }
.drawer-search { display: flex; align-items: center; gap: 10px; margin: 0 18px 12px; padding: 10px 14px; border-radius: 12px; background: var(--glass-hi); border: 1px solid var(--line); }
.drawer-search svg { width: 18px; height: 18px; color: var(--ink-faint); flex: none; }
.drawer-search.big { margin-bottom: 8px; padding: 13px 16px; }
.drawer-search input { flex: 1; background: none; border: none; outline: none; color: var(--ink); font-size: 0.95rem; font-family: var(--font-sans); }
.drawer-search input::placeholder { color: var(--ink-faint); }

/* surah list */
.surah-list { flex: 1; overflow-y: auto; padding: 4px 12px 20px; }
.surah-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border-radius: 12px; background: transparent; border: 1px solid transparent; text-align: left; transition: all 0.2s var(--ease); }
.surah-row:hover { background: var(--glass-hi); border-color: var(--line); }
.surah-row.current { background: color-mix(in srgb, var(--gold) 14%, transparent); border-color: var(--glass-brd); }
.sr-num { display: grid; place-items: center; width: 36px; height: 36px; flex: none; font-family: var(--font-ar); font-weight: 700; font-size: 0.9rem; color: var(--gold); border: 1px solid var(--line); border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--gold) 10%, transparent), transparent); }
.sr-body { flex: 1; min-width: 0; }
.sr-en { font-weight: 600; font-size: 0.9rem; }
.sr-meta { font-size: 0.72rem; color: var(--ink-faint); }
.sr-ar { font-family: var(--font-ar); font-size: 1.3rem; color: var(--gold); }

/* ---------- Search ---------- */
.search-scope, .bm-tabs { display: flex; gap: 8px; padding: 0 18px 12px; }
.chip { font-size: 0.78rem; padding: 6px 14px; border-radius: 999px; background: var(--glass-hi); border: 1px solid var(--line); color: var(--ink-soft); transition: all 0.2s var(--ease); }
.chip.active { color: var(--bg-1); background: var(--gold); border-color: transparent; }
.search-results, .bookmark-list { flex: 1; overflow-y: auto; padding: 4px 12px 24px; }
.empty-hint { color: var(--ink-faint); text-align: center; padding: 30px 24px; font-size: 0.9rem; line-height: 1.6; }
.result { display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 12px; background: transparent; border: 1px solid transparent; margin-bottom: 4px; transition: all 0.2s var(--ease); }
.result:hover { background: var(--glass-hi); border-color: var(--line); }
.result-ref { font-size: 0.72rem; color: var(--gold-soft); font-weight: 700; letter-spacing: 0.04em; margin-bottom: 6px; display: flex; justify-content: space-between; }
.result-ar { font-family: var(--font-quran); font-size: 1.4rem; line-height: 2; direction: rtl; text-align: right; color: var(--ink); }
.result-en { font-size: 0.86rem; color: var(--ink-soft); margin-top: 4px; line-height: 1.55; }
.result mark { background: color-mix(in srgb, var(--gold) 45%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }

/* ---------- Bookmarks ---------- */
.bm-item { display: flex; align-items: flex-start; gap: 10px; padding: 12px 12px; border-radius: 12px; border: 1px solid transparent; transition: all 0.2s var(--ease); }
.bm-item:hover { background: var(--glass-hi); border-color: var(--line); }
.bm-open { flex: 1; text-align: left; background: none; border: none; min-width: 0; }
.bm-ref { font-size: 0.74rem; color: var(--gold-soft); font-weight: 700; }
.bm-ar { font-family: var(--font-quran); font-size: 1.25rem; direction: rtl; text-align: right; color: var(--ink); margin-top: 3px; line-height: 1.9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bm-note { font-size: 0.8rem; color: var(--ink-soft); font-style: italic; margin-top: 2px; }
.bm-del { flex: none; color: var(--ink-faint); background: none; border: none; padding: 4px; border-radius: 8px; }
.bm-del:hover { color: #e5484d; }
.review-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; padding: 4px 20px 14px; font-size: 0.74rem; color: var(--ink-soft); }
.review-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-right: 6px; vertical-align: -2px; }

/* ---------- Annotation palette (tools + colours) ---------- */
.palette {
  position: fixed; right: 16px; top: 50%; transform: translateY(-50%); z-index: 45;
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 10px; border-radius: var(--radius-lg);
  animation: pop 0.3s var(--ease); max-height: 86vh;
}
@keyframes pop { from { transform: translateY(-50%) scale(0.85); opacity: 0; } }
.palette-tools { display: flex; flex-direction: column; gap: 6px; }
.ptool { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: transparent; border: 1px solid var(--line); color: var(--ink-soft); transition: all 0.2s var(--ease); }
.ptool:hover { color: var(--ink); background: var(--glass-hi); }
.ptool.active { color: var(--bg-1); background: var(--gold); border-color: transparent; }
.ptool svg { width: 20px; height: 20px; }
.palette-div { width: 60%; height: 1px; background: var(--line); }
.palette-colors { display: flex; flex-direction: column; gap: 8px; transition: opacity 0.2s; }
.palette-colors.dim { opacity: 0.35; pointer-events: none; }
.pcolor { position: relative; width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; transition: all 0.2s var(--ease); }
.pcolor:hover { transform: scale(1.12); }
.pcolor.active { border-color: var(--ink); box-shadow: 0 0 0 2px var(--glass-bg), 0 0 0 4px currentColor; }
.palette-done { display: grid; place-items: center; gap: 1px; width: 42px; height: 42px; border-radius: 12px; background: transparent; border: 1px solid var(--line); color: var(--ink-soft); font-size: 0.56rem; }
.palette-done:hover { color: var(--ink); background: var(--glass-hi); }
.palette-done svg { width: 16px; height: 16px; }
.palette-min { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; background: transparent; border: 1px solid var(--line); color: var(--ink-soft); }
.palette-min:hover { color: var(--ink); background: var(--glass-hi); }
.palette-min svg { width: 18px; height: 18px; transition: transform 0.2s var(--ease); }
.palette-min .pm-pen { display: none; }   /* expanded → chevron (minimise); minimised → pen */
#toolUndo svg { width: 20px; height: 20px; }
/* minimized → a single gold handle docked to the bottom-right corner, out of the
   reading area, so it never covers the muṣḥaf while you draw */
.palette.min { padding: 4px; gap: 0; top: 50%; bottom: auto; right: 4px; transform: translateY(-50%); }
.palette.min > :not(.palette-min) { display: none; }
.palette.min .palette-min { width: 40px; height: 40px; border-radius: 13px; color: var(--bg-1); background: var(--gold); border-color: transparent; box-shadow: 0 3px 10px rgba(0,0,0,0.35); }
.palette.min .palette-min svg { width: 24px; height: 24px; }
.palette.min .palette-min .pm-chevron { display: none; }   /* minimised → show the pen, not the arrow */
.palette.min .palette-min .pm-pen { display: block; }
/* Quick-undo when collapsed: a distinct glass button above the gold pen handle, so a wrong
   stroke can be undone without re-opening the full palette. Hidden while the palette is open. */
.palette-undo { display: none; }
.palette.min { gap: 8px; }
.palette.min .palette-undo { display: none; }
.palette.min .palette-undo svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Audio player ---------- */
.player {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 47; display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px;
  animation: pop 0.3s var(--ease); max-width: 92vw; transition: bottom 0.3s var(--ease);
}
.player-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: transparent; border: none; color: var(--ink); }
.player-btn:hover { background: var(--glass-hi); }
.player-btn.play { width: 48px; height: 48px; background: linear-gradient(145deg, var(--emerald), var(--emerald-deep)); color: #fff; }
.player-btn.ghost { color: var(--ink-faint); }
.player-btn.spd { display: inline-flex; align-items: center; justify-content: center; gap: 3px; width: auto; height: 34px; min-width: 2.6em; padding: 0 0.6em; border-radius: 999px; font-family: var(--font-sans); font-weight: 700; font-size: 0.78rem; color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); font-variant-numeric: tabular-nums; }
.player-btn.spd:hover { background: color-mix(in srgb, var(--gold) 12%, transparent); }
.pl-rep { width: 14px !important; height: 14px !important; }
.player-btn svg { width: 20px; height: 20px; }
.ic-pause { display: none; }
.player.playing .ic-play { display: none; }
.player.playing .ic-pause { display: block; }
.player-info { display: flex; flex-direction: column; line-height: 1.15; padding: 0 8px; min-width: 80px; }
.player-info span { font-weight: 600; font-size: 0.85rem; }
.player-info small { font-size: 0.68rem; color: var(--ink-faint); }

/* ---------- Ayah context menu (popover on medallion tap) ---------- */
.ayah-menu { position: fixed; z-index: 55; display: flex; flex-direction: column; padding: 7px; border-radius: 16px; min-width: 210px; animation: pop 0.2s var(--ease); }
.ayah-menu .am-head { font-family: var(--font-ar); color: var(--gold); font-size: 1.05rem; padding: 4px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; text-align: center; }
.ayah-menu button { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; background: none; border: none; color: var(--ink); font-size: 0.9rem; text-align: left; width: 100%; }
.ayah-menu button:hover { background: var(--glass-hi); }
.ayah-menu button.on { color: var(--gold); }
.ayah-menu svg { width: 18px; height: 18px; color: var(--ink-soft); flex: none; }
.ayah-menu button.on svg { color: var(--gold); }
/* annotations viewer */
.anno-h { font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold-soft); font-weight: 700; margin: 4px 2px 8px; }
.anno-row { display: block; width: 100%; text-align: start; border: 1px solid var(--line); border-radius: 12px; background: var(--glass-hi); padding: 12px 14px; margin-bottom: 8px; color: var(--ink); cursor: pointer; }
.anno-row:hover { border-color: var(--gold-soft); }
.anno-ref { font-size: 0.82rem; color: var(--gold); font-weight: 600; }
.anno-words { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.anno-word { display: inline-flex; align-items: center; gap: 5px; font-family: var(--font-quran); font-size: 1.25rem; color: var(--ink); }
.anno-sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.anno-n { font-size: 0.8rem; color: var(--ink-faint); margin-top: 4px; }
/* tajwīd rule sheet */
.taj-sheet { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 90; width: min(440px, 94vw); max-height: 60vh; overflow-y: auto; border-radius: 18px; direction: rtl; padding: 0 0 8px; animation: pop 0.25s var(--ease); }
.taj-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px 9px; border-bottom: 1px solid var(--line); font-family: var(--font-ar); font-weight: 700; color: var(--gold); position: sticky; top: 0; background: inherit; }
.taj-x { background: none; border: none; color: var(--ink-soft); font-size: 1rem; cursor: pointer; width: 30px; height: 30px; border-radius: 8px; flex: none; }
.taj-x:hover { background: var(--glass-hi); color: var(--ink); }
.taj-body { padding: 8px 14px 6px; display: flex; flex-direction: column; gap: 11px; }
.taj-rule { border-inline-start: 3px solid var(--gold-soft); padding-inline-start: 10px; }
.taj-name { font-family: var(--font-ar); font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.taj-beats { font-size: 0.72rem; color: var(--gold); font-weight: 600; }
.taj-how { font-size: 0.85rem; color: var(--ink-soft); margin-top: 3px; line-height: 1.6; }
.taj-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-inline-end: 7px; vertical-align: middle; border: 0.5px solid rgba(255,255,255,.2); }
/* Al-Anʿām longer-version choice */
.anaam-choice { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; background: rgba(0,0,0,0.55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: mmFade 0.2s var(--ease); padding: 18px; }
.ac-card { position: relative; width: min(400px, 92vw); padding: 26px 22px; border-radius: 20px; direction: rtl; text-align: center; }
.ac-x { position: absolute; top: 12px; left: 12px; background: none; border: none; color: var(--ink-soft); font-size: 1rem; cursor: pointer; width: 30px; height: 30px; border-radius: 8px; }
.ac-x:hover { background: var(--glass-hi); color: var(--ink); }
.ac-title { font-family: var(--font-quran); font-size: 1.6rem; color: var(--gold); margin-bottom: 8px; }
.ac-sub { font-size: 0.92rem; color: var(--ink-soft); line-height: 1.6; margin-bottom: 18px; }
.ac-btns { display: flex; flex-direction: column; gap: 10px; }
.ac-btns .btn-gold, .ac-btns .btn-ghost { width: 100%; padding: 13px; font-size: 0.95rem; }
/* quick "back to Sulam" chip while reading */
.sulam-resume { position: fixed; top: calc(9px + env(safe-area-inset-top)); left: 0; right: 0; margin-inline: auto; width: fit-content; z-index: 60; display: flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent); color: var(--gold); font-family: var(--font-ar); font-weight: 700; font-size: 0.9rem; cursor: pointer; animation: pop 0.25s var(--ease); }
.sulam-resume svg { width: 18px; height: 18px; }
.sulam-resume:active { transform: scale(0.96); }
.am-note { display: flex; flex-direction: column; gap: 8px; padding: 6px; }
.am-note textarea { width: 100%; min-height: 74px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass-hi); color: var(--ink); font-family: var(--font-sans); font-size: 0.86rem; resize: vertical; outline: none; }
.am-note .am-actions { display: flex; gap: 8px; }
.am-note .am-actions button { justify-content: center; border: 1px solid var(--line); border-radius: 10px; font-size: 0.82rem; }
.am-note .am-save { background: var(--gold); color: var(--bg-1); border-color: transparent; font-weight: 600; }

/* ---------- Settings ---------- */
.settings-body { flex: 1; overflow-y: auto; padding: 12px 18px 36px; }
.set-group { margin-bottom: 14px; background: var(--glass-hi); border: 1px solid var(--line); border-radius: 16px; padding: 12px 16px; }
.set-label { font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-soft); font-weight: 700; margin-bottom: 4px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.set-row:last-child { border-bottom: none; }
/* segmented control (theme toggle in Settings) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.seg button { padding: 6px 15px; background: transparent; border: none; color: var(--ink-soft); font-family: var(--font-ar); font-size: 0.9rem; cursor: pointer; }
.seg button.active { background: color-mix(in srgb, var(--gold) 22%, transparent); color: var(--gold); font-weight: 700; }
/* ayah results merged into the index drawer (below the surah list) */
#indexResults { flex: none; overflow: visible; padding: 0 12px 14px; border-top: 1px solid var(--line); margin-top: 4px; }
#indexResults:empty { display: none; }
.ir-head { font-family: var(--font-ar); font-size: 0.78rem; color: var(--gold-soft); padding: 10px 4px 4px; }
.set-hint { font-size: 0.76rem; line-height: 1.55; color: var(--ink-faint); padding: 8px 0 2px; }
.set-select { font-family: var(--font-ar); font-size: 0.92rem; color: var(--ink); background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; max-width: 62%; direction: rtl; cursor: pointer; }
.set-select:focus { outline: none; border-color: var(--gold); }
.seg { display: inline-flex; background: var(--bg-1); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { padding: 6px 14px; border-radius: 8px; background: none; border: none; color: var(--ink-soft); font-size: 0.82rem; }
.seg button.active { background: var(--gold); color: var(--bg-1); font-weight: 600; }
.switch { position: relative; width: 46px; height: 27px; border-radius: 999px; background: var(--glass-hi); border: 1px solid var(--line); transition: all 0.25s var(--ease); flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%; background: var(--ink-soft); transition: all 0.25s var(--ease); }
.switch.on { background: var(--emerald); border-color: transparent; }
.switch.on::after { left: 21px; background: #fff; }
.range { -webkit-appearance: none; appearance: none; width: 150px; height: 4px; border-radius: 4px; background: var(--line); outline: none; }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--gold); cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.btn-danger { padding: 9px 16px; border-radius: 10px; background: color-mix(in srgb,#e5484d 16%,transparent); border: 1px solid color-mix(in srgb,#e5484d 40%,transparent); color: #e5484d; font-size: 0.84rem; }
.set-about { font-size: 0.76rem; color: var(--ink-faint); line-height: 1.7; margin-top: 6px; }
.set-about b { color: var(--ink-soft); }
.set-about a { color: var(--gold-soft); }
/* account card in settings */
.acc-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--glass-hi); border: 1px solid var(--line); }
.acc-card-body { flex: 1; min-width: 0; text-align: left; }
.acc-card .acc-name { font-weight: 700; color: var(--ink); font-size: 0.98rem; }
.acc-card .acc-role { font-size: 0.78rem; color: var(--gold-soft); }
.btn-gold { padding: 9px 16px; border-radius: 10px; background: linear-gradient(145deg, var(--gold), var(--gold-soft)); color: var(--bg-1); font-weight: 700; font-size: 0.84rem; border: none; flex: none; }
.btn-ghost { padding: 9px 14px; border-radius: 10px; background: transparent; border: 1px solid var(--line); color: var(--ink-soft); font-size: 0.84rem; flex: none; }
.btn-ghost:hover { color: var(--ink); border-color: var(--glass-brd); }

/* ---------- Parent: children dashboard cards ---------- */
.child-card { margin-bottom: 10px; padding: 12px 13px; border-radius: 14px; background: var(--glass-hi); border: 1px solid var(--line); }
.child-head { display: flex; align-items: center; gap: 11px; }
.child-ava { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 50%; font-weight: 800; color: var(--bg-1); background: linear-gradient(145deg, var(--gold), var(--gold-soft)); }
.child-idbox { flex: 1; min-width: 0; }
.child-name { font-weight: 700; color: var(--ink); font-size: 0.98rem; }
.child-sub { font-size: 0.74rem; color: var(--ink-faint); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.child-toggle { flex: none; padding: 6px 11px; border-radius: 999px; background: transparent; border: 1px solid var(--line); color: var(--gold-soft); font-family: inherit; font-size: 0.76rem; cursor: pointer; }
.child-toggle:hover { color: var(--gold); border-color: var(--glass-brd); }
.child-quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 11px; }
.child-quick .cq { text-align: center; padding: 9px 4px; border-radius: 11px; background: var(--glass-bg); border: 1px solid var(--line); }
.child-quick .cq b { display: block; font-size: 1.25rem; font-weight: 800; color: var(--gold); line-height: 1; }
.child-quick .cq span { display: block; margin-top: 4px; font-size: 0.68rem; color: var(--ink-faint); }
.child-more { margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line); }
.child-more .child-chart { margin-bottom: 10px; }
.child-last { font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 10px; }
.child-last b { color: var(--gold); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 80; padding: 11px 20px; border-radius: 999px; font-size: 0.86rem; color: var(--ink);
  background: var(--glass-bg); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  border: 1px solid var(--glass-brd); box-shadow: var(--shadow); animation: toastIn 0.3s var(--ease);
}
@keyframes toastIn { from { transform: translate(-50%, 12px); opacity: 0; } }

/* ---------- Utilities ---------- */
[hidden] { display: none !important; }
.reader-inner::-webkit-scrollbar, .drawer *::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  :root { --arabic-size: 1.75rem; }
  .wm-en { display: none; }
  .surah-pill { max-width: 60vw; }
  .sp-name { display: none; }
  .reader-inner { padding: 18px 14px 42vh; }
  .sh-name-ar { font-size: 2.1rem; }
  .topbar-actions .icon-btn:not(#btnMark):not(#btnTheme) { }
}
@media (min-width: 641px) {
  .surah-pill { min-width: 200px; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.05ms !important; }
}

/* ============================================================
   Page-flip muṣḥaf book
   ============================================================ */
:root { --page-bg: #10140f; }
html[data-theme="day"]   { --page-bg: #fbf7ec; }
html[data-theme="night"] { --page-bg: #11150f; }

html, body { height: 100%; }
/* svh = the SMALL viewport (browser toolbars visible) so the bottom page bar is never
   hidden under Safari's toolbar; the app doesn't scroll so toolbars stay put anyway.
   touch-action: manipulation kills pinch/double-tap zoom — the muṣḥaf stays fixed. */
body { height: 100vh; height: var(--appvh, 100vh); height: 100svh; overflow: hidden; display: flex; flex-direction: column; touch-action: manipulation; }
.topbar { flex: none; position: fixed; top: 0; left: 0; right: 0; z-index: 46; transition: transform 0.3s var(--ease), opacity 0.3s var(--ease); }
body.immersive .topbar { transform: translateY(-105%); opacity: 0; pointer-events: none; }
body.immersive .pagebar { transform: translate(-50%, 185%); opacity: 0; pointer-events: none; }
body.immersive .player { bottom: calc(18px + env(safe-area-inset-bottom)); }
/* side gutter holds the juz/ḥizb margin tabs; max() keeps clear of a landscape notch */
.reader { flex: 1 1 auto; min-height: 0; position: relative; display: grid; place-items: center;
  padding: 4px max(18px, env(safe-area-inset-right)) 4px max(18px, env(safe-area-inset-left)); }
.book { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }
.page-view { position: relative; width: 100%; height: 100%; perspective: 2000px; }
.page-stack { position: absolute; inset: 0; display: flex; align-items: stretch; justify-content: center; backface-visibility: hidden; will-change: transform, opacity; }
.page-stack.spread { gap: 16px; }

.page {
  position: relative; height: 100%; aspect-ratio: 0.52; max-width: 100%; max-height: 100%;
  background: var(--page-bg);
  border: none; border-radius: 12px;   /* gilt frame removed — clean page (design pass) */
  box-shadow: var(--shadow);
  padding: 10px 14px;
  display: flex; flex-direction: column;
}
/* Phone landscape: one ENLARGED, vertically-scrollable page — not a tiny letterboxed
   page and not the 2-page spread. The page grows taller than the short viewport so the
   text is big + readable, and the reader scrolls. (Tablets keep the spread — their
   height > 520 so this doesn't apply.) */
@media (orientation: landscape) and (max-height: 520px) {
  .reader { overflow-y: auto; overflow-x: hidden; place-items: start center; }
  .book, .page-view, .page-stack { position: static; inset: auto; height: auto; }
  .page-stack { display: block; }
  .page { height: calc((var(--appvh, 100vh) - var(--topbar-h)) * 1.7); height: calc((100svh - var(--topbar-h)) * 1.7); max-height: none; margin: 0 auto; }
}
/* eight-point-star medallions — hidden with the gilt frame (design pass) */
.pf-m { display: none; position: absolute; width: var(--band); height: var(--band); z-index: 3; pointer-events: none; background: var(--gold);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23fff'%3E%3Crect x='5' y='5' width='14' height='14'/%3E%3Crect x='5' y='5' width='14' height='14' transform='rotate(45 12 12)'/%3E%3C/g%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cg fill='%23fff'%3E%3Crect x='5' y='5' width='14' height='14'/%3E%3Crect x='5' y='5' width='14' height='14' transform='rotate(45 12 12)'/%3E%3C/g%3E%3C/svg%3E") center/contain no-repeat; }
.pf-m.m-tl { top: calc(-1 * var(--band)); left: calc(-1 * var(--band)); } .pf-m.m-tr { top: calc(-1 * var(--band)); right: calc(-1 * var(--band)); }
.pf-m.m-bl { bottom: calc(-1 * var(--band)); left: calc(-1 * var(--band)); } .pf-m.m-br { bottom: calc(-1 * var(--band)); right: calc(-1 * var(--band)); }
.pf-m.m-t { top: calc(-1 * var(--band)); left: 50%; transform: translateX(-50%); }
.pf-m.m-b { bottom: calc(-1 * var(--band)); left: 50%; transform: translateX(-50%); }
.pf-m.m-l { left: calc(-1 * var(--band)); top: 50%; transform: translateY(-50%); }
.pf-m.m-r { right: calc(-1 * var(--band)); top: 50%; transform: translateY(-50%); }
/* vertical breathing room so the top line's ascenders and the bottom line's
   descenders/tashkīl clear the frame instead of being clipped by overflow:hidden
   (space-between otherwise pins the first/last line flush to the edges). Scales
   with the page font size so it holds on every device. */
.page-body { position: relative; flex: 1 1 auto; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; padding: calc(var(--qfs, 20px) * 0.55) 0; }

/* ---- ornate illuminated frame (double gold keyline + corner ornaments) ---- */
.page-frame { position: absolute; inset: 7px; pointer-events: none; z-index: 4;
  border: 1px solid color-mix(in srgb, var(--gold) 55%, transparent); border-radius: 8px; }
.page-frame::before { content: ""; position: absolute; inset: 3px; border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--gold) 26%, transparent); }
.pf-c { position: absolute; width: 9px; height: 9px; background: var(--gold);
  transform: rotate(45deg); opacity: 0.92; box-shadow: 0 0 0 2px var(--page-bg); }
.pf-c.tl { top: -5px; left: -5px; } .pf-c.tr { top: -5px; right: -5px; }
.pf-c.bl { bottom: -5px; left: -5px; } .pf-c.br { bottom: -5px; right: -5px; }

.ln { display: flex; direction: rtl; justify-content: center; gap: 0; align-items: center; white-space: nowrap; line-height: 1; font-size: var(--qfs, 20px); color: var(--ink); }
.ln.justify { justify-content: space-between; gap: 0; }   /* stretch near-full lines edge-to-edge like the print */
.ln.short { justify-content: center; gap: 0; }
.g { cursor: pointer; border-radius: 5px; padding: 0 0.01em; transition: background 0.12s ease; }
/* keep the QCF glyphs invisible until their page font loads (no fallback-letter flash) */
.page-body:not(.qcf-ready) .g { visibility: hidden; }
.g.end { color: var(--gold); padding: 0 0.06em; }
.g.marked { background: color-mix(in srgb, var(--hl, var(--gold)) 34%, transparent); box-shadow: 0 2px 0 color-mix(in srgb, var(--hl, var(--gold)) 55%, transparent); }
.g.playing { background: color-mix(in srgb, var(--emerald) 22%, transparent); }
.g.flash { background: color-mix(in srgb, var(--gold) 42%, transparent); }

.ln.banner { justify-content: center; gap: 0.45em; font-family: var(--font-ar); font-weight: 700; color: var(--gold); font-size: calc(var(--qfs) * 0.92); line-height: 1.5; }
.ln.banner .bn-orn { color: var(--gold-soft); opacity: 0.75; font-size: 0.85em; }
.ln.banner .bn-name {
  padding: 0.3em 1.5em;
  border: 1.5px solid color-mix(in srgb, var(--gold) 62%, transparent);
  border-radius: 6px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--gold) 18%, transparent), color-mix(in srgb, var(--gold) 4%, transparent) 78%);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--gold) 13%, transparent), 0 1px 4px rgba(0,0,0,0.22);
  letter-spacing: 0.02em;
}
.ln.bism { justify-content: center; font-family: var(--font-quran); color: var(--gold); font-size: calc(var(--qfs) * 0.9); line-height: 1.95; transform: translateY(-0.14em); padding-bottom: 0.12em; }
/* surah heading + basmala combined on a single line (surahs with only one empty line
   before them, e.g. An-Najm) so the title never goes missing */
.ln.banner.with-bism { flex-direction: column; align-items: center; gap: 0.24em; }
.ln.banner.with-bism .bn-title { display: flex; align-items: center; justify-content: center; gap: 0.45em; }
.ln.banner .bn-bism { font-family: var(--font-quran); font-weight: 400; color: var(--gold); font-size: 0.72em; line-height: 1.8; transform: translateY(-0.1em); padding-bottom: 0.16em; }
.ln.blank { min-height: 0.2em; }
/* tajwīd colouring (opt-in): the v4 COLR page font carries the colours; pick the CPAL
   palette that suits the theme (palettes are registered per page in mushaf.js). Default
   (no .tajwid) renders the authentic monochrome v2 font, so the muṣḥaf is untouched. */
html.tajwid .ln { font-palette: --qtNight; }
html.tajwid[data-theme="day"] .ln { font-palette: --qtDay; }
html.tajwid[data-theme="day"] .ln { font-palette: --qtDay; }

.page-head { flex: none; display: flex; direction: rtl; justify-content: space-between; align-items: center; gap: 10px; padding-bottom: 6px; margin-bottom: 8px; border-bottom: 1px solid var(--line); font-family: var(--font-ar); font-size: 0.8rem; }
.page-head span:first-child { color: var(--gold-soft); }
.page-head span:last-child { color: var(--gold); font-weight: 700; }
.page-foot { flex: none; display: flex; justify-content: center; align-items: center; padding-top: 6px; margin-top: 8px; border-top: 1px solid var(--line); }
.page-foot .pg-num { font-family: var(--font-ar); font-weight: 700; color: var(--gold); font-size: 0.98rem; min-width: 2.1em; text-align: center; padding: 2px 18px; border: 1px solid color-mix(in srgb, var(--gold) 50%, transparent); border-radius: 999px; background: radial-gradient(circle, color-mix(in srgb, var(--gold) 16%, transparent), transparent 74%); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--gold) 10%, transparent); }

.page-body .ink { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 5; }

/* sajda: the ۩ prostration glyph is already in the QCF page font at the exact spot, and the
   outer-margin tab (سجدة) marks the ayah. We add no overline — that was ours, not the print. */

/* juz / hizb / sajda tabs — hung in the outer margin/gutter, clear of the text (vertical) */
.page-marks { position: absolute; top: 0; bottom: 0; width: 0; z-index: 6; pointer-events: none; }
.page-marks.side-right { right: 0; }
.page-marks.side-left { left: 0; }
.pmark { position: absolute; top: calc(10% + (var(--ln) - 0.5) / 15 * 80%);
  writing-mode: vertical-rl; text-orientation: mixed; white-space: nowrap; text-align: center;
  font-family: var(--font-ar); font-size: 0.58rem; font-weight: 700; line-height: 1.1; color: var(--gold);
  background: var(--page-bg); padding: 7px 2px; border-radius: 6px; max-height: 42%; overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--gold) 42%, transparent); box-shadow: 0 1px 4px rgba(0,0,0,0.22); }
/* straddle the page's outer edge (half in the slim gutter) so the juz/ḥizb/sajda
   tabs stay visible on the full-screen page — the old +20px cleared a frame that's gone */
.page-marks.side-right .pmark { right: 0; transform: translate(50%, -50%); }
.page-marks.side-left  .pmark { left: 0;  transform: translate(-50%, -50%); }
.pmark .pm-sajda { color: var(--emerald); }

/* immersive page-turn — right-bound book (page peels toward the right to advance) */
@keyframes turnNext {
  0%   { transform: translateX(0) rotateY(0deg) scale(1); opacity: 1; box-shadow: 0 0 0 rgba(0,0,0,0); }
  55%  { opacity: 1; }
  100% { transform: translateX(56%) rotateY(-46deg) scale(0.96); opacity: 0; box-shadow: -50px 0 70px rgba(0,0,0,0.55); }
}
@keyframes turnPrev {
  0%   { transform: translateX(56%) rotateY(-46deg) scale(0.96); opacity: 0; box-shadow: -50px 0 70px rgba(0,0,0,0.55); }
  45%  { opacity: 1; }
  100% { transform: translateX(0) rotateY(0deg) scale(1); opacity: 1; box-shadow: 0 0 0 rgba(0,0,0,0); }
}
.page-stack.turn-next { transform-origin: right center; animation: turnNext 0.32s cubic-bezier(0.4, 0.0, 0.2, 1) both; }
.page-stack.turn-prev { transform-origin: right center; animation: turnPrev 0.3s cubic-bezier(0.3, 0.0, 0.2, 1) both; }

/* page bar */
/* max-width leaves the bottom-right corner free for the minimised annotation handle */
.pagebar { position: fixed; bottom: calc(10px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 45; display: flex; align-items: center; gap: 12px; padding: 6px 16px; border-radius: 999px; width: min(96vw, 680px); max-width: calc(100vw - 92px); transition: transform 0.3s var(--ease), opacity 0.3s var(--ease); }
.pg-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: transparent; border: none; color: var(--ink-soft); }
.pg-btn:hover { background: var(--glass-hi); color: var(--ink); }
.pg-label { font-family: var(--font-ar); font-size: 0.86rem; color: var(--ink-soft); min-width: 66px; text-align: center; }
#pgSlider { flex: 1; min-width: 0; direction: rtl; accent-color: var(--gold); height: 4px; }

@media (max-width: 380px) { .pg-label { min-width: 54px; font-size: 0.78rem; } }

/* ============================================================ Accounts ============================================================ */
#btnAccount.signed { color: var(--bg-1); }
.acc-initial { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-family: var(--font-ar); font-weight: 700; font-size: 0.95rem; color: var(--bg-1); background: linear-gradient(145deg, var(--gold), var(--gold-soft)); }
.acc-initial.big { width: 44px; height: 44px; font-size: 1.3rem; }

.auth-modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 18px; background: var(--scrim); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); animation: fade 0.3s var(--ease); }
.auth-card { position: relative; width: min(420px, 96vw); max-height: 92vh; overflow-y: auto; padding: 26px 24px; border-radius: var(--radius-lg); direction: rtl; text-align: center; }
.auth-x { position: absolute; top: 12px; left: 12px; }
.auth-brand { font-family: var(--font-ar); font-weight: 700; font-size: 1.7rem; color: var(--gold); }
.auth-sub { color: var(--ink-soft); font-size: 0.86rem; margin: 6px 0 16px; line-height: 1.5; }
.auth-field { margin: 9px 0; }
.auth-field input, #roleName { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass-hi); color: var(--ink); font-family: var(--font-sans); font-size: 0.95rem; outline: none; text-align: right; }
.auth-field input:focus { border-color: var(--glass-brd); }
.role-row { display: flex; align-items: center; gap: 8px; justify-content: center; margin: 10px 0; font-size: 0.88rem; color: var(--ink-soft); }
.role-chip { padding: 7px 18px; border-radius: 999px; background: var(--glass-hi); border: 1px solid var(--line); color: var(--ink-soft); }
.role-chip.active { background: var(--gold); color: var(--bg-1); border-color: transparent; font-weight: 600; }
.auth-error { color: #e5484d; font-size: 0.82rem; min-height: 1.1em; margin: 4px 0; }
.auth-submit { width: 100%; padding: 13px; border-radius: 12px; border: none; background: linear-gradient(145deg, var(--gold), var(--gold-soft)); color: var(--bg-1); font-weight: 700; font-size: 1rem; margin-top: 4px; }
.auth-or { color: var(--ink-faint); font-size: 0.8rem; margin: 14px 0 10px; position: relative; }
.auth-apple, .auth-google, .auth-passkey, .auth-guest { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass-hi); color: var(--ink); font-size: 0.92rem; display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; }
.auth-apple:hover, .auth-google:hover, .auth-passkey:hover, .auth-guest:hover { border-color: var(--glass-brd); }
.auth-guest { background: transparent; color: var(--ink-faint); border-color: transparent; }
.role-pick { display: flex; gap: 12px; margin-top: 14px; }
.role-big { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 22px 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--glass-hi); color: var(--ink); font-family: var(--font-ar); font-weight: 700; font-size: 1.1rem; }
.role-big span { font-size: 1.8rem; }
.role-big:hover { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, transparent); }

.acc-menu { position: fixed; z-index: 88; min-width: 220px; padding: 8px; border-radius: 16px; direction: rtl; animation: pop 0.2s var(--ease); }
.acc-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; text-align: right; }
.acc-name { font-weight: 700; color: var(--ink); }
.acc-role { font-size: 0.8rem; color: var(--gold-soft); }
.acc-menu button { display: block; width: 100%; text-align: right; padding: 10px 12px; border-radius: 10px; background: none; border: none; color: var(--ink); font-size: 0.9rem; }
.acc-menu button:hover { background: var(--glass-hi); }
.main-menu { max-height: 82vh; overflow-y: auto; min-width: 248px; }
.main-menu .mm-item { display: flex; align-items: center; gap: 12px; text-align: start; padding: 9px 12px; width: 100%; background: none; border: none; border-radius: 10px; color: var(--ink); font-family: inherit; font-size: 0.9rem; cursor: pointer; }
.main-menu .mm-item:hover { background: var(--glass-hi); }
.main-menu .mm-ic { flex: none; width: 22px; height: 22px; color: var(--gold-soft); }
.main-menu .mm-item:hover .mm-ic { color: var(--gold); }
.main-menu .mm-tx { display: flex; flex-direction: column; gap: 1px; min-width: 0; line-height: 1.25; }
.main-menu .mm-tx b { font-weight: 600; }
.main-menu .mm-tx small { font-size: 0.72rem; color: var(--ink-faint); font-weight: 400; }
.main-menu .mm-hero { margin: 2px 0 6px; padding: 12px; border-radius: 12px; background: linear-gradient(180deg, rgba(200,160,70,0.18), rgba(200,160,70,0.05)); border: 1px solid color-mix(in srgb, var(--gold) 38%, transparent); }
.main-menu .mm-hero .mm-ic { color: var(--gold); width: 25px; height: 25px; }
.main-menu .mm-hero .mm-tx b { color: var(--gold); font-size: 1.02rem; font-weight: 700; }
.main-menu .mm-hero .mm-tx small { color: var(--gold-soft); }
/* main menu as a full-height side-sheet (slides from the ☰ side) */
.mm-scrim { position: fixed; inset: 0; z-index: 229; background: rgba(0,0,0,0.5); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); animation: mmFade 0.2s var(--ease); }
.menu-sheet { position: fixed; top: 0; bottom: 0; right: 0; left: auto; width: min(360px, 90vw); min-width: 0; max-height: none; z-index: 230; display: flex; flex-direction: column; overflow: hidden; padding: 0; border: none; border-left: 1px solid var(--line); border-radius: 0; direction: rtl; animation: mmSlide 0.28s var(--ease); }
.menu-sheet .mm-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: calc(12px + env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid var(--line); }
.menu-sheet .mm-head-title { font-weight: 700; color: var(--gold); font-size: 1.05rem; }
.menu-sheet .mm-close { flex: none; background: none; border: none; color: var(--ink-soft); width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; cursor: pointer; }
.menu-sheet .mm-close:hover { background: var(--glass-hi); }
.menu-sheet .mm-close svg { width: 20px; height: 20px; }
.menu-sheet .mm-body { flex: 1; overflow-y: auto; padding: 12px 12px calc(18px + env(safe-area-inset-bottom)); }
[data-applang="en"] .menu-sheet, [data-applang="fr"] .menu-sheet { direction: ltr; }
@keyframes mmSlide { from { transform: translateX(100%); } }
@keyframes mmFade { from { opacity: 0; } }
/* English / French: left-align the app chrome (the Qur'an, adhkār & dhikr stay Arabic/RTL) */
[data-applang="en"] .acc-menu button, [data-applang="fr"] .acc-menu button,
[data-applang="en"] .main-menu .mm-group, [data-applang="fr"] .main-menu .mm-group,
[data-applang="en"] .set-label, [data-applang="fr"] .set-label,
[data-applang="en"] .set-row, [data-applang="fr"] .set-row,
[data-applang="en"] .set-hint, [data-applang="fr"] .set-hint,
[data-applang="en"] .set-about, [data-applang="fr"] .set-about,
[data-applang="en"] .dr-item, [data-applang="fr"] .dr-item,
[data-applang="en"] .dr-phase, [data-applang="fr"] .dr-phase,
[data-applang="en"] .dr-label, [data-applang="fr"] .dr-label,
[data-applang="en"] .adh-title, [data-applang="fr"] .adh-title,
[data-applang="en"] .acc-name, [data-applang="fr"] .acc-name,
[data-applang="en"] .acc-role, [data-applang="fr"] .acc-role { direction: ltr; text-align: left; }
/* keep the Arabic dhikr phrase under a routine item reading right-to-left */
[data-applang="en"] .dr-label small, [data-applang="fr"] .dr-label small { direction: rtl; text-align: right; }
.main-menu .mm-group { font-size: 0.7rem; color: var(--gold-soft); font-weight: 700; padding: 9px 12px 3px; letter-spacing: 0.02em; }
.main-menu .mm-div { height: 1px; background: var(--line); margin: 6px 8px; }
.lb-me { text-align: center; color: var(--ink-faint); font-size: 0.9rem; padding: 4px 4px 12px; }
.lb-me b { color: var(--gold); }
.lb-list { display: flex; flex-direction: column; gap: 4px; max-height: 62vh; overflow-y: auto; }
.lb-row { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass-hi); }
.lb-row.me { border-color: var(--gold); }
.lb-rank { min-width: 30px; text-align: center; font-weight: 700; color: var(--ink); }
.lb-name { flex: 1; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-pts { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
.rp-list { display: flex; flex-direction: column; gap: 4px; max-height: 64vh; overflow-y: auto; }
.rp-row { text-align: right; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass-hi); color: var(--ink); font-family: inherit; font-size: 0.95rem; }
.rp-row.on { border-color: var(--gold); color: var(--gold); font-weight: 700; }

/* ---- teacher pool (recitation review) ---- */
.g.tmark { background: color-mix(in srgb, #e5484d 42%, transparent); box-shadow: 0 2px 0 #e5484d; border-radius: 4px; }
/* teacher's live highlight during a review (student sees it in real time) */
.g.thl { background: color-mix(in srgb, var(--thl, var(--gold)) 34%, transparent); border-radius: 5px; }
/* teacher's live note → ring on the ayah-end number */
.g.end.has-tnote { outline: 2px solid color-mix(in srgb, var(--gold) 70%, transparent); outline-offset: 1px; border-radius: 50%; }
.icon-btn.has-badge, .icon-btn.pending { position: relative; }
.icon-btn.has-badge::after, .icon-btn.pending::after { content: ""; position: absolute; top: 6px; inset-inline-end: 6px; width: 8px; height: 8px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 2px var(--bg-1); }
.review-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 60; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 999px; direction: rtl; animation: pop 0.3s var(--ease); }
.rb-title { font-family: var(--font-ar); font-size: 0.9rem; color: var(--ink); }
.review-bar button { border: none; border-radius: 999px; padding: 8px 14px; font-size: 0.85rem; font-weight: 700; }
.rb-pass { background: color-mix(in srgb, var(--emerald) 24%, transparent); color: var(--emerald); }
.rb-repeat { background: color-mix(in srgb, #e8a838 26%, transparent); color: #e8a838; }
.rb-exit { background: transparent; color: var(--ink-faint); display: grid; place-items: center; padding: 8px; }
.student-banner { position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--topbar-h) + 8px); z-index: 60; display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 999px; direction: rtl; font-size: 0.85rem; color: var(--ink); max-width: 92vw; animation: pop 0.3s var(--ease); }
.sb-cancel { flex: none; background: transparent; border: 1px solid color-mix(in srgb, var(--rose, #e5484d) 45%, transparent); color: var(--rose, #e5484d); border-radius: 999px; padding: 2px 12px; font: inherit; font-size: 0.78rem; cursor: pointer; }
.student-banner .pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--emerald); animation: pulseDot 1.4s ease-in-out infinite; flex: none; }
@keyframes pulseDot { 0%,100% { opacity: 1; box-shadow: 0 0 0 0 color-mix(in srgb, var(--emerald) 50%, transparent); } 50% { opacity: 0.5; box-shadow: 0 0 0 6px transparent; } }
/* persistent teacher review-marks the student clears as they fix each word (tap to remove) */
.g.rmark { background: color-mix(in srgb, #e5484d 30%, transparent); box-shadow: inset 0 -2px 0 #e5484d; border-radius: 4px; cursor: pointer; }
/* the active-session controls, now inside the bell dropdown instead of a blocking bottom bar */
.ib-note { display: flex; align-items: center; gap: 8px; padding: 8px 12px 4px; font-size: 0.82rem; color: var(--ink-soft); }
.ib-note .pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--emerald); animation: pulseDot 1.4s ease-in-out infinite; flex: none; }
.ib-act { display: block; width: 100%; text-align: center; padding: 10px 12px; margin: 4px 0; border: none; border-radius: 10px; font-family: inherit; font-weight: 700; font-size: 0.88rem; cursor: pointer; }
.ib-act.pass { background: color-mix(in srgb, var(--emerald) 22%, transparent); color: var(--emerald); }
.ib-act.repeat { background: color-mix(in srgb, #e8a838 24%, transparent); color: #e8a838; }
.ib-act.exit { background: transparent; color: var(--ink-faint); }
.ib-div { height: 1px; background: var(--line); margin: 8px 4px; }
.ib-since { color: var(--gold-soft); }
.ib-tag { font-size: 0.66rem; font-weight: 700; color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent); border-radius: 999px; padding: 1px 7px; }
/* a pending request row: student info + (for sulam) a one-tap "اعتمد ✓" fast-approve */
.ib-req { display: flex; align-items: stretch; gap: 6px; }
.ib-req-main { flex: 1; text-align: right; background: transparent; border: none; color: inherit; font: inherit; cursor: pointer; padding: 8px 10px; }
.ib-quick { width: auto; align-self: center; margin: 0; white-space: nowrap; }
/* Sulam checkpoint waiting-for-teacher-approval state */
.sv-pending { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 16px; color: var(--ink-soft); font-size: 0.92rem; text-align: center; }
.sv-pending .pulse { width: 9px; height: 9px; border-radius: 50%; background: #e8a838; animation: pulseDot 1.4s ease-in-out infinite; flex: none; }

/* ---- progress / follow-up sheet ---- */
.progress-body { flex: 1; overflow-y: auto; padding: 6px 14px 24px; direction: rtl; }
.prog-summary { font-family: var(--font-ar); color: var(--gold); font-size: 0.95rem; padding: 10px 12px; margin-bottom: 8px; border-bottom: 1px solid var(--line); text-align: center; }
.prog-item { padding: 11px 12px; border-radius: 12px; border: 1px solid transparent; cursor: pointer; margin-bottom: 2px; }
.prog-item:hover { background: var(--glass-hi); border-color: var(--line); }
.prog-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.prog-ref { font-weight: 600; color: var(--ink); font-size: 0.9rem; }
.prog-pass { color: var(--emerald); font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.prog-repeat { color: #e8a838; font-size: 0.8rem; font-weight: 700; white-space: nowrap; }
.prog-sub { color: var(--ink-faint); font-size: 0.8rem; margin-top: 3px; }

/* narrow phones: keep all top-bar actions reachable */
@media (max-width: 480px) {
  .wordmark { display: none; }
  .surah-pill { max-width: 64vw; padding: 4px 12px 4px 5px; gap: 8px; }
  .topbar { gap: 1px; padding: 0 6px; }
  .topbar-actions { gap: 0; }
  .icon-btn { width: 38px; }
}

/* ---------- Tafsīr sheet ---------- */
.tafsir-sheet { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; }
.tafsir-sheet[hidden] { display: none; }
.ts-scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.ts-panel { position: relative; z-index: 1; width: min(560px, 92vw); max-height: 82vh; display: flex; flex-direction: column;
  direction: rtl; border-radius: var(--radius-lg); padding: 16px 20px 18px; overflow: hidden; }
.ts-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.ts-title { font-family: var(--font-ar); font-weight: 700; color: var(--gold); font-size: 1.02rem; }
.ts-close { flex: none; width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--line); background: transparent; color: var(--ink-soft); font-size: 0.95rem; cursor: pointer; }
.ts-close:hover { color: var(--ink); background: var(--glass-hi); }
.ts-ayah { font-family: var(--font-quran); font-size: 1.4rem; line-height: 2.1; color: var(--gold); text-align: center; padding: 16px 4px 14px; border-bottom: 1px solid var(--line); }
.ts-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 2px 6px; font-family: var(--font-ar); font-size: 1.02rem; line-height: 2.05; color: var(--ink); text-align: justify; }
.ts-src { flex: none; padding-top: 10px; margin-top: 8px; border-top: 1px solid var(--line); font-size: 0.72rem; color: var(--ink-faint); text-align: center; }

/* ---------- Sulam (السُّلَّم) — 55-step memorisation ladder ---------- */
.sulam-view { position: fixed; inset: 0; z-index: 210; display: flex; flex-direction: column; align-items: stretch;
  background: var(--bg-1); direction: rtl; overflow: hidden; }
.sv-main { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-bottom: 16px; }
.sv-tabs { flex: none; display: flex; border-top: 1px solid var(--line); background: var(--bg-1); padding-bottom: env(safe-area-inset-bottom); }
.sv-tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 7px; background: none; border: none; color: var(--ink-faint); font-family: inherit; font-size: 0.72rem; cursor: pointer; }
.sv-tab svg { width: 22px; height: 22px; }
.sv-tab.active { color: var(--gold); }
.sv-old { width: 100%; max-width: 480px; margin: 0 auto; padding: 14px 16px; }
.sv-old .hl-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 72vh; }
.sv-old .hl-row { width: 100%; }
.hl-row-wrap { display: flex; align-items: stretch; gap: 6px; }
.hl-row-wrap .hl-row { flex: 1 1 auto; width: auto; }
.hl-del { flex: none; width: 44px; border-radius: 12px; border: 1px solid color-mix(in srgb, #e5484d 40%, var(--line)); background: color-mix(in srgb, #e5484d 12%, transparent); color: #e5484d; font-size: 1.05rem; cursor: pointer; display: grid; place-items: center; }
.hl-del:active { transform: scale(0.94); }
.sv-head { position: sticky; top: 0; z-index: 1; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--bg-1); border-bottom: 1px solid var(--line); }
.sv-h-title { flex: 1; font-family: var(--font-ar); font-weight: 700; font-size: 1.15rem; color: var(--gold); }
.sv-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; border: 1px solid var(--line); background: transparent; color: var(--ink-soft); cursor: pointer; }
.sv-icon:hover { color: var(--ink); background: var(--glass-hi); }
.sv-icon svg { width: 22px; height: 22px; }
.sv-portion { text-align: center; padding: 18px 16px 12px; }
.sv-surah { font-family: var(--font-quran); font-size: 1.7rem; color: var(--ink); }
.sv-range { font-size: 0.9rem; color: var(--ink-soft); margin-top: 4px; }
.sv-timer { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding: 2px 16px 4px; direction: rtl; }
.sv-timer .t-pill { display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--gold) 32%, transparent); background: radial-gradient(circle, color-mix(in srgb, var(--gold) 8%, transparent), transparent 80%); }
.sv-timer .t-label { font-size: 0.72rem; color: var(--ink-soft); }
.sv-timer .t-val { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.02rem; color: var(--gold); min-width: 3.4em; text-align: center; letter-spacing: 0.02em; }
.sv-prog { width: min(92vw, 440px); margin: 10px auto 2px; }
.sv-prog-track { height: 9px; border-radius: 999px; background: var(--glass-hi); border: 1px solid var(--line); overflow: hidden; }
.sv-prog-track span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold-soft), var(--gold)); box-shadow: 0 0 10px color-mix(in srgb, var(--gold) 40%, transparent); transition: width 0.45s var(--ease); }
.sv-prog-num { text-align: center; margin-top: 6px; font-size: 0.82rem; color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
.sv-ladder { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; padding: 12px; margin: 10px auto 16px; width: fit-content; max-width: 96vw; direction: ltr; background: var(--glass-hi); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.sv-row { display: flex; gap: 5px; justify-content: flex-start; }
.sv-cell { position: relative; width: min(8.4vw, 42px); aspect-ratio: 1; border-radius: 8px; border: 1.5px solid transparent;
  font-weight: 700; font-size: clamp(0.72rem, 2.6vw, 0.95rem); color: #1c2b1c; cursor: pointer; overflow: hidden;
  font-variant-numeric: tabular-nums; transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease); }
.sv-cell.blank   { background: #f3edcf; }
.sv-cell.green   { background: #8fce8c; }
.sv-cell.crossed { background: #8fce8c; }
.sv-cell.crossed::after { content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, transparent 0 5px, rgba(30,55,30,0.5) 5px 7px); }
.sv-cell.current { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 45%, transparent); transform: scale(1.06); z-index: 1; }
.sv-cell > * , .sv-cell { z-index: 0; }
.sv-controls { display: flex; gap: 28px; justify-content: center; align-items: flex-start; padding: 8px 16px 6px; }
.sv-ctl { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sv-ctl span { font-size: 0.8rem; color: var(--ink-soft); }
.sv-fab { width: 66px; height: 66px; border-radius: 50%; border: none; display: grid; place-items: center; color: #fff; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.28); transition: transform 0.12s var(--ease); }
.sv-fab:active { transform: scale(0.93); }
.sv-fab svg { width: 28px; height: 28px; }
.sv-fab.red { background: #e5484d; }
.sv-fab.green { background: #2fa84f; }
.sv-fab.amber { background: #f0932b; }

/* --- hifz phase UI: ladder types, decay taper, review colours, library --- */
.sv-head-r { display: flex; gap: 8px; }
.sv-body { width: 100%; display: flex; flex-direction: column; align-items: center; }
.sv-next { text-align: center; font-size: 0.9rem; color: var(--ink); padding: 10px 16px 2px; }
.sv-next b { color: var(--gold); }
.sv-cell.certified { background: var(--gold); }
.sv-cell[disabled] { cursor: default; }
.sv-cell.done { filter: grayscale(0.6); opacity: 0.82; }
.sv-cell.done::before { content: ""; position: absolute; inset: 0; z-index: 3; background: linear-gradient(to top right, transparent calc(50% - 1.4px), #e5484d calc(50% - 1.4px), #e5484d calc(50% + 1.4px), transparent calc(50% + 1.4px)); }
.sv-recite { margin: 8px auto 12px; min-width: 60%; padding: 15px 28px; border-radius: 16px; border: none; cursor: pointer;
  font-family: inherit; font-size: 1.05rem; font-weight: 700; color: var(--bg-1); background: var(--gold);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3); transition: transform 0.12s var(--ease); }
.sv-recite:active { transform: scale(0.97); }
.sv-vals { display: flex; flex-direction: column; gap: 10px; width: min(92vw, 420px); margin: 6px auto 14px; }
.sv-val { padding: 13px 18px; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  background: transparent; color: var(--ink); font-family: inherit; font-size: 0.95rem; cursor: pointer; }
.sv-val:hover { background: var(--glass-hi); }
.sv-val.done { color: #2fa84f; border-color: color-mix(in srgb, #2fa84f 55%, transparent); opacity: 0.85; cursor: default; }
/* decay taper */
.sv-decay { text-align: center; padding: 14px 16px 4px; }
.dc-target { font-size: 1.02rem; color: var(--ink); }
.dc-target b, .dc-prog b { color: var(--gold); font-size: 1.25rem; }
.dc-prog { margin-top: 6px; color: var(--ink-soft); }
.dc-dots { display: flex; gap: 10px; justify-content: center; margin-top: 18px; direction: ltr; }
.dc-dot { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; font-weight: 700;
  font-variant-numeric: tabular-nums; border: 1.5px solid var(--line); color: var(--ink-soft); }
.dc-dot.past { background: #2fa84f; color: #fff; border-color: transparent; }
.dc-dot.cur { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 40%, transparent); }
/* القديم / تثبيت staircase (5→1 countdown) */
.dc-stair { display: flex; flex-direction: row; justify-content: center; align-items: flex-end; gap: 8px; margin: 16px auto 8px; direction: rtl; flex-wrap: nowrap; overflow-x: auto; padding: 4px; }
.dc-scol { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; border-radius: 12px; padding: 4px; }
.dc-scol.cur { box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 55%, transparent); background: color-mix(in srgb, var(--gold) 8%, transparent); }
.dc-scol.todo { opacity: .45; }
.dc-scell { width: min(9vw, 44px); height: min(8vw, 40px); display: grid; place-items: center; border-radius: 8px;
  background: rgba(255,255,255,.05); border: 1px solid var(--line); font-variant-numeric: tabular-nums; font-size: .95rem; color: var(--ink); }
.dc-scell.top { border-color: transparent; }
.dc-scol-lab { font-size: .82rem; font-weight: 700; color: var(--ink-faint); margin-top: 2px; }
.dc-scol.cur .dc-scol-lab { color: var(--gold); }
.dc-steps { display: flex; justify-content: center; gap: 34px; margin: 8px 0 4px; }
.dc-step { display: flex; flex-direction: column; align-items: center; gap: 6px; border: none; background: none; cursor: pointer; }
.dc-step .circ { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; font-size: 1.7rem; color: #fff; }
.dc-step.back .circ { background: #e5484d; }
.dc-step.fwd .circ { background: #2fa84f; }
.dc-step small { font-size: .76rem; color: var(--ink-faint); }
.dc-step:active .circ { transform: scale(.94); }
/* review status */
.sv-review { text-align: center; padding: 20px 16px 8px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.sv-review.rv-green { color: #2fa84f; } .sv-review.rv-yellow { color: #f0932b; } .sv-review.rv-red { color: #e5484d; }
.rv-dot { width: 54px; height: 54px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 6px color-mix(in srgb, currentColor 22%, transparent); }
.rv-status { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.rv-since { color: var(--ink-soft); font-size: 0.9rem; } .rv-since b { color: var(--gold); }
/* library overlay */
.hifz-lib { position: fixed; inset: 0; z-index: 220; display: grid; place-items: center; padding: 18px; background: var(--scrim);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade 0.25s var(--ease); }
.hl-card { width: min(94vw, 460px); max-height: 82vh; display: flex; flex-direction: column; border-radius: 18px; overflow: hidden; }
.hl-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; font-family: var(--font-ar);
  font-size: 1.1rem; color: var(--gold); border-bottom: 1px solid var(--line); }
.hl-x { background: transparent; border: none; color: var(--ink-soft); font-size: 1.05rem; cursor: pointer; }
.hl-list { overflow-y: auto; padding: 8px; direction: rtl; }
.hl-row { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--ink); font-family: inherit; cursor: pointer; }
.hl-row:hover { background: var(--glass-hi); }
.hl-name { font-family: var(--font-quran); font-size: 1.15rem; }
.hl-badge { font-size: 0.74rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.hl-badge.ladder { color: var(--gold); border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent); }
.hl-badge.decay { color: #f0932b; border: 1px solid color-mix(in srgb, #f0932b 45%, transparent); }
.hl-badge.rv-green { color: #2fa84f; border: 1px solid color-mix(in srgb, #2fa84f 45%, transparent); }
.hl-badge.rv-yellow { color: #f0932b; border: 1px solid color-mix(in srgb, #f0932b 45%, transparent); }
.hl-badge.rv-red { color: #e5484d; border: 1px solid color-mix(in srgb, #e5484d 45%, transparent); }
.hl-empty { padding: 30px 16px; text-align: center; color: var(--ink-faint); font-size: 0.9rem; }

/* ---------- Progress drawer additions + Admin/teacher portal ---------- */
.prog-chart { margin-bottom: 14px; }
.prog-portal { width: 100%; margin: 4px 0 14px; padding: 11px; border-radius: 12px; border: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  background: color-mix(in srgb, var(--gold) 12%, transparent); color: var(--gold); font-family: var(--font-ar); font-weight: 700; font-size: 0.95rem; cursor: pointer; }
.prog-portal:hover { background: color-mix(in srgb, var(--gold) 20%, transparent); }

.admin-portal { position: fixed; inset: 0; z-index: 95; display: grid; place-items: center; direction: rtl; background: rgba(0,0,0,0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.ap-panel { width: min(720px, 94vw); max-height: 88vh; display: flex; flex-direction: column; background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.ap-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.ap-title { font-family: var(--font-ar); font-weight: 700; color: var(--gold); font-size: 1.15rem; margin: 0; }
.ap-close { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: transparent; color: var(--ink-soft); font-size: 1rem; cursor: pointer; }
.ap-close:hover { color: var(--ink); background: var(--glass-hi); }
.ap-toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.ap-search { flex: 1; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--glass-hi); color: var(--ink); font-family: var(--font-ar); font-size: 0.92rem; }
.ap-search:focus { outline: none; border-color: var(--gold); }
.ap-count { font-size: 0.8rem; color: var(--ink-faint); white-space: nowrap; }
.ap-status { padding: 40px 20px; text-align: center; color: var(--ink-faint); font-size: 0.95rem; }
.ap-status[data-kind="error"], .ap-status[data-kind="denied"] { color: #e5768a; }
/* tabs */
.ap-tabs { display: flex; gap: 6px; padding: 10px 16px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ap-tab { padding: 9px 16px; border: none; background: transparent; color: var(--ink-soft); font-family: var(--font-ar); font-size: 0.92rem; cursor: pointer; border-radius: 10px 10px 0 0; border-bottom: 2px solid transparent; }
.ap-tab:hover { color: var(--ink); }
.ap-tab.active { color: var(--gold); border-bottom-color: var(--gold); }
/* content area (scrolls) */
.ap-content, .ap-list { flex: 1 1 auto; overflow-y: auto; padding: 12px 14px 16px; }
/* overview cards */
.ap-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.ap-card { padding: 18px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass-hi); text-align: center; }
.ap-card.warn { border-color: color-mix(in srgb, #f0932b 55%, transparent); }
.ap-card-num { font-size: 1.9rem; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.ap-card-label { font-size: 0.8rem; color: var(--ink-soft); margin-top: 4px; }
.ap-hint { margin-top: 16px; text-align: center; font-size: 0.82rem; color: var(--ink-faint); }
.ap-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 12px; border-bottom: 1px solid var(--line); }
.ap-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ap-avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: var(--bg-1);
  background: linear-gradient(145deg, var(--gold), var(--gold-soft)); }
.ap-meta { display: flex; flex-direction: column; min-width: 0; }
.ap-name { font-weight: 600; color: var(--ink); font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-email { font-size: 0.76rem; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-role { flex: none; font-size: 0.72rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-soft); }
.ap-role[data-role="teacher"] { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); }
.ap-progress { display: flex; gap: 14px; }
.ap-stat { display: flex; flex-direction: column; align-items: center; min-width: 46px; }
.ap-stat-value { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.ap-stat-label { font-size: 0.66rem; color: var(--ink-faint); }
.ap-noprog { color: var(--ink-faint); }
.ap-requests { padding: 12px 20px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--gold) 6%, transparent); }
.ap-req-title { font-family: var(--font-ar); font-weight: 700; color: var(--gold); font-size: 0.9rem; margin-bottom: 8px; }
.ap-req { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.ap-req-actions { display: flex; gap: 8px; }
.ap-btn { padding: 6px 14px; border-radius: 9px; border: 1px solid var(--line); background: transparent; font-family: var(--font-ar); font-weight: 600; font-size: 0.82rem; cursor: pointer; white-space: nowrap; }
.ap-btn:disabled { opacity: 0.5; cursor: default; }
.ap-btn.view { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 40%, transparent); }
/* student-file detail panel (teacher/admin taps a student) */
.ap-detail { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; background: rgba(0,0,0,0.5); padding: 16px; }
.ap-detail-card { width: min(560px, 96%); max-height: 88%; overflow-y: auto; background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow); }
.ap-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.ap-detail-name { font-family: var(--font-ar); font-weight: 700; font-size: 1.2rem; color: var(--gold); }
.ap-detail-label { font-family: var(--font-ar); font-size: 0.8rem; color: var(--gold-soft); margin: 16px 0 8px; }
.ap-detail-list { display: flex; flex-direction: column; gap: 8px; }
.ap-ses { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.ap-ses-top { font-family: var(--font-ar); font-size: 0.92rem; color: var(--ink); }
.ap-ses-note { font-size: 0.82rem; color: var(--ink-soft); margin-top: 4px; }
.ap-btn.approve { color: #2fa84f; border-color: color-mix(in srgb, #2fa84f 50%, transparent); }
.ap-btn.approve:hover:not(:disabled) { background: color-mix(in srgb, #2fa84f 15%, transparent); }
.ap-btn.deny { color: #e5484d; border-color: color-mix(in srgb, #e5484d 50%, transparent); }
.ap-btn.deny:hover:not(:disabled) { background: color-mix(in srgb, #e5484d 15%, transparent); }
/* ---- communities + teams tab ---- */
.ap-teams { display: flex; flex-direction: column; gap: 14px; }
.ap-team-form { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: color-mix(in srgb, var(--gold) 5%, transparent); }
.ap-team-form.sub { background: transparent; border-style: dashed; margin-top: 10px; }
.ap-form-title { font-family: var(--font-ar); font-weight: 700; color: var(--gold); font-size: 0.9rem; margin-bottom: 8px; }
.ap-form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ap-input { flex: 1 1 140px; min-width: 0; padding: 7px 11px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-0); color: var(--ink); font-family: var(--font-ar); font-size: 0.86rem; }
.ap-input.slim { flex: 0 1 auto; padding: 5px 9px; font-size: 0.8rem; }
select.ap-input { cursor: pointer; }
.ap-comm { border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.ap-comm-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.ap-team-list { display: flex; flex-direction: column; gap: 8px; }
.ap-team { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-1); }
.ap-team-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.ap-code { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.14em; font-weight: 700; font-size: 0.9rem; color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, transparent); border: 1px dashed color-mix(in srgb, var(--gold) 45%, transparent); border-radius: 8px; padding: 5px 10px; cursor: pointer; white-space: nowrap; }
.ap-code:hover { background: color-mix(in srgb, var(--gold) 20%, transparent); }
.ap-pool-badge { font-family: var(--font-ar); font-weight: 700; font-size: 0.68rem; padding: 2px 8px; border-radius: 999px; vertical-align: middle; }
.ap-pool-badge.f { color: #d6529b; background: color-mix(in srgb, #d6529b 15%, transparent); }
.ap-pool-badge.m { color: #3d7fd6; background: color-mix(in srgb, #3d7fd6 15%, transparent); }
.ap-noprog.small { font-size: 0.8rem; padding: 4px 2px; }
.ap-btn.slim { padding: 4px 9px; font-size: 0.78rem; }
@media (max-width: 560px) { .ap-progress { width: 100%; justify-content: space-between; } .ap-team { flex-direction: column; align-items: stretch; } .ap-team-actions { justify-content: space-between; } }
.acc-note { padding: 9px 12px; font-size: 0.82rem; color: var(--ink-soft); }
