:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --ink: #1d1d1b;
  --muted: #6d6a63;
  --line: #e7e3da;
  --quran: #1f6f50;
  --quran-tint: rgba(31, 111, 80, 0.10);
  --hadith: #9a5b13;
  --hadith-tint: rgba(196, 128, 32, 0.12);
  --live: #2f9e44;
  --warn: #d9480f;
  --shadow: 0 10px 40px rgba(29, 29, 27, 0.18);
  --text-scale: 1;
  --font-latin: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-arabic: "Noto Naskh Arabic", "Geeza Pro", "Arabic Typesetting", serif;
  --font-quran: "Amiri Quran", "Noto Naskh Arabic", serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1e1e1b;
    --ink: #ecebe6;
    --muted: #9b978d;
    --line: #2f2e2a;
    --quran: #6cc59c;
    --quran-tint: rgba(108, 197, 156, 0.14);
    --hadith: #e0a458;
    --hadith-tint: rgba(224, 164, 88, 0.14);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
html { scroll-padding-top: calc(80px + env(safe-area-inset-top)); } /* keep scrolled-to items clear of the sticky bar */
body { font-family: var(--font-latin); -webkit-font-smoothing: antialiased; }

/* -- top bar -------------------------------------------------------------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.title-wrap { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
h1 { font-size: 15px; font-weight: 600; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.status[data-state="live"] i { background: var(--live); box-shadow: 0 0 0 0 rgba(47, 158, 68, 0.6); animation: pulse 2s infinite; }
.status[data-state="offline"] i { background: var(--warn); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47,158,68,.5); } 70% { box-shadow: 0 0 0 7px rgba(47,158,68,0); } 100% { box-shadow: 0 0 0 0 rgba(47,158,68,0); } }

.actions { display: flex; gap: 6px; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  height: 34px; min-width: 34px; padding: 0 10px; border-radius: 9px; font: 500 14px var(--font-latin); cursor: pointer;
}
.icon-btn:hover { border-color: var(--muted); }
.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: 40px; min-width: 170px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
}
.menu-list a { display: block; padding: 9px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 14px; }
.menu-list a:hover { background: var(--bg); }

/* -- transcript ---------------------------------------------------------- */
main { max-width: 760px; margin: 0 auto; padding: 18px 18px 140px; }
.empty { color: var(--muted); text-align: center; margin-top: 30vh; }
.seg { margin: 0 0 16px; line-height: 1.65; font-size: calc(17px * var(--text-scale)); animation: fadein .35s ease; }
.seg[dir="rtl"] { font-family: var(--font-arabic); font-size: calc(21px * var(--text-scale)); line-height: 1.95; }
.seg .chips { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-inline-start: 6px; vertical-align: 2px; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

mark { color: inherit; border-radius: 4px; padding: 0 1px; transition: background .3s; }
mark.quran { background: var(--quran-tint); box-shadow: inset 0 -2px 0 var(--quran); }
mark.hadith { background: var(--hadith-tint); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--hadith) 70%, transparent); }
mark.suggestion { background: transparent; box-shadow: inset 0 -2px 0 color-mix(in srgb, currentColor 0%, transparent); border-bottom: 2px dashed var(--hadith); border-radius: 0; }
mark.quran.suggestion { border-bottom-color: var(--quran); }
mark.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { background: color-mix(in srgb, var(--quran) 35%, transparent); } }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font: 600 12px/1 var(--font-latin); direction: ltr;
  padding: 6px 9px; border-radius: 999px; cursor: pointer; border: 1px solid transparent;
  animation: fadein .35s ease;
}
.chip.quran { color: var(--quran); background: var(--quran-tint); border-color: color-mix(in srgb, var(--quran) 30%, transparent); }
.chip.hadith { color: var(--hadith); background: var(--hadith-tint); border-color: color-mix(in srgb, var(--hadith) 30%, transparent); }
.chip.suggestion { border-style: dashed; }
.chip .pct { font-weight: 500; opacity: .75; }

.partial { color: var(--muted); font-size: calc(17px * var(--text-scale)); line-height: 1.65; margin: 0; }
.partial[dir="rtl"] { font-family: var(--font-arabic); font-size: calc(21px * var(--text-scale)); line-height: 1.95; }
.partial::after { content: ""; display: inline-block; width: 2px; height: 1em; background: var(--muted); margin-inline-start: 3px; vertical-align: -2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.jump {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  border: 0; border-radius: 999px; padding: 10px 16px; font: 600 14px var(--font-latin);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow); cursor: pointer;
}

/* -- source sheet ---------------------------------------------------------- */
.sheet {
  border: 0; padding: 0; width: min(680px, 100%); max-height: 85vh; margin: auto auto 0;
  border-radius: 18px 18px 0 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
}
@media (min-width: 720px) { .sheet { margin: auto; border-radius: 18px; } }
.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet[open] { animation: up .25s ease; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-inner { padding: 20px 20px calc(22px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.kind { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.kind.quran { color: var(--quran); } .kind.hadith { color: var(--hadith); }
.sheet h2 { margin: 4px 0 2px; font-size: 22px; }
.sub { color: var(--muted); font-size: 14px; }
.sub .ar { font-family: var(--font-arabic); font-size: 16px; }
.badge { display: inline-block; margin: 14px 0 4px; font-size: 13px; font-weight: 500; padding: 5px 10px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
.source { direction: rtl; text-align: right; margin: 14px 0; padding: 16px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.source.quran { font-family: var(--font-quran); font-size: 25px; line-height: 2.3; }
.source.hadith { font-family: var(--font-arabic); font-size: 19px; line-height: 2; max-height: 40vh; overflow: auto; }
.source .isnad { color: var(--muted); font-size: .82em; }
.source .matn { font-weight: 600; }
.ayah-num { font-family: var(--font-arabic); font-size: .7em; color: var(--quran); margin: 0 4px; }
.meta { font-size: 14px; color: var(--muted); display: grid; gap: 4px; }
.source-link { color: inherit; font-weight: 600; }
.note { font-size: 12px; color: var(--muted); margin: 14px 0 0; }

.auth { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); text-align: center; color: var(--muted); }

/* -- talk ended / archive ---------------------------------------------------- */
.ended {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; justify-content: center;
  width: max-content; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 14px;
}
.ended a { color: var(--quran); font-weight: 600; text-decoration: none; }
.ended:not([hidden]) ~ .jump { bottom: calc(84px + env(safe-area-inset-bottom)); }
.talk-list ul { list-style: none; margin: 0; padding: 0; }
.talk-list li { display: flex; flex-direction: column; gap: 3px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.talk-list a { color: var(--ink); font-weight: 600; font-size: 17px; text-decoration: none; }
.talk-list a:hover { color: var(--quran); }
.talk-list .when { color: var(--muted); font-size: 13px; }
.back { display: block; font-size: 12px; color: var(--muted); text-decoration: none; margin-bottom: 2px; }

/* -- recording player (archived talks) ------------------------------------------ */
.player {
  position: fixed; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(736px, calc(100% - 24px)); height: 44px; border-radius: 999px; box-shadow: var(--shadow); z-index: 4;
}
.ts {
  border: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer;
  font: 500 11px var(--font-latin); font-variant-numeric: tabular-nums;
  padding: 1px 7px; border-radius: 999px; margin-inline-end: 8px; vertical-align: 2px;
}
.ts:hover { color: var(--ink); border-color: var(--muted); }
.seg.playing { background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: 8px;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--ink) 6%, transparent); }
