/* =============================================
   Mushaf Al-Madinah — Digital Edition
   KFGQPC HAFS Uthmanic Script
   ============================================= */

@font-face {
  font-family: 'KFGQPC';
  src: url('fonts/KFGQPC_HAFS_quran.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: block;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --page-w: 560px;
  --page-h: 810px;
  --page-pad-h: 30px;
  --quran-size: 22px;
  --surah-name-size: 24px;
  --bismillah-size: 23px;

  --bg: #0f1117;
  --frame-bg: #16191f;
  --page-bg: #fdf8ef;
  --gold: #c8a84b;
  --gold-light: #e8c97a;
  --gold-dark: #8c6a1a;
  --text-main: #1a0a00;
  --waqf-color: #8B1A1A;          /* authentic Mushaf waqf red */
  --sajdah-color: #8B1A1A;
  --highlight-bg: rgba(255, 200, 40, 0.45);
  --highlight-border: #e8a000;
  --result-hover: rgba(200, 168, 75, 0.12);
  --nav-bg: #1e2130;
  --nav-border: #2e3450;
  --input-bg: #252a3a;
  --input-text: #d0d8f0;
  --btn-bg: #2e3450;
  --btn-hover: #3e4460;
  --panel-bg: #1a1d28;
  --panel-border: #2e3450;
  --tooltip-bg: #1e2130;
  --tooltip-text: #d0d8f0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--input-text);
  font-family: 'Segoe UI', Arial, sans-serif;
  direction: rtl;
  overflow: hidden;
}

.hidden { display: none !important; }

/* =============================================
   NAVIGATION BAR
   ============================================= */
#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  padding: 8px 16px;
  gap: 12px;
  height: 56px;
  flex-shrink: 0;
  z-index: 100;
  position: relative;
}

#nav-right, #nav-left { flex: 1; display: flex; align-items: center; gap: 8px; }
#nav-left  { justify-content: flex-start; }
#nav-right { justify-content: flex-end; }
#brand-home {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  width: 125px;
  height: 40px;
  overflow: hidden;
}
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
#brand-home img { display: block; width: auto; max-width: 100%; height: 40px; object-fit: contain; }
#nav-center { display: flex; align-items: center; gap: 8px; }

#surah-select {
  background: var(--input-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  font-family: 'KFGQPC', 'Traditional Arabic', 'Segoe UI', sans-serif;
  cursor: pointer;
  max-width: 210px;
  direction: rtl;
}
#surah-select:focus { outline: 1px solid var(--gold); }

#page-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
#page-input {
  width: 90px;
  text-align: center;
  background: var(--input-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  direction: rtl;
}
#page-input:focus { outline: 1px solid var(--gold); }
#page-total { color: #888; font-size: 13px; white-space: nowrap; }

#btn-prev, #btn-next,
#btn-prev-result, #btn-next-result {
  background: var(--btn-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
#btn-prev:hover, #btn-next:hover,
#btn-prev-result:hover, #btn-next-result:hover { background: var(--btn-hover); }
#btn-prev:disabled, #btn-next:disabled { opacity: 0.3; cursor: default; }

#search-box { display: flex; align-items: center; gap: 6px; position: relative; }
#search-input {
  width: 230px;
  background: var(--input-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 15px;
  font-family: 'KFGQPC', 'Traditional Arabic', 'Segoe UI', sans-serif;
  direction: rtl;
}
#search-input:focus { outline: 1px solid var(--gold); border-color: var(--gold); }
#search-input::placeholder { font-family: 'Segoe UI', sans-serif; font-size: 13px; }
#search-mode {
  background: var(--input-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
  cursor: pointer;
  direction: rtl;
}
#btn-search {
  background: #2a3a5a;
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
  white-space: nowrap;
}
#btn-search:hover { background: #3a4a6a; }

/* Variations toggle button */
#btn-variations {
  background: var(--btn-bg);
  color: #888;
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
#btn-variations:hover { background: var(--btn-hover); color: var(--input-text); }
#btn-variations.active {
  background: rgba(200, 168, 75, 0.18);
  border-color: var(--gold);
  color: var(--gold);
}
#btn-match-harakat,
#btn-quran-keyboard {
  background: var(--btn-bg);
  color: #888;
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  font-family: 'Segoe UI', sans-serif;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
#btn-match-harakat:hover, #btn-quran-keyboard:hover { background: var(--btn-hover); color: var(--input-text); }
#btn-match-harakat.active, #btn-quran-keyboard[aria-expanded="true"] {
  background: rgba(100, 180, 140, 0.18);
  border-color: #5aaa80;
  color: #5aaa80;
}
#btn-topics,
#btn-tadabbur-paths {
  background: var(--btn-bg);
  color: #888;
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 12px;
  font-family: 'Segoe UI', sans-serif;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
#btn-topics:hover, #btn-tadabbur-paths:hover { background: var(--btn-hover); color: var(--input-text); }
#btn-topics.active, #btn-tadabbur-paths.active { background: rgba(200,168,75,0.18); border-color: var(--gold); color: var(--gold); }

/* ── Search History Dropdown ── */
#search-history-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 260px;
  max-width: 420px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--panel-bg, #1a2035);
  border: 1px solid var(--panel-border, #2a3050);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
  z-index: 600;
  direction: rtl;
  padding: 4px 0;
}
#search-history-dropdown.hidden { display: none; }
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px 4px;
  border-bottom: 1px solid var(--panel-border, #2a3050);
}
.history-title { font-size: 11px; color: var(--text-muted, #888); }
.history-clear-btn {
  background: none; border: none; color: var(--text-muted, #888);
  font-size: 11px; cursor: pointer; padding: 2px 5px; border-radius: 4px;
}
.history-clear-btn:hover { color: #e05; background: rgba(255,0,0,.08); }
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background .12s;
}
.history-item:hover { background: rgba(200,168,75,.08); }
.history-icon { font-size: 12px; color: var(--text-muted, #777); flex-shrink: 0; }
.history-text {
  flex: 1;
  font-size: 14px;
  color: var(--text, #ddd);
  font-family: 'KFGQPC', serif;
  direction: rtl;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-del-btn {
  flex-shrink: 0;
  background: none; border: none; color: transparent;
  font-size: 11px; cursor: pointer; padding: 2px 4px; border-radius: 3px;
  transition: color .12s;
}
.history-item:hover .history-del-btn { color: var(--text-muted, #888); }
.history-del-btn:hover { color: #e05 !important; background: rgba(255,0,0,.08); }
#search-history-dropdown::-webkit-scrollbar { width: 4px; }
#search-history-dropdown::-webkit-scrollbar-thumb { background: #2a3050; border-radius: 2px; }
body.light-mode #search-history-dropdown { background: #f0ead8; border-color: #ccc; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
body.light-mode .history-text { color: #333; }

#topics-panel,
#tadabbur-paths-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: min(680px, calc(100vw - 24px));
  max-height: min(76vh, 720px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 500;
  padding: 10px;
  direction: rtl;
}
.tadabbur-path-header, .tadabbur-path-title, .tadabbur-path-actions, .tadabbur-path-stats { display:flex; align-items:center; gap:8px; }
.tadabbur-path-header, .tadabbur-path-title { justify-content:space-between; }
.tadabbur-path-header { margin-bottom:8px; color:var(--input-text); }
.tadabbur-path-header button { padding:4px 8px; border:1px solid var(--nav-border); border-radius:5px; background:var(--btn-bg); color:var(--input-text); cursor:pointer; }
.tadabbur-path-card { padding:12px; border:1px solid var(--gold-dark); border-radius:9px; background:rgba(200,168,75,.06); color:var(--muted-text); }
.tadabbur-path-card + .tadabbur-path-card { margin-top:10px; }
.tadabbur-path-title strong { color:var(--gold); font-size:1rem; }
.tadabbur-path-title span { padding:2px 7px; border:1px solid var(--gold-dark); border-radius:10px; font-size:.7rem; color:var(--gold); }
.tadabbur-path-card p { margin:8px 0; font-size:.84rem; line-height:1.65; }
.tadabbur-path-stats { flex-wrap:wrap; margin:8px 0; }
.tadabbur-path-stats span { padding:4px 8px; border-radius:5px; background:var(--input-bg); color:var(--input-text); font-size:.76rem; }
.tadabbur-path-card details { margin:9px 0; font-size:.78rem; }
.tadabbur-path-card summary { color:var(--input-text); cursor:pointer; }
.tadabbur-path-actions { flex-wrap:wrap; margin:10px 0 7px; }
.tadabbur-path-actions button { padding:7px 11px; border:1px solid var(--gold-dark); border-radius:6px; background:var(--btn-bg); color:var(--gold); cursor:pointer; font-family:inherit; }
.tadabbur-path-card small { display:block; color:#8f96aa; line-height:1.55; }
#search-mode-note {
  flex: 0 0 auto;
  min-height: 30px;
  display: flex;
  align-items: center;
  padding: 5px 16px;
  border-bottom: 1px solid var(--nav-border);
  background: var(--nav-bg);
  color: #aeb5c8;
  font-family: 'Segoe UI', sans-serif;
  font-size: 12px;
  line-height: 1.55;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
}
#quran-keyboard {
  position: absolute;
  top: calc(100% + 30px);
  right: 0;
  z-index: 130;
  width: min(430px, 92vw);
  padding: 10px;
  border: 1px solid var(--gold-dark);
  border-radius: 8px;
  background: var(--panel-bg);
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
  direction: rtl;
}
.quran-keyboard-header,
.quran-keyboard-group,
.quran-keyboard-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.quran-keyboard-header { justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.quran-keyboard-group { padding: 7px 0; border-top: 1px solid var(--panel-border); }
.quran-keyboard-group > span { width: 90px; color: #8990a5; font-size: 11px; }
.quran-keyboard-group button {
  min-width: 34px;
  min-height: 34px;
  padding: 3px 8px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--input-bg);
  color: var(--input-text);
  font: 24px 'KFGQPC', serif;
  cursor: pointer;
}
.quran-keyboard-group button:hover { border-color: var(--gold); color: var(--gold); }
.quran-keyboard-actions { justify-content: flex-end; padding-top: 8px; border-top: 1px solid var(--panel-border); }
.quran-keyboard-actions button,
#btn-close-quran-keyboard {
  padding: 5px 9px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--btn-bg);
  color: var(--input-text);
  cursor: pointer;
}

.topics-method-note {
  margin: 2px 4px 10px;
  padding: 8px 10px;
  border: 1px solid rgba(200,168,75,0.35);
  border-radius: 6px;
  color: var(--muted-text);
  background: rgba(200,168,75,0.08);
  font-size: 0.78rem;
  line-height: 1.55;
}
.search-template-section-title { margin: 12px 2px 8px; font-size: 0.95rem; color: var(--input-text); }
.search-template-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.search-template-grid.custom { grid-template-columns: 1fr; }
.search-template-card { padding: 10px; border: 1px solid var(--panel-border); border-radius: 8px; background: rgba(255,255,255,.025); min-width: 0; }
.search-template-card-header, .search-template-custom-header, .search-template-form-header, .search-template-actions, .search-template-tools { display: flex; align-items: center; gap: 7px; }
.search-template-card-header, .search-template-custom-header, .search-template-form-header { justify-content: space-between; }
.search-template-card-header strong { color: var(--input-text); font-size: 0.9rem; }
.search-template-badge { padding: 2px 7px; border-radius: 10px; font-size: 0.7rem; border: 1px solid #508cc8; color: #8bb8e8; }
.search-template-badge.synonyms { border-color: #50b464; color: #80d494; }
.search-template-terms { margin-top: 7px; padding: 7px; border-radius: 5px; background: var(--input-bg); color: var(--gold); font: 0.9rem/1.7 'KFGQPC', serif; overflow-wrap: anywhere; }
.search-template-notes, .search-template-empty { margin: 7px 0 0; color: var(--muted-text); font-size: 0.78rem; line-height: 1.5; }
.search-template-actions { margin-top: 8px; flex-wrap: wrap; }
.search-template-actions button, .search-template-tools button, #btn-new-search-template, .search-template-form button { padding: 5px 9px; border: 1px solid var(--nav-border); border-radius: 5px; background: var(--btn-bg); color: var(--input-text); cursor: pointer; font-family: inherit; }
.search-template-actions button:first-child, #btn-save-search-template { border-color: var(--gold-dark); color: var(--gold); }
.search-template-actions .danger { margin-inline-start: auto; color: #e88; }
.search-template-form { margin: 9px 0; padding: 10px; border: 1px solid var(--gold-dark); border-radius: 8px; background: var(--input-bg); }
.search-template-form-row { display: grid; grid-template-columns: 150px 1fr; gap: 8px; }
.search-template-form label { display: grid; gap: 4px; margin-top: 8px; color: var(--muted-text); font-size: 0.78rem; }
.search-template-form input, .search-template-form select, .search-template-form textarea { width: 100%; box-sizing: border-box; padding: 7px 8px; border: 1px solid var(--nav-border); border-radius: 5px; background: var(--panel-bg); color: var(--input-text); font: 0.9rem/1.5 inherit; direction: rtl; resize: vertical; }
.search-template-form small { display: block; margin-top: 4px; color: var(--gold); }
#search-template-form-status { min-height: 1.3em; margin-top: 5px; color: #e88; font-size: 0.75rem; }
.search-template-form-actions, .search-template-tools { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.search-template-tools { padding-top: 9px; border-top: 1px solid var(--panel-border); }
body.light-mode .search-template-card { background: rgba(80,60,20,.035); }
@media (max-width: 620px) {
  #topics-panel, #tadabbur-paths-panel { position: fixed; top: 64px; left: 8px; right: 8px; width: auto; }
  .search-template-grid, .search-template-form-row { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  #brand-home { width: 42px; }
  #brand-home img { width: 125px; max-width: none; height: 40px; object-fit: contain; object-position: left center; }
}
.topics-cat-label {
  font-size: 10px;
  color: #667;
  font-family: 'Segoe UI', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 2px 3px;
  border-top: 1px solid var(--panel-border);
  margin-top: 4px;
}
.topics-cat-label:first-child { border-top: none; margin-top: 0; }
.topics-cat-row { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 2px; }
.topic-chip {
  font-family: 'KFGQPC', serif;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 14px;
  border: 1px solid;
  cursor: pointer;
  transition: opacity 0.1s;
  background: transparent;
}
.topic-chip:hover { opacity: 0.75; }
.topic-cat-عقيدة { color: #8bb8e8; border-color: #508cc8; }
.topic-cat-عبادة { color: #80d494; border-color: #50b464; }
.topic-cat-اخلاق { color: var(--gold); border-color: #c8a84b; }
.topic-cat-اخرة  { color: #c094e8; border-color: #a064c8; }

#btn-clear-search {
  background: var(--btn-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
#btn-clear-search:hover { background: #5a2a2a; }

/* =============================================
   MAIN AREA
   ============================================= */
#main-area {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* =============================================
   QURAN / WORKSPACE TABS
   ============================================= */
#workspace-tabs {
  flex: 0 0 38px;
  height: 38px;
  display: flex;
  align-items: end;
  gap: 4px;
  padding: 5px 12px 0;
  overflow-x: auto;
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
}
#workspace-tab-list { display: contents; }
.workspace-tab, #btn-new-workspace, #btn-workspace-manager, #btn-feature-guide, #btn-report-error, #btn-disclaimer {
  flex: 0 0 auto;
  max-width: 190px;
  padding: 6px 11px;
  border: 1px solid var(--nav-border);
  border-bottom: none;
  border-radius: 7px 7px 0 0;
  background: var(--btn-bg);
  color: #9ba3b8;
  cursor: pointer;
  white-space: nowrap;
}
.workspace-tab.active { background: var(--frame-bg); color: var(--gold); border-color: var(--gold-dark); }
.workspace-tab .tab-close { margin-right: 8px; color: #777; }
#btn-new-workspace { padding: 5px 10px; }
.workspace-tab .tab-close {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  border-radius: 50%;
  color: #8990a0;
  font-size: 12px;
}
.workspace-tab .tab-close:hover { background: rgba(180,70,70,.25); color: #e28b8b; }
#workspace-menu {
  position: fixed;
  top: 94px;
  right: 12px;
  z-index: 180;
  min-width: 260px;
  max-height: 60vh;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--gold-dark);
  border-radius: 7px;
  background: var(--panel-bg);
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
#workspace-menu button { display: block; width: 100%; padding: 8px; border: 0; border-bottom: 1px solid var(--panel-border); background: transparent; color: var(--input-text); text-align: right; cursor: pointer; }
#workspace-menu button:hover { background: var(--result-hover); }
#workspace-menu .workspace-menu-empty { padding: 10px; color: #888; font-size: 12px; }
#workspace-menu .workspace-menu-row { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--panel-border); }
#workspace-menu .workspace-menu-row .workspace-open { flex: 1; border-bottom: 0; }
#workspace-menu .workspace-menu-row .workspace-delete {
  width: auto;
  flex: 0 0 auto;
  border: 1px solid rgba(190,75,75,.45);
  border-radius: 5px;
  color: #e59a9a;
  text-align: center;
}
#workspace-menu .workspace-menu-row .workspace-delete:hover { background: rgba(160,45,45,.25); color: #ffd0d0; }

#workspace-view {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  padding: 18px;
  overflow: auto;
  background: var(--frame-bg);
}
#workspace-toolbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 980px;
  margin: 0 auto;
  padding: 10px;
  background: var(--nav-bg);
  border: 1px solid var(--nav-border);
  border-radius: 8px 8px 0 0;
}
#workspace-title {
  flex: 1 1 240px;
  min-width: 180px;
  padding: 7px 10px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--input-bg);
  color: var(--input-text);
  font-size: 16px;
  direction: rtl;
}
#workspace-toolbar button {
  padding: 6px 9px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--btn-bg);
  color: var(--input-text);
  cursor: pointer;
}
#workspace-save-status { color: #799584; font-size: 11px; }
#workspace-editor {
  min-height: calc(100vh - 190px);
  max-width: 980px;
  margin: 0 auto;
  padding: 38px 52px;
  outline: none;
  background: #fffdf8;
  color: #21180f;
  border: 1px solid #bba77c;
  font: 17px/2 'Segoe UI', Arial, sans-serif;
  box-shadow: 0 12px 35px rgba(0,0,0,.25);
}
#workspace-editor:empty::before { content: attr(data-placeholder); color: #aaa; }
.workspace-ayah-block {
  margin: 16px 0;
  padding: 14px 18px;
  border-right: 4px solid #a7822e;
  border-radius: 5px;
  background: #faf3e4;
}
.workspace-ayah-text { font: 22px/2.1 'KFGQPC', serif; color: #211004; }
.workspace-ayah-ref { margin-top: 5px; color: #80651f; font-size: 12px; }

.ayah-select, .result-ayah-select { accent-color: var(--gold-dark); cursor: pointer; }
.ayah-row.selected { background: rgba(200,168,75,.18); }
.result-select-wrap { display: flex; align-items: center; gap: 7px; }

#selection-bar {
  position: fixed;
  z-index: 170;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--gold-dark);
  border-radius: 10px;
  background: var(--nav-bg);
  box-shadow: 0 10px 30px rgba(0,0,0,.45);
}
#selection-bar button, .context-card button, .context-card select {
  padding: 6px 10px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--btn-bg);
  color: var(--input-text);
  cursor: pointer;
}
#context-dialog, #workspace-picker-dialog {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.7);
}
#feature-guide, .legal-dialog {
  position: fixed;
  inset: 0;
  z-index: 210;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0,0,0,.72);
}
.feature-guide-card {
  width: min(820px, 96vw);
  max-height: 88vh;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--gold-dark);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--input-text);
}
.feature-guide-card section { padding: 12px 2px; border-top: 1px solid var(--panel-border); }
.feature-guide-card h3 { margin-bottom: 6px; color: var(--gold); font-size: 15px; }
.feature-guide-card p { margin: 4px 0; color: #b8bfd0; line-height: 1.7; font-size: 13px; }
.feature-guide-card code { color: var(--gold-light); font: 18px 'KFGQPC', serif; }
.legal-card { direction: rtl; text-align: right; }
.legal-card .context-header strong { color: var(--gold-light); font-size: 18px; }
.legal-card p, .legal-card li { color: #c3c8d5; font-size: 14px; line-height: 1.9; }
.legal-card a { color: var(--gold-light); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.legal-card a:hover { color: #f1d77e; }
.legal-card ul { margin: 6px 0; padding-inline-start: 24px; }
.legal-card .legal-intro { border-top: 0; }
.contact-pending { margin-top: 8px; padding: 12px !important; border: 1px solid rgba(200,168,75,.35) !important; border-radius: 8px; background: rgba(200,168,75,.07); }
.legal-update { margin-top: 14px !important; color: #8f96a9 !important; font-size: 12px !important; }
.context-card {
  width: min(760px, 96vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  border: 1px solid var(--gold-dark);
  border-radius: 10px;
  background: var(--panel-bg);
}
.context-header, .context-controls, .context-actions { display: flex; align-items: center; gap: 12px; }
.context-header { justify-content: space-between; }
.context-controls { margin: 12px 0; flex-wrap: wrap; }
.context-controls label { display: flex; align-items: center; gap: 6px; }
#context-summary { color: #9fa6ba; font-size: 12px; margin-bottom: 8px; }
#context-preview { overflow: auto; padding: 10px; background: #fdf8ef; color: #211004; border-radius: 6px; }
.context-preview-ayah { padding: 8px; font: 20px/1.9 'KFGQPC', serif; border-bottom: 1px solid #eadfc9; }
.context-preview-ayah.selected-context { background: #fff0b8; }
.context-preview-ref { color: #886d2f; font: 11px 'Segoe UI', sans-serif; }
.context-actions { justify-content: flex-end; margin-top: 12px; }

.workspace-picker-card {
  width: min(520px, 96vw);
  max-height: 86vh;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--gold-dark);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--input-text);
}
#workspace-picker-summary { margin: 12px 0 8px; color: #b8bfd0; font-size: 14px; }
#workspace-picker-list { display: grid; gap: 7px; max-height: 40vh; overflow: auto; }
.workspace-picker-option, .workspace-picker-new {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--nav-border);
  border-radius: 7px;
  background: var(--input-bg);
  cursor: pointer;
}
.workspace-picker-option:has(input:checked), .workspace-picker-new:has(input:checked) {
  border-color: var(--gold);
  background: rgba(200,168,75,.12);
}
.workspace-picker-option small { grid-column: 2; color: #8f96a9; font-size: 12px; }
.workspace-picker-new { margin-top: 8px; }
#workspace-picker-new-title {
  grid-column: 2;
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--panel-bg);
  color: var(--input-text);
  font: inherit;
}
#workspace-picker-dialog button {
  padding: 7px 11px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--btn-bg);
  color: var(--input-text);
  cursor: pointer;
}

/* =============================================
   MUSHAF FRAME
   ============================================= */
#mushaf-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 12px 16px;
  background: var(--frame-bg);
}

/* Page info bars */
#page-header, #page-footer {
  width: var(--page-w);
  max-width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: #999;
  padding: 4px 8px;
  direction: rtl;
}
#header-surah-name {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: 14px;
  color: var(--gold-dark);
  letter-spacing: 0;
}
#header-rub { font-size: 11px; }
#footer-page-num {
  font-family: 'KFGQPC', serif;
  font-size: 14px;
  color: var(--gold-dark);
  background: transparent;
  padding: 2px 8px;
  border-top: 1px solid var(--gold-dark);
  border-bottom: 1px solid var(--gold-dark);
}

/* The actual Mushaf page */
#mushaf-page {
  width: var(--page-w);
  height: var(--page-h);
  max-width: 100%;
  background: var(--page-bg);
  border: 2px solid var(--gold);
  border-radius: 2px;
  box-shadow:
    0 0 0 4px var(--frame-bg),
    0 0 0 5px var(--gold-dark),
    0 20px 60px rgba(0,0,0,0.6);
  position: relative;
  overflow: visible;   /* allow diacritics to overflow border */
  display: flex;
  flex-direction: column;
}

/* Inner decorative border lines */
#mushaf-page::before,
#mushaf-page::after {
  content: '';
  position: absolute;
  left: 8px; right: 8px;
  height: 1.5px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  z-index: 1;
  pointer-events: none;
}
#mushaf-page::before { top: 10px; }
#mushaf-page::after  { bottom: 10px; }

#page-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  font-family: 'KFGQPC', serif;
  font-size: 18px;
  color: var(--gold);
  z-index: 10;
  border-radius: 2px;
}

/* =============================================
   PAGE CONTENT — AYAH-PER-ROW FLOW LAYOUT
   ============================================= */
#page-content {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px var(--page-pad-h) 20px;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
  gap: 0;
}
#page-content::-webkit-scrollbar { width: 4px; }
#page-content::-webkit-scrollbar-thumb { background: var(--gold-dark); border-radius: 2px; opacity: 0.5; }

/* =============================================
   SURAH HEADER
   ============================================= */
.surah-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 4px;
  margin: 6px 0 2px;
}

.surah-banner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #F0E8D0;    /* authentic warm cream, no gradient */
  border: 1.5px solid var(--gold);
  border-radius: 3px;
  position: relative;
  padding: 4px 28px;
  overflow: hidden;
  min-height: 36px;
}

/* Authentic Arabic ornamental brackets ﴾ ﴿ (U+FD3E / U+FD3F) */
.surah-banner::before {
  content: '﴾'; /* U+FD3E — ornamental OPENER on the RIGHT in RTL */
  position: absolute;
  right: 6px; top: 50%; transform: translateY(-50%);
  color: var(--gold); font-size: 20px;
  font-family: 'Traditional Arabic', 'Arabic Typesetting', 'Scheherazade New',
               'Noto Naskh Arabic', 'Arial Unicode MS', 'Segoe UI', serif;
}
.surah-banner::after {
  content: '﴿'; /* U+FD3F — ornamental CLOSER on the LEFT in RTL */
  position: absolute;
  left: 6px; top: 50%; transform: translateY(-50%);
  color: var(--gold); font-size: 20px;
  font-family: 'Traditional Arabic', 'Arabic Typesetting', 'Scheherazade New',
               'Noto Naskh Arabic', 'Arial Unicode MS', 'Segoe UI', serif;
}

.surah-name-ar {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: var(--surah-name-size);
  color: var(--text-main);
  line-height: 1.1;
  text-align: center;
  direction: rtl;
}

.surah-info {
  font-size: 11px;
  color: var(--gold-dark);
  font-family: 'KFGQPC', 'Traditional Arabic', 'Segoe UI', sans-serif;  /* I2: use Arabic font */
  text-align: center;
  margin-top: 1px;
}

/* Bismillah — separate row below banner */
.surah-bismillah {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: var(--bismillah-size);
  color: var(--text-main);
  text-align: center;
  direction: rtl;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 0 2px;
}

/* =============================================
   AYAH ROWS — one per ayah, words wrap naturally
   ============================================= */
.ayah-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  direction: rtl;
  padding: 8px 4px 6px;
  position: relative;
  overflow: visible;
  transition: background 0.12s;
  line-height: 1.9;          /* generous line-height so diacritics above/below don't clip */
  border-bottom: 1px solid rgba(200, 168, 75, 0.10);  /* subtle gold separator */
}
.ayah-row:last-child { border-bottom: none; }
.ayah-row:hover { background: rgba(200, 168, 75, 0.08); }

/* I4/I6: Al-Fatiha Basmala (1:1) — centered and visually elevated like printed Mushaf */
.ayah-row[data-surah="1"][data-ayah="1"] {
  justify-content: center;
  padding: 10px 4px 16px;
}
.ayah-row[data-surah="1"][data-ayah="1"] .ayah-text {
  flex: none;
  justify-content: center;
  font-size: 1.08em;
}

/* keep legacy class name in case any old code references it */
.quran-line { display: flex; flex-direction: row; direction: rtl; align-items: center; }

/* =============================================
   AYAH ROW INTERNALS
   ============================================= */

/* Text container — fills remaining space */
.ayah-text {
  flex: 1;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  direction: rtl;
  overflow: visible;
}

/* Action buttons container — far left in RTL row */
.ayah-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.15s;
  margin-inline-end: 2px;
}
.ayah-row:hover .ayah-actions { opacity: 1; }
.ayah-row:has(.ayah-bkmk-btn.bookmarked) .ayah-actions { opacity: 1; }

.ayah-copy-btn,
.ayah-bkmk-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: #668;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  line-height: 1;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.ayah-copy-btn:hover { background: rgba(200,168,75,0.15); color: var(--gold); border-color: var(--gold-dark); }
.ayah-bkmk-btn:hover { background: rgba(200,168,75,0.15); color: var(--gold); border-color: var(--gold-dark); }
.ayah-bkmk-btn.bookmarked { color: var(--gold); }

.quran-small-meem {
  display: inline-block;
  position: relative;
  width: 0;
  margin: 0;
  vertical-align: baseline;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}
#mushaf-sheet {
  flex: 0 0 auto;
  width: var(--page-w);
  display: flex;
  flex-direction: column;
  align-items: center;
  transform-origin: center center;
}
.quran-small-meem::before {
  content: 'م';
  position: absolute;
  inset-inline-start: -0.18em;
  top: 0.72em;
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: 0.24em;
  line-height: 1;
  color: currentColor;
}
.quran-small-meem.after-alef::before {
  inset-inline-start: auto;
  left: 0;
  transform: translateX(0.48em);
}

/* =============================================
   WORDS
   ============================================= */
.word {
  font-family: 'KFGQPC', 'Traditional Arabic', 'Scheherazade New', serif;
  font-size: var(--quran-size);
  color: var(--text-main);
  direction: rtl;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 3px;
  transition: background 0.12s;
  line-height: 1.9;
  white-space: nowrap;
  user-select: text;
  position: relative;
}

.word:hover { background: rgba(200, 168, 75, 0.18); }

.word.highlighted {
  background: var(--highlight-bg);
  border-radius: 3px;
  outline: 1px solid var(--highlight-border);
}

.word.search-current {
  background: rgba(255, 120, 40, 0.42);
  outline: 1.5px solid #e85000;
}

/* OR search: per-term highlight colors (term 0 = existing .highlighted gold) */
.word.highlighted-1 { background: rgba(80,140,200,0.28); border-radius:3px; outline:1px solid #508cc8; }
.word.highlighted-2 { background: rgba(80,180,100,0.28); border-radius:3px; outline:1px solid #50b464; }
.word.highlighted-3 { background: rgba(160,100,200,0.28); border-radius:3px; outline:1px solid #a064c8; }
.word.highlighted-4 { background: rgba(220,130,60,0.28);  border-radius:3px; outline:1px solid #dc8230; }
mark.result-hit-1 { background: rgba(80,140,200,0.3);  color:inherit; border-radius:3px; padding:0 2px; font-weight:bold; }
mark.result-hit-2 { background: rgba(80,180,100,0.3);  color:inherit; border-radius:3px; padding:0 2px; font-weight:bold; }
mark.result-hit-3 { background: rgba(160,100,200,0.3); color:inherit; border-radius:3px; padding:0 2px; font-weight:bold; }
mark.result-hit-4 { background: rgba(220,130,60,0.3);  color:inherit; border-radius:3px; padding:0 2px; font-weight:bold; }

/* Mushaf layout markers are independent siblings, not clickable word text. */
.quran-layout-marker {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  pointer-events: none;
  user-select: none;
  cursor: default;
  flex: 0 0 auto;
}
.section-marker { color: var(--gold-dark); font-size: 0.9em; margin: 0 2px; }
.sajdah-marker { color: var(--sajdah-color); font-size: 0.62em; margin: 0 3px; vertical-align: super; }

/* Waqf mark — I1 fix: superscript above word, not inline at baseline */
.waqf-mark {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: 0.75em;
  color: var(--waqf-color);   /* authentic Mushaf red */
  direction: rtl;
  pointer-events: none;
  cursor: default;
  user-select: none;
  padding: 0;
  line-height: 1;
  white-space: nowrap;
  vertical-align: super;   /* float above baseline like superscript */
  position: relative;
  top: 0.1em;              /* fine-tune vertical alignment */
}

/* Ayah end marker — plain inline number */
.ayah-marker {
  display: inline;
  color: var(--gold-dark);
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: 0.95em;
  direction: rtl;
  cursor: default;
  pointer-events: none;
  margin: 0 4px;
  vertical-align: middle;
  flex-shrink: 0;
}


/* =============================================
   SEARCH PANEL
   ============================================= */
#search-panel {
  width: 320px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.quran-hamza-key { display: inline-flex !important; align-items: center; justify-content: center; width: auto !important; min-width: 78px; padding-inline: 7px !important; gap: 5px; }
.quran-hamza-key span { font-family: 'Segoe UI', sans-serif; font-size: 10px; color: #aeb5c8; }
#search-panel.tadabbur-mode { width: min(430px, 38vw); }
#search-panel.tadabbur-mode #search-panel-header { flex-direction: column; align-items: stretch; padding: 12px 14px 9px; }
#search-panel.tadabbur-mode #search-panel-controls { justify-content: flex-end; flex-wrap: wrap; padding-top: 8px; border-top: 1px solid var(--panel-border); }
#search-panel.tadabbur-mode #search-results-count { display: grid; gap: 2px; line-height: 1.45; }
#search-panel.tadabbur-mode #search-results-count strong { color: var(--gold); font-size: 16px; }
#search-panel.tadabbur-mode #search-results-count small { color: #8f96aa; font: 12px/1.4 'Segoe UI', sans-serif; }
.path-result-kicker { color: #8f96aa; font: 11px/1.3 'Segoe UI', sans-serif; }
#search-panel.tadabbur-mode .search-result-item { padding: 12px 16px; }
#search-panel.tadabbur-mode .result-text { font-size: 19px; line-height: 2.1; }
#search-panel.tadabbur-mode .result-ref { font-size: 12px; }
#search-panel.tadabbur-mode .result-group-header { padding: 9px 14px; }

#search-panel-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: #20243a;
  gap: 8px;
  flex-shrink: 0;
}

#search-results-count {
  font-size: 13px;
  color: #aab;
  font-family: 'KFGQPC', serif;
  direction: rtl;
  min-width: 0;
  overflow-wrap: anywhere;
}

#search-panel-controls { display: flex; align-items: center; justify-content: flex-start; flex-wrap: wrap; gap: 5px; }
#search-result-pos {
  font-size: 15px;
  font-weight: 600;
  color: #d5d9e6;
  min-width: 118px;
  text-align: center;
  white-space: nowrap;
}
#btn-select-all-results {
  min-width: 72px;
  padding: 5px 8px;
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  background: var(--btn-bg);
  color: var(--input-text);
  font: 12px/1.2 'Segoe UI', sans-serif;
  white-space: nowrap;
  cursor: pointer;
}
#btn-select-all-results:hover { background: var(--btn-hover); border-color: var(--gold-dark); }

#btn-close-search {
  background: transparent; border: none; color: #888;
  cursor: pointer; padding: 4px 6px; font-size: 14px; border-radius: 4px;
}
#btn-close-search:hover { background: #3a2a2a; color: #f88; }

#sort-select {
  background: var(--input-bg, #1a2035);
  color: var(--text-muted, #aaa);
  border: 1px solid var(--nav-border, #2a3050);
  border-radius: 5px;
  padding: 2px 5px;
  font-size: 11px;
  font-family: 'KFGQPC', serif;
  direction: rtl;
  cursor: pointer;
  max-width: 110px;
}
#sort-select:focus { outline: 1px solid var(--gold); }
body.light-mode #sort-select { background: #e8e0cc; color: #333; border-color: #bbb; }
#btn-copy-results, #btn-export-txt {
  background: transparent; border: none; color: #888;
  cursor: pointer; padding: 4px 5px; font-size: 13px; border-radius: 4px;
}
#btn-copy-results:hover, #btn-export-txt:hover { background: #2a3050; color: var(--gold); }
#btn-copy-results:disabled, #btn-export-txt:disabled { opacity: 0.5; cursor: wait; }

#search-results-list { flex: 1; overflow-y: auto; direction: rtl; }
#search-results-limit-note {
  padding: 8px 12px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(200, 168, 75, 0.09);
  color: #c9b36f;
  font: 12px/1.65 'Segoe UI', sans-serif;
  text-align: right;
}
body.light-mode #search-results-limit-note {
  background: rgba(120, 90, 20, 0.08);
  color: #705a20;
}
#search-results-list::-webkit-scrollbar { width: 4px; }
#search-results-list::-webkit-scrollbar-thumb { background: #3a4060; border-radius: 2px; }

.search-result-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--panel-border);
  cursor: pointer;
  direction: rtl;
  transition: background 0.1s;
}
.search-result-item:hover { background: var(--result-hover); }
.search-result-item.active {
  background: rgba(200, 168, 75, 0.13);
  border-right: 2px solid var(--gold);
}

.result-ref {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  margin-bottom: 7px;
  font-family: 'Segoe UI', sans-serif;
  direction: rtl;
}
.result-hit-count {
  display: inline-block;
  margin-right: 7px;
  padding: 1px 6px;
  border: 1px solid rgba(200, 168, 75, 0.38);
  border-radius: 9px;
  color: var(--gold);
  font: 11px/1.5 'Segoe UI', sans-serif;
  white-space: nowrap;
}
.result-text {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: 17px;
  color: var(--input-text);
  direction: rtl;
  line-height: 2;
  white-space: normal;
  overflow-wrap: break-word;
}
mark.result-hit {
  background: rgba(200, 168, 75, 0.3);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
  font-weight: bold;
}

#search-summary-card {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 12px 10px;
  background: #181c2e;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
  direction: rtl;
}
.summary-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 52px;
}
.summary-num {
  font-size: 23px;
  font-weight: 700;
  font-family: 'KFGQPC', serif;
  color: var(--gold);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.summary-lbl {
  font-size: 12px;
  color: #aeb4c6;
  font-family: 'Segoe UI', sans-serif;
  line-height: 1.2;
}
.summary-divider {
  width: 1px;
  height: 38px;
  background: var(--panel-border);
}
body.light-mode #search-summary-card { background: #e0dbd0; }
body.light-mode #search-result-pos { color: #343843; }
body.light-mode .summary-lbl { color: #575b66; }

@media (max-width: 520px) {
  #search-result-pos { font-size: 14px; min-width: 108px; }
  #search-summary-card { padding: 10px 6px; }
  .summary-stat { min-width: 46px; }
  .summary-num { font-size: 21px; }
  .summary-lbl { font-size: 11px; }
  .result-ref { font-size: 13px; }
}

#search-or-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 12px;
  background: #1a1e30;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
  direction: rtl;
}
.or-chip {
  font-family: 'KFGQPC', serif;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid;
}
.or-chip-count { font-size: 10px; opacity: 0.8; }
.or-chip-0 { background: rgba(200,168,75,0.2);  border-color: var(--gold);  color: var(--gold); }
.or-chip-1 { background: rgba(80,140,200,0.2);  border-color: #508cc8; color: #8bb8e8; }
.or-chip-2 { background: rgba(80,180,100,0.2);  border-color: #50b464; color: #80d494; }
.or-chip-3 { background: rgba(160,100,200,0.2); border-color: #a064c8; color: #c094e8; }
.or-chip-4 { background: rgba(220,130,60,0.2);  border-color: #dc8230; color: #ecaa60; }
body.light-mode #search-or-legend { background: #e8e4d8; }

#search-scope-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: #1e2236;
  border-bottom: 1px solid var(--panel-border);
  flex-shrink: 0;
  direction: rtl;
}
#search-scope-bar select {
  flex: 1;
  background: var(--input-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 11px;
  font-family: 'KFGQPC', serif;
  direction: rtl;
  cursor: pointer;
  min-width: 0;
}
#search-scope-bar select:focus { outline: 1px solid var(--gold); }
#btn-this-surah {
  flex-shrink: 0;
  background: rgba(200,168,75,.12);
  color: var(--gold, #c8a84b);
  border: 1px solid rgba(200,168,75,.35);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11px;
  font-family: 'KFGQPC', serif;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
#btn-this-surah:hover {
  background: rgba(200,168,75,.25);
  border-color: var(--gold, #c8a84b);
}
body.light-mode #search-scope-bar { background: #dedad0; }
body.light-mode #btn-this-surah { background: rgba(120,90,20,.1); border-color: rgba(120,90,20,.4); }

.result-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: #1a1e32;
  border-bottom: 1px solid var(--panel-border);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 1;
}
.result-group-header:hover { background: #1e2340; }
.result-group-arrow { font-size: 11px; color: #667; flex-shrink: 0; }
.result-group-name {
  font-family: 'KFGQPC', serif;
  font-size: 14px;
  color: var(--gold);
  direction: rtl;
  flex: 1;
}
.result-group-count {
  font-size: 11px;
  color: #888;
  background: #2a2e48;
  border-radius: 10px;
  padding: 1px 7px;
  flex-shrink: 0;
}
.result-group.collapsed .search-result-item { display: none; }

/* =============================================
   BOOKMARKS PANEL
   ============================================= */
#bookmarks-panel {
  width: 280px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

#bookmarks-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #20243a;
  font-size: 13px;
  color: var(--gold);
  font-family: 'Segoe UI', sans-serif;
  direction: rtl;
  flex-shrink: 0;
}

#btn-close-bookmarks {
  background: transparent; border: none; color: #888;
  cursor: pointer; padding: 4px 6px; font-size: 14px; border-radius: 4px;
}
#btn-close-bookmarks:hover { background: #3a2a2a; color: #f88; }

#bookmarks-list { flex: 1; overflow-y: auto; direction: rtl; }
#bookmarks-list::-webkit-scrollbar { width: 4px; }
#bookmarks-list::-webkit-scrollbar-thumb { background: #3a4060; border-radius: 2px; }

.bookmark-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--panel-border);
  cursor: pointer;
  direction: rtl;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.1s;
}
.bookmark-item:hover { background: var(--result-hover); }

.bookmark-ref {
  font-size: 13px;
  color: var(--input-text);
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
}

.bookmark-remove {
  background: transparent; border: none; color: #668;
  cursor: pointer; padding: 2px 6px; font-size: 12px; border-radius: 3px;
  flex-shrink: 0;
}
.bookmark-remove:hover { background: #3a2a2a; color: #f88; }

/* =============================================
   WORD TOOLTIP
   ============================================= */
#word-tooltip {
  position: fixed;
  background: var(--tooltip-bg);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 14px 16px 10px;
  min-width: 230px;
  max-width: 310px;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  direction: rtl;
}

#tooltip-close {
  position: absolute; top: 6px; left: 8px;
  background: transparent; border: none; color: #888;
  cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 3px;
}
#tooltip-close:hover { background: #3a2a2a; color: #f88; }

#tooltip-visual {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: 30px;
  color: var(--gold-light);
  text-align: center;
  margin-bottom: 10px;
  direction: rtl;
  line-height: 1.4;
}

#tooltip-rows { font-size: 13px; color: #aab; line-height: 1.8; }
.tooltip-row {
  display: flex; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid #2a3050; padding: 2px 0;
}
.tooltip-label { color: #9aa2b8; min-width: 92px; flex-shrink: 0; }
.tooltip-val {
  font-family: 'KFGQPC', 'Traditional Arabic', serif;
  font-size: 14px; color: var(--tooltip-text); direction: rtl;
  text-align: right;   /* M4 fix: right = logical start in RTL, aligns Arabic text correctly */
}

#tooltip-copy {
  display: block;
  margin: 8px auto 0;
  background: #2a3450; color: #aab; border: 1px solid #3a4060;
  border-radius: 4px; padding: 4px 12px; cursor: pointer; font-size: 12px;
}
#tooltip-copy:hover { background: #3a4470; }
#tooltip-copy.copied { color: #6c6; border-color: #4a6a4a; }

/* =============================================
   SCROLLBAR
   ============================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #3a4060; border-radius: 3px; }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 720px) {
  :root {
    --page-w: 560px;
    --page-h: 810px;
    --quran-size: 17px;
    --page-pad-h: 14px;
  }
  #search-panel { width: min(90vw, 320px); }
  #search-input { width: 190px; }
  #surah-select { max-width: 180px; font-size: 13px; }
  #navbar {
    height: auto;
    display: grid;
    grid-template-columns: 1fr;
    padding: 6px 8px;
    gap: 6px;
  }
  #nav-right, #nav-center, #nav-left {
    flex: none;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  #nav-right::-webkit-scrollbar, #nav-center::-webkit-scrollbar, #nav-left::-webkit-scrollbar,
  #workspace-tabs::-webkit-scrollbar { display: none; }
  #nav-right { order: 1; justify-content: space-between; }
  #nav-center { order: 2; justify-content: center; }
  #nav-left { order: 3; justify-content: flex-start; }
  #brand-home { width: 112px; }
  #main-area, #workspace-view { height: auto; flex: 1 1 auto; min-height: 0; }
  #workspace-tabs { scrollbar-width: none; }
  #mushaf-frame {
    justify-content: flex-start;
    padding: 10px 8px 24px;
    overscroll-behavior: contain;
  }
  #mushaf-sheet { transform-origin: top center; margin: 0 auto; }
  #workspace-editor { padding: 22px 18px; }
  #selection-bar { width: calc(100vw - 18px); overflow-x: auto; justify-content: flex-start; }
}
#tooltip-explanation {
  margin: 9px 0 7px;
  padding-top: 8px;
  border-top: 1px solid var(--panel-border);
  color: #8f96a9;
  font: 12px/1.6 'Segoe UI', sans-serif;
}

/* =============================================
   FONT SIZE SLIDER
   ============================================= */
#font-ctrl {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #888;
}
#font-ctrl .fs-sm { font-size: 13px; font-family: 'KFGQPC', serif; }
#font-ctrl .fs-lg { font-size: 20px; font-family: 'KFGQPC', serif; }
#font-size-slider {
  -webkit-appearance: none;
  width: 80px;
  height: 4px;
  border-radius: 2px;
  background: var(--nav-border);
  outline: none;
  cursor: pointer;
}
#font-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--gold);
  cursor: pointer;
}

#btn-theme, #btn-scroll, #btn-bookmarks {
  background: var(--btn-bg);
  color: var(--input-text);
  border: 1px solid var(--nav-border);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s;
  white-space: nowrap;
}
#btn-theme:hover, #btn-scroll:hover, #btn-bookmarks:hover { background: var(--btn-hover); }
#btn-scroll.active, #btn-bookmarks.active {
  background: rgba(200, 168, 75, 0.2);
  border-color: var(--gold);
  color: var(--gold);
}

/* =============================================
   PROGRESS BAR (inside navbar, bottom edge)
   ============================================= */
#progress-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  pointer-events: none;
}
#progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold));
  transition: width 0.4s ease;
}

/* =============================================
   LIGHT MODE
   ============================================= */
body.light-mode {
  --bg: #e8e0d0;
  --frame-bg: #d8cfbf;
  --page-bg: #fdf8ef;
  --text-main: #1a0a00;
  --nav-bg: #c8bfaf;
  --nav-border: #a89880;
  --input-bg: #f0e8d8;
  --input-text: #2a1800;
  --btn-bg: #d8cfbf;
  --btn-hover: #c8bfaf;
  --panel-bg: #f0e8d8;
  --panel-border: #c8b898;
  --tooltip-bg: #f0e8d8;
  --tooltip-text: #2a1800;
}
body.light-mode #navbar { border-bottom-color: var(--nav-border); }
body.light-mode .search-result-item { border-bottom-color: var(--panel-border); }
body.light-mode .result-group-header { background: #e8e4d8; }
body.light-mode .result-group-header:hover { background: #dedad0; }
body.light-mode .result-group-count { background: #d0ccbf; }
body.light-mode .bookmark-item { border-bottom-color: var(--panel-border); }
body.light-mode #bookmarks-header { background: var(--btn-bg); }
body.light-mode .ayah-row { border-bottom-color: rgba(139, 90, 20, 0.15); }
body.light-mode .ayah-row:hover { background: rgba(200,168,75,0.10); }
body.light-mode #progress-bar { background: rgba(0,0,0,0.1); }

/* =============================================
   PRINT
   ============================================= */
@media print {
  body { background: white; }
  #navbar, #search-panel, #word-tooltip { display: none !important; }
  #mushaf-frame { padding: 0; }
  #mushaf-page { box-shadow: none; border: 1px solid #c8a84b; overflow: hidden; }
  body.print-workspace > * { display: none !important; }
  body.print-workspace #workspace-view { display: block !important; height: auto; padding: 0; overflow: visible; }
  body.print-workspace #workspace-toolbar { display: none !important; }
  body.print-workspace #workspace-view::before {
    content: attr(data-print-title);
    display: block;
    margin-bottom: 20px;
    color: #111;
    text-align: center;
    font: bold 24pt Arial, sans-serif;
  }
  body.print-workspace #workspace-editor { min-height: 0; margin: 0; padding: 0; border: 0; box-shadow: none; }
}

/* ── Concordance Panel (full-screen overlay) ── */
#concordance-panel {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#concordance-panel.hidden { display: none; }

#concordance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel-bg, #1a2035);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#concordance-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent, #c8a84b);
  direction: rtl;
}
#btn-concordance-close {
  background: none;
  border: none;
  color: var(--text-muted, #aaa);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s, background .15s;
}
#btn-concordance-close:hover { color: var(--text); background: rgba(255,255,255,.07); }

#concordance-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  direction: rtl;
}

.conc-surah-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 24px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.conc-surah-header:first-child { margin-top: 0; }
.conc-surah-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent, #c8a84b);
}
.conc-surah-count {
  font-size: 12px;
  background: rgba(200,168,75,.15);
  color: var(--accent, #c8a84b);
  border-radius: 10px;
  padding: 1px 8px;
}

.conc-card {
  background: var(--panel-bg, #1a2035);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.conc-card:hover {
  border-color: var(--accent, #c8a84b);
  background: rgba(200,168,75,.06);
}
.conc-ref {
  font-size: 11px;
  color: var(--text-muted, #888);
  margin-bottom: 8px;
  direction: rtl;
}
.conc-text {
  font-family: 'KFGQPC HAFS', serif;
  font-size: 20px;
  line-height: 2;
  color: var(--text);
  direction: rtl;
  text-align: right;
}

#concordance-body::-webkit-scrollbar { width: 5px; }
#concordance-body::-webkit-scrollbar-track { background: transparent; }
#concordance-body::-webkit-scrollbar-thumb { background: #2a3050; border-radius: 3px; }

/* =============================================
   FOCUSED SEARCH + READING LAYOUT
   ============================================= */
#navbar {
  min-height: 62px;
  height: auto;
}
#nav-right {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}
#nav-left {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
#nav-center { display: none; }
#search-box {
  flex: 1 1 auto;
  justify-content: flex-start;
}
#search-input { width: clamp(230px, 25vw, 420px); }
#search-mode-note { display: flex; }

#reading-tools {
  flex: 0 0 54px;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 7px;
  background: var(--nav-bg);
  border-left: 1px solid var(--nav-border);
  z-index: 12;
}
#reading-tools > button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--nav-border);
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--input-text);
  cursor: pointer;
  font-size: 18px;
}
#reading-tools > button:hover,
#reading-tools > button.active {
  background: var(--btn-hover);
  color: var(--gold-light);
  border-color: var(--gold-dark);
}
#reading-tools #font-ctrl {
  flex-direction: column;
  padding-top: 3px;
}
#reading-tools #font-size-slider {
  width: 4px;
  height: 92px;
  writing-mode: vertical-lr;
  direction: rtl;
}

#workspace-more {
  position: relative;
  flex: 0 0 auto;
}
#workspace-more > summary {
  list-style: none;
  padding: 6px 11px;
  border: 1px solid var(--nav-border);
  border-bottom: none;
  border-radius: 7px 7px 0 0;
  background: var(--btn-bg);
  color: #9ba3b8;
  cursor: pointer;
  white-space: nowrap;
}
#workspace-more > summary::-webkit-details-marker { display: none; }
#workspace-more-menu {
  position: absolute;
  top: calc(100% + 1px);
  left: 0;
  z-index: 220;
  min-width: 170px;
  padding: 6px;
  border: 1px solid var(--nav-border);
  border-radius: 0 0 8px 8px;
  background: var(--panel-bg);
  box-shadow: 0 12px 28px rgba(0,0,0,.4);
}
#workspace-more-menu button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid var(--panel-border);
  background: transparent;
  color: var(--input-text);
  text-align: right;
  cursor: pointer;
}
#workspace-more-menu button:hover { background: var(--result-hover); }

#mushaf-frame { justify-content: flex-start; }
#mushaf-sheet {
  transform-origin: top center;
  margin: 0 auto 74px;
}
#page-nav-dock {
  position: sticky;
  bottom: 12px;
  z-index: 30;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 20px);
  margin: 0 auto;
  padding: 8px 10px;
  border: 1px solid var(--gold-dark);
  border-radius: 12px;
  background: rgba(30,33,48,.96);
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  backdrop-filter: blur(10px);
}

@media (max-width: 720px) {
  #navbar {
    display: grid;
    grid-template-columns: auto 1fr;
    padding: 6px 8px;
    gap: 6px;
  }
  #nav-right { grid-column: 1; }
  #nav-left {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  #nav-left::-webkit-scrollbar,
  #workspace-tabs::-webkit-scrollbar { display: none; }
  #reading-tools {
    position: fixed;
    right: 6px;
    bottom: 72px;
    z-index: 90;
    width: 42px;
    height: auto;
    padding: 5px;
    border: 1px solid var(--nav-border);
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0,0,0,.35);
  }
  #reading-tools > button { width: 32px; height: 32px; font-size: 15px; }
  #reading-tools #font-ctrl { display: none; }
  #mushaf-sheet { margin: 0 auto 62px; }
  #page-nav-dock { bottom: 8px; gap: 5px; padding: 6px; }
  #page-nav-dock #surah-select { max-width: 125px; }
  #page-nav-dock #page-input { width: 58px; }
  #page-nav-dock #page-total { display: none; }
}

@media print {
  #reading-tools, #page-nav-dock { display: none !important; }
}
