:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --card-2: #f0f1f4;
  --text: #14171a;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #d94a24;
  --accent-soft: #fdece6;
  --win: #16855c;
  --loss: #c2402b;
  --gold: #d9a520;
  --shadow: 0 1px 2px rgba(16, 20, 26, 0.06), 0 4px 14px rgba(16, 20, 26, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --card: #171a1f;
    --card-2: #1f242a;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --line: #2a2f36;
    --accent: #ff6b3d;
    --accent-soft: #33201a;
    --win: #35c48c;
    --loss: #ef6a52;
    --gold: #e8b93c;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand span { margin-left: 2px; }

.live { font-size: 1.6rem; line-height: 1; color: var(--muted); transition: color 0.3s; }
.live.on { color: var(--win); }
.live.off { color: var(--loss); }

/* ---------- Structure ---------- */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 14px 12px calc(84px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.35rem; margin: 4px 0 14px; letter-spacing: -0.02em; }
h2 { font-size: 1.02rem; margin: 22px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 0.9rem; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pad { padding: 14px; }

/* ---------- Onglets bas ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  font-size: 0.63rem;
  color: var(--muted);
  min-height: 52px;
}

.tabbar a span { font-size: 1.15rem; line-height: 1.1; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

/* ---------- Saisie d'un résultat ---------- */
.saisie { margin-bottom: 16px; }
.saisie-title { margin: 0 0 10px; font-size: 1.05rem; }
.saisie select {
  padding: 12px 26px 12px 12px;
  font-weight: 600;
  text-align: center;
  /* petit chevron pour signaler que c'est une liste déroulante */
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) calc(50% + 2px), calc(100% - 12px) calc(50% + 2px);
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

.linkish {
  background: none;
  border: 0;
  padding: 8px 0 0;
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.linkish.undo { padding: 0 0 0 6px; text-decoration: underline; color: inherit; }

.grid-add { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 8px; }

/* Points en jeu, sous les deux listes de joueurs */
.apercu {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.apercu .muted { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* Jeton bonus ×2 */
.bonus-row { margin-top: 12px; }
.bonus-row em { font-style: normal; text-decoration: underline; }
.chips { display: flex; gap: 6px; margin-top: 6px; }

.chip {
  flex: 1;
  min-width: 0;
  padding: 11px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.chip.discret { flex: 0 0 auto; padding-inline: 12px; }
.chip:disabled { opacity: 0.45; cursor: default; }

/* Défis proposés */
button.row.defi {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

button.row.defi:last-child { border-bottom: 0; }

/* Les deux camps du défi, chacun avec ses chances et son gain */
.camps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 10px;
  margin-top: 5px;
  font-size: 0.78rem;
  white-space: nowrap;
  color: var(--muted);
  line-height: 1.45;
}

.camps b { color: var(--text); font-weight: 600; }
.camps b.pos { color: var(--win); font-variant-numeric: tabular-nums; }

/* ---------- Podium ---------- */
.podium {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  align-items: end;
  gap: 8px;
  margin-bottom: 16px;
}

.podium .step {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px 12px 8px 8px;
  padding: 10px 6px 12px;
  text-align: center;
  box-shadow: var(--shadow);
}

.podium .step .medal { font-size: 1.4rem; }
.podium .step .name { font-weight: 700; font-size: 0.9rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .step .elo { color: var(--accent); font-weight: 700; font-size: 0.95rem; }
.podium .step.first { padding-top: 16px; border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }

/* ---------- Lignes de classement ---------- */
.rows { display: flex; flex-direction: column; }

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
}

.row:last-child { border-bottom: 0; }
.row .rank { width: 24px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; flex: none; }
.row .rank.top { color: var(--gold); }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 0.78rem; color: var(--muted); margin-top: 1px; }
.row .value { text-align: right; flex: none; }
.row .value b { font-size: 1.02rem; font-variant-numeric: tabular-nums; }
.row .value .bonus { font-size: 0.72rem; color: var(--muted); display: block; }

.tag {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 6px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: 1px;
  margin-left: 6px;
}

.tag.grey { background: var(--card-2); color: var(--muted); }

/* ---------- Matchs ---------- */
.match {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
}

.match:last-child { border-bottom: 0; }
.match .who { flex: 1; min-width: 0; font-size: 0.92rem; line-height: 1.35; }
.match .who .w { font-weight: 600; color: var(--win); }
.match .who .l { color: var(--muted); }

.pos { color: var(--win); }
.neg { color: var(--loss); }

/* ---------- Statistiques ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
@media (min-width: 480px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 0.7rem; color: var(--muted); margin-top: 2px; }

/* ---------- Formulaires ---------- */
label { display: block; font-size: 0.8rem; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }

input, select, textarea, button {
  font: inherit;
  font-size: 16px; /* évite le zoom automatique sur iOS */
}

input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card-2);
  color: var(--text);
  appearance: none;
}

select { background-image: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: block;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }
.btn.secondary { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--loss); border: 1px solid var(--line); }
.btn.small { width: auto; padding: 7px 12px; font-size: 0.8rem; min-height: 0; border-radius: 8px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.notice {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  margin: 10px 0;
  font-weight: 600;
}

.notice.ok { background: color-mix(in srgb, var(--win) 15%, transparent); color: var(--win); }

/* ---------- Choix vainqueur ---------- */
.winner-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
/* tant que les deux joueurs ne sont pas choisis, un seul bouton occupe la ligne */
.winner-pick:has(button[hidden]) { grid-template-columns: 1fr; }

.winner-pick button {
  padding: 18px 8px;
  border: 2px solid color-mix(in srgb, var(--win) 45%, var(--line));
  border-radius: 12px;
  background: color-mix(in srgb, var(--win) 12%, transparent);
  color: var(--win);
  font-weight: 700;
  cursor: pointer;
  min-height: 62px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.winner-pick button:active { transform: translateY(1px); }
.winner-pick button:disabled { opacity: 0.4; }

/* ---------- Avatars ---------- */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex: none;
  object-fit: cover;
  background: var(--card-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #fff;
}

.avatar.initiale {
  background: hsl(var(--teinte, 20) 55% 42%);
}

.avatar.grand {
  width: 56px;
  height: 56px;
  font-size: 1.4rem;
}

.podium .avatar { margin: 2px auto 4px; display: flex; }

.fiche-tete { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.fiche-tete .linkish { padding: 4px 0 0; }

/* ---------- Discussion ---------- */
.fil {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.bulle-ligne { display: flex; align-items: flex-end; gap: 8px; }

/* Les messages de l'auteur identifié sur cet appareil passent à droite. */
.bulle-ligne.moi { flex-direction: row-reverse; }

.avatar.petit { width: 26px; height: 26px; font-size: 0.72rem; }

.bulle {
  max-width: 78%;
  padding: 8px 11px;
  border-radius: 14px;
  background: var(--card-2);
  border: 1px solid var(--line);
}

.bulle-ligne.moi .bulle {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}

.bulle-tete { font-size: 0.7rem; font-weight: 700; margin-bottom: 2px; }
.bulle-tete .muted { font-weight: 400; margin-left: 4px; }
.bulle-texte { font-size: 0.92rem; line-height: 1.35; overflow-wrap: anywhere; }

.bulle-suppr {
  align-self: center;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  opacity: 0.5;
}

.ecrire { margin-top: 12px; }


/* ---------- Réactions audio ---------- */
audio { color-scheme: light dark; }

.audio-btn {
  flex: none;
  min-width: 34px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--card-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.audio-btn.ecoute { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.audio-btn.en-lecture { background: var(--accent); color: #fff; border-color: var(--accent); }

.liste-audio { margin-bottom: 12px; text-align: left; }

.ligne-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}

.ligne-audio:last-child { border-bottom: 0; }
.ligne-audio audio {
  flex: 1;
  min-width: 0;
  height: 34px;
  /* les contrôles natifs suivent le thème au lieu de rester blancs */
  color-scheme: light dark;
}
.ligne-audio .small { flex: none; }

.btn.rec { background: var(--loss); }

.btn.rec.en-cours {
  background: var(--loss);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.55; }
}

/* ---------- Diaporama ---------- */
.diaporama {
  position: relative;
  height: 130px;
  margin-bottom: 14px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--card-2);
  border: 1px solid var(--line);
  touch-action: pan-y;
  user-select: none;
}

.diaporama img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.diaporama img.visible { opacity: 1; }

.diapo-btn {
  position: absolute;
  z-index: 2;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(12, 15, 19, 0.55);
  color: #fff;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(3px);
}

.diapo-btn.plus { top: 8px; right: 8px; }
.diapo-btn.suppr { top: 8px; left: 8px; font-size: 1.2rem; }

.points {
  position: absolute;
  z-index: 2;
  bottom: 8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 5px;
}

.points span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  transition: background 0.3s;
}

.points span.on { background: #fff; }

.ajout-vide { width: 100%; margin-bottom: 14px; }

.diaporama img.visible { cursor: zoom-in; }

/* ---------- Photo en grand ---------- */
.visionneuse {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05070a;
  touch-action: none;
}

.visionneuse img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.fermer-visionneuse {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  padding: 9px 14px;
  border: 0;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.visionneuse .compteur {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* ---------- Recadrage de la photo ---------- */
.modale {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 13, 0.72);
  backdrop-filter: blur(4px);
}

.modale-carte {
  width: 100%;
  max-width: 320px;
  padding: 18px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  text-align: center;
}

.modale-titre { font-weight: 700; margin-bottom: 14px; }

.recadrage {
  width: 100%;
  max-width: 240px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--card-2);
  /* le glissement ne doit pas faire défiler la page */
  touch-action: none;
  cursor: grab;
  user-select: none;
  border: 3px solid var(--line);
}

.recadrage:active { cursor: grabbing; }

.zoom-row { display: flex; align-items: center; gap: 10px; margin: 14px 4px 0; }

.zoom-row input[type='range'] {
  flex: 1;
  padding: 0;
  border: 0;
  background: transparent;
  appearance: auto;
  accent-color: var(--accent);
}

.btn-duo { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Récap de fin de journée ---------- */
.recap {
  margin-bottom: 16px;
  background: linear-gradient(160deg, var(--accent-soft), var(--card) 65%);
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
}

.recap-titre {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.recap ul { margin: 0; padding-left: 18px; }
.recap li { margin: 5px 0; font-size: 0.9rem; line-height: 1.4; }

/* ---------- Divers ---------- */
.chart { width: 100%; height: 120px; display: block; }
.pager { display: flex; gap: 8px; margin-top: 12px; }
.back { display: inline-block; margin-bottom: 8px; color: var(--accent); font-weight: 600; font-size: 0.88rem; }
