/* Tahfeez (تحفيظ) - Emerald & Gold Mushaf Theme (Mobile-First RTL) */
:root {
  --bg: #f6f3ea;
  --surface: #ffffff;
  --surface-alt: #f0ebe0;
  --border: #dfd6c3;
  --text: #1c2420;
  --text-muted: #5d6a63;
  --primary: #0b4f3a;
  --primary-hover: #083d2c;
  --primary-soft: rgba(11, 79, 58, 0.1);
  --gold: #c99732;
  --gold-soft: rgba(201, 151, 50, 0.15);
  --success: #15803d;
  --success-bg: #dcfce7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --shadow: 0 6px 24px rgba(11, 79, 58, 0.08);
  --radius: 16px;
  --quran-size: 1.85rem;
}

body.theme-dark {
  --bg: #0c1411;
  --surface: #13201b;
  --surface-alt: #192b24;
  --border: #253d34;
  --text: #eef3f0;
  --text-muted: #9eb3aa;
  --primary: #1c8c67;
  --primary-hover: #22a87c;
  --primary-soft: rgba(28, 140, 103, 0.18);
  --gold: #e5b856;
  --gold-soft: rgba(229, 184, 86, 0.16);
  --success: #4ade80;
  --success-bg: rgba(22, 101, 52, 0.35);
  --danger: #f87171;
  --danger-bg: rgba(153, 27, 27, 0.35);
  --warn: #fbbf24;
  --warn-bg: rgba(146, 64, 14, 0.35);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Cairo", system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background-color 0.25s, color 0.25s;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.header-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
}

.brand-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.1;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.wird-pill {
  background: var(--gold-soft);
  color: var(--text);
  border: 1px solid var(--gold);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}

.font-controls {
  display: flex;
  gap: 0.25rem;
}

.btn-icon {
  position: relative;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  min-width: 38px;
  height: 38px;
  padding: 0 0.5rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, background-color 0.2s;
}

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

.badge-mini {
  position: absolute;
  top: -5px;
  left: -5px;
  background: var(--gold);
  color: #fff;
  font-size: 0.68rem;
  padding: 0 5px;
  border-radius: 999px;
  line-height: 1.4;
}

/* Main Container */
.main-container {
  max-width: 980px;
  margin: 1.25rem auto 3rem;
  padding: 0 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem;
  margin-bottom: 1rem;
}

/* Resume Card */
.resume-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  border: 2px solid var(--gold);
  background: linear-gradient(135deg, var(--surface) 0%, var(--gold-soft) 100%);
}

.resume-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--primary);
  background: var(--surface);
  border: 1px solid var(--gold);
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.35rem;
}

.resume-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Selection Screen */
.hero-banner {
  text-align: center;
  padding: 1.25rem 1rem 1.5rem;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 1.35rem;
}

.hero-ornament {
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: 1.45rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.hero-banner h2 {
  font-size: 1.45rem;
  font-weight: 800;
  margin-bottom: 0.35rem;
}

.hero-banner p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.selector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group label {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
}

.input-field,
.select-sm {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  color: var(--text);
  font-family: inherit;
  font-size: 0.96rem;
}

.select-sm {
  width: auto;
  padding: 0.4rem 0.7rem;
  font-size: 0.88rem;
}

.input-field:focus,
.select-sm:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.ayah-range-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.range-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.range-title {
  font-weight: 700;
}

.meta-badge {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.chip-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.38rem 0.85rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.range-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.selection-footer {
  display: flex;
  justify-content: center;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-outline {
  border-radius: 12px;
  padding: 0.7rem 1.35rem;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: transform 0.15s, background-color 0.2s;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-secondary {
  background: var(--gold);
  color: #fff;
}

.btn-outline {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-outline.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}

.btn-sm {
  padding: 0.42rem 0.85rem;
  font-size: 0.86rem;
}

.btn-lg {
  padding: 0.85rem 1.75rem;
  font-size: 1.05rem;
}

/* Stepper */
.stepper-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.step-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 12px;
  padding: 0.65rem 0.5rem;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.step-tab .step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-alt);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.step-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.step-tab.active .step-num {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.workspace-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.2rem;
}

.muted-text {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.step1-tools {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.6rem;
}

#learning-workspace {
  padding-bottom: 7.5rem;
}

.floating-player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 45;
  background: var(--surface);
  border-top: 2px solid var(--primary);
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
  padding: 0.65rem 1rem;
}

.floating-player-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.floating-player-bar .audio-main-controls {
  margin-bottom: 0;
  gap: 0.55rem;
}

.floating-player-bar .audio-status-bar {
  width: 100%;
  margin-top: 0.15rem;
  padding: 0.25rem 0.6rem;
  font-size: 0.82rem;
}

/* Audio Control Card */
.audio-main-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.btn-play {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.8rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-circle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
}

.audio-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
}

.inline-opt {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.audio-status-bar {
  margin-top: 0.75rem;
  text-align: center;
  padding: 0.4rem 0.75rem;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 700;
}

/* Mushaf Ayah Cards */
.mushaf-basmala {
  text-align: center;
  font-family: "Amiri", "Scheherazade New", serif;
  font-size: 1.75rem;
  color: var(--primary);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.ayahs-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.ayah-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.3rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.ayah-card.playing {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.ayah-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.ayah-num-badge {
  background: var(--gold-soft);
  color: var(--text);
  border: 1px solid var(--gold);
  border-radius: 999px;
  padding: 0.15rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 700;
}

.quran-text,
.quran-text-lg {
  font-family: "Scheherazade New", "Amiri", serif;
  font-size: var(--quran-size);
  line-height: 2.25;
  text-align: justify;
  direction: rtl;
}

.ayah-end-symbol {
  color: var(--gold);
  font-weight: 700;
  margin: 0 0.25rem;
}

.ayah-word {
  display: inline;
  padding: 0.04rem 0.22rem;
  border-radius: 6px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ayah-word.word-active {
  background: var(--gold-soft);
  color: var(--primary);
  box-shadow: 0 2px 0 var(--gold);
}

.ayah-word.word-passed {
  color: var(--primary);
}

.ayah-card-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stage-hint {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.tafsir-box {
  margin-top: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface-alt);
  border-right: 3px solid var(--primary);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Mic & Verification */
.stage-intro-card h3 {
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.verify-mode-bar,
.rabt-bar,
.test-mode-tabs,
.mask-levels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
  align-items: center;
}

.mic-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin: 1rem 0;
}

.btn-mic {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.5rem;
  font-family: inherit;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-mic.listening {
  background: var(--danger);
  animation: pulseMic 1.3s infinite;
}

.mic-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
}

@keyframes pulseMic {
  0% { box-shadow: 0 0 0 0 rgba(185, 28, 28, 0.5); }
  70% { box-shadow: 0 0 0 12px rgba(185, 28, 28, 0); }
  100% { box-shadow: 0 0 0 0 rgba(185, 28, 28, 0); }
}

.manual-check-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.result-box {
  margin-top: 1.1rem;
  padding: 1rem;
  border-radius: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.score-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.score-badge {
  font-size: 1.05rem;
  font-weight: 800;
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
}

.score-badge.pass { background: var(--success-bg); color: var(--success); }
.score-badge.warn { background: var(--warn-bg); color: var(--warn); }
.score-badge.fail { background: var(--danger-bg); color: var(--danger); }

.words-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  font-family: "Scheherazade New", "Amiri", serif;
  font-size: 1.65rem;
  line-height: 2;
}

.w-tok {
  padding: 0.1rem 0.45rem;
  border-radius: 8px;
}
.w-tok.correct { background: var(--success-bg); color: var(--success); }
.w-tok.mismatch { background: var(--danger-bg); color: var(--danger); text-decoration: underline wavy; }
.w-tok.missing { background: var(--warn-bg); color: var(--warn); }

/* Step 3: Masking */
.mask-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.45rem 0.9rem;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
}

.mask-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.mem-word {
  display: inline-block;
  margin: 0 0.18rem;
  padding: 0.05rem 0.35rem;
  border-radius: 6px;
}

.mem-word.hidden-word {
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px dashed var(--primary);
  cursor: pointer;
  min-width: 52px;
  text-align: center;
  font-family: "Cairo", sans-serif;
  font-size: 1rem;
}

.mem-word.revealed {
  background: var(--gold-soft);
}

/* Step 4: Live Recite Canvas & Quiz */
.live-recite-canvas {
  min-height: 110px;
  padding: 1rem;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 12px;
  font-family: "Scheherazade New", "Amiri", serif;
  font-size: var(--quran-size);
  line-height: 2.2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.live-word.hidden-live {
  color: transparent;
  background: var(--border);
  border-radius: 6px;
  user-select: none;
}

.live-word.matched-live {
  color: var(--success);
  background: var(--success-bg);
  border-radius: 6px;
  padding: 0 0.3rem;
}

.quiz-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0;
}

.quiz-choice-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 1.15rem;
  border-radius: 12px;
  font-family: "Scheherazade New", "Amiri", serif;
  font-size: 1.5rem;
  cursor: pointer;
}

.quiz-choice-btn.right { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.quiz-choice-btn.wrong { background: var(--danger-bg); border-color: var(--danger); color: var(--danger); }

.quiz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
}

.step-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.step-footer.space-between {
  justify-content: space-between;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  margin-bottom: 1.1rem;
}

.stat-box {
  background: var(--surface-alt);
  border-radius: 12px;
  padding: 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
}

.stat-val { font-size: 1.4rem; font-weight: 800; color: var(--primary); }
.stat-lbl { font-size: 0.78rem; color: var(--text-muted); }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  background: var(--surface-alt);
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 0.7rem 1.35rem;
  border-radius: 999px;
  font-weight: 700;
  z-index: 80;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

@media (max-width: 640px) {
  .stepper-bar { grid-template-columns: repeat(2, 1fr); }
  .brand-subtitle { display: none; }
  .step-footer { flex-direction: column; }
  .step-footer button { width: 100%; }
}
