:root {
  --fs: 24px;
  --bg: #f2f3f5;
  --surface: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #111827;
  --speak: #22c55e;
  --danger: #ef4444;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.06), 0 4px 14px rgba(17, 24, 39, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

/* Google Material Icons (Round) */
.mi {
  font-family: 'Material Icons Round';
  font-weight: normal;
  font-style: normal;
  font-size: 1.2em;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  direction: ltr;
  display: inline-block;
  vertical-align: -0.2em;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'liga';
}

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

#home {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.card {
  width: 100%;
  max-width: 440px;
  padding: 28px 22px 24px;
  text-align: center;
  background: var(--surface);
  border-radius: 28px;
  box-shadow: var(--shadow);
}
.card img { border-radius: 20px; }
.card h1 { font-size: 30px; margin: 10px 0 4px; letter-spacing: -0.02em; }
.lead { font-size: 18px; color: var(--muted); margin: 0 0 20px; }
.card label { display: block; text-align: left; font-size: 16px; font-weight: 600; color: var(--muted); margin: 16px 4px 6px; }

.card input {
  width: 100%;
  height: 60px;
  padding: 0 18px;
  font-size: 22px;
  background: var(--bg);
  border: 2px solid transparent;
  border-radius: 18px;
}
.card input::placeholder { color: #9ca3af; }
.card input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
#code { text-align: center; letter-spacing: 4px; font-size: 28px; font-variant-numeric: tabular-nums; }

.btn {
  width: 100%;
  min-height: 62px;
  margin-top: 14px;
  padding: 10px 16px;
  font-size: 20px;
  font-weight: 700;
  background: var(--bg);
  border: 0;
  border-radius: 31px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; }

.or { color: var(--muted); font-size: 16px; margin: 14px 0 0; }
#home-error { color: #dc2626; font-size: 18px; font-weight: 600; min-height: 1.4em; margin: 14px 0 0; }
.hint { color: var(--muted); font-size: 15px; margin: 6px 0 0; }

/* ---------- Appel ---------- */

#call {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 0;
}

#topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 600;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
}
#topbar .mi { color: var(--muted); }
#room-code { font-variant-numeric: tabular-nums; letter-spacing: 1px; }

#videos {
  flex: 0 0 34dvh;
  min-height: 0;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--n, 1), 1fr);
  grid-template-rows: minmax(0, 1fr) minmax(0, 32%);
}
#videos.solo { grid-template-rows: minmax(0, 1fr); }

.tile {
  --c: #111827;
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #e3e5ea;
  border-radius: 20px;
  outline: 3px solid transparent;
  outline-offset: -3px;
  transition: outline-color 0.15s;
}
.tile.featured { grid-column: 1 / -1; grid-row: 1; border-radius: 24px; }
.tile.speaking { outline-color: var(--speak); }

.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile.mirror video { transform: scaleX(-1); }
.tile.cam-off video { visibility: hidden; }

.tile .avatar {
  position: absolute; left: 50%; top: 40%;
  height: 46%; max-height: 110px; aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: none; align-items: center; justify-content: center;
  font-size: clamp(18px, 5vh, 44px); font-weight: 700; color: #fff;
  background: var(--c);
  border-radius: 50%;
}
.tile.cam-off .avatar { display: flex; }

.tile .label {
  position: absolute; left: 8px; bottom: 8px;
  max-width: calc(100% - 16px);
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px;
  font-size: 13px; font-weight: 600; color: #fff;
  background: rgba(17, 24, 39, 0.55);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-radius: 999px;
  white-space: nowrap; overflow: hidden;
}
.tile .label .name { overflow: hidden; text-overflow: ellipsis; }
.tile .label .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--c); border: 1.5px solid #fff; }
.tile .label .mi { flex: none; font-size: 15px; vertical-align: 0; }
.tile.featured .label { font-size: 15px; left: 10px; bottom: 10px; }

.tile .wait {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; text-align: center;
  font-size: 18px; font-weight: 600; color: #fff;
  background: rgba(17, 24, 39, 0.45);
}

/* Mode « texte seul » : les vidéos deviennent une petite bande. */
body.text-only #videos {
  flex-basis: 84px;
  grid-template-columns: repeat(var(--count, 1), 1fr);
  grid-template-rows: minmax(0, 1fr);
}
body.text-only .tile.featured { grid-column: auto; grid-row: auto; border-radius: 20px; }
body.text-only .tile .wait { display: none; }
body.text-only .tile .label, body.text-only .tile.featured .label { font-size: 12px; left: 6px; bottom: 6px; }

#captions {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

#captions header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 6px 16px;
}
#status { flex: 1; font-size: 14px; color: var(--muted); }
#status.ok { color: #15803d; }
#status.bad { color: #b45309; }

.mini {
  min-width: 48px; min-height: 44px; padding: 0 14px;
  font-size: 17px; font-weight: 700;
  background: var(--bg); border: 0; border-radius: 22px;
}

#lines {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 16px 14px;
  font-size: var(--fs);
  line-height: 1.35;
}

.line { margin: 0 0 0.55em; overflow-wrap: anywhere; }
.line .who { color: var(--c, #111827); font-weight: 800; }
.line .txt { color: var(--text); }
.line.typed .txt { font-style: italic; }

.empty { color: var(--muted); font-size: 18px; text-align: center; margin-top: 18px; }

#to-bottom {
  position: absolute; left: 50%; bottom: 70px; transform: translateX(-50%);
  min-height: 46px; padding: 0 20px;
  font-size: 17px; font-weight: 700; color: #fff;
  background: var(--accent); border: 0; border-radius: 23px;
  box-shadow: 0 6px 20px rgba(17, 24, 39, 0.25);
}

#chat { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--line); }
#chat input {
  flex: 1; min-width: 0; height: 44px; padding: 0 16px;
  font-size: 17px;
  background: var(--bg); border: 0; border-radius: 22px;
}
#chat input:focus { outline: 2px solid var(--accent); }
#chat .mini { background: var(--accent); color: #fff; }

#controls {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 2px;
  padding: 2px 2px max(8px, env(safe-area-inset-bottom));
}
#controls button {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 0; background: none; border: 0;
}
#controls .mi {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  background: var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow);
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
#controls button:active .mi { transform: scale(0.94); }
#controls .lbl { font-size: 11px; font-weight: 600; color: var(--muted); line-height: 1.1; text-align: center; }
#controls button.off .mi { background: #fee2e2; color: #dc2626; }
#controls button.off .lbl { color: #dc2626; }
#controls button.on .mi { background: var(--accent); color: #fff; }
#controls button.danger .mi { background: var(--danger); color: #fff; }
#controls button:disabled { opacity: 0.35; }

#unmute {
  position: fixed; left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top)); z-index: 5;
  min-height: 62px; font-size: 19px; font-weight: 700; color: #fff;
  background: var(--accent); border: 0; border-radius: 31px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.3);
}

#toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 6;
  max-width: calc(100% - 24px); padding: 12px 20px;
  font-size: 17px; font-weight: 600; text-align: center; color: #fff;
  background: rgba(17, 24, 39, 0.92); border-radius: 24px;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.25);
}

/* Écran large ou téléphone à l'horizontale : vidéos à gauche, texte à droite. */
@media (min-width: 800px), (orientation: landscape) and (min-width: 560px) {
  #call {
    display: grid;
    gap: 8px 10px;
    padding-bottom: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  #topbar { grid-column: 1; grid-row: 1; }
  #videos { grid-column: 1; grid-row: 2; }
  #captions { grid-column: 2; grid-row: 1 / 4; }
  #controls { grid-column: 1; grid-row: 3; padding-bottom: 0; }
  body.text-only #call { grid-template-columns: 170px minmax(0, 1fr); }
  body.text-only #videos { grid-template-columns: 1fr; grid-auto-rows: minmax(0, 1fr); grid-template-rows: none; }
  body.text-only #controls { flex-wrap: wrap; row-gap: 6px; }
  body.text-only #controls button { flex-basis: 30%; }
}
