@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --bg-primary: #0c1015;
  --bg-secondary: #121822;
  --bg-card: #161e2a;
  --bg-raised: #1b2533;
  --border: rgba(201,163,92,0.14);
  --border-soft: rgba(255,255,255,0.06);
  --accent-gold: #c9a35c;
  --accent-glow: #e8c684;
  --green: #4fc681;
  --blue: #5b9dd8;
  --red: #e56d6d;
  --purple: #b678d8;
  --text-primary: #ece5d4;
  --text-secondary: #8b99ad;
  --shadow: 0 6px 24px rgba(0,0,0,0.35);
  --shadow-soft: 0 2px 10px rgba(0,0,0,0.25);
  --radius: 14px;
  --radius-sm: 8px;
  --ease: cubic-bezier(.4,0,.2,1);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
html, body { overflow-x: clip; max-width: 100%; }
body {
  font-family: 'Amiri', 'Inter', 'Segoe UI', sans-serif;
  background:
    radial-gradient(1200px 500px at 50% -200px, rgba(201,163,92,0.05), transparent 70%),
    var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}
button { font-family: 'Inter', 'Segoe UI', sans-serif; }
:focus-visible { outline: 2px solid var(--accent-gold); outline-offset: 2px; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
  background: rgba(18,24,34,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1.4rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 100;
}
.header-title { display: flex; align-items: center; gap: 0.75rem; }
.header-title .icon { font-size: 1.5rem; filter: drop-shadow(0 2px 6px rgba(201,163,92,0.35)); }
.header-title h1 {
  font-family: 'Amiri', serif;
  font-size: 1.15rem; color: var(--accent-glow); font-weight: 700;
  letter-spacing: 0.3px;
}
.header-title .subtitle {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem; color: var(--text-secondary);
  letter-spacing: 0.6px; text-transform: uppercase;
}
.nav-scroll { min-width: 0; }
.nav-controls { display: flex; align-items: center; gap: 0.9rem; }
.pager-group, .action-group { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }

/* Unified button system: quiet ghost buttons, tinted only by their role */
.nav-btn {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-soft);
  color: var(--text-secondary);
  padding: 0.42rem 0.85rem; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.74rem; font-weight: 500;
  transition: background .18s var(--ease), color .18s var(--ease),
              border-color .18s var(--ease), transform .12s var(--ease);
}
.nav-btn:hover {
  background: rgba(201,163,92,0.12);
  border-color: rgba(201,163,92,0.35);
  color: var(--accent-glow);
}
.nav-btn:active { transform: scale(0.97); }
.nav-btn:disabled { opacity: 0.28; cursor: default; transform: none; }
.nav-btn:disabled:hover { background: rgba(255,255,255,0.03); border-color: var(--border-soft); color: var(--text-secondary); }

.nav-btn.export-btn { color: var(--green); border-color: rgba(79,198,129,0.25); }
.nav-btn.export-btn:hover { background: rgba(79,198,129,0.12); border-color: rgba(79,198,129,0.5); color: var(--green); }
.nav-btn.export-btn.running { background: rgba(201,163,92,0.14); color: var(--accent-gold); border-color: var(--border); cursor: wait; }
.nav-btn.suras-btn { color: var(--blue); border-color: rgba(91,157,216,0.25); }
.nav-btn.suras-btn:hover { background: rgba(91,157,216,0.12); border-color: rgba(91,157,216,0.5); color: var(--blue); }
.nav-btn.suras-btn:disabled { opacity: 0.3; }
.nav-btn.import-btn { color: var(--purple); border-color: rgba(182,120,216,0.25); }
.nav-btn.import-btn:hover { background: rgba(182,120,216,0.12); border-color: rgba(182,120,216,0.5); color: var(--purple); }
.nav-btn.edit-btn { color: var(--red); border-color: rgba(229,109,109,0.25); }
.nav-btn.edit-btn:hover { background: rgba(229,109,109,0.12); border-color: rgba(229,109,109,0.5); color: var(--red); }
.nav-btn.edit-btn.active {
  background: rgba(229,109,109,0.22); border-color: var(--red); color: #fff;
  box-shadow: 0 0 14px rgba(229,109,109,0.3);
}

.page-indicator {
  color: var(--text-secondary); font-size: 0.74rem; min-width: 84px;
  text-align: center; font-family: 'Inter', sans-serif;
  font-variant-numeric: tabular-nums;
}
.page-indicator strong { color: var(--accent-glow); }
.goto-input {
  width: 54px; padding: 0.4rem; border-radius: var(--radius-sm); font-size: 0.74rem;
  border: 1px solid var(--border-soft); background: rgba(255,255,255,0.03);
  color: var(--accent-glow); text-align: center; font-family: 'Inter', sans-serif;
  transition: border-color .18s var(--ease), background .18s var(--ease);
}
.goto-input::placeholder { color: var(--text-secondary); opacity: 0.5; }
.goto-input:focus {
  outline: none; border-color: var(--accent-gold);
  background: rgba(201,163,92,0.1);
  box-shadow: 0 0 0 3px rgba(201,163,92,0.12);
}
.badge {
  background: rgba(201,163,92,0.12); color: var(--accent-glow);
  border: 1px solid rgba(201,163,92,0.2);
  padding: 0.22rem 0.7rem; border-radius: 999px;
  font-size: 0.62rem; font-weight: 600; font-family: 'Inter', sans-serif;
}

/* ── Layout ─────────────────────────────────────────────────────────────── */
.main-container {
  display: flex; gap: 1.2rem; padding: 1.2rem;
  max-width: 1800px; margin: 0 auto; min-height: calc(100vh - 60px);
}
.page-panel { flex: 0 0 45%; max-width: 45%; }
.page-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.04);
  position: sticky; top: 74px;
}
.page-card-header {
  padding: 0.7rem 1.1rem; border-bottom: 1px solid var(--border-soft);
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(180deg, rgba(201,163,92,0.05), transparent);
}
.page-card-header h2 {
  font-size: 0.85rem; color: var(--accent-glow); font-weight: 600;
  font-family: 'Inter', sans-serif; letter-spacing: 0.3px;
}
.page-image-container {
  position: relative; background: #f7f2e7; min-height: 200px;
  box-shadow: inset 0 0 40px rgba(120,90,40,0.07);
}
.page-image-container img { display: block; width: 100%; height: auto; }
.image-wrapper { position: relative; display: inline-block; width: 100%; }

.bbox-overlay {
  position: absolute; border: 2px solid transparent; border-radius: 4px;
  cursor: pointer; transition: background .15s var(--ease), border-color .15s var(--ease),
              box-shadow .15s var(--ease); z-index: 10;
}
.bbox-overlay:hover, .bbox-overlay.active {
  border-color: rgba(201,163,92,0.9); background: rgba(201,163,92,0.28);
  box-shadow: 0 0 12px rgba(201,163,92,0.45);
}
.bbox-overlay.ayah-hover-hl {
  border-color: rgba(100,220,255,0.95) !important;
  background: rgba(100,220,255,0.26) !important;
  box-shadow: 0 0 18px rgba(100,220,255,0.55) !important;
  z-index: 20 !important;
}

/* ── Words panel ────────────────────────────────────────────────────────── */
.words-panel { flex: 1; min-width: 0; }
.surah-info {
  background: linear-gradient(180deg, var(--bg-raised), var(--bg-card));
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 0.9rem;
  box-shadow: var(--shadow-soft); text-align: center; position: relative;
}
.surah-info::before, .surah-info::after {
  content: ''; position: absolute; top: 50%; width: 44px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(201,163,92,0.5), transparent);
}
.surah-info::before { left: 1.2rem; }
.surah-info::after { right: 1.2rem; }
.surah-info .surah-name-ar {
  font-family: 'Amiri', serif; font-size: 1.8rem; color: var(--accent-glow);
  font-weight: 700; text-shadow: 0 2px 12px rgba(201,163,92,0.25);
}
.surah-info .surah-name-en {
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem; color: var(--text-secondary); margin-top: 0.25rem;
}
.surah-info .ayah-range {
  font-family: 'Inter', sans-serif;
  font-size: 0.62rem; color: var(--text-secondary); margin-top: 0.15rem;
  letter-spacing: 0.5px;
}
.stats-bar {
  background: var(--bg-secondary); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); padding: 0.55rem 1rem; margin-bottom: 0.9rem;
  display: flex; gap: 1.1rem; font-size: 0.68rem; color: var(--text-secondary);
  flex-wrap: wrap; font-family: 'Inter', sans-serif;
}
.stats-bar .stat { display: flex; align-items: center; gap: 0.3rem; }
.stats-bar .stat-value { color: var(--accent-glow); font-weight: 700; font-variant-numeric: tabular-nums; }

.line-separator { text-align: center; margin: 0.8rem 0 0.5rem; position: relative; }
.line-separator::before {
  content: ''; position: absolute; top: 50%; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.line-separator .line-label {
  position: relative; background: var(--bg-primary); padding: 0 0.7rem;
  font-size: 0.58rem; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 1.5px;
  font-family: 'Inter', sans-serif;
}
.words-line { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; direction: rtl; }

.word-card {
  background: var(--bg-card); border: 1px solid var(--border-soft);
  border-radius: 12px; padding: 0.55rem; min-width: 80px; max-width: 180px;
  text-align: center; cursor: pointer; position: relative;
  display: flex; flex-direction: column;
  transition: border-color .18s var(--ease), transform .18s var(--ease),
              box-shadow .18s var(--ease), background .18s var(--ease);
}
.word-card:hover {
  border-color: rgba(201,163,92,0.4); transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.word-card.active {
  border-color: var(--accent-gold);
  box-shadow: 0 0 16px rgba(201,163,92,0.3);
  background: var(--bg-raised);
}
.word-card .word-idx { display: none; }
.word-card .crop-preview {
  max-width: 100%; max-height: 50px; border-radius: 6px;
  margin-bottom: 0.35rem; background: #f7f2e7;
  object-fit: contain; flex-shrink: 0; align-self: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.word-card .tashkeel-text {
  font-family: 'Amiri', serif; font-size: 1.6rem; color: var(--accent-glow);
  line-height: 1.8; direction: rtl;
}
.word-card .tashkeel-ref { display: none; }
.word-card .ocr-base { display: none; }

.word-card .translations {
  margin-top: 0.45rem; padding-top: 0.4rem;
  border-top: 1px solid var(--border-soft);
  display: flex; flex-direction: column; gap: 0.25rem;
}
.word-card .translation-row {
  display: flex; align-items: baseline; gap: 0.4rem;
  direction: ltr; text-align: left;
}
.word-card .lang-badge {
  font-family: 'Inter', sans-serif;
  font-size: 0.5rem; font-weight: 700; letter-spacing: 0.8px;
  text-transform: uppercase; padding: 2px 5px; border-radius: 4px;
  flex-shrink: 0; min-width: 22px; text-align: center;
}
.word-card .lang-badge.en { background: rgba(91,157,216,0.15); color: #9ec8ee; }
.word-card .lang-badge.tr { background: rgba(229,109,109,0.15); color: #f0b0b0; }
.word-card .translation-text {
  font-family: 'Inter', sans-serif; font-size: 0.76rem; line-height: 1.35;
}
.word-card .translation-row .lang-badge.en + .translation-text { color: #b5d6f2; }
.word-card .translation-row .lang-badge.tr + .translation-text { color: #f2c4c4; }

.word-card .tajweed-rules {
  margin-top: 0.45rem; padding: 0.4rem;
  background: rgba(0,0,0,0.22); border-radius: 8px;
  border: 1px solid var(--border-soft);
  display: flex; flex-wrap: wrap; gap: 5px;
  direction: ltr; justify-content: center; order: 99;
}
.word-card.has-tajweed { box-shadow: 0 0 8px rgba(201,163,92,0.12); }
.word-card.has-tajweed .tajweed-top-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  border-radius: 12px 12px 0 0;
}
.tajweed-badge {
  font-family: 'Inter', sans-serif;
  font-size: 0.58rem; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase; padding: 3px 9px; border-radius: 999px;
  white-space: nowrap; cursor: help; line-height: 1.3;
  border-width: 1px; border-style: solid;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.color-0 { border-left: 3px solid #e56d6d; }
.color-1 { border-left: 3px solid #59c97a; }
.color-2 { border-left: 3px solid #5b9dd8; }
.color-3 { border-left: 3px solid #e3bb4a; }
.color-4 { border-left: 3px solid #b678d8; }
.color-5 { border-left: 3px solid #e59a55; }
.color-6 { border-left: 3px solid #3ec5a1; }
.color-7 { border-left: 3px solid #d99ce8; }
.color-8 { border-left: 3px solid #82b8ef; }
.color-9 { border-left: 3px solid #a8cf62; }

.ayah-marker-overlay {
  position: absolute; z-index: 15; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  border: 2px solid var(--accent-gold);
  background: transparent; color: transparent;
  box-shadow: 0 0 8px rgba(201,163,92,0.3);
}
.ayah-marker-card {
  background: var(--bg-card); border: 1px solid var(--border-soft);
  border-radius: 12px; padding: 0.55rem; min-width: 80px; max-width: 120px;
  text-align: center; position: relative;
  border-left: 3px solid var(--accent-gold);
  display: flex; flex-direction: column; align-items: center; gap: 0.3rem;
}
.ayah-marker-card .marker-crop {
  width: 54px; height: 54px; border-radius: 50%; object-fit: cover;
  background: #f7f2e7; display: block;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.ayah-marker-card .marker-label {
  font-family: 'Amiri', serif; font-size: 0.82rem; color: var(--accent-glow);
  font-weight: 700;
}

/* ── Ayah grouped view ──────────────────────────────────────────────────── */
.view-toggle-bar {
  display: flex; justify-content: center; margin-bottom: 0.9rem;
  background: var(--bg-secondary); border: 1px solid var(--border-soft);
  border-radius: 999px; padding: 3px; width: fit-content;
  margin-left: auto; margin-right: auto; gap: 2px;
}
.view-toggle-btn {
  background: transparent; border: none;
  border-radius: 999px; padding: 0.35rem 1.1rem; cursor: pointer;
  font-size: 0.7rem; font-weight: 500; color: var(--text-secondary);
  transition: background .18s var(--ease), color .18s var(--ease);
  font-family: 'Inter', sans-serif;
}
.view-toggle-btn:hover { color: var(--accent-glow); }
.view-toggle-btn.active {
  background: var(--accent-gold); color: var(--bg-primary);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(201,163,92,0.35);
}

.ayah-group {
  background: var(--bg-card); border: 1px solid var(--border-soft);
  border-radius: 12px; margin-bottom: 0.55rem; overflow: hidden;
  box-shadow: var(--shadow-soft);
  transition: border-color .18s var(--ease);
}
.ayah-group.expanded { border-color: rgba(201,163,92,0.3); }
.ayah-group-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem; cursor: pointer; user-select: none;
  background: transparent;
  transition: background .18s var(--ease);
  direction: rtl; gap: 0.7rem;
}
.ayah-group-header:hover { background: rgba(201,163,92,0.06); }
.ayah-group.expanded .ayah-group-header {
  background: rgba(201,163,92,0.05);
  border-bottom: 1px solid var(--border-soft);
}
.ayah-group-header .ayah-badge {
  background: linear-gradient(135deg, var(--accent-gold), #ab8546);
  color: var(--bg-primary);
  border-radius: 999px; min-width: 32px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
  padding: 0 8px; font-family: 'Inter', sans-serif;
  box-shadow: 0 1px 4px rgba(201,163,92,0.3);
}
.ayah-group-header .ayah-last-word { display: none; }
.ayah-group-header .ayah-last-word .header-crop { display: none; }
.ayah-group-header .ayah-meal-inline {
  flex: 1; direction: ltr; text-align: left;
  font-family: 'Inter', sans-serif; font-size: 0.86rem;
  color: #e9d3a0; line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.ayah-group-header .ayah-word-count { display: none; }
.ayah-group-header .expand-icon {
  font-size: 0.7rem; color: var(--text-secondary);
  transition: transform .25s var(--ease); flex-shrink: 0;
}
.ayah-group.expanded .ayah-group-header .expand-icon { transform: rotate(180deg); }
.ayah-meal { display: none; }
.ayah-meal .meal-label {
  font-size: 0.55rem; font-weight: 700; letter-spacing: 0.5px;
  text-transform: uppercase; padding: 1px 4px; border-radius: 3px;
  background: rgba(201,163,92,0.15); color: var(--accent-gold);
  display: inline-block; margin-right: 0.4rem; vertical-align: middle;
}
.ayah-meal .meal-text {
  font-size: 0.8rem; color: #e9d3a0; line-height: 1.5;
  font-family: 'Inter', sans-serif;
}
.ayah-group-body { display: none; padding: 0.6rem; }
.ayah-group.expanded .ayah-group-body {
  display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; direction: rtl;
  animation: fadeIn 0.25s var(--ease);
}
.bbox-info { display: none !important; }
.bbox-info .color-swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* ── Audio player ───────────────────────────────────────────────────────── */
.audio-player-bar {
  display: none;
  align-items: center; gap: 0.75rem;
  padding: 0.55rem 0.9rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin: 0 0 0.9rem;
  box-shadow: var(--shadow-soft);
}
.audio-player-bar.visible { display: flex; }
.audio-play-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-glow), var(--accent-gold));
  color: var(--bg-primary); border: none; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform .15s var(--ease), box-shadow .15s var(--ease);
  box-shadow: 0 2px 10px rgba(201,163,92,0.35);
}
.audio-play-btn:hover { transform: scale(1.06); box-shadow: 0 2px 16px rgba(201,163,92,0.5); }
.audio-play-btn.playing { background: linear-gradient(135deg, #ef8585, #d55e5e); box-shadow: 0 2px 10px rgba(229,109,109,0.35); }
.audio-progress-wrap { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.audio-progress-track {
  width: 100%; height: 6px; background: rgba(255,255,255,0.08);
  border-radius: 999px; cursor: pointer; position: relative; overflow: hidden;
}
.audio-progress-track:hover { background: rgba(255,255,255,0.12); }
.audio-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-gold), var(--accent-glow));
  border-radius: 999px; width: 0%;
  transition: width 0.1s linear;
}
.audio-time-row {
  display: flex; justify-content: space-between;
  font-size: 0.6rem; color: var(--text-secondary);
  font-family: 'Inter', sans-serif; font-variant-numeric: tabular-nums;
}
.audio-reciter-label {
  font-size: 0.64rem; color: var(--accent-glow); font-weight: 600;
  white-space: nowrap; flex-shrink: 0;
}
.bbox-overlay.audio-active-word {
  border-color: rgba(255,205,80,0.95) !important;
  background: rgba(255,205,80,0.28) !important;
  box-shadow: 0 0 20px rgba(255,205,80,0.55) !important;
  z-index: 25 !important;
}
.word-card.audio-active-card {
  border-color: var(--accent-gold) !important;
  box-shadow: 0 0 12px rgba(201,163,92,0.5) !important;
  background: rgba(201,163,92,0.1) !important;
}

/* ── Recitation checker ─────────────────────────────────────────────────── */
.recitation-bar {
  display: none;
  align-items: center; gap: 0.65rem;
  padding: 0.55rem 0.9rem;
  background: var(--bg-raised);
  border: 1px solid rgba(79,198,129,0.18);
  border-radius: 12px;
  margin: 0 0 0.9rem;
  box-shadow: var(--shadow-soft);
}
.recitation-bar.visible { display: flex; }
.rec-mic-btn {
  width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid rgba(79,198,129,0.4);
  background: rgba(79,198,129,0.1); color: var(--green); font-size: 1.15rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .18s var(--ease), border-color .18s var(--ease),
              transform .15s var(--ease); flex-shrink: 0;
}
.rec-mic-btn:hover {
  background: rgba(79,198,129,0.2); border-color: rgba(79,198,129,0.7);
  transform: scale(1.05);
}
.rec-mic-btn.recording {
  background: rgba(229,109,109,0.2); border-color: var(--red); color: var(--red);
  animation: recPulse 1.6s var(--ease) infinite;
}
@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,109,109,0.35); }
  50% { box-shadow: 0 0 0 8px rgba(229,109,109,0); }
}
.rec-mic-btn.processing {
  background: rgba(201,163,92,0.16); border-color: var(--accent-gold);
  color: var(--accent-gold); cursor: wait; animation: none;
}
.rec-status-text {
  flex: 1; min-width: 0;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rec-status-text.recording { color: var(--red); font-weight: 600; }
.rec-status-text.processing { color: var(--accent-gold); }
.rec-clear-btn {
  background: none; border: 1px solid var(--border-soft); color: var(--text-secondary);
  padding: 0.25rem 0.6rem; border-radius: var(--radius-sm); font-size: 0.65rem;
  cursor: pointer; display: none; flex-shrink: 0;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.rec-clear-btn.visible { display: inline-block; }
.rec-clear-btn:hover { background: rgba(255,255,255,0.07); color: var(--text-primary); }
.rec-refresh-btn {
  background: none; border: 1px solid rgba(91,157,216,0.25); color: rgba(130,184,239,0.85);
  padding: 0.25rem 0.65rem; border-radius: var(--radius-sm); font-size: 0.68rem;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.rec-refresh-btn:hover {
  background: rgba(91,157,216,0.12); color: #82b8ef;
  border-color: rgba(91,157,216,0.5);
}

.bbox-overlay.rec-correct {
  border-color: rgba(79,198,129,0.95) !important;
  background: rgba(79,198,129,0.24) !important;
  box-shadow: 0 0 14px rgba(79,198,129,0.5) !important;
  z-index: 22 !important;
}
.bbox-overlay.rec-partial {
  border-color: rgba(227,187,74,0.95) !important;
  background: rgba(227,187,74,0.26) !important;
  box-shadow: 0 0 14px rgba(227,187,74,0.5) !important;
  z-index: 22 !important;
}
.bbox-overlay.rec-wrong {
  border-color: rgba(229,109,109,0.95) !important;
  background: rgba(229,109,109,0.28) !important;
  box-shadow: 0 0 14px rgba(229,109,109,0.5) !important;
  z-index: 22 !important;
}
.word-card.rec-correct { border-color: rgba(79,198,129,0.5) !important; background: rgba(79,198,129,0.07) !important; }
.word-card.rec-partial { border-color: rgba(227,187,74,0.5) !important; background: rgba(227,187,74,0.07) !important; }
.word-card.rec-wrong { border-color: rgba(229,109,109,0.5) !important; background: rgba(229,109,109,0.07) !important; }

/* ── Edit mode ──────────────────────────────────────────────────────────── */
.edit-toolbar {
  display: none;
  background: var(--bg-raised);
  border-top: 1px solid rgba(229,109,109,0.2);
  padding: 0.45rem 0.8rem;
  align-items: center; gap: 0.4rem; flex-wrap: wrap; font-size: 0.7rem;
  position: sticky; bottom: 0; z-index: 30;
  border-radius: 0 0 var(--radius) var(--radius);
}
.edit-toolbar.visible { display: flex; }
.edit-toolbar .et-label {
  color: var(--red); font-weight: 700; font-size: 0.62rem;
  letter-spacing: 1px; margin-right: 0.5rem;
  font-family: 'Inter', sans-serif;
}
.edit-toolbar .et-btn {
  padding: 0.32rem 0.7rem; border-radius: var(--radius-sm); font-size: 0.66rem;
  cursor: pointer; border: 1px solid var(--border-soft);
  background: rgba(255,255,255,0.03); color: var(--text-secondary);
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.edit-toolbar .et-btn:hover { background: rgba(229,109,109,0.14); color: var(--red); border-color: rgba(229,109,109,0.3); }
.edit-toolbar .et-btn.active { background: rgba(229,109,109,0.22); color: var(--red); border-color: var(--red); }
.edit-toolbar .et-btn:disabled { opacity: 0.3; cursor: default; }
.edit-toolbar .et-btn.save-btn { color: var(--green); border-color: rgba(79,198,129,0.3); }
.edit-toolbar .et-btn.save-btn:hover { background: rgba(79,198,129,0.16); color: var(--green); }
.edit-toolbar .et-btn.danger { color: var(--red); border-color: rgba(229,109,109,0.3); }
.edit-toolbar .et-btn.danger:hover { background: rgba(229,109,109,0.25); }
.edit-toolbar .et-sep { width: 1px; height: 20px; background: var(--border-soft); margin: 0 0.3rem; }
.edit-toolbar .et-info {
  flex: 1; text-align: right; color: var(--text-secondary);
  font-size: 0.62rem; font-family: 'Inter', sans-serif;
}
body.edit-mode .bbox-overlay { cursor: move; }
body.edit-mode .bbox-overlay.edit-selected {
  border-color: var(--red) !important; border-width: 2px;
  background: rgba(229,109,109,0.14) !important;
  box-shadow: 0 0 12px rgba(229,109,109,0.4);
}
.resize-handle {
  position: absolute; width: 9px; height: 9px; background: var(--red);
  border: 1px solid #fff; border-radius: 3px; z-index: 20;
}
.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }
.resize-handle.n { top: -5px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.resize-handle.s { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.resize-handle.w { top: 50%; left: -5px; transform: translateY(-50%); cursor: w-resize; }
.resize-handle.e { top: 50%; right: -5px; transform: translateY(-50%); cursor: e-resize; }
body.edit-mode .image-wrapper.drawing { cursor: crosshair; }
.draw-rect {
  position: absolute; border: 2px dashed var(--green);
  background: rgba(79,198,129,0.1);
  pointer-events: none; z-index: 25;
}

/* ── Edit panel modal ───────────────────────────────────────────────────── */
.edit-panel-overlay {
  display: none; position: fixed; inset: 0; z-index: 9996;
  background: rgba(6,9,13,0.7); backdrop-filter: blur(4px);
}
.edit-panel-overlay.open { display: flex; align-items: center; justify-content: center; }
.edit-panel {
  background: var(--bg-card); border: 1px solid rgba(229,109,109,0.3);
  border-radius: var(--radius);
  width: min(500px, 90vw); padding: 1.5rem;
  box-shadow: 0 16px 56px rgba(0,0,0,0.6);
  color: var(--text-primary);
  animation: modalIn 0.22s var(--ease);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.edit-panel h3 {
  color: var(--red); margin: 0 0 1.1rem; font-size: 0.92rem;
  display: flex; align-items: center; gap: 0.5rem;
  font-family: 'Inter', sans-serif;
}
.edit-panel .ep-row { display: flex; gap: 0.5rem; margin-bottom: 0.65rem; align-items: center; }
.edit-panel .ep-row label {
  min-width: 80px; font-size: 0.68rem; color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
}
.edit-panel .ep-row input, .edit-panel .ep-row select {
  flex: 1; padding: 0.45rem 0.6rem; border-radius: var(--radius-sm); font-size: 0.78rem;
  border: 1px solid var(--border-soft); background: rgba(255,255,255,0.04);
  color: var(--text-primary); font-family: 'Amiri', serif;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.edit-panel .ep-row input:focus {
  outline: none; border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(229,109,109,0.12);
}
.edit-panel .ep-row .coord-input { width: 70px; flex: none; text-align: center; font-family: 'Inter', monospace; }
.edit-panel .ep-actions { display: flex; gap: 0.5rem; margin-top: 1.2rem; justify-content: flex-end; }
.edit-panel .ep-actions button {
  padding: 0.45rem 1.1rem; border-radius: var(--radius-sm); font-size: 0.72rem;
  cursor: pointer; border: 1px solid var(--border-soft); font-weight: 500;
  transition: background .15s var(--ease);
}
.edit-panel .ep-actions .btn-apply { background: rgba(79,198,129,0.18); border-color: rgba(79,198,129,0.4); color: var(--green); }
.edit-panel .ep-actions .btn-apply:hover { background: rgba(79,198,129,0.3); }
.edit-panel .ep-actions .btn-cancel { background: transparent; border-color: var(--border-soft); color: var(--text-secondary); }
.edit-panel .ep-actions .btn-cancel:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.export-toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.4rem; box-shadow: 0 10px 36px rgba(0,0,0,0.55);
  font-size: 0.8rem; color: var(--text-primary); max-width: 380px;
  transform: translateY(120%); opacity: 0;
  transition: transform .3s var(--ease), opacity .3s var(--ease);
}
.export-toast.visible { transform: translateY(0); opacity: 1; }
.export-toast .toast-title { color: var(--accent-glow); font-weight: 700; margin-bottom: 0.3rem; font-family: 'Inter', sans-serif; }
.export-toast .toast-status { color: var(--text-secondary); font-size: 0.7rem; font-family: 'Inter', sans-serif; }
.export-toast .toast-bar { height: 4px; background: rgba(201,163,92,0.15); border-radius: 999px; margin-top: 0.55rem; overflow: hidden; }
.export-toast .toast-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-gold), var(--accent-glow)); border-radius: 999px; transition: width 0.5s var(--ease); }

/* ── Suras panel ────────────────────────────────────────────────────────── */
.suras-overlay {
  display: none; position: fixed; inset: 0; z-index: 9998;
  background: rgba(6,9,13,0.7); backdrop-filter: blur(4px);
}
.suras-overlay.open { display: flex; align-items: center; justify-content: center; }
.suras-panel {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(700px, 90vw); max-height: 80vh; overflow-y: auto; padding: 1.5rem;
  box-shadow: 0 16px 56px rgba(0,0,0,0.6); color: var(--text-primary);
  animation: modalIn 0.22s var(--ease);
}
.suras-panel h2 { color: var(--accent-glow); margin: 0 0 1rem; font-size: 1.05rem; font-family: 'Inter', sans-serif; }
.suras-panel .sp-close {
  float: left; cursor: pointer; color: var(--text-secondary);
  font-size: 1.1rem; padding: 0.2rem 0.5rem; border-radius: var(--radius-sm);
  transition: color .15s var(--ease), background .15s var(--ease);
}
.suras-panel .sp-close:hover { color: var(--accent-glow); background: rgba(255,255,255,0.05); }
.suras-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.5rem; }
.sura-card {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-soft); border-radius: 10px; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
  text-decoration: none; color: var(--text-primary); font-size: 0.75rem;
}
.sura-card:hover {
  background: rgba(201,163,92,0.07);
  border-color: rgba(201,163,92,0.25);
  transform: translateY(-1px);
}
.sura-num {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-size: 0.62rem; font-weight: 700; color: #fff; flex-shrink: 0;
  font-family: 'Inter', sans-serif;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.sura-info { flex: 1; min-width: 0; }
.sura-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sura-meta { color: var(--text-secondary); font-size: 0.63rem; font-family: 'Inter', sans-serif; }

/* ── Export panel ───────────────────────────────────────────────────────── */
.export-overlay {
  display: none; position: fixed; inset: 0; z-index: 9997;
  background: rgba(6,9,13,0.7); backdrop-filter: blur(4px);
}
.export-overlay.open { display: flex; align-items: center; justify-content: center; }
.export-panel {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(780px, 92vw); max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 16px 56px rgba(0,0,0,0.6); color: var(--text-primary);
  animation: modalIn 0.22s var(--ease);
}
.ep-header {
  padding: 1rem 1.5rem; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 0.8rem; flex-shrink: 0;
}
.ep-header h2 { flex: 1; color: var(--accent-glow); margin: 0; font-size: 0.98rem; font-family: 'Inter', sans-serif; }
.ep-close {
  cursor: pointer; color: var(--text-secondary); font-size: 1.1rem;
  padding: 0.2rem 0.5rem; border-radius: var(--radius-sm);
  transition: color .15s var(--ease), background .15s var(--ease);
}
.ep-close:hover { color: var(--accent-glow); background: rgba(255,255,255,0.05); }
.ep-toolbar {
  padding: 0.6rem 1.5rem; border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; flex-wrap: wrap;
}
.ep-toolbar .ep-btn {
  padding: 0.32rem 0.75rem; border-radius: var(--radius-sm); font-size: 0.7rem;
  cursor: pointer; border: 1px solid var(--border-soft);
  background: rgba(255,255,255,0.03); color: var(--text-secondary);
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.ep-toolbar .ep-btn:hover { background: rgba(201,163,92,0.12); color: var(--accent-glow); border-color: rgba(201,163,92,0.3); }
.ep-toolbar .ep-btn.primary { background: rgba(79,198,129,0.14); border-color: rgba(79,198,129,0.3); color: var(--green); }
.ep-toolbar .ep-btn.primary:hover { background: rgba(79,198,129,0.24); }
.ep-toolbar .ep-btn.primary:disabled { opacity: 0.35; cursor: default; }
.ep-count { flex: 1; text-align: right; color: var(--text-secondary); font-size: 0.7rem; font-family: 'Inter', sans-serif; }
.ep-grid { flex: 1; overflow-y: auto; padding: 0.8rem 1.5rem; }
.ep-sura-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.4rem; }
.ep-sura-card {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem;
  border: 1px solid var(--border-soft); border-radius: 10px; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease);
  font-size: 0.72rem; user-select: none;
}
.ep-sura-card:hover { background: rgba(201,163,92,0.07); border-color: rgba(201,163,92,0.2); }
.ep-sura-card.selected { background: rgba(79,198,129,0.09); border-color: rgba(79,198,129,0.35); }
.ep-sura-card .ep-cb { width: 14px; height: 14px; accent-color: var(--green); flex-shrink: 0; pointer-events: none; }
.ep-sura-card .sura-num { width: 24px; height: 24px; font-size: 0.58rem; }
.ep-sura-card .sura-name { font-size: 0.7rem; }
.ep-sura-card .sura-meta { font-size: 0.6rem; }

/* ── Misc ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(201,163,92,0.25); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(201,163,92,0.45); }

.loading { display: flex; flex-direction: column; align-items: center; padding: 3rem; gap: 1rem; }
.spinner {
  width: 34px; height: 34px; border: 3px solid rgba(201,163,92,0.15);
  border-top-color: var(--accent-gold); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 0.78rem; color: #7d6a45; font-family: 'Inter', sans-serif; }
.empty-state { text-align: center; padding: 2rem; color: var(--text-secondary); }
.fade-in { animation: fadeIn 0.35s var(--ease); }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.kbd-hint {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(12,16,21,0.9);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border-soft);
  padding: 0.4rem 1rem; display: flex; justify-content: center; gap: 1.5rem;
  font-size: 0.62rem; color: var(--text-secondary); z-index: 50;
  font-family: 'Inter', sans-serif;
}
kbd {
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border-soft);
  border-bottom-width: 2px;
  color: var(--accent-glow);
  padding: 0.1rem 0.42rem; border-radius: 4px;
  font-size: 0.58rem; font-family: 'Inter', monospace;
}

/* ── Responsive & accessibility ─────────────────────────────────────────── */
@media (max-width: 1024px) {
  .main-container { flex-direction: column; padding: 0.8rem; }
  .page-panel { flex: none; max-width: 100%; }
  .page-card { position: static; }
  .header { padding: 0.6rem 0.9rem; }
  .kbd-hint { display: none; }
  body { padding-bottom: env(safe-area-inset-bottom); }
}

@media (max-width: 768px) {
  /* Header stacks: title row, then a swipeable control row */
  .header {
    flex-direction: column; align-items: stretch; gap: 0.55rem;
    padding: 0.55rem 0.8rem calc(0.55rem);
    padding-left: max(0.8rem, env(safe-area-inset-left));
    padding-right: max(0.8rem, env(safe-area-inset-right));
  }
  .header-title { justify-content: center; }
  .header-title h1 { font-size: 1rem; }
  .header-title .subtitle { display: none; }
  .nav-scroll {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: 100%; padding: 2px 0;
  }
  .nav-scroll::-webkit-scrollbar { display: none; }
  .nav-controls { width: max-content; margin: 0 auto; gap: 0.7rem; }

  /* Keep any wide content from pushing the page sideways (RTL shows this as a left gap) */
  .words-panel, .page-panel, #wordsContainer { max-width: 100%; min-width: 0; }
  .words-line { max-width: 100%; }
  .stats-bar { overflow-x: auto; }

  /* Comfortable touch targets */
  .nav-btn, .goto-input { min-height: 40px; padding: 0.45rem 0.8rem; font-size: 0.78rem; }
  .view-toggle-btn { min-height: 38px; padding: 0.4rem 1.2rem; font-size: 0.76rem; }
  .rec-clear-btn, .rec-refresh-btn { min-height: 36px; padding: 0.35rem 0.7rem; }
  .rec-mic-btn { width: 46px; height: 46px; }
  .audio-play-btn { width: 44px; height: 44px; }
  .ayah-group-header { padding: 0.75rem 0.9rem; }

  /* Edit toolbar becomes a horizontal swipe strip */
  .edit-toolbar {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; gap: 0.35rem; padding: 0.5rem 0.7rem;
  }
  .edit-toolbar::-webkit-scrollbar { display: none; }
  .edit-toolbar .et-btn { min-height: 38px; padding: 0.4rem 0.7rem; white-space: nowrap; flex-shrink: 0; }
  .edit-toolbar .et-label, .edit-toolbar .et-sep { flex-shrink: 0; }
  .edit-toolbar .et-info { display: none; }

  /* Panels fill more of the screen */
  .suras-panel, .export-panel, .edit-panel {
    width: 94vw; max-height: 88vh;
  }
  .ep-header, .ep-toolbar { padding-left: 1rem; padding-right: 1rem; }
  .ep-grid { padding: 0.7rem 1rem; }
  .ep-toolbar .ep-btn { min-height: 36px; }
  .ep-count { flex-basis: 100%; text-align: left; order: 5; }
  .edit-panel { padding: 1.1rem; }
  .edit-panel .ep-row { flex-wrap: wrap; }
  .edit-panel .ep-row label { min-width: 100%; }
  .edit-panel .ep-row-coords .coord-input { flex: 1; min-width: 0; width: auto; }
  .edit-panel .ep-row input { min-height: 42px; font-size: 16px; }
  .goto-input { font-size: 16px; }  /* prevent iOS zoom on focus */
  .edit-panel .ep-actions button { min-height: 42px; flex: 1; }

  /* Toast anchored full-width above the bottom edge */
  .export-toast {
    left: 0.8rem; right: 0.8rem; max-width: none;
    bottom: calc(0.8rem + env(safe-area-inset-bottom));
  }
}

@media (max-width: 480px) {
  .main-container { padding: 0.6rem; gap: 0.8rem; }
  .header-title .icon { font-size: 1.25rem; }
  .surah-info { padding: 0.8rem 0.9rem; }
  .surah-info::before, .surah-info::after { display: none; }
  .surah-info .surah-name-ar { font-size: 1.5rem; }
  .stats-bar { gap: 0.7rem; font-size: 0.64rem; padding: 0.5rem 0.8rem; }
  .word-card { min-width: 68px; max-width: 150px; padding: 0.45rem; }
  .word-card .tashkeel-text { font-size: 1.35rem; }
  .word-card .translation-text { font-size: 0.7rem; }
  .ayah-group-header .ayah-meal-inline { font-size: 0.78rem; }
  .audio-player-bar, .recitation-bar { padding: 0.5rem 0.7rem; gap: 0.55rem; }
  .audio-reciter-label { display: none; }
  .page-card-header { padding: 0.6rem 0.8rem; }
  .badge { font-size: 0.58rem; }
  .suras-grid, .ep-sura-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}