/* قارئ المصحف: ورقةٌ في الوسط، وزجاجٌ حولها. */

body.reader { overflow: hidden; height: 100dvh; }
.reader .nav { display: none; }

.rbar {
  position: fixed;
  inset-inline: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  pointer-events: none;
  transition: transform 0.5s var(--ease), opacity 0.4s;
}
.rbar > * { pointer-events: auto; }
.rbar--top { top: 12px; }
.rbar--bottom { bottom: 14px; }
.reader.is-calm .rbar--top { transform: translateY(-120%); opacity: 0; }
.reader.is-calm .rbar--bottom { transform: translateY(130%); opacity: 0; }

.rtop {
  width: min(1180px, 100% - 24px);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 22px;
}
.rtop__home { display: flex; align-items: center; gap: 10px; padding-inline: 8px 12px; font-family: var(--f-display); font-size: 25px; font-weight: 600; }
.rtop__home img { width: 36px; height: 36px; }
.rtop__title { text-align: center; line-height: 1.25; min-width: 0; }
.rtop__title strong { display: block; font-family: var(--f-display); font-weight: 600; font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtop__title span { display: block; font-size: 16.5px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rtop__actions { display: flex; gap: 6px; }

.rbottom {
  width: min(620px, 100% - 24px);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px;
  border-radius: 999px;
}
.rbottom input[type="range"] { flex: 1; min-width: 0; accent-color: var(--range); direction: rtl; }
.rbottom__num {
  min-width: 64px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 17px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--hl-hover);
}

/* ——— المسرح والورق ——— */
.stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 78px 12px 84px;
  touch-action: pan-y;
}
.spread { display: flex; gap: 0; align-items: stretch; justify-content: center; max-width: 100%; }
.paper {
  --ph: calc(100dvh - 176px);
  position: relative;
  height: var(--ph);
  aspect-ratio: 0.655;
  max-width: calc(100vw - 24px);
  max-height: calc((100vw - 24px) / 0.655);
  background: var(--paper);
  border-radius: 18px;
  box-shadow: var(--shadow-lift);
  padding: 4.2% 3.6% 5.6%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}
/* إطار المطبوع: خطٌّ ذهبيّ رقيق داخل الحافة. */
.paper::after {
  content: '';
  position: absolute;
  inset: 10px;
  border: 1px solid color-mix(in srgb, var(--sand) 55%, transparent);
  border-radius: 12px;
  pointer-events: none;
}
.spread--two .paper:first-child { border-start-end-radius: 4px; border-end-end-radius: 4px; }
.spread--two .paper:last-child { border-start-start-radius: 4px; border-end-start-radius: 4px; }
.spread--two .paper + .paper { box-shadow: var(--shadow-lift), inset -18px 0 26px -22px rgba(21, 42, 68, 0.35); }
.spread--two .paper:first-child { box-shadow: var(--shadow-lift), inset 18px 0 26px -22px rgba(21, 42, 68, 0.35); }
.paper__num {
  position: absolute;
  bottom: 16px;
  inset-inline: 0;
  text-align: center;
  font-size: 16px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.paper .skeleton-lines { display: grid; gap: 5.2%; padding: 6% 2%; height: 100%; align-content: center; }
.paper .skeleton-lines i { display: block; height: 1.1em; }

.qpage { width: 100%; height: 100%; overflow: visible; user-select: none; -webkit-user-select: none; }
.qpage__ink text { fill: var(--quran-ink); cursor: pointer; }
.qpage__ink .mk { cursor: pointer; }
.qpage__ink text.qpage__basmala { fill: var(--basmala); cursor: default; }
/* على الشريط: ذهبٌ رقّيّ فوق الكحلي، في الوضعين. */
.qpage__ink text.qpage__surah { fill: #F0DCAC; cursor: default; }
.qpage__hl rect.hover { fill: var(--hl-hover); }
.qpage__hl rect.sel { fill: var(--hl); }


/* ——— الفهرس ——— */
.drawer-scrim {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8, 17, 30, 0.28);
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s;
}
.drawer {
  position: fixed;
  z-index: 61;
  top: 12px;
  bottom: 12px;
  inset-inline-start: 12px;
  width: min(400px, 100vw - 24px);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  transform: translateX(calc(100% + 24px));
  transition: transform 0.5s var(--ease);
  background: var(--glass-strong);
  overflow: hidden;
}
.drawer-open .drawer { transform: none; }
.drawer-open .drawer-scrim { opacity: 1; pointer-events: auto; }
.drawer__head { padding: 18px 18px 10px; display: grid; gap: 12px; }
.drawer__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.drawer__row h2 { margin: 0; font-family: var(--f-display); font-weight: 600; font-size: 24px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 999px; background: var(--hl-hover); }
.tabs button { border: 0; background: transparent; padding: 8px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 17px; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--brand); color: var(--on-brand); }
.field { display: flex; align-items: center; gap: 8px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass); }
.field svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.field input { flex: 1; min-width: 0; border: 0; background: transparent; font: inherit; font-size: 16px; padding: 11px 0; color: var(--ink); outline: none; }
.goto { display: flex; gap: 8px; }
.goto .field { flex: 1; }
.goto button { border: 0; border-radius: 14px; padding: 0 16px; background: var(--brand); color: var(--on-brand); font-weight: 600; cursor: pointer; }
.drawer__list { list-style: none; margin: 0; padding: 4px 10px 18px; overflow-y: auto; flex: 1; overscroll-behavior: contain; }
.drawer__list button {
  width: 100%;
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 12px;
  text-align: start;
  padding: 10px 10px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  cursor: pointer;
  transition: background 0.2s;
}
.drawer__list button:hover { background: var(--hl-hover); }
.drawer__list button[aria-current="true"] { background: var(--hl); }
.num-badge {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  border: 1.5px solid color-mix(in srgb, var(--sand) 70%, transparent);
  border-radius: 12px 12px 12px 12px;
  transform: rotate(45deg);
}
.num-badge > span { transform: rotate(-45deg); }
.drawer__list b { display: block; font-weight: 600; font-size: 16.5px; line-height: 1.3; }
.drawer__list small { color: var(--muted); font-size: 16.5px; }
.drawer__list em { font-style: normal; font-size: 16.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ——— بطاقة الآية ——— */
.sheet {
  position: fixed;
  z-index: 70;
  inset-inline-end: 16px;
  bottom: 16px;
  width: min(460px, 100vw - 32px);
  max-height: min(72dvh, 680px);
  border-radius: var(--r-lg);
  display: flex;
  flex-direction: column;
  background: var(--glass-strong);
  transform: translateY(calc(100% + 40px));
  opacity: 0;
  transition: transform 0.55s var(--ease), opacity 0.35s;
}
.sheet.is-open { transform: none; opacity: 1; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 16px 8px 18px; }
.sheet__head strong { font-family: var(--f-display); font-weight: 600; font-size: 20px; }
.sheet__head span { color: var(--muted); font-size: 16px; margin-inline-start: 8px; }
.sheet__body { overflow-y: auto; padding: 4px 20px 8px; overscroll-behavior: contain; }
.sheet__ayah { font-family: var(--f-quran); font-size: 25px; line-height: 2.05; color: var(--quran-ink); margin: 0 0 12px; text-align: justify; }
.sheet__ayah .end { font-size: 0.8em; color: var(--gold); }
.sheet__label { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; color: var(--gold); margin: 6px 0 6px; }
.sheet__label::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.sheet__tafsir { margin: 0 0 14px; font-size: 18.5px; line-height: 2; font-weight: 500; color: var(--ink); white-space: pre-line; }
.sheet__foot { display: flex; gap: 8px; padding: 10px 16px 16px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--glass);
  font-weight: 600; font-size: 16.5px; cursor: pointer;
  transition: background 0.2s, transform 0.25s var(--ease);
}
.chip:hover { background: var(--hl-hover); transform: translateY(-1px); }
.chip svg { width: 17px; height: 17px; }

@media (max-width: 640px) {
  .rtop__home { padding-inline: 6px; }
  .rtop__title span { font-size: 15px; }
  .stage { padding: 72px 8px 80px; }
  .paper { border-radius: 14px; padding: 4.5% 3% 6.5%; }
  .paper::after { inset: 6px; border-radius: 10px; }
  .paper__num { bottom: 9px; font-size: 14px; }
  .sheet { inset-inline: 8px; bottom: 8px; width: auto; }
}

/* ——— أزرار الشريط: عنوانٌ مكتوب لكلّ زرّ ——— */
.pill-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--glass); cursor: pointer;
  font-weight: 600; font-size: 16px; color: var(--ink);
  white-space: nowrap;
  transition: background 0.25s, border-color 0.25s;
}
.pill-btn:hover { background: var(--hl-hover); border-color: color-mix(in srgb, var(--sand) 60%, transparent); }
.pill-btn__ic { display: inline-grid; }
.pill-btn__ic svg { width: 20px; height: 20px; color: var(--gold); }
.seg { display: inline-grid; grid-auto-flow: column; gap: 3px; padding: 3px; border-radius: 14px; background: var(--hl-hover); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; height: 36px; padding: 0 16px; border-radius: 11px; font-weight: 600; font-size: 16px; color: var(--ink-2); cursor: pointer; transition: background 0.25s, color 0.25s; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--on-brand); box-shadow: 0 6px 14px -8px rgba(21, 42, 68, 0.7); }
.rtop__actions { display: flex; gap: 8px; align-items: center; }

/* زرّ السمة: يظهر ما سيُفعَّل — «ليلي» في النهار و«نهاري» في الليل. */
.tg { display: inline-flex; align-items: center; gap: 8px; }
.tg--sun { display: none; }
:root[data-theme="dark"] .tg--moon { display: none; }
:root[data-theme="dark"] .tg--sun { display: inline-flex; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tg--moon { display: none; }
  :root:not([data-theme="light"]) .tg--sun { display: inline-flex; }
}
/* حتى 1100px: العناوين تبقى، ويُخفى اسم «مكنون» بجانب الشعار لتتّسع. */
@media (max-width: 1100px) {
  .rtop__home span { display: none; }
  .rtop__home { padding-inline: 6px; }
  .pill-btn { padding: 0 12px; gap: 6px; font-size: 15px; }
  .seg button { padding: 0 12px; font-size: 15px; }
}
/* الهاتف: صفّان — العنوان ثم الأزرار، وكلّ زرٍّ أيقونةٌ فوق عنوانه. */
@media (max-width: 760px) {
  .rtop { grid-template-columns: auto 1fr; border-radius: 22px; row-gap: 6px; }
  .rtop__actions { grid-column: 1 / -1; justify-content: space-between; gap: 6px; }
  .pill-btn { flex-direction: column; gap: 3px; height: 52px; min-width: 56px; padding: 0 6px; font-size: 12.5px; border-radius: 12px; }
  .pill-btn__ic svg { width: 19px; height: 19px; }
  .tg { flex-direction: column; gap: 3px; }
  .seg { align-self: stretch; }
  .seg button { height: auto; padding: 0 10px; font-size: 14.5px; }
  .reader .stage { padding-top: 136px; }
  .reader.mode-scroll .stage { padding-top: 136px; }
  .paper { --ph: calc(100dvh - 234px); }
}
@media (max-width: 380px) {
  .rtop__actions { gap: 4px; }
  .seg button { padding: 0 8px; }
}

/* ——— تقليب الورقة ——— */
.spread { perspective: 2400px; transform-style: preserve-3d; }
.turn-layer { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
.turn-under { position: fixed; margin: 0; }
.leaf { position: fixed; transform-style: preserve-3d; will-change: transform; }
.leaf__face { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; margin: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; max-width: none !important; max-height: none !important; }
.leaf__back { transform: rotateY(180deg); }
.leaf__shade { position: absolute; inset: 0; z-index: 3; border-radius: inherit; pointer-events: none; opacity: 0; background: linear-gradient(to left, rgba(8, 17, 30, 0.35), transparent 55%); }

/* ——— وضع التمرير المتصل ——— */
.flow { display: none; }
.mode-scroll .stage { display: block; overflow-y: auto; overscroll-behavior: contain; padding: 86px 12px 96px; touch-action: pan-y; scroll-behavior: auto; }
.mode-scroll .spread { display: none; }
/* عمودٌ بعرضٍ صريح: الصفحات تعرف ارتفاعها قبل أن تُرسم، فيصحّ القفز إلى أيّ صفحة. */
.mode-scroll .flow { display: grid; gap: 22px; grid-template-columns: minmax(0, 720px); justify-content: center; }
.paper--flow { height: auto; width: 100%; max-width: 100%; max-height: none; aspect-ratio: 0.655; }
.paper--flow:not([data-drawn]) { background: color-mix(in srgb, var(--paper) 70%, transparent); }
.paper__err { text-align: center; color: var(--muted); padding: 2em; font-size: 16px; }
.paper__err a { color: var(--gold); font-weight: 600; }
.drawer__list .empty { padding: 18px; color: var(--muted); }

/* ——— زرّا الحافتين: نقرةٌ واحدة تقلّب، على الشاشات الواسعة ذات الفأرة ——— */
.edge {
  position: fixed; top: 50%; z-index: 35;
  width: 56px; height: 56px; margin-top: -28px;
  border-radius: 50%; border: 1px solid var(--glass-edge);
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  display: grid; place-items: center; cursor: pointer;
  opacity: 0.55; box-shadow: var(--shadow);
  transition: opacity 0.25s, transform 0.3s var(--ease), background 0.25s;
}
.edge:hover { opacity: 1; background: var(--glass-strong); transform: scale(1.08); }
.edge:active { transform: scale(0.96); }
.edge svg { width: 28px; height: 28px; color: var(--ink); }
.edge--next { left: 22px; }
.edge--prev { right: 22px; }
.reader.is-calm .edge, .reader.mode-scroll .edge { opacity: 0; pointer-events: none; }
@media (max-width: 1100px), (pointer: coarse) { .edge { display: none; } }

/* طبقة التقليب تحمل عناصر الصفحات الحقيقية. */
.turn-under, .leaf__face { will-change: transform; }
/* حاوية الرسم المسبق: خارج الشاشة، مخفيّة لكن تُخطَّط (لا display:none). */
.prewarm { position: fixed; left: -4000px; top: 0; width: 560px; height: 860px; visibility: hidden; pointer-events: none; }
.prewarm .qpage { width: 100%; height: 100%; }
