/* Quran.tv Tilawa — 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: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  --tl-quran: 'HafsSmart', 'Amiri Quran', 'Traditional Arabic', serif;
  --tl-page: #fffdf6;
  --tl-page-edge: #d7c29a;
}

.qtv-tilawa[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-tilawa {
  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-tilawa[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.4rem;
  padding: 0.55rem 0.65rem;
  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.38rem 0.45rem;
  font: inherit;
  font-size: 0.82rem;
  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: 9px;
  min-width: 2.2rem;
  height: 2.4rem;
  font-size: 1.25rem;
  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: 11px;
  min-width: 5.4rem;
  height: 2.4rem;
  padding: 0 0.85rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}
.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-icon-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-radius: 10px;
  min-width: 2.25rem;
  height: 2.4rem;
  font-size: 1.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.4fr 0.7fr 0.9fr;
  gap: 0.4rem 0.45rem;
  padding: 0.5rem 0.65rem;
  background: transparent !important;
  border-bottom: 1px solid var(--tl-page-edge);
  flex-shrink: 0;
}
.qtv-tilawa[data-theme="dark"] .tl-opts {
  background: transparent !important;
}

.tl-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--tl-muted);
  min-width: 0;
}
.tl-field-inline span { line-height: 1.2; }
.tl-opts-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.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-tilawa[data-theme="dark"] .tl-chip {
  background: rgba(11, 107, 86, 0.18);
  border-color: #2a3a33;
}

.tl-status-wrap {
  padding: 0.3rem 0.65rem 0.35rem;
  background: transparent !important;
  border-bottom: 1px solid rgba(215, 194, 154, 0.35);
  flex-shrink: 0;
}
.qtv-tilawa[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-tilawa[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-tilawa[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-tilawa[data-theme="dark"] .tl-basmala { color: #e8efe9; }

.tl-ayahs {
  font-family: var(--tl-quran);
  font-size: 1.42rem;
  line-height: 2.35;
  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: 1px solid #cda05a;
  border-radius: 50%;
  font-family: var(--tl-ui);
  font-size: 0.58em;
  color: #8a601d;
  vertical-align: middle;
  background: var(--tl-page);
  font-weight: 700;
}
.qtv-tilawa[data-theme="dark"] .tl-ayah-num {
  background: #24332c;
  border-color: #c4a35a;
  color: #c4a35a;
}

.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-tilawa[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-tilawa[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-tilawa[data-blank="1"] .tl-word.is-current.is-miss:not(.is-matched) {
  color: #e53935 !important;
  background: rgba(176, 48, 48, 0.4);
  box-shadow: inset 0 -2px 0 rgba(176, 48, 48, 0.95);
  animation: tl-miss-pulse 0.9s ease-in-out 2;
}

.qtv-tilawa: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-tilawa:not([data-blank="1"]) .tl-word.is-current.is-miss {
  color: #e53935 !important;
  background: rgba(176, 48, 48, 0.42);
  box-shadow: 0 0 0 1px rgba(176, 48, 48, 0.65);
  animation: tl-miss-pulse 0.9s ease-in-out 2;
}

@keyframes tl-miss-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.15); }
}

.qtv-tilawa: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-tilawa[data-theme="dark"]:not([data-blank="1"]) .tl-word.is-matched {
  color: #b8e0cf !important;
  background: rgba(11, 107, 86, 0.28) !important;
}

.qtv-tilawa[data-blank="1"] .tl-word.is-matched {
  background: transparent !important;
  box-shadow: none !important;
  color: #111;
  animation: tl-reveal 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.qtv-tilawa[data-theme="dark"][data-blank="1"] .tl-word.is-matched {
  color: #e8efe9;
  animation-name: tl-reveal-dark;
}

@keyframes tl-reveal {
  0% { color: transparent; filter: blur(2px); opacity: 0.45; }
  100% { color: #111; filter: none; opacity: 1; }
}
@keyframes tl-reveal-dark {
  0% { color: transparent; filter: blur(2px); opacity: 0.45; }
  100% { color: #e8efe9; filter: none; opacity: 1; }
}

.qtv-tilawa[data-blank="1"] .tl-ayah-num { opacity: 0.55; }

@media (max-width: 820px) {
  .qtv-tilawa {
    margin: 0.4rem;
    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.45rem 0.5rem; }
  .tl-mic-btn { min-width: 4.5rem; padding: 0 0.5rem; font-size: 0.84rem; height: 2.25rem; }
  .tl-page-label { min-width: 2.9rem; font-size: 0.72rem; }
  .tl-nav-btn { min-width: 2rem; height: 2.25rem; }
  .tl-icon-btn { height: 2.25rem; min-width: 2.1rem; }
  .tl-opts {
    grid-template-columns: 1fr 0.65fr 0.85fr;
    padding: 0.45rem 0.55rem;
  }
  .tl-chip {
    font-size: 0.72rem;
    padding: 0.3rem 0.55rem;
    min-width: 3.2rem;
  }
}

@media (max-width: 380px) {
  .tl-opts {
    grid-template-columns: 1fr 1fr;
  }
  .tl-field-level {
    grid-column: 1 / -1;
  }
  .tl-page-label { min-width: 2.6rem; font-size: 0.7rem; }
  .tl-mic-btn { min-width: 4rem; font-size: 0.8rem; }
}
