/* Thème clair unique, texte noir partout : contraste maximal, y compris
   quand le téléphone est en mode sombre. */
:root {
  color-scheme: light;
  --fond: #ffffff;
  --texte: #000000;
  --jaune: #ffd400;
  --vert: #8dffb5;
  --bleu: #bfe3ff;
  --focus: #0047ff;
  --accent: #ffd400;          /* grand bouton */
  --accent-texte: #000000;
  --reponse: #fff8d6;         /* zone de réponse */
  --echelle: 1;               /* taille du texte choisie dans l'application */
}

/* Thèmes de contraste (mode basse vision). Tous dépassent le rapport 7:1 (WCAG AAA).
   Sur les fonds clairs, le texte reste toujours noir. */
:root[data-theme="jaune-noir"] {
  --fond: #000000; --texte: #ffd400; --accent: #ffd400; --accent-texte: #000000;
  --reponse: #000000; --focus: #ffffff;
}
:root[data-theme="blanc-bleu"] {
  --fond: #002b80; --texte: #ffffff; --accent: #ffffff; --accent-texte: #002b80;
  --reponse: #00205f; --focus: #ffd400;
}
:root[data-theme="noir-jaune"] {
  --fond: #ffd400; --texte: #000000; --accent: #000000; --accent-texte: #ffd400;
  --reponse: #fff3a0; --focus: #0047ff;
}

html { font-size: calc(100% * var(--echelle)); }

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  container-type: inline-size;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#camera {
  /* Hauteur fixe : sans min-height: 0, une vidéo en portrait garde sa taille naturelle
     et écrase le reste de l'écran. */
  flex: 0 0 18dvh;
  height: 18dvh;
  min-height: 0;
  width: 100%;
  object-fit: cover;
  background: #e6e6e6;
  border: 3px solid var(--texte);
  border-radius: 16px;
}

button {
  font: inherit;
  background: var(--fond);
  border-color: var(--texte);
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
  color: var(--texte);
  border: 4px solid var(--texte);
  border-radius: 20px;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible,
#answer:focus-visible {
  outline: 5px solid var(--focus);
  outline-offset: 3px;
}

#talk {
  flex: 1 1 auto;
  min-height: 22dvh;
  background: var(--accent);
  color: var(--accent-texte);
  border-color: var(--texte);
  font-size: clamp(2.2rem, 11vw, 4.5rem);
  touch-action: none; /* les balayages sont gérés par l'application */
  user-select: none;
}
#talk[data-state="listening"] { background: var(--vert); color: #000; }
#talk[data-state="thinking"]  { background: var(--bleu); color: #000; }

#answer {
  flex: 0 1 auto;
  min-height: 3.4em; /* toujours au moins deux lignes de réponse visibles */
  max-height: 26dvh;
  overflow-y: auto;
  overflow-wrap: anywhere;
  margin: 0;
  padding: 12px 14px;
  font-size: clamp(1.15rem, 4.8vw, 1.6rem);
  line-height: 1.35;
  font-weight: 600;
  background: var(--reponse);
  color: var(--texte);
  border-color: var(--texte);
  border: 3px solid var(--texte);
  border-radius: 16px;
}

#obstacle-status {
  margin: 0;
  padding: 8px 12px;
  font-size: clamp(1.2rem, 5vw, 1.7rem);
  font-weight: 800;
  text-align: center;
  color: #000;
  background: var(--vert);
  border: 3px solid var(--texte);
  border-radius: 16px;
}
#obstacle-status[data-level="2"] { background: #ffb347; }
#obstacle-status[data-level="3"] { background: #ff8080; }

nav {
  display: grid;
  /* 2 × 2 par défaut ; 4 sur une ligne seulement si la place suffit pour la taille de police
     choisie dans le téléphone (grandes polices, écran extérieur du Fold : 2 × 2). */
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
nav button {
  min-width: 0;
  min-height: 64px;
  padding: 6px 4px;
  background: var(--fond);
  font-size: clamp(0.95rem, 4vw, 1.3rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
  hyphens: auto;
}
@container (min-width: 22em) {
  nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
nav button:active { background: var(--accent); color: var(--accent-texte); }

@media (prefers-reduced-motion: no-preference) {
  #talk { transition: background-color 120ms linear; }
}

/* Panneau « Plus » : plein écran, gros boutons, texte noir sur fond clair. */
dialog#more, dialog#loupe { container-type: inline-size; }
dialog#more {
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: max(14px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  border: none;
  background: var(--fond);
  color: var(--texte);
  overflow-y: auto;
}
dialog#more::backdrop { background: rgba(0, 0, 0, 0.5); }

dialog#more h2 { margin: 0 0 6px; font-size: 1.8rem; }
dialog#more h3 { margin: 18px 0 8px; font-size: 1.3rem; }

dialog#more button,
dialog#more input {
  display: block;
  width: 100%;
  min-height: 64px;
  margin-bottom: 10px;
  padding: 10px 14px;
  font-size: 1.25rem;
  text-align: left;
  background: var(--fond);
}
dialog#more button:active { background: var(--accent); color: var(--accent-texte); }
dialog#more button[aria-pressed="true"] { background: var(--vert); color: #000; }
dialog#more .close { background: var(--accent); color: var(--accent-texte); text-align: center; margin-top: 20px; }

dialog#more label { display: block; font-weight: 700; font-size: 1.2rem; margin-bottom: 6px; }
dialog#more input {
  font: inherit;
  font-size: 1.4rem;
  color: var(--texte);
  border: 4px solid var(--texte);
  border-radius: 20px;
}
dialog#more input::placeholder { color: var(--texte); opacity: 0.7; }
dialog#more input:focus-visible { outline: 5px solid var(--focus); outline-offset: 3px; }

/* ---------- Loupe (mode basse vision) ---------- */
dialog#loupe {
  width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0;
  border: none; background: #000; color: var(--texte);
}
dialog#loupe[open] { display: flex; flex-direction: column; }
#loupe-view {
  position: relative; flex: 1 1 auto; overflow: hidden; background: #000;
  touch-action: pan-x pan-y;
}
#loupe-view.frozen { overflow: auto; }
#loupe-video { width: 100%; height: 100%; object-fit: contain; transform-origin: center; }
#loupe-still { display: block; transform-origin: top left; }
#loupe-tools {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom)); background: var(--fond);
}
@container (min-width: 30em) { #loupe-tools { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
#loupe-tools button { min-height: 60px; font-size: clamp(1rem, 4.2vw, 1.35rem); padding: 6px; }
#loupe-tools button[aria-pressed="true"] { background: var(--vert); color: #000; }
#loupe-tools .close { grid-column: 1 / -1; background: var(--accent); color: var(--accent-texte); }
#loupe-zoom {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; z-index: 1;
  margin: 0; padding: 4px 10px; font-size: 1.3rem; font-weight: 800;
  background: #fff; color: #000; border: 3px solid #000; border-radius: 12px;
}
