:root {
  --bg: #0f1115;
  --panel: #181b22;
  --border: #2a2f3a;
  --text: #f2f4f8;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --accent-2: #2ecc9a;
  --danger: #ff5c6c;
  --font-size: 42px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Page figée : seul le cadre de texte défile. Évite le "tirer pour recharger". */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
body {
  position: fixed;
  inset: 0;
  width: 100%;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100vh;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow: hidden;
}
.scrollable { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form .btn { margin-top: 6px; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: .95rem; line-height: 1.4; }
.notice {
  margin: 0;
  padding: 12px 14px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: .98rem;
  line-height: 1.4;
}
h2 { margin: 0; font-size: 1.3rem; }
.btn:disabled, .mic:disabled { opacity: .55; cursor: default; }

h1 { margin: 12vh 0 0; font-size: 1.8rem; }
.lead { margin: 0 0 12px; color: var(--muted); }
label { color: var(--muted); font-size: .9rem; }

input, select {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn {
  padding: 14px 18px;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 8px 12px; font-size: .95rem; }
.btn:active { transform: scale(.98); }

.role-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }

/* En-tête : badge + statut sur une ligne, tous les boutons ensemble sur la ligne du dessous */
.topbar { display: flex; flex-direction: column; gap: 10px; flex: none; }
.topline { display: flex; align-items: center; gap: 10px; min-width: 0; }
.toolbar { display: flex; align-items: stretch; gap: 8px; }
.toolbar .btn { flex: 1 1 0; min-width: 0; padding: 10px 4px; font-size: 1rem; white-space: nowrap; }
.toolbar select { flex: 1 1 auto; width: auto; min-width: 0; padding: 10px 12px; font-size: 1rem; }
.toolbar select + .btn { flex: 0 0 56px; }
.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .8rem;
  font-weight: 600;
}
.badge.alt { background: var(--accent-2); color: #06281d; }
.status { color: var(--muted); font-size: .9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status.ok::before, .status.off::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent-2);
}
.status.off::before { background: var(--danger); }

.mic {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 12px;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 20px;
  font-size: 1.1rem;
  cursor: pointer;
}
.mic-icon { font-size: 3rem; }
.mic[aria-pressed="true"] {
  border-color: var(--danger);
  background: rgba(255, 92, 108, .12);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 92, 108, .35); }
  50% { box-shadow: 0 0 0 14px rgba(255, 92, 108, 0); }
}

/* Zone de texte : seule partie qui défile */
.wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}
.transcript {
  flex: 1;
  min-height: 0;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  line-height: 1.45;
  font-size: 1.05rem;
}
.transcript.big { font-size: var(--font-size); }

.jump {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 10px 14px;
  font-size: .95rem;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
  cursor: pointer;
}

/* Tout le texte est blanc dès son apparition (provisoire ou final) */
.seg { margin: 0 0 .5em; color: var(--text); }
.seg.corrected { animation: flash 1.2s ease-out; }
@keyframes flash {
  0% { background: rgba(46, 204, 154, .3); }
  100% { background: transparent; }
}
.placeholder { color: var(--muted); font-size: .6em; line-height: 1.4; }
.seg, .placeholder { overflow-wrap: anywhere; }

.error { margin: 0; color: var(--danger); font-size: .95rem; flex: none; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(20px, env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px;
  color: var(--text);
  background: #232838;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
  font-size: .95rem;
  line-height: 1.4;
  z-index: 10;
}

/* Fenêtre "Votre salon" */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, .72);
}
.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
}
.panel .lead { margin: 0; }
.qr {
  align-self: center;
  background: #fff;           /* fond blanc : indispensable pour que le QR code soit lisible */
  border-radius: 12px;
  overflow: hidden;
  line-height: 0;
}
.qr svg { display: block; width: min(68vw, 300px); height: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.center { justify-content: center; }
.row.between { justify-content: space-between; }

/* Numéro de version (pour vérifier qu'une mise à jour est bien arrivée) */
.version { flex: none; margin-left: auto; color: var(--muted); font-size: .75rem; opacity: .7; }
p.version { margin: auto 0 0; text-align: center; }

/* Journal de diagnostic (?debug=1) */
.debug {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 42vh;
  padding: 8px;
  background: rgba(0, 0, 0, .92);
  border-top: 1px solid var(--border);
}
.debug pre {
  margin: 0;
  overflow: auto;
  color: #9fe8b8;
  font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Demandes d'accès : en haut de l'écran, au-dessus de tout */
.requests {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 560px;
  margin: 0 auto;
}
.req {
  padding: 16px;
  background: #232838;
  border: 2px solid var(--accent);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .6);
}
.req-text { margin: 0 0 6px; font-size: 1.1rem; line-height: 1.35; }
.req-warn { margin: 0 0 6px; color: #ffcf6e; font-size: .92rem; }
.req .row { margin-top: 10px; }
.req .btn { flex: 1; padding: 14px 10px; }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .mic[aria-pressed="true"], .seg.corrected { animation: none; }
}
