/* Quran.tv Tahfez — all controls inside one mushaf stage */
:root {
  --tl-ink: #14201c;
  --tl-muted: #5c6b64;
  --tl-paper: #f3efe4;
  --tl-card: #fffdf8;
  --tl-line: #d9d2c2;
  --tl-green: #0b6b56;
  --tl-green-deep: #084d3e;
  --tl-accent: #c4a35a;
  --tl-match: #d7efe4;
  --tl-current: #ffe8a3;
  --tl-err: #b42318;
  --tl-radius: 16px;
  --tl-ui: 'Segoe UI', Tahoma, 'Noto Sans Arabic', sans-serif;
  --tl-quran: 'UthmanicHafs', 'HafsSmart', 'Traditional Arabic', 'Amiri Quran', serif;
  --tl-page: #fffdf6;
  --tl-page-edge: #d7c29a;
}

.qtv-tahfez[data-theme="dark"] {
  --tl-ink: #e8efe9;
  --tl-muted: #9aaba3;
  --tl-paper: #0f1714;
  --tl-card: #17221e;
  --tl-line: #2a3a33;
  --tl-match: #1e3d32;
  --tl-current: #4a3d18;
  --tl-page: #1c2622;
  --tl-page-edge: #3a4a40;
}

.qtv-tahfez {
  font-family: var(--tl-ui);
  color: var(--tl-ink);
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  overflow: visible;
  max-width: 560px;
  margin: 0.75rem auto;
  box-shadow: none !important;
  position: relative;
  display: block;
  min-height: 0;
  padding: 0 !important;
}

/* صندوق واحد فقط: أزرار + قائمة + مصحف */
.tl-stage {
  display: flex !important;
  flex-direction: column !important;
  min-height: 70vh;
  max-height: min(920px, 92dvh);
  background: var(--tl-page) !important;
  border: 1px solid var(--tl-page-edge) !important;
  border-radius: var(--tl-radius) !important;
  box-shadow: 0 14px 42px rgba(55, 40, 12, 0.16);
  overflow: hidden !important;
  position: relative;
  margin: 0 !important;
  padding: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.qtv-tahfez[data-theme="dark"] .tl-stage {
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.4);
}

/* شريط التشغيل أعلى الصندوق مع القائمة */
.tl-toolbar {
  display: flex !important;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.5rem;
  background: linear-gradient(120deg, var(--tl-green), var(--tl-green-deep)) !important;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.tl-page-label {
  min-width: 3.4rem;
  text-align: center;
  font-weight: 800;
  font-size: 0.8rem;
  color: #fff;
}

.tl-select {
  border: 1px solid var(--tl-line);
  border-radius: 8px;
  padding: 0.28rem 0.35rem;
  font: inherit;
  font-size: 0.78rem;
  width: 100%;
  box-sizing: border-box;
  background: var(--tl-card);
  color: var(--tl-ink);
}
.tl-select-sm { max-width: 100%; }

.tl-dock-nav {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  flex: 1 1 auto;
  min-width: 0;
}

.tl-nav-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-radius: 8px;
  min-width: 2rem;
  height: 2.1rem;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.tl-nav-btn:hover { background: rgba(255, 255, 255, 0.24); }

.tl-mic-btn {
  border: 0;
  background: #fff;
  color: var(--tl-green-deep);
  border-radius: 50%;
  width: 2.1rem;
  min-width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}
.tl-mic-btn:hover { filter: brightness(0.97); }
.tl-mic-btn:disabled { opacity: 0.55; cursor: wait; }
.tl-mic-btn.is-live {
  background: var(--tl-err);
  color: #fff;
  box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.45);
  animation: tl-pulse 1.4s infinite;
}
.tl-mic-icon {
  display: block;
  pointer-events: none;
}

.tl-field-lang-tb {
  display: flex !important;
  align-items: center;
  margin: 0 !important;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 9.5rem;
}

.tl-select-lang {
  min-width: 5.6rem;
  max-width: 8rem;
  height: 2.1rem;
  padding: 0.15rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.35) !important;
  background: rgba(255, 255, 255, 0.96) !important;
  color: #0f3d2a !important;
  font-weight: 700;
  font-size: 0.72rem;
}

.tl-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.tl-icon-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-radius: 8px;
  min-width: 2.1rem;
  height: 2.1rem;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
}
.tl-icon-btn:hover { background: rgba(255, 255, 255, 0.24); }

@keyframes tl-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(180, 35, 24, 0); }
}

/* خيارات داخل الصندوق تحت شريط التشغيل */
.tl-opts {
  display: grid !important;
  grid-template-columns: 1.35fr 0.55fr 0.75fr;
  gap: 0.3rem;
  align-items: center;
  padding: 0.35rem 0.5rem;
  background: transparent !important;
  border-bottom: 1px solid var(--tl-page-edge);
  flex-shrink: 0;
}
.qtv-tahfez[data-theme="dark"] .tl-opts {
  background: transparent !important;
}

.tl-field {
  display: flex;
  flex-direction: column;
  gap: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--tl-muted);
  min-width: 0;
  margin: 0;
}
.tl-field-inline span { line-height: 1.2; }
.tl-opts-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  align-items: center;
  width: 100%;
}
.tl-opts-actions .tl-tool {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  height: 2.2rem;
}
.tl-tools-sep {
  width: 2px;
  height: 1.4rem;
  margin: 0 0.1rem;
  background: var(--tl-accent);
  opacity: 0.5;
  flex: 0 0 2px;
  align-self: center;
}

.tl-listen {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  align-items: center;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--tl-page-edge);
  flex-shrink: 0;
}
.tl-field-reciter {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}

/* أزرار أيقونات مضغوطة */
.tl-tool {
  border: 1px solid var(--tl-page-edge);
  background: rgba(11, 107, 86, 0.07);
  color: var(--tl-ink);
  border-radius: 9px;
  width: 2.05rem;
  min-width: 2.05rem;
  height: 2.05rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}
.tl-tool:hover { background: rgba(11, 107, 86, 0.14); }
.tl-tool.is-on {
  background: var(--tl-green);
  border-color: var(--tl-green);
  color: #fff;
}
.qtv-tahfez[data-theme="dark"] .tl-tool {
  background: rgba(11, 107, 86, 0.18);
  border-color: #3a4a40;
  color: #e8efe9;
}
.qtv-tahfez[data-theme="dark"] .tl-tool.is-on {
  background: var(--tl-green);
  color: #fff;
}
.tl-ico {
  display: block;
  pointer-events: none;
}
#tl-blank .tl-ico-show { display: none; }
#tl-blank:not(.is-on) .tl-ico-blank { display: none; }
#tl-blank:not(.is-on) .tl-ico-show { display: block; }

.tl-chip {
  border: 1px solid var(--tl-page-edge);
  background: rgba(11, 107, 86, 0.07);
  color: var(--tl-ink);
  border-radius: 999px;
  padding: 0.32rem 0.7rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  flex: 1 1 auto;
  min-width: 3.8rem;
  text-align: center;
}
.tl-chip:hover { background: rgba(11, 107, 86, 0.14); }
.tl-chip.is-on {
  background: var(--tl-green);
  color: #fff;
  border-color: var(--tl-green);
}
.qtv-tahfez[data-theme="dark"] .tl-chip {
  background: rgba(11, 107, 86, 0.18);
  border-color: #2a3a33;
}

.tl-status-wrap {
  padding: 0.2rem 0.5rem 0.25rem;
  background: transparent !important;
  border-bottom: 1px solid rgba(215, 194, 154, 0.35);
  flex-shrink: 0;
}
.qtv-tahfez[data-theme="dark"] .tl-status-wrap {
  border-bottom-color: #2a3a33;
}
.tl-status-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem;
  align-items: flex-start;
}
.tl-status {
  margin: 0;
  color: var(--tl-muted);
  font-size: 0.78rem;
  flex: 1;
  line-height: 1.35;
  max-height: 3.2em;
  overflow: auto;
}
.tl-status.is-err { color: var(--tl-err); font-weight: 700; }
.tl-status.is-live { color: var(--tl-green); font-weight: 700; }
.tl-status.is-ok { color: var(--tl-green-deep); font-weight: 700; }
.tl-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(11, 107, 86, 0.1);
  color: var(--tl-green);
  border: 1px solid rgba(11, 107, 86, 0.22);
  flex-shrink: 0;
}
.tl-progress { margin-top: 0.25rem; }
.tl-progress[hidden] { display: none !important; }
.tl-progress-track {
  height: 4px;
  background: var(--tl-line);
  border-radius: 999px;
  overflow: hidden;
}
.tl-progress-track span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--tl-green), #14a07d);
  transition: width 0.25s ease;
}
.tl-progress-text {
  margin-top: 0.12rem;
  font-size: 0.65rem;
  color: var(--tl-muted);
}
.tl-transcript {
  margin: 0.15rem 0 0;
  min-height: 0;
  max-height: 2.4em;
  overflow: auto;
  color: var(--tl-green-deep);
  font-weight: 700;
  font-size: 0.82rem;
  line-height: 1.3;
}
.tl-transcript[hidden] { display: none !important; }
.tl-type-panel { margin-top: 0.3rem; }
.tl-type-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--tl-line);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.95rem;
  background: var(--tl-card);
  color: var(--tl-ink);
}

/* منطقة القرآن داخل نفس الصندوق */
.tl-mushaf {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: auto !important;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px 18px;
  display: block !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  margin: 0 !important;
  max-width: none !important;
  width: 100% !important;
}

.tl-page-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--tl-ui);
  font-size: 0.78rem;
  color: #7a5a25;
  border-bottom: 1px solid #ead9b7;
  padding: 4px 2px 8px;
  margin-bottom: 10px;
  position: sticky;
  top: 0;
  background: var(--tl-page);
  z-index: 2;
}
.qtv-tahfez[data-theme="dark"] .tl-page-meta {
  color: #c4a35a;
  border-bottom-color: #3a4a40;
}

.tl-mushaf-body {
  width: 100%;
}

.tl-loading {
  font-family: var(--tl-ui);
  color: var(--tl-muted);
  text-align: center;
  padding: 2.5rem 1rem;
}

.tl-surah-title {
  margin: 10px auto 8px;
  padding: 5px 22px;
  border: 1px solid #d9bd86;
  border-radius: 999px;
  background: #fff8e7;
  color: #07583d;
  font-family: var(--tl-ui);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
  width: fit-content;
  min-width: 160px;
}
.qtv-tahfez[data-theme="dark"] .tl-surah-title {
  background: #24332c;
  border-color: #4a5c50;
  color: #b8e0cf;
}
.tl-basmala {
  text-align: center;
  font-family: var(--tl-quran);
  font-size: 1.3rem;
  line-height: 2.2;
  color: #111;
  margin: 2px 0 8px;
}
.qtv-tahfez[data-theme="dark"] .tl-basmala { color: #e8efe9; }

.tl-ayahs {
  font-family: var(--tl-quran);
  font-size: 1.55rem;
  line-height: 2.6;
  text-align: justify;
  text-align-last: center;
  direction: rtl;
  word-spacing: 0.06em;
}
.tl-ayah {
  display: inline;
  margin: 0;
  padding: 0;
  background: transparent !important;
  box-shadow: none !important;
}
.tl-ayah-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55em;
  height: 1.55em;
  margin: 0 0.18em;
  border: 1.5px solid #c4a35a;
  border-radius: 50%;
  font-family: var(--tl-ui);
  font-size: 0.58em;
  /* أرقام الآيات تبقى ظاهرة دائماً — حتى في الوضع الفارغ */
  color: #7a5218 !important;
  vertical-align: middle;
  background: var(--tl-page);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(196, 163, 90, 0.35);
  opacity: 1 !important;
  visibility: visible !important;
  user-select: none;
}
.qtv-tahfez[data-theme="dark"] .tl-ayah-num {
  background: #24332c;
  border-color: #c4a35a;
  color: #e0c07a !important;
  box-shadow: inset 0 0 0 1px rgba(196, 163, 90, 0.45);
}

.tl-word {
  display: inline;
  padding: 0.02em 0.03em;
  border-radius: 3px;
  transition: color 0.22s ease, background 0.22s ease, opacity 0.22s ease, filter 0.22s ease;
}

.qtv-tahfez[data-blank="1"] .tl-basmala {
  color: transparent !important;
  user-select: none;
  -webkit-user-select: none;
}

.qtv-tahfez[data-blank="1"] .tl-word:not(.is-matched):not(.is-current) {
  color: transparent !important;
  background: transparent !important;
  border: 0 !important;
  text-shadow: none !important;
  user-select: none;
  -webkit-user-select: none;
}

.qtv-tahfez[data-blank="1"] .tl-word.is-current:not(.is-matched) {
  color: transparent !important;
  background: rgba(196, 163, 90, 0.28);
  box-shadow: inset 0 -2px 0 rgba(196, 163, 90, 0.65);
  border-radius: 4px;
}

.qtv-tahfez[data-blank="1"] .tl-word.is-current.is-miss:not(.is-matched) {
  color: #e53935 !important;
  background: rgba(176, 48, 48, 0.28);
  box-shadow: inset 0 -2px 0 rgba(176, 48, 48, 0.85);
  animation: none !important;
}

.qtv-tahfez:not([data-blank="1"]) .tl-word.is-current {
  background: var(--tl-current);
  box-shadow: 0 0 0 1px rgba(196, 163, 90, 0.35);
}

.qtv-tahfez:not([data-blank="1"]) .tl-word.is-current.is-miss {
  color: #e53935 !important;
  background: rgba(176, 48, 48, 0.28);
  box-shadow: 0 0 0 1px rgba(176, 48, 48, 0.45);
  animation: none !important;
}

.qtv-tahfez:not([data-blank="1"]) .tl-word.is-matched {
  animation: none !important;
  color: #07583d !important;
  background: rgba(11, 107, 86, 0.14) !important;
  border-radius: 4px;
  filter: none !important;
  opacity: 1 !important;
}
.qtv-tahfez[data-theme="dark"]:not([data-blank="1"]) .tl-word.is-matched {
  color: #b8e0cf !important;
  background: rgba(11, 107, 86, 0.28) !important;
}

/* تطابق صحيح: ظهور ثابت بلا وميض */
.qtv-tahfez[data-blank="1"] .tl-word.is-matched {
  background: transparent !important;
  box-shadow: none !important;
  color: #111 !important;
  animation: none !important;
  filter: none !important;
  opacity: 1 !important;
}
.qtv-tahfez[data-theme="dark"][data-blank="1"] .tl-word.is-matched {
  color: #e8efe9 !important;
  animation: none !important;
}

/* إشعار قصير لوضع الآيات المخفية */
.tl-toast {
  position: absolute;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%) translateY(8px);
  z-index: 40;
  max-width: calc(100% - 2rem);
  padding: 0.55rem 1rem;
  border-radius: 10px;
  background: rgba(18, 24, 22, 0.92);
  color: #fff;
  font-family: var(--tl-ui);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.tl-toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 820px) {
  .qtv-tahfez {
    margin: 0.35rem;
    max-width: none;
    width: auto;
  }
  .tl-stage {
    min-height: calc(100dvh - 7.5rem);
    height: auto;
    max-height: none;
    border-radius: 14px !important;
    border: 1px solid var(--tl-page-edge) !important;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  }
  .tl-ayahs { font-size: 1.2rem; line-height: 2.2; }
  .tl-surah-title { font-size: 0.8rem; min-width: 130px; padding: 4px 16px; }

  .tl-toolbar {
    gap: 0.3rem;
    padding: 0.35rem 0.45rem;
  }
  .tl-mic-btn {
    width: 2.7rem;
    min-width: 2.7rem;
    height: 2.7rem;
  }
  .tl-mic-icon {
    width: 22px;
    height: 22px;
  }
  .tl-field-lang-tb { max-width: 6.2rem; }
  .tl-select-lang {
    min-width: 4.6rem;
    max-width: 6.2rem;
    height: 2.2rem;
    font-size: 0.68rem;
  }
  .tl-page-label { min-width: 2.4rem; font-size: 0.7rem; }
  .tl-nav-btn { min-width: 1.9rem; height: 2.2rem; }
  .tl-icon-btn { height: 2.2rem; min-width: 2.1rem; }

  .tl-opts {
    grid-template-columns: 1.25fr 0.5fr 0.7fr;
    gap: 0.28rem;
    padding: 0.3rem 0.4rem 0.2rem;
  }
  .tl-opts-actions {
    grid-column: 1 / -1;
    display: flex;
    width: 100%;
    gap: 0.28rem;
    justify-content: stretch;
    margin-top: 0.1rem;
  }
  .tl-opts-actions .tl-tool {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    height: 2.45rem;
    border-radius: 10px;
  }
  .tl-tools-sep {
    width: 2px;
    height: 1.6rem;
    margin: 0 0.05rem;
    flex: 0 0 2px;
    background: var(--tl-accent);
    opacity: 0.55;
  }
  .tl-listen {
    padding: 0.25rem 0.4rem 0.35rem;
  }
  .tl-field-reciter .tl-select {
    height: 2.35rem;
  }
  .tl-status-wrap {
    padding: 0.15rem 0.4rem 0.2rem;
  }
  .tl-toast {
    bottom: 1rem;
    font-size: 0.84rem;
  }
}

@media (max-width: 380px) {
  .tl-opts {
    grid-template-columns: 1fr 0.55fr 0.75fr;
  }
  .tl-field-level {
    grid-column: auto;
  }
  .tl-page-label { min-width: 2.3rem; font-size: 0.68rem; }
  .tl-mic-btn {
    width: 2.85rem;
    min-width: 2.85rem;
    height: 2.85rem;
  }
  .tl-mic-icon {
    width: 24px;
    height: 24px;
  }
  .tl-opts-actions .tl-tool {
    height: 2.55rem;
  }
}
