/* ============================================
   VARIABLES CSS (thème clair)
   ============================================ */
:root {
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --text-sm: 0.875rem;
  --text-md: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --footer-height: 3.5rem;
  --btn-sm: 2rem;
  --btn-lg: 3.2rem;
  --border-radius: 0.5rem;
  --border-radius-lg: 0.75rem;
  --color-green: #1a5e25;
  --color-blue: #1976d2;
  --color-brown: #6d4c41;
  --color-gray: #6c757d;
  --color-violet: #9c27b0;
  --color-red: #d32f2f;
  --color-gold: #ffaa00;
  --color-white: #ffffff;
  --primary: var(--color-green);
  --primary-dark: #0d4214;
  --primary-light: rgba(26, 94, 37, 0.1);
  --success: var(--color-green);
  --error: var(--color-red);
  --bg: white;
  --surface: #ffffff;
  --surface-alt: #f9f9f9;
  --text: #333333;
  --text-light: #666666;
  --text-lighter: #999999;
  --border: #dddddd;
  --border-dark: #cccccc;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  --shadow-heavy: 0 5px 20px rgba(0, 0, 0, 0.15);
  --overlay-bg: rgba(0, 0, 0, 0.7);
  --menu-bg: #000000;
  --menu-text: #ffffff;
  --menu-border: #333333;
  --badge-search: var(--color-brown);
  --badge-juzhizb: var(--color-blue);
  --quran-text-red: var(--color-red);
  --stat-results: var(--color-red);
  --stat-suras: var(--color-green);
  --tag-bg: var(--primary-light);
  --tag-color: var(--primary);
  --search-text-color: var(--color-red);
  --border-width: 2px;
  --overlay-padding-x: 5px;
  --transition-default: opacity 0.3s ease, background 0.2s, color 0.2s;
  --current-item-bg: rgb(146, 178, 152);
  --mini-bar-bg: #ffffffd7;
}

.night-mode {
  --color-green: #4caf50;
  --color-blue: #64b5f6;
  --color-brown: #bcaaa4;
  --color-gray: #a0a0a0;
  --color-violet: #ce93d8;
  --color-red: #ff6b6b;
  --color-gold: #ffcc00;
  --color-white: #2d2d2d;
  --primary: var(--color-green);
  --primary-dark: #388e3c;
  --primary-light: rgba(76, 175, 80, 0.2);
  --bg: #000000;
  --surface: #1e1e1e;
  --surface-alt: #252525;
  --text: #ffffff;
  --text-light: #b0b0b0;
  --text-lighter: #777777;
  --border: #333333;
  --border-dark: #444444;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-heavy: 0 5px 20px rgba(0, 0, 0, 0.4);
  --badge-search: var(--color-brown);
  --badge-juzhizb: var(--color-blue);
  --quran-text-red: var(--color-red);
  --stat-results: var(--color-red);
  --stat-suras: var(--color-green);
  --search-text-color: var(--color-red);
  --current-item-bg: #2a4a2a;
  --mini-bar-bg: #1a1a1ad7;
}

/* ============================================
   RESET & BASE
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: none;
}

html {
  font-size: 16px;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  direction: rtl;
}

#app {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.page-container {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: env(safe-area-inset-bottom);
}

@font-face {
  font-family: 'MyNotoKufi';
  src: url('./media/NotoKufiArabic-Bold.woff2') format('woff2');
  font-weight: bold;
  font-display: swap;
}

/* ============================================
   HEADER & FOOTER
   ============================================ */
.header {
  position: fixed;
  inset: 10px 5px auto 5px;
  z-index: 1001;
  background: transparent;
  display: flex;
  align-items: center;
  height: var(--footer-height);
  justify-content: space-between;
  transition: var(--transition-default);
}

.footer {
  position: fixed;
  inset: auto 3px 0 3px;
  z-index: 1001;
  background: transparent;
  display: grid !important;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: var(--footer-height);
  transition: opacity 0.3s ease, visibility 0.3s ease;
  transform: translateZ(0);
}

.header.hidden,
.footer.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.footer-item {
  display: flex !important;
  align-items: center;
  min-height: 30px;
}

.footer-item:first-child {
  justify-content: flex-start;
}

.footer-item:last-child {
  justify-content: flex-end;
}

.footer-surah,
.footer-value {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 1rem;
  padding: var(--space-sm) !important;
  color: var(--text);
  font-weight: bold;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.1);
  display: inline-block !important;
  min-width: auto;
  min-height: 30px;
  font-size: var(--text-sm);
  line-height: 1.5 !important;
}

.footer-value {
  color: var(--primary);
}

.night-mode .footer-surah,
.night-mode .footer-value {
  background: rgba(30, 30, 30, 0.7);
}

.footer-surah {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================
   BOUTONS GÉNÉRIQUES
   ============================================ */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  outline: none;
  font-family: inherit;
}

.header-btn {
  width: var(--btn-lg);
  height: var(--btn-lg);
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  color: var(--primary);
  font-size: var(--text-xl);
  box-shadow: var(--shadow);
}

.night-mode .header-btn {
  background: rgba(30, 30, 30, 0.7);
  color: var(--success);
}

.close-btn {
  background: none;
  color: var(--error);
  font-size: 1.8rem;
  width: var(--btn-lg);
  height: var(--btn-lg);
  border-radius: 50%;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-default);
  border: 2px solid transparent;
  line-height: 1;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
}

.close-btn:active {
  transform: scale(0.94);
}

.icon-btn {
  width: var(--btn-sm);
  height: var(--btn-sm);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  cursor: pointer;
  border: 1px solid transparent;
  background: var(--surface-alt);
  transition: var(--transition-default);
  color: var(--primary);
  border-color: var(--border);
}

.night-mode .icon-btn {
  color: var(--success);
}

.icon-btn:hover {
  background: var(--primary-light);
}

.confirm-btn {
  min-width: 80px;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--border-radius);
  font-weight: bold;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition-default);
  line-height: 1.2;
  margin: 0 0.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.confirm-btn.ok {
  background: var(--color-white);
  color: var(--primary);
  border-color: var(--primary);
}

.confirm-btn.ok:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.night-mode .confirm-btn.ok {
  background: #2d2d2d;
  color: var(--success);
  border-color: var(--success);
}

.confirm-btn.cancel {
  background: var(--color-white);
  color: var(--color-gray);
  border-color: var(--color-gray);
}

.confirm-btn.cancel:hover {
  background: #f8f9fa;
  color: #5a6268;
}

.night-mode .confirm-btn.cancel {
  background: #2d2d2d;
  color: var(--color-gray);
  border-color: var(--color-gray);
}

.confirm-btn.blue {
  background: var(--color-white);
  color: var(--color-blue);
  border-color: var(--color-blue);
}

.confirm-btn.blue:hover {
  background: #e3f2fd;
}

.night-mode .confirm-btn.blue {
  background: #2d2d2d;
  color: var(--color-blue);
  border-color: var(--color-blue);
}

.confirm-btn.brown {
  background: var(--color-white);
  color: var(--color-brown);
  border-color: var(--color-brown);
}

.confirm-btn.brown:hover {
  background: #efebe9;
}

.night-mode .confirm-btn.brown {
  background: #2d2d2d;
  color: var(--color-brown);
  border-color: var(--color-brown);
}

.autoscroll-speed-btn {
  font-size: 1.3rem;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.7);
  color: var(--primary) !important;
  border: 1px solid var(--border) !important;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.night-mode .autoscroll-speed-btn {
  background: #2d2d2d !important;
  color: var(--success) !important;
  border-color: var(--border-dark) !important;
}

.autoscroll-speed-btn.visible {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.autoscroll-speed-btn:disabled {
  opacity: 0.3 !important;
  pointer-events: none;
}

.tafsir-font-btn {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--color-white);
  border: 1px solid var(--border);
  color: var(--primary);
  border-radius: 50%;
  font-size: 1.2rem;
  font-weight: bold;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-default);
}

.night-mode .tafsir-font-btn {
  background: #2d2d2d;
  color: var(--success);
  border-color: var(--border-dark);
}

.tafsir-font-btn:hover {
  background: var(--primary-light);
}

/* ============================================
   PAGE SCROLL & IMAGES
   ============================================ */
.page-scroll {
  position: relative;
  z-index: 999;
  flex: 1;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: none;
  touch-action: pan-y;
  padding: 0 !important;
  margin: 0 !important;
}

.page-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--bg);
  position: relative;
}

.page-image {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  aspect-ratio: 700/1100;
  margin: 0;
  padding: 0;
  background-color: #fff;
}

.page-image[data-loaded="false"] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.page-image[data-loaded="true"] {
  opacity: 1;
}

.night-mode .page-image {
  filter: invert(1) hue-rotate(-180deg);
  content-visibility: auto;
}

.night-mode .tajweed-image img,
.night-mode .khatm-page img {
  filter: invert(0.93) hue-rotate(180deg) brightness(0.9) contrast(1.1);
  background-color: var(--bg);
}

/* Mode portrait (book) */
.mode-portrait .page-scroll {
  overflow: hidden;
  display: block;
  height: 100vh;
  width: 100vw;
  position: relative;
  transition: all 0.3s ease;
  background: var(--bg);
  z-index: 1;
}

.mode-portrait .page-wrapper {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  transition: opacity 0.2s ease;
  background: var(--bg);
}

.mode-portrait .page-wrapper.active {
  display: flex;
}

.mode-portrait .portrait-image {
  width: 100%;
  display: block;
  object-fit: fill;
}

/* Mode paysage (scroll) */
.mode-landscape .page-scroll {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  display: block !important;
  scroll-behavior: smooth;
  transition: all 0.3s ease;
}

.mode-landscape .page-wrapper {
  width: 100vw !important;
  display: flex !important;
  transition: none !important;
}

.mode-landscape .landscape-image {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 700 / 1100 !important;
  object-fit: contain !important;
  display: block;
  transition: none !important;
}

/* ============================================
   OVERLAYS (générique & menu)
   ============================================ */
.overlay,
.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 15vh var(--overlay-padding-x) var(--overlay-padding-x) var(--overlay-padding-x);
}

.overlay {
  background: var(--overlay-bg);
}

.menu-overlay {
  background: rgba(0, 0, 0, 0.5);
}

.overlay.show,
.menu-overlay.show {
  display: flex;
}

.overlay-content {
  background: var(--surface);
  width: 100%;
  max-width: 31.25rem;
  max-height: 70vh;
  border-radius: var(--border-radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-heavy);
}

.overlay-content.fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  border-radius: 0;
  position: absolute;
  inset: 0;
  z-index: 10000;
}

.overlay-header {
  height: 3.75rem;
  padding: 0 var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.overlay-header h2 {
  font-family: 'MyNotoKufi', sans-serif;
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.overlay-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: auto !important;
  text-align: justify !important;
  text-align-last: right !important;
}

.menu-content {
  width: 15.625rem;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  background: var(--menu-bg);
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.menu-header {
  padding: var(--space-sm);
  border-bottom: 1px solid var(--menu-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.menu-header h2 {
  color: var(--menu-text);
  font-size: var(--text-lg);
  margin: 0;
  font-family: 'MyNotoKufi', sans-serif;
}

.menu-icon-svg {
  width: 1.375rem;
  height: 1.375rem;
  fill: white;
  stroke: white;
  flex-shrink: 0;
}

.menu-text {
  color: white;
  flex: 1;
  text-align: right;
  font-size: var(--text-md);
  font-family: 'MyNotoKufi', sans-serif;
  padding-right: var(--space-md);
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--menu-border);
  padding: var(--space-md) var(--space-lg);
  width: 100%;
  cursor: pointer;
  color: white;
  transition: background-color 0.2s;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   BADGES UNIFORMES
   ============================================ */
.badge,
.surah-number,
.item-badge,
.sura-badge {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: bold;
  flex-shrink: 0;
  background: var(--primary);
  color: white;
}

.surah-number {
  background: var(--primary);
}

.item-badge {
  --badge-bg: var(--primary);
  background: var(--badge-bg);
}

.item-search .item-badge {
  --badge-bg: var(--badge-search);
}

.item-juzhizb .item-badge {
  --badge-bg: var(--badge-juzhizb);
}

.sura-badge {
  background: var(--primary);
}

.night-mode .sura-badge {
  background: var(--success);
}

/* ============================================
   BOUTONS D'ACTION UNIFORMES
   ============================================ */
.action-icon {
  background: none;
  border: none;
  cursor: pointer;
  width: var(--btn-sm);
  height: var(--btn-sm);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition-default);
  color: var(--text-light);
  flex-shrink: 0;
}

.action-icon.bordered {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--primary);
}

.action-icon.pinned {
  color: var(--color-gold);
}

.action-icon:active {
  transform: scale(0.94);
  background: var(--primary-light);
}

.action-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.night-mode .action-icon:hover,
.night-mode .action-icon:active {
  background: rgba(76, 175, 80, 0.2);
  color: var(--success);
}

.pin-btn:hover,
.info-btn:hover,
.icon-btn--edit:hover,
.icon-btn--replace:hover,
.icon-btn--remove:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.night-mode .pin-btn:hover,
.night-mode .info-btn:hover,
.night-mode .icon-btn--edit:hover,
.night-mode .icon-btn--replace:hover,
.night-mode .icon-btn--remove:hover {
  background: rgba(76, 175, 80, 0.2);
  color: var(--success);
}

/* ============================================
   ÉLÉMENTS DE LISTE (harmonisés)
   ============================================ */
.item-container {
  padding: 0 3px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  width: 100%;
  transition: background 0.2s ease;
}

.item-container:last-child {
  border-bottom: none;
}

.item-container.current-item {
  background-color: var(--current-item-bg);
}

.item-container.current-item .item-title,
.item-container.current-item .page-tag,
.item-container.current-item .item-sajda-icon {
  color: var(--quran-text-red) !important;
}

.item-line-1,
.item-line-2,
.item-line-3 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  gap: var(--space-sm);
}

.item-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex: 1;
  min-width: 0;
}

.item-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-left: 5px;
  flex-shrink: 0;
}

.item-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  font-size: var(--text-md);
}

.item-sajda-icon {
  color: var(--primary);
  font-size: 1.25em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.page-tag {
  background: var(--tag-bg);
  color: var(--tag-color);
  padding: 3px 6px;
  border-radius: var(--border-radius);
  font-weight: 600;
  font-size: var(--text-sm);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  min-width: 3.2rem;
  justify-content: right;
}

/* ============================================
   TITRES DE SECTION UNIFORMES
   ============================================ */
.section-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-light);
  padding: var(--space-md) var(--space-lg);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  margin: 0;
  backdrop-filter: blur(4px);
  text-align: right;
}

/* ============================================
   SOURATES (structure spécifique)
   ============================================ */
.surah-section {
  margin-bottom: 1rem;
}

.surah-section-pinned,
.surah-section-all {
  width: 100%;
}

.surah-section-pinned .section-title,
.surah-section-all .section-title {
  background: var(--surface-alt);
  padding: 0.75rem 1rem;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
}

.surah-section-pinned {
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.item-surah {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
}

.item-surah .pin-btn {
  grid-row: 1 / span 2;
  align-self: center;
  justify-self: center;
  margin: 0 3px 0 10px;
}

.item-surah .surah-rows {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  width: 100%;
}

.item-surah .surah-row {
  grid-column: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.item-surah .surah-row-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.item-surah .surah-row-left {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
}

.item-surah .surah-name {
  font-size: var(--text-lg);
  font-weight: 700;
  font-family: 'MyNotoKufi';
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.item-surah .surah-revel,
.item-surah .info-btn {
  font-size: var(--text-lg);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 5px;
  color: var(--text-light);
  transition: var(--transition-default);
}

.item-surah .info-btn:hover {
  color: var(--primary);
}

.item-surah .surah-bookmark {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
}

.item-surah .surah-juz {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  min-width: 2rem;
}

.item-surah .surah-sajda {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
  min-width: 2rem;
}

.item-surah .surah-page {
  grid-column: 3;
  grid-row: 1;
  justify-self: right;
}

.item-surah .surah-verses {
  grid-column: 3;
  grid-row: 2;
  justify-self: right;
}

.item-surah .surah-bookmark,
.item-surah .surah-juz,
.item-surah .surah-page,
.item-surah .surah-sajda,
.item-surah .surah-verses {
  display: flex;
  align-items: center;
  align-self: center;
  gap: 4px;
  min-height: 2rem;
}

.item-surah .surah-juz .juz-badge {
  color: var(--badge-juzhizb, var(--primary));
  font-weight: bold;
  font-size: var(--text-sm);
}

.item-surah .surah-page .page-tag {
  background: var(--tag-bg);
  color: var(--tag-color);
  padding: 2px 6px;
  border-radius: var(--border-radius);
  font-size: var(--text-sm);
}

.item-surah .surah-sajda .item-sajda-icon {
  color: var(--primary);
  font-size: 1.2rem;
}

.item-surah .surah-verses {
  font-size: var(--text-sm);
  color: var(--text-light);
  white-space: nowrap;
}

.item-surah .surah-row-right .note-small {
  min-width: 9ch;
  display: inline-block;
  flex-shrink: 0;
  text-align: right;
}

.surah-info-title {
  font-weight: bold;
  text-decoration: underline;
  font-family: 'MyNotoKufi', sans-serif;
  font-size: var(--text-lg);
  color: var(--color-gold);

}

/* ============================================
   JUZ/HIZB
   ============================================ */
.item-juzhizb .juz-line2,
.item-juzhizb .juz-line3 {
  margin-right: calc(2.2rem + var(--space-md));
  width: auto;
  display: block;
}

.aya-text {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--color-red);
  font-family: 'MyNotoKufi', sans-serif;
  font-size: var(--text-sm);
  margin-bottom: 4px;
}

.note-small {
  color: var(--text-light);
  font-size: var(--text-sm);
  display: block;
}

.item-search,
.item-juzhizb {
  padding: 0 var(--space-sm) !important;
}

/* ============================================
   MARQUE-PAGES (bookmarks)
   ============================================ */
.bookmarks-overlay-content {
  width: 100%;
  padding: 5px 10px 10px 10px;
  margin: 0;
}

.bookmarks-list {
  flex: 1;
  overflow-y: auto;
}

.bookmarks-add-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  flex-direction: row-reverse;
  margin-top: 5px;
  padding: 0;
}

.bookmarks-add-form .search-input {
  flex: 1;
  min-width: 120px;
  padding: var(--space-md);
  border: 1px solid #ccc;
  border-radius: var(--border-radius);
  width: 100%;
}

.bookmarks-add-form .btn {
  flex: 0 0 auto;
  padding: var(--space-md) var(--space-lg);
  border: none;
  border-radius: var(--border-radius);
  font-weight: bold;
  cursor: pointer;
}

.item-bookmark.editing-bookmark {
  background-color: var(--primary-light);
  border: 2px solid var(--primary);
  border-radius: 8px;
}

.bookmarks-button-container {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

/* ============================================
   KHATM
   ============================================ */
.khatm-content {
  flex: 1;
  width: auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: 0;
  gap: 0;
  align-items: stretch;
}

.khatm-page {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.khatm-page img {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  border-radius: 0;
  box-shadow: none;
  margin: 0;
  padding: 0;
}

.tajweed-image img {
  width: 100%;
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  box-shadow: var(--shadow);
}

/* ============================================
   RECHERCHE
   ============================================ */
.search-container {
  padding: 3px;
  background: var(--surface);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

.search-input {
  width: 100%;
  padding: var(--space-md) var(--space-lg);
  padding-left: 40px;
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  font-size: var(--text-md);
  background: var(--surface);
  color: var(--text);
  text-align: right;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.clear-search-btn {
  position: absolute;
  left: 5px;
  top: 0;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-light);
  padding: 0;
  line-height: 1;
  z-index: 10;
  transition: color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-search-btn:hover {
  color: var(--text);
}

.search-stats {
  padding: var(--space-sm) 0;
}

.search-stats-content {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  color: var(--text);
  font-size: var(--text-sm);
  gap: var(--space-sm);
}

.stat-results,
.stat-suras {
  font-weight: bold;
}

.stat-results {
  color: var(--stat-results);
}

.stat-suras {
  color: var(--stat-suras);
}

#searchResults {
  padding: 0;
  text-align: center !important;
}

#searchResults .search-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  color: var(--text-light);
}

#searchResults .search-empty p {
  margin: 0.5rem 0;
  text-align: center;
}

.item-search-text {
  font-family: 'MyNotoKufi', sans-serif;
  font-weight: bold;
  font-size: 14px;
  color: var(--search-text-color);
  text-align: justify !important;
  text-align-last: right !important;
  line-height: 2.2 !important;
  word-spacing: -1px !important;
  padding: 0 var(--overlay-padding-x);
}

.item-search .item-line-2[data-clickable="true"] {
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.item-search .item-line-2[data-clickable="true"]:hover {
  background-color: var(--primary-light);
}

.night-mode .item-search .item-line-2[data-clickable="true"]:hover {
  background-color: rgba(76, 175, 80, 0.2);
}

/* ============================================
   TAFSIR
   ============================================ */
.tafsir-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tafsir-controls .custom-select {
  flex: 1 1 120px;
  min-width: 100px;
}

.tafsir-controls .tafsir-font-btn {
  flex: 0 0 auto;
}

.tafsir-container {
  margin: 0;
  border-radius: 0;
  box-shadow: none;
  border: none;
  background: var(--surface);
}

.tafsir-aya-container {
  margin-bottom: 0;
  padding: 8px 5px;
  border-bottom: var(--border-width) solid var(--border);
  scroll-margin-top: 70px;
}

.tafsir-aya-container:last-child {
  border-bottom: 1px solid var(--border);
}

.tafsir-explanation {
  color: var(--text);
  font-family: 'Segoe UI', sans-serif;
  font-weight: normal;
  text-align: justify !important;
  text-align-last: right !important;
  line-height: 1.5 !important;
  font-size: 16px;
}

.tafsir-content-container {
  padding: 0 var(--overlay-padding-x) !important;
  line-height: 1.8;
  scroll-behavior: auto !important;
  overflow-anchor: none !important;
  text-align: justify !important;
  text-align-last: right !important;
}

#tafsirContent {
  scroll-behavior: auto !important;
  overflow-anchor: none !important;
}

.sura-title-container {
  text-align: center;
  margin: 1.5rem 0 1rem 0;
  padding: 0.5rem 0;
  border-bottom: var(--border-width) solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.sura-name-kufi {
  font-family: 'MyNotoKufi', sans-serif;
  font-weight: bold;
  font-size: 1.5rem;
  color: var(--primary);
  line-height: 1.4;
}

.night-mode .sura-title-container {
  border-bottom-color: var(--success);
}

.night-mode .sura-name-kufi {
  color: var(--success);
}

/* ============================================
   TAJWEED
   ============================================ */
.tajweed-text {
  line-height: 1.9;
  font-size: var(--text-md);
  color: var(--text);
  padding: 5px 2px;
  margin-right: 5px;
  gap: 15px;
  text-align: justify !important;
  text-align-last: right !important;
}

.tajweed-text ul {
  text-align: justify !important;
  text-align-last: right !important;
  padding-right: 10px !important;
}

/* ============================================
   À PROPOS
   ============================================ */
.about-content {
  flex: 1;
  width: auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: var(--space-md);
  gap: var(--space-sm);
  color: var(--text);
  text-align: justify;
  text-align-last: right;
}

.about-content strong {
  color: var(--primary);
}

.night-mode .about-content strong {
  color: var(--success);
}

.about-title {
  text-align: center;
  font-size: var(--text-lg);
  color: var(--primary);
  line-height: 1.5;
}

.night-mode .about-title {
  color: var(--success);
}

.about-version {
  font-size: var(--text-sm);
  color: var(--text-light);
}

.about-desc {
  font-size: var(--text-md);
  line-height: 1.7;
  color: var(--text);
  text-align: justify;
}

.about-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
  margin: var(--space-md) 0;
}

.about-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: var(--space-md);
  gap: 0.25rem;
}

.about-stat span {
  font-size: var(--text-sm);
  color: var(--text-light);
}

.about-stat strong {
  font-size: var(--text-lg);
  font-weight: bold;
  color: var(--primary);
}

.night-mode .about-stat strong {
  color: var(--success);
}

.about-footer {
  text-align: center;
  text-align-last: center;
  font-size: var(--text-sm);
  color: var(--text-light);
  line-height: 1.8;
  margin-top: auto;
  padding-top: var(--space-md);
}

.about-footer a {
  color: var(--primary);
  text-decoration: none;
}

.night-mode .about-footer a {
  color: var(--success);
}

.contact-grid-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 15px 0;
}

.contact-box-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 5px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--border-radius-lg);
  text-decoration: none;
  transition: var(--transition-default);
  min-height: 60px;
  cursor: pointer;
  font-family: inherit;
}

.contact-box-item.contact-green {
  color: var(--primary) !important;
  border-color: var(--primary) !important;
}

.contact-box-item.contact-blue {
  color: var(--color-blue) !important;
  border-color: var(--color-blue) !important;
}

.contact-box-item.contact-brown {
  color: var(--color-brown) !important;
  border-color: var(--color-brown) !important;
}

.contact-box-item.contact-violet {
  color: var(--color-violet) !important;
  border-color: var(--color-violet) !important;
}

.contact-box-item span {
  font-size: var(--text-sm);
  font-weight: bold;
  text-align: center;
}

.contact-box-item:active {
  transform: scale(0.96);
  filter: brightness(0.9);
}

.night-mode .contact-box-item {
  background: #2a2a2a;
}

/* ============================================
   AUDIO – OVERLAY & MINI-BAR
   ============================================ */
.audio-body {
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.audio-riwaya-info {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-light);
  border-radius: var(--border-radius);
  background: var(--surface-alt);
}

.audio-current-info {
  background: var(--surface-alt);
  border-radius: var(--border-radius);
  padding: 0.5rem;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.audio-current-info span {
  white-space: nowrap;
  font-size: var(--text-sm);
  color: var(--text-light);
}

.audio-current-info .audio-current-display {
  flex: 1;
  margin: 0;
  background: transparent;
  border: none;
  color: inherit;
  padding: 0.2rem 0;
  font-size: var(--text-sm);
  text-align: center;
}

.night-mode .audio-current-display {
  background: rgba(76, 175, 80, 0.15);
  color: var(--success);
  border-color: var(--success);
}

.audio-select-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}

#reciterSelect {
  text-align: right;
  text-align-last: right;
}

#surahSelectAudio,
#ayaSelectAudio,
#pageSelectAudio {
  flex: 1 1 120px;
}

.select-ok:focus,
.select-blue:focus,
.select-brown:focus,
.select-violet:focus {
  outline: none;
  border-color: #ff9800 !important;
  box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.3) !important;
}

.audio-progress-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: var(--text-sm);
  color: var(--text-light);
  margin: 0.2rem 0;
}

.audio-progress {
  flex: 1;
  height: 4px;
  accent-color: var(--primary);
  cursor: pointer;
}

.audio-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0.2rem 0;
}

.audio-status {
  text-align: center;
  color: var(--text-light);
  font-size: var(--text-sm);
  padding: 0.3rem;
  display: none;
}

.audio-status:not(:empty) {
  display: block;
}

.audio-warning {
  background: rgba(255, 193, 7, 0.2);
  color: #b45f06;
  padding: var(--space-md);
  border-radius: var(--border-radius);
  font-size: var(--text-sm);
  text-align: center;
  margin-bottom: var(--space-md);
}

.night-mode .audio-warning {
  background: rgba(255, 193, 7, 0.1);
  color: #ffb74d;
}

.audio-btn {
  font-size: 1.2rem;
  width: var(--btn-sm);
  height: var(--btn-sm);
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-default), transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.audio-btn:active {
  transform: scale(0.92);
  background: var(--primary-light);
}

.audio-btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.audio-btn.speed-btn {
  font-family: monospace;
  font-size: 1rem;
  background: var(--surface-alt);
  border-radius: 2rem;
  letter-spacing: -3px;
  padding: 2px 4px;
  min-width: 2.2rem;
}

.audio-controls .audio-btn.speed-btn {
  width: 2.8rem;
  min-width: 2.8rem;
}

.audio-mini-bar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 1200;
  background: var(--mini-bar-bg);
  backdrop-filter: blur(8px);
  transform: translateY(0);
  transition: transform 0.3s ease, opacity 0.3s ease;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.audio-mini-bar .mini-bar-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px 0 10px;
  flex-shrink: 0;
}

.audio-mini-bar.hidden {
  transform: translateY(100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.audio-mini-bar .mini-bar-controls {
  display: flex;
  flex: 1;
  justify-content: space-around;
}

.audio-mini-bar .audio-btn svg {
  width: 30px;
  height: 30px;
}

.audio-controls .audio-btn svg {
  width: 32px;
  height: 32px;
}

.audio-fab {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  left: 1rem;
  z-index: 1100;
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 50%;
  background: var(--mini-bar-bg);
  color: white;
  font-size: 1.5rem;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-heavy);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
  opacity: 1;
  transform: scale(1);
}

.audio-fab.hidden {
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
}

.audio-fab:active {
  transform: scale(0.9);
}

.night-mode .audio-fab {
  background: var(--mini-bar-bg);
}

.fab-indicator {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--text-lighter);
  transition: background-color 0.2s;
}

.audio-fab.playing .fab-indicator {
  background-color: var(--success);
}

/* ============================================
   SÉLECTEURS DE COULEUR (audio & tafsir)
   ============================================ */
.select-ok,
.select-blue,
.select-brown,
.select-violet {
  background-color: var(--color-white);
  border: 1px solid;
}

.select-ok {
  color: var(--primary);
  border-color: var(--primary);
}

.select-blue {
  color: var(--color-blue);
  border-color: var(--color-blue);
}

.select-brown {
  color: var(--color-brown);
  border-color: var(--color-brown);
}

.select-violet {
  color: var(--color-violet);
  border-color: var(--color-violet);
}

.night-mode .select-ok,
.night-mode .select-blue,
.night-mode .select-brown,
.night-mode .select-violet {
  background-color: #2d2d2d;
}

.night-mode .select-ok {
  color: var(--success);
  border-color: var(--success);
}

.night-mode .select-blue {
  color: var(--color-blue);
  border-color: var(--color-blue);
}

.night-mode .select-brown {
  color: var(--color-brown);
  border-color: var(--color-brown);
}

.night-mode .select-violet {
  color: var(--color-violet);
  border-color: var(--color-violet);
}

#pinReciterBtn {
  transition: transform 0.2s, color 0.2s;
}

#pinReciterBtn:active {
  transform: scale(0.9);
}

/* ============================================
   UTILITAIRES & DIVERS
   ============================================ */
.loading-placeholder,
.empty-message {
  text-align: center;
  color: var(--text-light);
  padding: var(--overlay-padding-x);
}

.loading-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: var(--space-lg) auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.spinner.small {
  width: 1.2rem;
  height: 1.2rem;
  border-width: 2px;
  margin: 0;
}

.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: var(--space-md) var(--space-lg);
  border-radius: 10px;
  z-index: 10000;
  max-width: 80%;
  text-align: center;
  display: none;
  font-size: var(--text-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  white-space: pre-line;
  line-height: 1.5;
  font-weight: 500;
}

.autoscroll-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

::-webkit-scrollbar {
  width: 0;
  background: transparent;
}

.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.confirm-dialog {
  background: var(--surface);
  border-radius: var(--border-radius-lg);
  padding: var(--space-lg);
  max-width: 20rem;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-heavy);
}

.confirm-dialog p {
  color: var(--text);
  margin-bottom: var(--space-lg);
  font-size: var(--text-md);
}

.confirm-buttons {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}

.aya-highlight {
  position: absolute;
  background: rgba(3, 167, 243, 0.212);
  border-radius: 4px;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 10;
}

.night-mode .aya-highlight {
  background: rgba(255, 213, 0, 0.2);
}

.error-title {
  color: var(--error);
}

.noscript-fallback {
  text-align: center;
  padding: 2rem;
  font-family: Arial, sans-serif;
  background: #fff;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
}

.noscript-title {
  color: #004494;
}

.hidden {
  display: none !important;
}

/* ============================================
   CUSTOM SELECT — remplacement <select> natif
   ============================================ */
.custom-select {
  position: relative;
  flex: 1;
  min-width: 0;
}

.custom-select-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.6rem;
  border-radius: var(--border-radius);
  font-size: var(--text-md);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  gap: 4px;
  min-height: 2.4rem;
}

.custom-select-val {
  flex: 1;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-arrow {
  flex-shrink: 0;
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.custom-select.open .custom-select-arrow {
  transform: rotate(180deg);
}

.custom-select-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  max-height: 50vh;
  overflow-y: auto;
  z-index: 10050;
  box-shadow: var(--shadow-heavy);
}

.custom-select.open .custom-select-dropdown {
  display: block;
}

.tafsir-controls,
.tafsir-content-container,
.overlay-body {
  overflow-anchor: none;
}

.tafsir-controls {
  overflow: visible;
}

.custom-select-group {
  padding: 0.4rem 0.75rem 0.2rem;
  font-size: var(--text-sm);
  color: var(--text-lighter);
  background: var(--surface-alt);
  font-weight: 600;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.custom-select-option {
  padding: 0.65rem 0.75rem;
  font-size: var(--text-md);
  cursor: pointer;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  min-height: 2.6rem;
  display: flex;
  align-items: center;
}

.custom-select-option:last-child {
  border-bottom: none;
}

.custom-select-option:active,
.custom-select-option.selected {
  background: var(--primary-light);
  color: var(--primary);
}

.night-mode .custom-select-option.selected {
  background: rgba(76, 175, 80, 0.2);
  color: var(--success);
}

.night-mode .custom-select-dropdown {
  background: var(--surface);
  border-color: var(--border-dark);
}

.custom-select-option.reciter-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.reciter-name {
  flex: 1;
  cursor: pointer;
  text-align: right;
}

.custom-select-option.reciter-option.selected {
  background: var(--primary-light);
}

.night-mode .custom-select-option.reciter-option.selected {
  background: rgba(76, 175, 80, 0.2);
}