:root {
  --bg: #f5f1e6;
  --bg-elevated: #ffffff;
  --text: #1c2b23;
  --text-dim: #5a6b60;
  --primary: #0f4d3f;
  --primary-light: #17694f;
  --accent: #c9973a;
  --border: #e2dbc7;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
  --page-bg: #fffdf7;
  --drawer-bg: #ffffff;
  --danger: #b3432c;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

body.dark {
  --bg: #10151a;
  --bg-elevated: #1a2128;
  --text: #eef1ee;
  --text-dim: #9aa6a0;
  --primary: #1c7a5e;
  --primary-light: #21916f;
  --accent: #d9a94b;
  --border: #2a3339;
  --shadow: 0 2px 14px rgba(0,0,0,0.4);
  --page-bg: #ede4cd;
  --drawer-bg: #161c22;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Tahoma', 'Segoe UI', 'Noto Sans Arabic', sans-serif;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ===== Top bar ===== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
  flex-shrink: 0;
}
.app-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 18px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.top-bar .icon-btn { color: #fff; }
.icon-btn:hover, .icon-btn:active { background: rgba(255,255,255,0.15); }
.icon-btn.bookmarked { color: var(--accent); }

/* ===== Page info bar ===== */
.page-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.page-info-center {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 600;
}
.page-info-center #current-surah-name { color: var(--primary); font-weight: 700; }
.dot { opacity: 0.5; }
.nav-arrow {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--primary);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
}
.nav-arrow:active { background: var(--border); }

/* ===== Page viewer ===== */
.page-viewer {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: pan-y;
}
.page-slider {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mushaf-page {
  max-width: 100%;
  max-height: 100%;
  height: 100%;
  width: auto;
  object-fit: contain;
  background: var(--page-bg);
  box-shadow: var(--shadow);
  border-radius: 4px;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 0.15s ease;
}
.mushaf-page.dimmed { opacity: 0.35; }
.page-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--primary);
  pointer-events: none;
}
.page-loading.active { display: flex; }

/* ===== Bottom audio player ===== */
.audio-player {
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + var(--safe-bottom));
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
  flex-shrink: 0;
  z-index: 15;
}
.player-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 8px;
}
.reciter-select-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--primary);
  padding: 6px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  max-width: 60%;
}
.reciter-select-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reciter-select-btn .small { font-size: 10px; opacity: 0.7; }
.player-surah-name {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.time-label {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 34px;
  text-align: center;
}
.progress-bar {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.progress-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  margin-top: -1px;
}
.progress-bar::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  border: none;
  cursor: pointer;
}
.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-top: 4px;
}
.control-btn { color: var(--primary); font-size: 18px; width: 38px; height: 38px; }
.flip { transform: scaleX(-1); }
.play-pause-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(15,77,63,0.35);
}
.play-pause-btn:active { transform: scale(0.95); }

/* ===== Drawer ===== */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s;
  z-index: 30;
}
.drawer-overlay.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed;
  top: 0;
  right: -100%;
  width: min(360px, 88vw);
  height: 100%;
  background: var(--drawer-bg);
  z-index: 40;
  transition: right 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.2);
}
.drawer.open { right: 0; }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.drawer-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  scrollbar-width: none;
}
.drawer-tabs::-webkit-scrollbar { display: none; }
.drawer-tab {
  flex: 1;
  min-width: 74px;
  background: transparent;
  border: none;
  padding: 12px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.drawer-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.drawer-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 14px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  flex-shrink: 0;
  color: var(--text-dim);
}
.drawer-search-wrap.hidden { display: none; }
#drawer-search {
  border: none;
  background: transparent;
  outline: none;
  flex: 1;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 20px;
}
.drawer-panel { display: none; }
.drawer-panel.active { display: block; }

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.list-item:hover, .list-item:active { background: var(--bg); }
.list-item.selected { background: rgba(15,77,63,0.1); }
.list-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 700; font-size: 14px; }
.list-item-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.list-item .fa-check-circle { color: var(--primary); font-size: 16px; }
.list-item .fa-play-circle { color: var(--text-dim); font-size: 15px; }
.list-item .fa-trash { color: var(--danger); font-size: 15px; padding: 6px; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.empty-state i { font-size: 32px; margin-bottom: 10px; display: block; opacity: 0.5; }

.support-content { padding: 20px 12px; text-align: center; }
.support-icon { font-size: 40px; color: var(--accent); margin-bottom: 14px; }
.support-content h3 { font-size: 17px; margin: 0 0 10px; color: var(--primary); }
.support-content p { font-size: 13.5px; color: var(--text-dim); line-height: 1.8; margin: 8px 0; }
.support-list { list-style: none; padding: 0; margin: 16px 0; text-align: right; }
.support-list li { padding: 10px 8px; font-size: 13.5px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.support-list i { color: var(--primary); width: 20px; text-align: center; }
.support-note { font-weight: 700; color: var(--primary); font-size: 15px; margin-top: 16px; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(110px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary);
  color: #fff;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Responsive: tablets/desktop */
@media (min-width: 720px) {
  .mushaf-page { max-width: 480px; }
  .audio-player { padding-inline: 24px; }
}
