/* Conçu pour la basse vision : contrastes ≥ 7:1 (AAA), grandes cibles tactiles (≥ 64 px),
   police Atkinson Hyperlegible, jamais d'information portée par la couleur seule. */

:root {
  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --size: 40px; /* taille du texte des sous-titres (réglable) */
  --radius: 18px;
  --tap: 64px;
}

/* Blanc sur noir (par défaut) */
:root[data-theme="noir"] {
  --bg: #000;
  --panel: #1a1a1a;
  --text: #fff;
  --muted: #d0d0d0;
  --line: #5a5a5a;
  --accent: #ffd400;
  --on-accent: #000;
  --danger: #ff6b6b;
  --spk1: #ffd400; --spk2: #5ec8ff; --spk3: #ff9e6b; --spk4: #8ef08e;
  --spk5: #ff9bd2; --spk6: #c9b3ff; --spk7: #6ff0dc; --spk8: #fff27a;
  color-scheme: dark;
}

/* Jaune sur noir : le contraste le plus utilisé en basse vision */
:root[data-theme="jaune"] {
  --bg: #000;
  --panel: #1a1a1a;
  --text: #ffeb3b;
  --muted: #fff59d;
  --line: #6b6200;
  --accent: #ffeb3b;
  --on-accent: #000;
  --danger: #ff6b6b;
  --spk1: #ffffff; --spk2: #5ec8ff; --spk3: #ff9e6b; --spk4: #8ef08e;
  --spk5: #ff9bd2; --spk6: #c9b3ff; --spk7: #6ff0dc; --spk8: #ffd0a0;
  color-scheme: dark;
}

/* Noir sur blanc */
:root[data-theme="blanc"] {
  --bg: #fff;
  --panel: #efefef;
  --text: #000;
  --muted: #333;
  --line: #8a8a8a;
  --accent: #003fa3;
  --on-accent: #fff;
  --danger: #b00020;
  --spk1: #003fa3; --spk2: #a01800; --spk3: #0b5d1e; --spk4: #6a1b9a;
  --spk5: #7a4200; --spk6: #00616b; --spk7: #9c004f; --spk8: #333333;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1.25rem;
  line-height: 1.4;
}

button, input, select { font: inherit; color: inherit; }

button {
  cursor: pointer;
  min-height: 48px;
  padding: 10px 16px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-weight: 700;
}

:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }

[hidden] { display: none !important; }

.screen { max-width: 640px; margin: 0 auto; padding: max(24px, env(safe-area-inset-top)) 16px 32px; }

/* ---------- Gros boutons ---------- */

.big {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 88px;
  padding: 16px 20px;
  text-align: left;
  font-size: 1.4rem;
}
.big strong { display: block; }
.big small { display: block; font-size: 1.05rem; font-weight: 400; color: var(--muted); margin-top: 2px; }
.big .ico { font-size: 2rem; line-height: 1; }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.primary small { color: var(--on-accent); }
.wide { width: 100%; min-height: var(--tap); }

/* ---------- Accueil ---------- */

.brand { display: flex; align-items: center; gap: 16px; }
.brand h1 { font-size: 2.6rem; margin: 0; }
.lead { font-size: 1.5rem; margin: 16px 0 32px; }
.big-actions { display: grid; gap: 16px; }

/* ---------- Rejoindre ---------- */

.join h1 { font-size: 2rem; }
.join form { display: grid; gap: 16px; }
.join label { font-size: 1.4rem; font-weight: 700; }
#room {
  width: 100%;
  padding: 16px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
}
#room::placeholder { color: var(--line); }
.hint { color: var(--muted); margin: 0; }
.back { justify-content: center; }
.join .primary { justify-content: center; }

/* ---------- Sous-titres ---------- */

.live {
  display: flex;
  flex-direction: column;
  max-width: none;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.bar, .controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--panel);
  border-color: var(--line);
  border-style: solid;
  border-width: 0;
}
.bar { border-bottom-width: 2px; }
.controls { border-top-width: 2px; flex-wrap: nowrap; }
.code strong { color: var(--accent); letter-spacing: 0.15em; }
.bar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bar-actions button { min-height: 52px; }

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  font-size: var(--size);
  line-height: 1.3;
  scroll-behavior: smooth;
}

.empty { color: var(--muted); font-size: 1.6rem; text-align: center; margin-top: 15vh; }

/* Une phrase : barre de couleur du locuteur à gauche + nom au-dessus */
.utt {
  margin: 0;
  padding: 0.15em 0 0.15em 0.45em;
  border-left: 0.18em solid var(--spk-color, var(--line));
}
.utt:not(.same-speaker) { margin-top: 0.5em; }
.utt .who {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--spk-color, var(--muted));
  font-size: max(20px, 0.5em);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.utt.same-speaker .who { display: none; }
.utt .txt { font-weight: 700; }
/* Phrase en cours : pas de gris ni d'italique (illisibles), juste un trait de soulignement discret */
.utt.partial .txt { text-decoration: underline dotted var(--line) 0.08em; text-underline-offset: 0.2em; }

.size-buttons { display: flex; gap: 8px; }
.size-buttons button { min-width: var(--tap); min-height: var(--tap); font-size: 1.5rem; }

.mic {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  max-width: 420px;
  min-height: 76px;
  padding: 8px 20px;
  text-align: left;
  font-size: 1.3rem;
}
.mic .mic-ico { font-size: 2rem; }
.mic strong, .mic small { display: block; }
.mic small { font-size: 1rem; font-weight: 400; }
.mic[aria-pressed="true"] { background: var(--danger); border-color: var(--danger); color: #000; }
:root[data-theme="blanc"] .mic[aria-pressed="true"] { color: #fff; }

/* Téléphone : une seule ligne de boutons en haut (le code reste visible dans « Inviter ») */
@media (max-width: 480px) {
  .code { display: none; }
  .bar { justify-content: center; }
  .bar-actions { flex-wrap: nowrap; width: 100%; }
  .bar-actions button { flex: 1; padding: 8px 6px; font-size: 1rem; white-space: nowrap; }
  .size-buttons button { min-width: 56px; }
  .mic { padding: 8px 12px; font-size: 1.15rem; }
}

/* ---------- Plein écran (paysage) ---------- */

.float { display: none; }

body.immersive .bar,
body.immersive .controls { display: none; }

body.immersive .transcript {
  padding: 16px max(32px, env(safe-area-inset-right)) 96px max(32px, env(safe-area-inset-left));
}

body.immersive .float {
  display: flex;
  align-items: center;
  gap: 6px;
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  padding: 6px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  opacity: 0.7;
  transition: opacity 0.2s;
}
body.immersive .float:hover,
body.immersive .float:focus-within { opacity: 1; }
.float button { min-width: 56px; min-height: 56px; padding: 6px 10px; }
.float button[aria-pressed="true"] { background: var(--danger); }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--line); margin: 0 6px; }
.dot.on { background: var(--danger); box-shadow: 0 0 10px var(--danger); }

/* ---------- Fenêtres (réglages, invitation) ---------- */

.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 24px 20px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: var(--bg);
  color: var(--text);
  font-size: 1.25rem;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.8); }
.sheet h2 { font-size: 2rem; margin: 0 0 8px; }
.sheet h3 { font-size: 1.35rem; margin: 0 0 12px; }
.sheet section { padding: 16px 0; border-bottom: 2px solid var(--line); }
.sheet > .big { margin-top: 20px; justify-content: center; }

.size-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.size-row button { min-height: var(--tap); font-size: 1.3rem; }
/* Aperçu à la taille réelle des sous-titres */
.size-preview {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  padding: 8px 12px;
  border-left: 0.18em solid var(--spk1);
  font-size: var(--size);
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choices.column { grid-template-columns: 1fr; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
}
.choice small { display: block; font-weight: 400; color: var(--muted); font-size: 1rem; }
.choice input { width: 26px; height: 26px; margin: 0; flex: none; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
/* Aperçu des jeux de couleurs */
.theme-noir { background: #000; color: #fff; }
.theme-jaune { background: #000; color: #ffeb3b; }
.theme-blanc { background: #fff; color: #000; }
@media (max-width: 480px) {
  .choices { grid-template-columns: 1fr; }
}

.field { display: grid; gap: 6px; margin-top: 12px; font-weight: 700; }
.field input, select.field {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 1.3rem;
}

.invite { text-align: center; }
.qr { display: inline-block; padding: 14px; background: #fff; border-radius: 16px; margin: 8px 0; }
.qr img, .qr canvas { display: block; }
.code-big { font-size: 2rem; letter-spacing: 0.2em; color: var(--accent); }
.invite-link { font-size: 0.9rem; color: var(--muted); word-break: break-all; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 110px;
  margin: 0 auto;
  max-width: 560px;
  padding: 16px 20px;
  border: 3px solid var(--danger);
  border-radius: var(--radius);
  background: var(--bg);
  font-weight: 700;
}
