/* =====================================================================
   مُسمِّع — Traditional Ornamental Mushaf display mode
   Printed-paper Mushaf: ivory sheet, emerald & antique-gold ornaments,
   ornamental surah banners, basmalah line, framed page and rosette
   verse medallions. This stylesheet is intentionally independent of the
   application's dark/light app theme: the Mushaf page always reads as ink
   on ivory paper, exactly like a printed edition.
   ===================================================================== */

:root {
  --mushaf-paper: #f7efdc;
  --mushaf-paper-warm: #f2e6cb;
  --mushaf-paper-edge: #e9d9b6;
  --mushaf-ink: #191510;
  --mushaf-emerald: #0f3b2e;
  --mushaf-emerald-deep: #082a20;
  --mushaf-emerald-soft: #16513d;
  --mushaf-gold: #b8893c;
  --mushaf-gold-light: #d9b872;
  --mushaf-gold-pale: #ecd9a8;
  --mushaf-beige: #e3d2ab;
  --mushaf-frame-dark: #4b3518;
  --mushaf-frame-gold: #a77f3b;
  --mushaf-turquoise: #2f7c72;
  --mushaf-turquoise-deep: #12443c;
  --mushaf-cream: #fbf4e3;
  /* Authentic KFGQPC Uthmanic Hafs is bundled in assets/fonts. Amiri,
     Scheherazade, Traditional Arabic and generic system fonts are
     intentionally excluded from the Quranic stack. */
  --mushaf-font: 'KFGQPC Uthmanic Hafs', 'KFGQPC Uthman Taha Naskh';
  --mushaf-features: "kern" 1, "liga" 1, "calt" 1, "mark" 1, "mkmk" 1;
  --quran-font-scale: 1;
}

/* Night Mushaf: a true charcoal page with silver ink and dark-adapted
   gold/emerald ornament. It is intentionally independent from the app's
   own light/dark UI theme, and applies to every Mushaf view. */
:root[data-mushaf-theme="dark"] {
  --mushaf-paper: #0c110e;
  --mushaf-paper-warm: #101712;
  --mushaf-paper-edge: #070b09;
  --mushaf-ink: #f2ecdd;
  --mushaf-gold: #d8b56a;
  --mushaf-gold-light: #ecd39a;
  --mushaf-gold-pale: #8a6e3c;
  --mushaf-frame-dark: #c8a15a;
  --mushaf-frame-gold: #d8b56a;
  --mushaf-cream: #1a221c;
  --mushaf-highlight: rgba(216, 181, 106, 0.2);
  --mushaf-highlight-line: transparent;
  --mushaf-highlight-gold: rgba(216, 181, 106, 0.27);
}

/* ─── reader shell ─────────────────────────────────────────────────── */
.mushaf-reader {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-inline: auto;
}

.mushaf-toolbar .field-grid {
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mushaf-jump {
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

.mushaf-jump .form-input {
  min-width: 0;
  height: 46px;
  text-align: center;
}

.mushaf-jump .btn-secondary {
  flex-shrink: 0;
  min-height: 46px;
  padding: 0 12px;
  font-size: 12px;
}

.mushaf-bookmark-btn {
  gap: 6px;
  padding-inline: 10px;
  font-size: 12px;
}
.mushaf-bookmark-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linejoin: round;
}
.mushaf-bookmark-btn.is-active {
  color: var(--mushaf-gold);
  border-color: rgba(184, 137, 60, 0.6);
  background: rgba(184, 137, 60, 0.14);
}
.mushaf-bookmark-btn.is-active svg { fill: currentColor; }
.mushaf-bookmark-btn span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── the page sheet ───────────────────────────────────────────────── */
.mushaf-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding-block: 1px;
  touch-action: pan-y;
}

.mushaf-sheet {
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  min-width: 0;
  padding: clamp(24px, 6.2vw, 40px) clamp(19px, 5.4vw, 30px) clamp(20px, 5.2vw, 32px);
  border-radius: clamp(5px, 1.6vw, 8px);
  color: var(--mushaf-ink);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 252, 244, 0.92) 0%, rgba(255, 252, 244, 0) 58%),
    radial-gradient(100% 70% at 50% 104%, rgba(155, 119, 61, 0.16), transparent 62%),
    radial-gradient(120% 100% at 50% 50%, transparent 56%, rgba(132, 96, 45, 0.08) 100%),
    repeating-linear-gradient(90deg, rgba(140, 110, 62, 0.025) 0 1px, transparent 1px 4px),
    linear-gradient(178deg, #faf3e2 0%, var(--mushaf-paper-warm) 62%, var(--mushaf-paper-edge) 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.78) inset,
    0 0 0 1px rgba(150, 118, 62, 0.28),
    0 16px 38px rgba(11, 20, 15, 0.28);
  overflow: hidden;
  animation: mushafSheetIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes mushafSheetIn {
  from { opacity: 0; transform: translate3d(0, 6px, 0); }
  to { opacity: 1; transform: none; }
}

.mushaf-sheet-content {
  position: relative;
  z-index: 2;
  min-width: 0;
}

.mushaf-page-body {
  min-width: 0;
}

/* ─── ornamental frame ─────────────────────────────────────────────── */
/* Classical Mushaf margin: an outer dark-gold rule, a woven band in
   gold/emerald/ivory, then two fine inner boundaries. The frame is
   absolutely positioned so it never distorts when the page scrolls. */
.mushaf-frame {
  position: absolute;
  inset: clamp(6px, 2vw, 8px);
  z-index: 1;
  border: 1px solid var(--mushaf-frame-dark);
  border-radius: 3px;
  pointer-events: none;
  box-shadow:
    0 0 0 1px rgba(247, 236, 210, 0.7) inset,
    0 0 0 2px rgba(122, 91, 40, 0.55) inset;
}

.mushaf-frame-edge {
  position: absolute;
  display: block;
  opacity: 0.98;
}

.mushaf-frame-edge.top,
.mushaf-frame-edge.bottom {
  left: clamp(10px, 3vw, 12px);
  right: clamp(10px, 3vw, 12px);
  height: clamp(8px, 2.4vw, 9px);
  background: url('../assets/mushaf/frame-band-h.svg') repeat-x 0 0 / 40px 100%;
}
.mushaf-frame-edge.top {
  top: 0;
  border-bottom: 1px solid rgba(75, 53, 24, 0.72);
}
.mushaf-frame-edge.bottom {
  bottom: 0;
  border-top: 1px solid rgba(75, 53, 24, 0.72);
}

.mushaf-frame-edge.left,
.mushaf-frame-edge.right {
  top: clamp(10px, 3vw, 12px);
  bottom: clamp(10px, 3vw, 12px);
  width: clamp(8px, 2.4vw, 9px);
  background: url('../assets/mushaf/frame-band-v.svg') repeat-y 0 0 / 100% 40px;
}
.mushaf-frame-edge.left {
  left: 0;
  border-right: 1px solid rgba(75, 53, 24, 0.72);
}
.mushaf-frame-edge.right {
  right: 0;
  border-left: 1px solid rgba(75, 53, 24, 0.72);
}

.mushaf-frame::before {
  content: '';
  position: absolute;
  inset: clamp(10px, 3vw, 12px);
  border: 1px solid rgba(15, 59, 46, 0.62);
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(184, 137, 60, 0.34),
    0 0 0 2px rgba(255, 250, 238, 0.3) inset;
}

.mushaf-frame::after {
  content: '';
  position: absolute;
  inset: clamp(13px, 4vw, 16px);
  border: 1px solid rgba(184, 137, 60, 0.32);
  border-radius: 1px;
}

.mushaf-frame-corner {
  position: absolute;
  width: clamp(28px, 8.6vw, 36px);
  height: clamp(28px, 8.6vw, 36px);
  color: var(--mushaf-gold);
  opacity: 0.95;
  z-index: 2;
}
.mushaf-frame-corner svg { display: block; width: 100%; height: 100%; }
.mushaf-frame-corner.tl { top: -5px; left: -5px; }
.mushaf-frame-corner.tr { top: -5px; right: -5px; transform: scaleX(-1); }
.mushaf-frame-corner.bl { bottom: -5px; left: -5px; transform: scaleY(-1); }
.mushaf-frame-corner.br { bottom: -5px; right: -5px; transform: scale(-1, -1); }

/* ─── ornamental surah banner ──────────────────────────────────────── */
/* A full-width rectangular band of olive-gold arabesque, flanked by a
   pair of turquoise rosettes and centred on a cream lobed cartouche. */
.mushaf-surah-banner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: clamp(48px, 12.2vw, 56px);
  margin: clamp(9px, 2.4vw, 16px) 0 clamp(5px, 1.4vw, 9px);
  padding: 4px 3px;
  border: 1px solid var(--mushaf-frame-dark);
  border-radius: 2px;
  background:
    linear-gradient(180deg, rgba(255, 238, 193, 0.2), transparent 38%, rgba(42, 26, 7, 0.2)),
    url('../assets/mushaf/surah-banner-pattern.svg') repeat-x 0 50% / auto calc(100% - 2px),
    linear-gradient(180deg, #8e6b34 0%, #7a592b 48%, #654822 100%);
  box-shadow:
    0 0 0 1px rgba(255, 240, 200, 0.28) inset,
    0 2px 3px rgba(43, 29, 8, 0.22),
    0 1px 0 rgba(255, 240, 200, 0.34) inset,
    0 -6px 10px rgba(48, 30, 7, 0.22) inset;
  overflow: hidden;
}

.mushaf-surah-banner::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(238, 212, 153, 0.55);
  border-radius: 1px;
  pointer-events: none;
}

.mushaf-surah-banner:first-child { margin-top: 0; }

.banner-medallion {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  width: clamp(19px, 5.2vw, 24px);
  height: clamp(19px, 5.2vw, 24px);
  filter: drop-shadow(0 1px 1px rgba(39, 25, 6, 0.35));
}
.banner-medallion svg { display: block; width: 100%; height: 100%; }

.banner-plate {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  min-width: 0;
  min-height: clamp(37px, 9.8vw, 46px);
  margin: 0 clamp(5px, 1.8vw, 10px);
  padding: clamp(3px, 1vw, 5px) clamp(26px, 7.8vw, 40px);
}

.banner-plate-frame {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 1px 1px rgba(57, 38, 10, 0.28));
}

.banner-copy {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  line-height: 1;
  /* Arabic ink sits above the geometric middle because the font's ascent
     is taller than its descent. A hair of downward optical correction
     makes the title read as truly centred inside the cartouche. */
  transform: translateY(0.06em);
}

.banner-name {
  display: block;
  font-family: var(--mushaf-font);
  font-size: clamp(17px, 4.7vw, 22px);
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: 0;
  color: #292013;
  white-space: nowrap;
  text-align: center;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.52);
  font-synthesis: none;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures contextual;
  font-feature-settings: var(--mushaf-features);
  -webkit-font-feature-settings: var(--mushaf-features);
  text-rendering: optimizeLegibility;
}

/* ─── basmalah line ────────────────────────────────────────────────── */
.mushaf-bismillah {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(2px, 0.8vw, 6px);
  min-height: 1.9em;
  margin: clamp(2px, 0.7vw, 4px) 0 clamp(4px, 1.3vw, 8px);
  color: var(--mushaf-ink);
}

.mushaf-bismillah > .bismillah-text {
  font-family: var(--mushaf-font);
  /* The basmalah follows the reader preference at a gentler ratio so it
     still fits between the two flourishes on narrow phones. */
  font-size: calc(clamp(15.5px, 4vw, 18.5px) * (0.6 + 0.4 * var(--quran-font-scale, 1)));
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.7;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
  color: var(--mushaf-emerald-deep);
  text-rendering: optimizeLegibility;
  font-variant-ligatures: common-ligatures contextual;
  -webkit-font-feature-settings: var(--mushaf-features);
  font-feature-settings: var(--mushaf-features);
}

.bismillah-flourish {
  flex: 0 1 44px;
  min-width: 14px;
  height: auto;
  color: var(--mushaf-gold);
  opacity: 0.85;
}
.bismillah-flourish.is-mirrored { transform: scaleX(-1); }

/* ─── Quranic text ─────────────────────────────────────────────────── */
.mushaf-page-text {
  font-family: var(--mushaf-font);
  font-size: calc(clamp(17.5px, 4.6vw, 20.5px) * var(--quran-font-scale, 1));
  font-weight: 400;
  line-height: 1.9;
  color: var(--mushaf-ink);
  direction: rtl;
  /* Every soft-wrapped Mushaf line is justified edge-to-edge. The final
     line of a block always keeps its natural, ragged width: stretching a
     sparse page-boundary line pulls its first and last words to opposite
     margins and opens a wide void in the middle. */
  text-align: justify;
  text-align-last: right;
  text-justify: inter-word;
  /* Browsers that implement Arabic kashida justification prefer it; the
     preceding inter-word value is the standards-compliant fallback. */
  text-justify: kashida;
  word-spacing: normal;
  letter-spacing: 0;
  text-indent: 0;
  margin: 0 0 clamp(4px, 1.4vw, 8px);
  padding: 0;
  -webkit-hyphens: none;
  hyphens: none;
  overflow-wrap: normal;
  word-break: normal;
  white-space: normal;
  text-rendering: optimizeLegibility;
  font-synthesis: none;
  font-kerning: normal;
  font-variant-ligatures: common-ligatures contextual;
  -webkit-font-feature-settings: var(--mushaf-features);
  font-feature-settings: var(--mushaf-features);
  -webkit-font-smoothing: antialiased;
}

.mushaf-page-text:last-child { margin-bottom: 0; }

/* A block may end mid-surah when a page boundary cuts it, but its closing
   line is still a normal ragged line. This must never be `justify`: that is
   what tore «قَوْمٌ مَّسْحُورُونَ ⑮» across page 262 (Al-Hijr) with a giant
   central gap. Soft-wrapped lines above stay justified; only the final line
   keeps its natural RTL width. */
.mushaf-page-text.is-page-continued,
.mushaf-page-text.is-surah-end { text-align-last: right; }

.mushaf-verse {
  display: inline;
  color: inherit;
  text-indent: 0;
  white-space: normal;
  /* Keep every word run on the line's shared optical centre instead of
     letting the tall Uthmani ascent pull the text above the medallions. */
  vertical-align: middle;
}

/* The final word and its ayah rosette stay on the same line and share
   one flex-centred vertical axis, so the rosette can never sit higher or
   lower than the word it belongs to. */
.ayah-tail {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  white-space: nowrap;
}

/* ─── ornamental verse medallions ──────────────────────────────────── */
.ayah-medallion {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55em;
  height: 1.55em;
  margin: 0 0.08em;
  /* Centre the medallion on the same horizontal axis as the words. */
  vertical-align: middle;
  flex-shrink: 0;
  direction: ltr;
  filter: drop-shadow(0 1px 0 rgba(255, 250, 238, 0.55));
}

.ayah-medallion > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.ayah-medallion > b {
  position: relative;
  z-index: 1;
  font-family: var(--font-ui);
  font-size: 0.4em;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--mushaf-emerald-deep);
  transform: translateY(0.02em);
}

/* ─── page footer ──────────────────────────────────────────────────── */
.mushaf-page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: clamp(9px, 2.6vw, 15px);
  padding-top: clamp(7px, 2vw, 11px);
  border-top: 3px double rgba(167, 127, 59, 0.55);
}

.mushaf-foot-label {
  font-family: var(--font-ui);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.4;
  color: rgba(15, 59, 46, 0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mushaf-page-number {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.mushaf-page-number > svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.mushaf-page-number > b {
  position: relative;
  z-index: 1;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  color: var(--mushaf-emerald-deep);
}

/* ─── loading / error states ───────────────────────────────────────── */
.mushaf-state {
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.8;
  text-align: center;
  color: var(--mushaf-emerald);
  padding: clamp(34px, 14vh, 96px) 8px;
}

.mushaf-state.is-error { color: #8d2f27; }

.mushaf-state .btn-secondary {
  margin-top: 12px;
  color: var(--mushaf-emerald);
  border-color: rgba(15, 59, 46, 0.35);
  background: rgba(255, 255, 255, 0.4);
}

/* ─── pager ────────────────────────────────────────────────────────── */
.mushaf-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
}

.mushaf-pager .btn-wajh-nav {
  min-height: 44px;
  padding-inline: 9px;
  font-size: 10.5px;
}

.mushaf-pager-meta {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.mushaf-pager-meta .wajh-indicator-number {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mushaf-pager-meta .wajh-indicator-surah-range {
  margin-top: 1px;
  font-size: 9.5px;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── bookmarks ────────────────────────────────────────────────────── */
.mushaf-bookmarks-card { padding: 12px 14px 14px; }

.mushaf-bookmark-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 138px;
  overflow-y: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}

.mushaf-bookmark-item {
  display: inline-flex;
  align-items: stretch;
  max-width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-surface);
  overflow: hidden;
}

.mushaf-bookmark-item .chip-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  max-width: 220px;
  padding: 0 10px;
  border: none;
  background: transparent;
  color: var(--ink-secondary);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  overflow: hidden;
}
.mushaf-bookmark-item .chip-main:hover { color: var(--accent-primary); }
.mushaf-bookmark-item .chip-page {
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
}
.mushaf-bookmark-item .chip-surah {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mushaf-bookmark-item .chip-juz {
  font-size: 9px;
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
}
.mushaf-bookmark-item .chip-remove {
  width: 30px;
  min-height: 38px;
  border: none;
  border-inline-start: 1px solid var(--border-color);
  background: transparent;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.mushaf-bookmark-item .chip-remove:hover { color: var(--status-bad); }

/* ─── standard (non-ornamental) display of the same Mushaf page ────── */
.mushaf-sheet[data-display="standard"] {
  padding: 13px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  color: var(--ink-primary);
  background: var(--bg-card);
  box-shadow: var(--shadow-sm);
}

.mushaf-sheet[data-display="standard"] .mushaf-frame { display: none; }

.mushaf-sheet[data-display="standard"] .std-block + .std-block { margin-top: 16px; }

.std-surah-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  margin-bottom: 6px;
  font-family: var(--font-mushaf);
  font-size: 21px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--accent-primary);
  text-align: center;
  font-synthesis: none;
  font-feature-settings: var(--quran-features);
  -webkit-font-feature-settings: var(--quran-features);
}

.std-surah-meta {
  font-family: var(--font-ui);
  font-size: 9.5px;
  font-weight: 600;
  color: var(--gold);
}

.std-bismillah {
  margin-bottom: 6px;
  font-family: var(--font-mushaf);
  font-size: calc(21px * (0.6 + 0.4 * var(--quran-font-scale, 1)));
  font-weight: 400;
  font-synthesis: none;
  line-height: 1.9;
  text-align: center;
  color: var(--ink-secondary);
  font-variant-ligatures: common-ligatures contextual;
  font-feature-settings: var(--quran-features);
  -webkit-font-feature-settings: var(--quran-features);
}

.mushaf-sheet[data-display="standard"] .mushaf-page-text {
  font-size: calc(clamp(17px, 4.4vw, 20px) * var(--quran-font-scale, 1));
  line-height: 1.9;
  color: var(--ink-primary);
  margin-bottom: 8px;
}

.mushaf-sheet[data-display="standard"] .mushaf-page-footer {
  border-top-color: var(--border-color);
}

.mushaf-sheet[data-display="standard"] .mushaf-foot-label { color: var(--ink-muted); }

.mushaf-sheet[data-display="standard"] .ayah-medallion > b { color: var(--gold); }

/* ─── night Mushaf surface ─────────────────────────────────────────── */
:root[data-mushaf-theme="dark"] .mushaf-sheet {
  color: var(--mushaf-ink);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(216, 181, 106, 0.09) 0%, rgba(216, 181, 106, 0) 58%),
    radial-gradient(100% 70% at 50% 104%, rgba(0, 0, 0, 0.5), transparent 62%),
    radial-gradient(120% 100% at 50% 50%, transparent 56%, rgba(0, 0, 0, 0.32) 100%),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 4px),
    linear-gradient(178deg, #141b16 0%, var(--mushaf-paper-warm) 62%, var(--mushaf-paper-edge) 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05) inset,
    0 0 0 1px rgba(216, 181, 106, 0.26),
    0 18px 42px rgba(0, 0, 0, 0.58);
}

:root[data-mushaf-theme="dark"] .mushaf-frame {
  border-color: rgba(216, 181, 106, 0.72);
  box-shadow:
    0 0 0 1px rgba(216, 181, 106, 0.14) inset,
    0 0 0 2px rgba(216, 181, 106, 0.3) inset;
}
:root[data-mushaf-theme="dark"] .mushaf-frame::before {
  border-color: rgba(216, 181, 106, 0.55);
  box-shadow:
    0 0 0 1px rgba(216, 181, 106, 0.22),
    0 0 0 2px rgba(255, 255, 255, 0.04) inset;
}
:root[data-mushaf-theme="dark"] .mushaf-frame::after { border-color: rgba(216, 181, 106, 0.3); }
:root[data-mushaf-theme="dark"] .mushaf-frame-edge { filter: brightness(0.82) saturate(0.86); opacity: 0.92; }
:root[data-mushaf-theme="dark"] .mushaf-frame-edge.top { border-bottom-color: rgba(216, 181, 106, 0.55); }
:root[data-mushaf-theme="dark"] .mushaf-frame-edge.bottom { border-top-color: rgba(216, 181, 106, 0.55); }
:root[data-mushaf-theme="dark"] .mushaf-frame-edge.left { border-right-color: rgba(216, 181, 106, 0.55); }
:root[data-mushaf-theme="dark"] .mushaf-frame-edge.right { border-left-color: rgba(216, 181, 106, 0.55); }

:root[data-mushaf-theme="dark"] .mushaf-bismillah { color: var(--mushaf-ink); }
:root[data-mushaf-theme="dark"] .mushaf-bismillah > .bismillah-text {
  color: #efe5cf;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}
:root[data-mushaf-theme="dark"] .mushaf-page-text { color: var(--mushaf-ink); }
:root[data-mushaf-theme="dark"] .mushaf-page-footer { border-top-color: rgba(216, 181, 106, 0.4); }
:root[data-mushaf-theme="dark"] .mushaf-foot-label { color: rgba(232, 222, 198, 0.62); }

:root[data-mushaf-theme="dark"] .mushaf-state { color: #d8cfbc; }
:root[data-mushaf-theme="dark"] .mushaf-state.is-error { color: #f0a0a0; }
:root[data-mushaf-theme="dark"] .mushaf-state .btn-secondary {
  color: var(--mushaf-ink);
  border-color: rgba(216, 181, 106, 0.35);
  background: rgba(255, 255, 255, 0.05);
}

/* Recitation status colours stay legible on the charcoal page. */
:root[data-mushaf-theme="dark"] .mushaf-sheet .w.ok {
  color: #8fe0ab;
  background-image: linear-gradient(180deg, rgba(76, 175, 120, 0.2), rgba(76, 175, 120, 0.2));
}
:root[data-mushaf-theme="dark"] .mushaf-sheet .w.bad {
  color: #ff9a9a;
  background-image: linear-gradient(180deg, rgba(220, 80, 80, 0.24), rgba(220, 80, 80, 0.24));
}
:root[data-mushaf-theme="dark"] .mushaf-sheet .w.missing {
  color: #f2c77e;
  background-image: linear-gradient(180deg, rgba(210, 150, 50, 0.22), rgba(210, 150, 50, 0.22));
}
:root[data-mushaf-theme="dark"] .mushaf-sheet .w.current { color: #f7efdc; }

/* Standard continuous mode follows the same night paper palette. */
:root[data-mushaf-theme="dark"] .mushaf-sheet[data-display="standard"] {
  color: var(--mushaf-ink);
  background: linear-gradient(160deg, #171e18, #0e1411);
  border-color: rgba(216, 181, 106, 0.28);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.42);
}
:root[data-mushaf-theme="dark"] .mushaf-sheet[data-display="standard"] .std-surah-title { color: var(--mushaf-gold-light); }
:root[data-mushaf-theme="dark"] .mushaf-sheet[data-display="standard"] .std-surah-meta { color: rgba(216, 181, 106, 0.9); }
:root[data-mushaf-theme="dark"] .mushaf-sheet[data-display="standard"] .std-bismillah { color: #e9dfc8; }
:root[data-mushaf-theme="dark"] .mushaf-sheet[data-display="standard"] .mushaf-page-text { color: var(--mushaf-ink); }
:root[data-mushaf-theme="dark"] .mushaf-sheet[data-display="standard"] .mushaf-page-footer { border-top-color: rgba(216, 181, 106, 0.24); }
:root[data-mushaf-theme="dark"] .mushaf-sheet[data-display="standard"] .mushaf-foot-label { color: rgba(232, 222, 198, 0.62); }

/* ─── phones: frame-safe reading column ────────────────────────────── */
/* The ornamental frame's innermost rule sits ~18–24px inside the sheet,
   so the text needs a matching gutter. On phones the sheet is widened to
   the viewport edges by exactly the amount its padding grows: the Quran
   text keeps its previous line width (no reflow), while glyphs, surah
   banners and the page footer gain clear air inside the frame. */
@media (max-width: 767.98px) {
  #v1 .mushaf-reader,
  #v2 .mushaf-reader,
  #v5 .mushaf-reader {
    width: calc(100% + clamp(12px, 5vw, 22px));
    max-width: none;
    margin-inline: calc(-1 * clamp(6px, 2.5vw, 11px));
    flex-shrink: 0;
  }

  .mushaf-sheet {
    padding: clamp(26px, 7.9vw, 36px);
  }
}

/* ─── narrow phones ────────────────────────────────────────────────── */
@media (max-width: 389.98px) {
  .mushaf-frame { inset: clamp(5px, 1.8vw, 6px); }
  .mushaf-frame-corner.tl { top: -4px; left: -4px; }
  .mushaf-frame-corner.tr { top: -4px; right: -4px; }
  .mushaf-frame-corner.bl { bottom: -4px; left: -4px; }
  .mushaf-frame-corner.br { bottom: -4px; right: -4px; }
  .mushaf-surah-banner { min-height: 46px; }
  .banner-plate { padding-inline: clamp(22px, 6.4vw, 24px); }
  .banner-name { font-size: 17px; }
  .mushaf-bismillah > .bismillah-text { font-size: calc(16.5px * (0.6 + 0.4 * var(--quran-font-scale, 1))); }
  .bismillah-flourish { flex-basis: 26px; }
  .mushaf-page-text { font-size: calc(17px * var(--quran-font-scale, 1)); line-height: 1.88; }
  .mushaf-bookmark-item .chip-juz { display: none; }
}

@media (max-width: 339.98px) {
  .mushaf-frame { inset: 5px; }
  .mushaf-frame-edge.top,
  .mushaf-frame-edge.bottom { left: 10px; right: 10px; height: 8px; background-size: 36px 100%; }
  .mushaf-frame-edge.left,
  .mushaf-frame-edge.right { top: 10px; bottom: 10px; width: 8px; background-size: 100% 36px; }
  .mushaf-frame::before { inset: 10px; }
  .mushaf-frame::after { inset: 13px; }
  .mushaf-frame-corner { width: 26px; height: 26px; }
  .banner-plate { padding-inline: 20px; margin-inline: 4px; }
  .banner-name { font-size: 16px; }
  .banner-medallion { width: 17px; height: 17px; }
  .mushaf-bismillah .bismillah-flourish { display: none; }
  .mushaf-page-text { font-size: calc(16px * var(--quran-font-scale, 1)); line-height: 1.86; }
  .mushaf-pager .btn-wajh-nav span { display: none; }
}

/* ─── dedicated desktop Mushaf canvas (>= 1024px) ──────────────────── */
@media (min-width: 1024px) {
  .mushaf-sheet {
    padding: clamp(38px, 3.6vw, 56px) clamp(42px, 4.2vw, 64px) clamp(30px, 3vw, 44px);
    border-radius: 10px;
  }

  .mushaf-page-text {
    font-size: calc(clamp(21px, 1.52vw, 25px) * var(--quran-font-scale, 1));
    line-height: 2.02;
    margin-bottom: 10px;
  }

  .mushaf-bismillah > .bismillah-text {
    font-size: calc(clamp(20px, 1.85vw, 26px) * (0.6 + 0.4 * var(--quran-font-scale, 1)));
  }

  .mushaf-surah-banner { min-height: 58px; }
  .banner-name { font-size: clamp(22px, 1.7vw, 27px); }
  .mushaf-frame-corner { width: 40px; height: 40px; }
  .mushaf-page-footer { margin-top: 18px; padding-top: 12px; }

  .mushaf-sheet[data-display="standard"] { padding: clamp(26px, 2.6vw, 40px); }
  .mushaf-sheet[data-display="standard"] .mushaf-page-text {
    font-size: calc(clamp(20px, 1.45vw, 24px) * var(--quran-font-scale, 1));
  }
  .mushaf-sheet[data-display="standard"] .std-surah-title { font-size: 25px; }
  .mushaf-sheet[data-display="standard"] .std-bismillah {
    font-size: calc(25px * (0.6 + 0.4 * var(--quran-font-scale, 1)));
  }
}

@media (prefers-reduced-motion: reduce) {
  .mushaf-sheet { animation: none; }
}
