/* ==========================================================
   Quran PWA - Master Stylesheet v8
   Deep-Contrast Light Theme, Permanent Nav on Secondary Views
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Amiri+Quran&family=Amiri:ital,wght@0,400;0,700;1,400&family=Tajawal:wght@400;500;700;800;900&display=swap');

:root {
  /* CRISP DEEP-CONTRAST LIGHT THEME (Default) */
  --bg-primary: #f8faf9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f3;
  --border-color: #cbd5e1;
  --border-gold: #8d6921;
  --gold-primary: #8d6921;
  --gold-text: #705214;
  --gold-accent: #785a1a;
  --gold-gradient: linear-gradient(135deg, #b88d3b 0%, #9d7529 100%);
  --text-main: #000000;
  --text-sub: #111827;
  --text-muted: #1f2937;
  --mushaf-screen-bg: #ffffff;
  --img-filter: none;
  --input-bg: #ffffff;
  --input-text: #000000;
  --modal-bg: #ffffff;
  --header-h: 48px;
  --mushaf-font: 'Amiri Quran', 'Amiri', serif;
  --ui-font: 'Tajawal', system-ui, -apple-system, sans-serif;
}

body.theme-light {
  --bg-primary: #f8faf9;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f3;
  --border-color: #cbd5e1;
  --border-gold: #8d6921;
  --gold-primary: #8d6921;
  --gold-text: #705214;
  --gold-accent: #785a1a;
  --gold-gradient: linear-gradient(135deg, #b88d3b 0%, #9d7529 100%);
  --text-main: #000000;
  --text-sub: #111827;
  --text-muted: #1f2937;
  --mushaf-screen-bg: #ffffff;
  --img-filter: none;
  --input-bg: #ffffff;
  --input-text: #000000;
  --modal-bg: #ffffff;
}

body.theme-sepia {
  /* WARM PAPER / SEPIA THEME */
  --bg-primary: #f4ecdf;
  --bg-secondary: #ebdcc8;
  --bg-card: #fcf8f0;
  --bg-card-hover: #f5edde;
  --border-color: #cbb898;
  --border-gold: #9d7529;
  --gold-primary: #8d6921;
  --gold-text: #6b4e13;
  --gold-accent: #785a1a;
  --gold-gradient: linear-gradient(135deg, #9d7529 0%, #b88d3b 50%, #835f1b 100%);
  --text-main: #1e1307;
  --text-sub: #3d2d1b;
  --text-muted: #5c452e;
  --mushaf-screen-bg: #f4ecdf;
  --img-filter: sepia(0.25) contrast(1.05);
  --input-bg: #ffffff;
  --input-text: #1e1307;
  --modal-bg: #faf4e9;
}

body.theme-dark {
  /* DARK THEME */
  --bg-primary: #07130f;
  --bg-secondary: rgba(11, 26, 20, 0.96);
  --bg-card: rgba(14, 33, 26, 0.96);
  --bg-card-hover: rgba(22, 50, 40, 0.98);
  --border-color: rgba(197, 160, 89, 0.28);
  --border-gold: #c5a059;
  --gold-primary: #d4af37;
  --gold-text: #f3e5ab;
  --gold-accent: #e2c275;
  --gold-gradient: linear-gradient(135deg, #d4af37 0%, #c5a059 50%, #9f7d34 100%);
  --text-main: #f3f7f5;
  --text-sub: #c0d4c8;
  --text-muted: #88a393;
  --mushaf-screen-bg: #07130f;
  --img-filter: invert(0.92) hue-rotate(180deg) brightness(0.95) contrast(1.1);
  --input-bg: rgba(13, 31, 25, 0.9);
  --input-text: #ffffff;
  --modal-bg: #0c1c16;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  direction: rtl;
  text-align: right;
  font-family: var(--ui-font);
  background-color: var(--mushaf-screen-bg);
  color: var(--text-main);
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================
   Full-Screen Immersion Mushaf Viewport
   ========================================================== */
#view-mushaf {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--mushaf-screen-bg);
  overflow: hidden;
  touch-action: pan-y;
  cursor: pointer;
}

.mushaf-page-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

@media (max-width: 640px) {
  .mushaf-img {
    width: 100vw;
    height: 100dvh;
    object-fit: fill;
    display: block;
    margin: 0 auto;
    pointer-events: none;
    user-select: none;
    filter: var(--img-filter);
    transition: opacity 0.18s cubic-bezier(0.2, 0.9, 0.3, 1), transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
    will-change: transform, opacity;
  }
}

@media (min-width: 641px) {
  .mushaf-img {
    max-width: 660px;
    height: 100dvh;
    object-fit: fill;
    display: block;
    margin: 0 auto;
    pointer-events: none;
    user-select: none;
    filter: var(--img-filter);
    transition: opacity 0.18s cubic-bezier(0.2, 0.9, 0.3, 1), transform 0.18s cubic-bezier(0.2, 0.9, 0.3, 1);
    will-change: transform, opacity;
  }
}

/* ==========================================================
   Top Header & Bottom Navigation Bars
   ========================================================== */
.top-header {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1.5px solid var(--border-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transform: translateY(-100%);
  transition: transform 0.24s cubic-bezier(0.1, 0.9, 0.2, 1);
}

.bottom-overlay-menu {
  position: fixed;
  bottom: 0;
  right: 0;
  left: 0;
  background: var(--bg-secondary);
  border-top: 1.5px solid var(--border-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.12);
  transform: translateY(100%);
  transition: transform 0.24s cubic-bezier(0.1, 0.9, 0.2, 1);
  display: flex;
  flex-direction: column;
}

/* In Mushaf mode: shown only when overlay is active */
body.overlay-active .top-header,
body:not(.in-mushaf-view) .top-header {
  transform: translateY(0) !important;
}

body.overlay-active .bottom-overlay-menu,
body:not(.in-mushaf-view) .bottom-overlay-menu {
  transform: translateY(0) !important;
}

.header-meta-group {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  font-weight: 700;
}

.header-surah-title {
  color: var(--gold-text);
  font-size: 0.95rem;
  font-weight: 800;
}

.header-page-badge {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 2px 8px;
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 800;
}

.header-juz-title {
  color: var(--text-sub);
  font-size: 0.82rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.header-btn:hover {
  border-color: var(--border-gold);
  color: var(--gold-text);
}

#btn-header-back-mushaf {
  background: var(--gold-gradient) !important;
  color: #121816 !important;
  font-weight: 900 !important;
  border: none !important;
}

.quick-action-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.04);
}

body.theme-dark .quick-action-row {
  background: rgba(0, 0, 0, 0.25);
}

.quick-action-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  font-family: var(--ui-font);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.quick-action-btn:hover, .quick-action-btn:active {
  color: var(--gold-text);
  background: var(--bg-card-hover);
}

.bottom-tabs-row {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 6px 12px 10px 12px;
}

.nav-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-sub);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.74rem;
  font-weight: 700;
  font-family: var(--ui-font);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: all 0.2s ease;
  flex: 1;
}

.nav-tab-btn.active-tab {
  color: var(--gold-text);
  font-weight: 900;
}

.tab-icon {
  font-size: 1.2rem;
}

/* ==========================================================
   Scrollable Secondary Tabs (Surahs, Athkar, Bookmarks, Settings)
   ========================================================== */
.tab-view.scrollable-tab {
  position: absolute;
  top: var(--header-h);
  bottom: 0;
  left: 0;
  right: 0;
  overflow-y: auto;
  padding: 16px 16px 110px 16px; /* Generous bottom padding so bottom menu never covers content! */
  max-width: 800px;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
  background-color: var(--bg-primary);
  z-index: 50;
}

.card-box {
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  border-radius: 14px;
  padding: 14px;
  color: var(--text-main);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  transition: all 0.2s ease;
}

body.theme-light .card-box {
  background: #ffffff !important;
  color: #000000 !important;
  border-color: #cbd5e1 !important;
}

body.theme-light .text-main,
body.theme-light .thekr-card,
body.theme-light .surah-index-card,
body.theme-light label {
  color: #000000 !important;
  font-weight: 700 !important;
}

body.theme-light .text-sub {
  color: #111827 !important;
  font-weight: 600 !important;
}

body.theme-light .text-muted {
  color: #1f2937 !important;
}

body.theme-light .input-theme {
  background: #ffffff !important;
  color: #000000 !important;
  border: 1.5px solid #94a3b8 !important;
}

.text-main { color: var(--text-main); }
.text-sub { color: var(--text-sub); }
.text-muted { color: var(--text-muted); }
.text-gold-accent { color: var(--gold-text); }

.input-theme {
  background: var(--input-bg);
  color: var(--input-text);
  border: 1px solid var(--border-color);
}
.input-theme:focus {
  border-color: var(--border-gold);
  outline: none;
}

/* ==========================================================
   Pure Speech Memorization Mode (No Ghost Reveals)
   ========================================================== */
.hifz-view-wrapper {
  width: 100%;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 16px 18px 16px;
  background-color: var(--bg-primary);
  color: var(--text-main);
  position: relative;
  z-index: 60;
  overflow: hidden;
}

.hifz-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1.5px solid var(--border-color);
  padding-bottom: 8px;
  flex-shrink: 0;
}

.hifz-exit-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  color: var(--text-sub);
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
}

.hifz-exit-btn:hover {
  color: #ef4444;
  border-color: #ef4444;
}

.hifz-live-status {
  padding: 6px 12px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--gold-text);
  font-weight: 700;
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.hifz-page-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px 6px;
  text-align: justify;
  text-justify: inter-word;
  line-height: 2.4;
  -webkit-overflow-scrolling: touch;
}

.hifz-word {
  display: inline-block;
  margin: 2px 3px;
  font-family: var(--mushaf-font);
  font-size: clamp(1.35rem, 2.9vh, 1.75rem);
  vertical-align: middle;
  transition: all 0.25s ease;
  cursor: pointer;
}

.hifz-word.masked {
  color: transparent !important;
  background: rgba(197, 160, 89, 0.25);
  border: 1.5px dashed rgba(197, 160, 89, 0.6);
  border-radius: 6px;
  min-width: 40px;
  height: 1.35em;
  user-select: none;
  font-size: 0.9em;
  text-align: center;
  line-height: 1.35em;
}

.hifz-word.masked:hover, .hifz-word.masked:active {
  background: rgba(197, 160, 89, 0.5);
  transform: scale(1.08);
}

.hifz-word.revealed {
  color: var(--gold-text) !important;
  background: transparent !important;
  border: none !important;
  font-weight: 900;
  animation: hifzGlow 0.4s ease-out;
}

@keyframes hifzGlow {
  0% { transform: scale(1.25); color: #000000; }
  100% { transform: scale(1); color: var(--gold-text); }
}

.hifz-bottom-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1.5px solid var(--border-color);
}

.hifz-rec-btn {
  background: var(--gold-gradient);
  color: #121816;
  border: none;
  font-weight: 900;
  font-size: 0.85rem;
  padding: 8px 18px;
  border-radius: 9999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.2);
  transition: all 0.2s;
}

.hifz-rec-btn.listening-active {
  background: #15803d !important;
  color: #ffffff !important;
}

.hifz-tool-btn {
  background: var(--bg-card);
  border: 1.5px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 9999px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.2s;
}

.hifz-tool-btn:hover {
  border-color: var(--border-gold);
  color: var(--gold-text);
}

/* Modals & Tasbeeh */
.app-modal-overlay {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.app-modal-dialog {
  background: var(--modal-bg);
  border: 2px solid var(--border-gold);
  border-radius: 18px;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 16px 36px rgba(0,0,0,0.4);
  padding: 20px;
  position: relative;
  color: var(--text-main);
}

.modal-close-btn {
  position: absolute;
  top: 14px;
  left: 14px;
  background: transparent;
  border: none;
  color: var(--text-sub);
  font-size: 1.3rem;
  cursor: pointer;
}

.tasbeeh-circle-btn {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--bg-card-hover) 0%, var(--bg-secondary) 100%);
  border: 4px double var(--border-gold);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--gold-text);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  margin: 16px auto;
  transition: transform 0.1s;
}

.tasbeeh-circle-btn:active {
  transform: scale(0.94);
}

.tasbeeh-count-display {
  font-size: 2.6rem;
  font-weight: 900;
  font-family: var(--ui-font);
  color: var(--text-main);
}

.bg-gold-btn {
  background: var(--gold-gradient);
  color: #121816;
  border: none;
  font-weight: 800;
}
.bg-gold-btn:hover {
  filter: brightness(1.1);
}
.hidden { display: none !important; }
.flex { display: flex !important; }


/* ==========================================================
   Qaloon Narration Sacred Layout Viewport
   ========================================================== */
.qaloon-page-container {
  width: 100%;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 18px 24px 18px;
  background-color: var(--mushaf-screen-bg);
  color: var(--text-main);
  border: 4px double var(--border-gold);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  user-select: none;
}

.qaloon-top-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1.5px solid var(--border-color);
  padding-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--gold-text);
  flex-shrink: 0;
}

.qaloon-text-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: justify;
  text-justify: inter-word;
  padding: 10px 4px;
  line-height: 2.35;
  font-family: var(--mushaf-font);
  font-size: clamp(1.35rem, 2.8vh, 1.8rem);
  overflow-y: auto;
}

.qaloon-footer-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1.5px solid var(--border-color);
  padding-top: 6px;
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--gold-text);
  flex-shrink: 0;
}

.qaloon-ayah-badge {
  font-family: var(--ui-font);
  font-size: 0.85em;
  color: var(--gold-text);
  font-weight: 900;
  display: inline-block;
  margin: 0 4px;
}


/* ==========================================================
   Complete Overlay Hiding during Memorization Mode
   ========================================================== */
body.in-hifz-active .top-header,
body.in-hifz-active .bottom-overlay-menu {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.hifz-exit-btn {
  background: #dc2626 !important;
  color: #ffffff !important;
  border: none !important;
  padding: 6px 14px !important;
  border-radius: 10px !important;
  font-size: 0.82rem !important;
  font-weight: 900 !important;
  cursor: pointer !important;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4) !important;
  transition: all 0.2s ease !important;
  z-index: 1000 !important;
}
.hifz-exit-btn:hover {
  background: #b91c1c !important;
  transform: scale(1.04);
}


/* ==========================================================
   Zero-Stutter Hardware-Accelerated Dual-Layer Mushaf Stage
   ========================================================== */
.mushaf-stage {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background: transparent;
}

.mushaf-img-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  object-fit: fill;
  pointer-events: none;
  user-select: none;
  filter: var(--img-filter);
  will-change: transform, opacity;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
}

.mushaf-img-layer.layer-active {
  opacity: 1;
  z-index: 2;
}

.mushaf-img-layer.layer-idle {
  opacity: 0;
  z-index: 1;
  pointer-events: none;
}


/* ==========================================================
   Royal Digital Mushaf Page (Pure Vector, Native Themes)
   ========================================================== */
.digital-mushaf-wrapper {
  position: relative;
  width: 100vw;
  height: 100dvh;
  box-sizing: border-box;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  user-select: none;
  transition: background 0.3s ease, color 0.3s ease;
}

.digital-mushaf-border-frame {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 8px;
  right: 8px;
  border: 2px solid var(--accent-gold);
  outline: 1px solid var(--accent-gold);
  outline-offset: -5px;
  border-radius: 6px;
  pointer-events: none;
  z-index: 5;
}

.surah-royal-cartouche {
  background: linear-gradient(135deg, #1b5e20, #0a3d12);
  color: #ffffff;
  border: 2px solid var(--accent-gold);
  border-radius: 9999px;
  padding: 4px 20px;
  text-align: center;
  font-family: 'Amiri Quran', serif;
  font-weight: bold;
  font-size: 1.15rem;
  margin: 4px auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  display: inline-block;
  align-self: center;
}

.basmalah-royal {
  text-align: center;
  font-family: 'Amiri Quran', serif;
  font-size: 1.25rem;
  color: var(--accent-gold);
  margin: 2px 0 6px 0;
  font-weight: bold;
}

.digital-mushaf-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  text-align: justify;
  text-justify: inter-word;
  font-family: 'Amiri Quran', serif;
  font-size: clamp(1.15rem, 4.2vw, 1.45rem);
  line-height: 2.25;
  padding: 4px 8px;
  color: var(--text-main);
  direction: rtl;
  overflow: hidden;
}

.digital-ayah-badge {
  color: var(--accent-gold);
  font-size: 0.9em;
  font-weight: 900;
  padding: 0 4px;
  display: inline-block;
  white-space: nowrap;
}

.digital-mushaf-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--accent-gold);
  border-top: 1px solid var(--border-theme);
  padding-top: 6px;
  margin-top: 4px;
  z-index: 6;
}


/* ==========================================================
   DESKTOP RESPONSIVE DESIGN (Centered Book, Desk Background)
   ========================================================== */
@media (min-width: 768px) {
  body {
    background-color: var(--desk-bg, #e2e8f0);
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  body.theme-light {
    --desk-bg: #e2e8f0;
  }
  body.theme-sepia {
    --desk-bg: #d7c9b5;
  }
  body.theme-dark {
    --desk-bg: #030806;
  }

  /* Centered Mushaf Stage (Book Aspect Ratio) */
  #view-mushaf {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100vw;
    height: 100dvh;
    position: relative;
  }

  .mushaf-page-container,
  .mushaf-stage,
  .digital-mushaf-wrapper {
    max-width: min(620px, 94vh * 0.65) !important;
    height: min(96dvh, 94vh) !important;
    margin: auto !important;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35), 0 4px 16px rgba(0, 0, 0, 0.15) !important;
    position: relative;
    overflow: hidden;
  }

  .mushaf-img,
  .mushaf-img-layer {
    width: 100% !important;
    height: 100% !important;
    max-width: min(620px, 94vh * 0.65) !important;
    left: 50% !important;
    transform: translate3d(-50%, 0, 0) !important;
    border-radius: 12px;
  }

  /* Secondary Tab Views (Surahs, Search, Athkar, Bookmarks, Settings) */
  .scrollable-tab {
    max-width: 680px !important;
    margin: 0 auto !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
  }

  /* Centered Top Header and Bottom Navigation */
  .top-header {
    max-width: 680px !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(-100%) !important;
    border-radius: 0 0 16px 16px;
  }

  body.overlay-active .top-header {
    transform: translateX(-50%) translateY(0) !important;
  }

  body:not(.in-mushaf-view) .top-header {
    transform: translateX(-50%) translateY(0) !important;
  }

  .bottom-overlay-menu {
    max-width: 680px !important;
    left: 50% !important;
    transform: translateX(-50%) translateY(100%) !important;
    border-radius: 20px 20px 0 0;
  }

  body.overlay-active .bottom-overlay-menu {
    transform: translateX(-50%) translateY(0) !important;
  }

  body:not(.in-mushaf-view) .bottom-overlay-menu {
    transform: translateX(-50%) translateY(0) !important;
  }

  /* Floating Desktop Navigation Arrows */
  .desktop-nav-arrow {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1.5px solid var(--border-theme);
    color: var(--accent-gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 50;
    transition: all 0.2s ease;
  }

  .desktop-nav-arrow:hover {
    background: var(--accent-gold);
    color: #ffffff;
    transform: translateY(-50%) scale(1.1);
  }

  .desktop-nav-arrow.arrow-prev {
    right: max(20px, calc(50vw - 390px));
  }

  .desktop-nav-arrow.arrow-next {
    left: max(20px, calc(50vw - 390px));
  }
}

/* ==========================================================
   AUTHENTIC MADINAH MUSHAF LAYOUT FOR QALOON (Pure Vector)
   ========================================================== */
.madinah-page-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  user-select: none;
}

/* Ornate Double Golden Border */
.madinah-border-frame {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 8px;
  right: 8px;
  border: 2px solid var(--accent-gold);
  outline: 1px solid var(--accent-gold);
  outline-offset: -4px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 10;
}

/* Outer Header: Surah Name on Right, Juz on Left */
.madinah-outer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 8px 4px 8px;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--accent-gold);
  border-bottom: 1px solid var(--border-theme);
  z-index: 12;
}

.madinah-header-badge {
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid var(--border-theme);
  background: rgba(0, 0, 0, 0.03);
}

/* King Fahd Surah Header Banner */
.madinah-surah-banner {
  margin: 6px auto;
  width: 96%;
  background: linear-gradient(135deg, #1b5e20, #0a3d12);
  border: 2px solid var(--accent-gold);
  border-radius: 8px;
  padding: 5px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 12;
}

.surah-banner-title {
  font-family: 'Amiri Quran', serif;
  font-weight: bold;
  font-size: 1.15rem;
  color: #ffffff;
}

.surah-banner-meta {
  font-size: 0.72rem;
  font-weight: 800;
  color: #f6e05e;
  border: 1px solid rgba(246, 224, 94, 0.4);
  padding: 1px 6px;
  border-radius: 6px;
}

/* Calligraphic Basmalah */
.madinah-basmalah {
  text-align: center;
  font-family: 'Amiri Quran', serif;
  font-size: 1.25rem;
  color: var(--accent-gold);
  margin: 2px 0 6px 0;
  font-weight: bold;
  z-index: 12;
}

/* 15-Line Fully Justified Text Block */
.madinah-text-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  text-align: justify;
  text-justify: inter-word;
  font-family: 'Amiri Quran', serif;
  font-size: clamp(1.12rem, 4vw, 1.4rem);
  line-height: 2.2;
  padding: 4px 6px;
  color: var(--text-main);
  direction: rtl;
  overflow: hidden;
  z-index: 12;
}

/* Verse Badges with Golden Rosettes */
.madinah-verse-rosette {
  color: var(--accent-gold);
  font-size: 0.9em;
  font-weight: 900;
  padding: 0 3px;
  display: inline-block;
  white-space: nowrap;
}

/* Outer Footer: Centered Page Number */
.madinah-outer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px 2px 8px;
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--accent-gold);
  border-top: 1px solid var(--border-theme);
  z-index: 12;
}



/* ==========================================================
   AUTHENTIC COMPACT QURANIC PAGE LAYOUT (Calibrated Dimensions)
   ========================================================== */
.quran-compact-page {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: clamp(14px, 2.8vh, 24px) clamp(20px, 4.8vw, 38px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: transparent;
  color: var(--text-main);
  direction: rtl;
  user-select: none;
  overflow: hidden;
  position: relative;
}

.quran-surah-title-calligraphy {
  text-align: center;
  font-family: 'Amiri Quran', serif;
  font-weight: 700;
  font-size: clamp(1.4rem, 4.8vw, 2.0rem);
  color: var(--text-main);
  margin: 4px 0 2px 0;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.quran-basmalah-calligraphy {
  text-align: center;
  font-family: 'Amiri Quran', serif;
  font-weight: 700;
  font-size: clamp(1.2rem, 4vw, 1.65rem);
  color: var(--text-main);
  margin: 2px 0 8px 0;
  flex-shrink: 0;
}

.quran-text-compact {
  text-align: justify;
  text-justify: inter-word;
  font-family: 'Amiri Quran', serif;
  font-weight: 700;
  font-size: clamp(1.15rem, min(4.2vw, 2.35vh), 1.62rem);
  line-height: 1.84;
  letter-spacing: 0.15px;
  word-spacing: 0.4px;
  color: var(--text-main);
  margin: auto 0;
  word-break: normal;
  overflow-wrap: break-word;
}

/* Unified Al-Fatiha 7-line Layout (Same font & weight as all pages) */
.fatiha-line {
  text-align: center;
  font-family: 'Amiri Quran', serif;
  font-weight: 700;
  font-size: clamp(1.18rem, min(4.4vw, 2.45vh), 1.68rem);
  line-height: 1.88;
  color: var(--text-main);
  margin: 2px 0;
}

/* Traditional Quranic Verse Rosette */
.mushaf-verse-end {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 1.55em;
  height: 1.55em;
  vertical-align: middle;
  margin: 0 4px;
}

.verse-rosette-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  color: var(--text-main);
}

.verse-rosette-num {
  position: relative;
  font-family: 'Amiri Quran', 'Amiri', serif;
  font-size: 0.56em;
  font-weight: 900;
  color: var(--text-main);
  line-height: 1;
  text-align: center;
  margin-top: 1px;
}
