:root {
  --bg: #fbfbfd;
  --surface: #ffffff;
  --text: #1d1d1f;
  --text-soft: #6e6e73;
  --text-faint: #75757a;   /* AA 4.5:1 sur --surface — porte l'historique des phrases, pas décoratif */
  --line: #e7e7ec;
  --fr: #059669;
  --en: #2563eb;
  --accent: #059669;   /* défaut, surchargé par colonne (--accent) */
  --quran: #b7791f;    /* traduction canonique (Coran), distincte de la MT */
  --hadith: #7c6f9c;   /* traduction canonique (Hadith), distincte du Coran */
  --radius: 28px;
  --text-scale: 1;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
          "Segoe UI", Roboto, "Noto Naskh Arabic", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Fond clair, deux voiles de couleur très légers (statique) */
.bg-decor {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 40% at 14% -8%, rgba(5, 150, 105, 0.05), transparent 60%),
    radial-gradient(55% 38% at 100% -8%, rgba(37, 99, 235, 0.05), transparent 60%);
}

/* ---------- Header : pilule flottante en verre (Creative Tim) ---------- */
.topbar {
  flex: 0 0 auto;
  margin: clamp(0.7rem, 1.4vw, 1.15rem) clamp(0.7rem, 1.6vw, 1.3rem) 0;
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 0.7rem 0.6rem 1.2rem;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 100px;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.05);
}
.brand { display: flex; align-items: center; gap: 0.6rem; flex: 0 0 auto; }
.emblem { color: var(--fr); display: inline-flex; align-items: center; }
.emblem svg { display: block; }
.brand-name { font-size: clamp(1.05rem, 1.4vw, 1.35rem); font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }

.live-badge {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  background: rgba(5, 150, 105, 0.10); color: var(--fr);
  font-size: 0.70rem; font-weight: 700; letter-spacing: 0.06em;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--fr); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.4); } 50% { box-shadow: 0 0 0 5px rgba(5, 150, 105, 0); } }
.live-badge.off { background: #f0f0f3; color: var(--text-faint); }
.live-badge.off .live-dot { background: var(--text-faint); animation: none; }

.now-speaking {
  flex: 1 1 auto; min-width: 0; text-align: center;
  color: var(--text-soft); font-size: clamp(1rem, 1.4vw, 1.4rem); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.config-hint {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.7rem; border-radius: 999px;
  background: rgba(176, 125, 30, 0.12); color: #9a6a10;
  font-size: 0.76rem; font-weight: 600; white-space: nowrap;
}

.controls { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 0.5rem; }
.btn, .btn-icon {
  display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer;
  font-family: inherit; font-weight: 600; color: var(--text);
  border: 1px solid var(--line); background: var(--surface);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn:focus-visible, .btn-icon:focus-visible, .pill-btn:focus-visible, .modal-close:focus-visible {
  outline: 2px solid var(--fr); outline-offset: 2px;
}
.btn { padding: 0.5rem 1rem; border-radius: 999px; font-size: 0.88rem; }
.btn:hover { background: #f5f5f7; }
.btn-icon { width: 40px; height: 40px; border-radius: 50%; justify-content: center; font-size: 1rem; }
.icon { flex: 0 0 auto; display: inline-block; vertical-align: middle; }
.btn-icon:hover { background: #f5f5f7; }
.btn-mic .mic-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fr); }
.btn-mic.recording { border-color: #e5484d; color: #e5484d; }
.btn-mic.recording .mic-dot { background: #e5484d; animation: pulse-rec 1.2s infinite; }
@keyframes pulse-rec { 0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.5); } 50% { box-shadow: 0 0 0 6px rgba(229, 72, 77, 0); } }

/* Contrôle opérateur (Démarrer/Suspendre) : neutre par défaut, accent quand la
   diffusion est active — pour que "ça diffuse en ce moment" saute aux yeux. */
.btn-broadcast .broadcast-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.btn-broadcast.live { border-color: var(--fr); color: var(--fr); }
.btn-broadcast.live .broadcast-dot { background: var(--fr); animation: pulse 1.8s infinite; }

/* ---------- Cartes propres (Creative Tim), sans barre d'accent ---------- */
.stage {
  flex: 1 1 auto; min-height: 0;
  display: grid; grid-template-columns: repeat(var(--cols, 2), 1fr);
  gap: clamp(0.9rem, 1.8vw, 1.6rem); padding: clamp(0.9rem, 1.8vw, 1.6rem);
}
.col {
  min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 14px 40px rgba(0, 0, 0, 0.06);
  overflow: hidden;
}
.col-head {
  flex: 0 0 auto; display: flex; align-items: center;
  padding: clamp(1.2rem, 1.8vw, 1.8rem) clamp(1.5rem, 2.2vw, 2.4rem) 0.7rem;
}
.col-dot { display: none; }
.col-name {   /* badge pilule (Creative Tim) */
  display: inline-flex; padding: 0.32rem 0.85rem; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, #ffffff);
  color: var(--accent); font-size: 0.82rem; font-weight: 600;
}

.col-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: clamp(1.2rem, 2vw, 2rem) clamp(1.5rem, 2.2vw, 2.4rem) clamp(1.6rem, 2.6vw, 2.6rem);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 4%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 4%, #000 100%);
}
.col.rtl .col-head, .col.rtl .col-body { direction: rtl; }
.col-wait { color: var(--text-faint); font-size: clamp(1.1rem, 1.6vw, 1.6rem); }

.seg {
  font-size: calc(clamp(1.3rem, 1.8vw, 2rem) * var(--text-scale)); line-height: 1.4;
  margin-bottom: 0.9rem; color: var(--text-faint); font-weight: 400;
  transition: color 0.5s ease;
  animation: segIn 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.seg.latest {
  color: var(--text); font-weight: 600;
  font-size: calc(clamp(2rem, 3vw, 3.6rem) * var(--text-scale)); line-height: 1.18; letter-spacing: -0.025em;
}
@keyframes segIn { from { opacity: 0; transform: translateY(10px); } }

.partial {
  font-size: calc(clamp(2rem, 3vw, 3.6rem) * var(--text-scale)); line-height: 1.18; letter-spacing: -0.025em;
  color: var(--accent); font-weight: 600;
}
.partial::after {
  content: ""; display: inline-block; width: 0.055em; height: 0.95em;
  margin-inline-start: 0.14em; vertical-align: -0.1em; background: currentColor;
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* ---------- Verset coranique (Phase 1) : traduction canonique, pas MT ---------- */
.quran-badge {
  display: block;
  font-size: clamp(0.68rem, 0.9vw, 0.8rem); font-weight: 700; letter-spacing: 0.04em;
  color: var(--quran); margin-bottom: 0.35em;
}
.seg.quran { color: var(--text); }
.partial.quran { color: var(--quran); }

/* ---------- Citation de hadith (Phase 2) : traduction canonique ---------- */
.hadith-badge {
  display: block; text-decoration: none;
  font-size: clamp(0.68rem, 0.9vw, 0.8rem); font-weight: 700; letter-spacing: 0.04em;
  color: var(--hadith); margin-bottom: 0.35em;
}
.hadith-badge:hover, .hadith-badge:focus-visible { text-decoration: underline; }
.seg.hadith { color: var(--text); }
.partial.hadith { color: var(--hadith); }

.col-body::-webkit-scrollbar { width: 5px; }
.col-body::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.14); border-radius: 3px; }

/* ---------- Écran d'accueil (avant la khoutba) vs direct (pendant) ----------
   Un seul document, deux états sur <body> — pas de rechargement/reconnexion
   WS. L'accueil est le seul endroit où le style peut s'exprimer (pas de
   contrainte de lecture continue) ; le direct reste sobre : toute animation y
   devient une friction de lecture pour un public en partie âgé, à distance. */
body.live .idle-hero { display: none; }
body.idle .stage { display: none; }

.idle-hero {
  flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(1.5rem, 4vw, 3rem);
}
.idle-hero-inner { display: flex; flex-direction: column; align-items: center; text-align: center; max-width: 34rem; }
.idle-hero-inner > * { opacity: 0; animation: idleIn 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards; }
.idle-emblem { color: var(--fr); margin-bottom: 1.1rem; animation-delay: 0.05s; }
.idle-title {
  font-size: clamp(1.9rem, 4vw, 3.1rem); font-weight: 600; letter-spacing: -0.02em;
  margin-bottom: 0.9rem; animation-delay: 0.15s;
}
.idle-subtitle {
  color: var(--text-soft); font-size: clamp(1rem, 1.6vw, 1.25rem); line-height: 1.6;
  margin-bottom: 2.2rem; animation-delay: 0.25s;
}
.idle-subtitle-en { color: var(--text-faint); font-size: 0.86em; }
.idle-qr-wrap { position: relative; animation-delay: 0.35s; }
.idle-qr-frame { position: relative; }
.idle-qr-frame img { display: block; width: 148px; height: 148px; }
.idle-qr-halo {
  position: absolute; inset: -20px; z-index: -1; border-radius: 30px;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--fr) 20%, transparent), transparent 72%);
  animation: haloPulse 3.6s ease-in-out infinite;
}
.idle-qr-caption {
  margin-top: 1rem; color: var(--text-soft); font-size: 0.9rem; animation-delay: 0.45s;
}
@keyframes idleIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes haloPulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ---------- Panneaux ---------- */
.settings-panel {
  position: fixed; top: 4.8rem; right: clamp(1rem, 2.4vw, 2rem); z-index: 30;
  min-width: 250px; padding: 0.85rem 1.25rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.14);
}
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.6rem 0; color: var(--text-soft); font-size: 0.95rem; }
.settings-row + .settings-row { border-top: 1px solid var(--line); }
.settings-row small { color: var(--text-faint); font-weight: 400; }
.settings-controls { display: inline-flex; gap: 0.4rem; }
.pill-btn { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px; padding: 0.36rem 0.82rem; font-family: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.pill-btn:hover { background: #f0f0f3; }

/* Choix des langues affichées (par appareil) */
.settings-row-langs { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
.lang-picker { display: flex; flex-wrap: wrap; gap: 0.4rem; width: 100%; }
.lang-chip {
  display: inline-flex; align-items: center; gap: 0.4rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; padding: 0.32rem 0.75rem;
  font-size: 0.85rem; font-weight: 600; color: var(--text-soft); background: var(--bg);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.lang-chip:has(input:checked) { background: color-mix(in srgb, var(--fr) 12%, #ffffff); border-color: var(--fr); color: var(--fr); }
.lang-chip input { accent-color: var(--fr); }

.modal { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.3); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal-card { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 28px; padding: 2.3rem 2.7rem; text-align: center; box-shadow: 0 30px 70px rgba(0, 0, 0, 0.2); }
.modal-badge { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.32rem 0.85rem; border-radius: 999px; background: rgba(5, 150, 105, 0.10); color: var(--fr); font-size: 0.85rem; font-weight: 600; margin-bottom: 1rem; }
.modal-card h2 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 1.35rem; }
.qr-frame { background: #fff; padding: 12px; border-radius: 16px; display: inline-block; border: 1px solid var(--line); }
.qr-frame img { display: block; width: 232px; max-width: 60vw; height: auto; }
.join-url { margin-top: 1rem; color: var(--fr); font-size: 1.05rem; font-weight: 600; word-break: break-all; }
.modal-close {
  position: absolute; top: 0.9rem; right: 1rem; width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--bg); color: var(--text-soft); cursor: pointer;
}
.modal-close:hover { background: #f0f0f3; }

/* ---------- Responsive (téléphones) ---------- */
@media (max-width: 900px) {
  .stage { grid-template-columns: 1fr; grid-auto-rows: 1fr; }
  .now-speaking { display: none; }
  /* "Rejoindre" ouvre le QR pour qu'un AUTRE appareil rejoigne — redondant sur
     le téléphone qui affiche déjà la page. Libère de la place dans la pilule. */
  .btn-join { display: none; }
  /* Sur un téléphone étroit (ex. appareil de capture séparé), les boutons
     opérateur (diffusion + micro) ne tiennent pas sur une seule ligne : la
     pilule passe en rectangle arrondi qui peut envelopper sur 2 lignes plutôt
     que de déborder hors écran. */
  .topbar { flex-wrap: wrap; border-radius: 22px; row-gap: 0.5rem; }
  .controls { flex-wrap: wrap; row-gap: 0.5rem; width: 100%; }
}
@media (max-width: 460px) {
  .brand-name { max-width: 9.5rem; overflow: hidden; text-overflow: ellipsis; }
}
@media (prefers-reduced-motion: reduce) {
  .seg, .live-dot, .btn-mic.recording .mic-dot,
  .idle-hero-inner > *, .idle-qr-halo, .btn-broadcast.live .broadcast-dot { animation: none !important; opacity: 1 !important; }
}

/* ==========================================================================
   Pages de compte (landing, signup, login, account) — écrans de gestion,
   pas de contrainte de lecture continue : mise en page classique en carte
   centrée, réutilise les tokens (--fr, --line, --radius, .btn) du direct.
   ========================================================================== */
body.page {
  overflow-y: auto; height: auto; min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  padding: clamp(1.5rem, 4vw, 3.5rem) 1.25rem;
}
.page-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: clamp(2rem, 5vw, 3.5rem); }
.page-header .emblem { color: var(--fr); }
.page-header .brand-name { font-size: 1.2rem; }
.page-header a { text-decoration: none; color: inherit; display: flex; align-items: center; gap: 0.6rem; }

.card {
  width: 100%; max-width: 30rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 14px 40px rgba(0, 0, 0, 0.06);
  padding: clamp(1.6rem, 4vw, 2.4rem);
  margin-bottom: 1.25rem;
}
.card h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 0.4rem; }
.card h2 { font-size: 1.1rem; font-weight: 600; letter-spacing: -0.005em; margin-bottom: 0.9rem; }
.card-subtitle { color: var(--text-soft); font-size: 0.94rem; margin-bottom: 1.6rem; line-height: 1.5; }
.card + .card { margin-top: 0; }

.field { margin-bottom: 1.1rem; }
.field label {
  display: block; font-size: 0.84rem; font-weight: 600; color: var(--text-soft);
  margin-bottom: 0.4rem;
}
.field input, .field select {
  width: 100%; font-family: inherit; font-size: 0.98rem; color: var(--text);
  padding: 0.65rem 0.9rem; border: 1px solid var(--line); border-radius: 14px;
  background: var(--bg); transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--fr);
}
.field-hint { font-size: 0.8rem; color: var(--text-faint); margin-top: 0.35rem; }
.field-row { display: flex; gap: 0.8rem; }
.field-row .field { flex: 1 1 0; min-width: 0; }
/* En dessous de 480px, deux champs côte à côte (ex. langue + source du micro)
   deviennent trop étroits — le <select> tronque son texte sans ellipsis
   ("Micro du navig…" illisible). On empile plutôt que de les compresser. */
@media (max-width: 480px) {
  .field-row { flex-direction: column; gap: 1.1rem; }
}

.btn-primary {
  width: 100%; justify-content: center; padding: 0.75rem 1rem;
  background: var(--fr); border-color: var(--fr); color: #fff; font-size: 0.98rem;
}
.btn-primary:hover { background: color-mix(in srgb, var(--fr) 88%, black); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.form-error {
  background: rgba(229, 72, 77, 0.1); color: #b3261e;
  border-radius: 12px; padding: 0.7rem 0.9rem; font-size: 0.88rem;
  margin-bottom: 1.1rem;
}
.form-success {
  background: rgba(5, 150, 105, 0.1); color: #05714f;
  border-radius: 12px; padding: 0.7rem 0.9rem; font-size: 0.88rem;
  margin-bottom: 1.1rem;
}

/* Bascule Email / Téléphone (signup + login) */
.auth-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.4rem; border-bottom: 1px solid var(--line); }
.auth-tab {
  flex: 1 1 0; text-align: center; padding: 0.6rem 0.4rem; border: none; background: none;
  color: var(--text-soft); font-size: 0.9rem; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.auth-tab[aria-selected="true"] { color: var(--fr); border-bottom-color: var(--fr); }
.auth-tab:focus-visible { outline: 2px solid var(--fr); outline-offset: 2px; }
.field-hint.phone-sent { color: #05714f; }

/* Usage Azure (quota gratuit 5h/mois) — dashboard compte */
.usage-block { margin-bottom: 1.1rem; }
.usage-row {
  display: flex; justify-content: space-between; font-size: 0.88rem;
  color: var(--text-soft); margin-bottom: 0.4rem;
}
.usage-bar { height: 6px; border-radius: 999px; background: #f0f0f3; overflow: hidden; }
.usage-bar-fill { height: 100%; border-radius: 999px; background: var(--fr); transition: width 0.3s ease; }
.usage-bar-fill.warning { background: #b45309; }
.usage-bar-fill.blocked { background: #b3261e; }
.usage-block .field-hint.warning { color: #b45309; }
.usage-block .field-hint.blocked { color: #b3261e; }

.card-footer { text-align: center; color: var(--text-soft); font-size: 0.9rem; }
.card-footer a, .link { color: var(--fr); font-weight: 600; text-decoration: none; }
.card-footer a:hover, .link:hover { text-decoration: underline; }
.link-btn {
  background: none; border: none; padding: 0; font: inherit; cursor: pointer;
  color: #b3261e; font-weight: 600; text-decoration: none;
}
.link-btn:hover, .link-btn:focus-visible { text-decoration: underline; }

.landing-actions { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 0.4rem; }
.landing-actions .btn { justify-content: center; padding: 0.75rem 1rem; }

/* Dashboard compte : sections en cartes empilées, largeur plus généreuse */
.account-shell { width: 100%; max-width: 40rem; }
.account-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.account-top h1 { font-size: 1.35rem; }
.copy-row {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px;
  padding: 0.6rem 0.7rem 0.6rem 0.9rem; margin-bottom: 0.6rem;
}
.copy-row code { flex: 1 1 auto; min-width: 0; overflow-x: auto; white-space: nowrap; font-size: 0.85rem; }
.copy-row .pill-btn { flex: 0 0 auto; }
.status-pill {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.28rem 0.7rem;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600;
}
.status-pill.ok { background: rgba(5, 150, 105, 0.1); color: var(--fr); }
.status-pill.off { background: #f0f0f3; color: var(--text-faint); }
.qr-inline { text-align: center; margin: 1rem 0; }
.qr-inline img { width: 140px; height: 140px; border-radius: 12px; border: 1px solid var(--line); padding: 8px; background: #fff; }
