/* Feuille de style commune à toutes les pages de Quizz Time.
   Les écrans joueur et TV sont complétés à l'étape 6. */

:root {
  /* Charte graphique : voir DESIGN.md. Thème clair uniquement.
     Toute couleur du site est déclarée ici — aucune valeur en dur ailleurs. */
  color-scheme: light;

  /* Fonds et texte */
  --bg: #f6f7fb;          /* fond des pages joueur et animateur */
  --bg-stage: #eceef5;    /* fond de l'écran TV, un cran plus sourd */
  --surface: #ffffff;
  --surface-2: #eef0f6;
  --text: #14161d;
  --muted: #5a6076;       /* 5.8:1 sur --bg */
  --border: #d7dbe6;
  --shadow: 0 1px 2px rgba(20, 22, 29, 0.06), 0 2px 8px rgba(20, 22, 29, 0.04);

  /* Couleur principale : indigo. 5.4:1 en blanc sur fond indigo (WCAG AA). */
  --accent: #3355ff;
  --accent-hover: #2742d9;
  --on-accent: #ffffff;

  /* États */
  --ok: #1d7a4c;
  --danger: #c0272d;
  --danger-bg: #fdeaea;
  --danger-text: #8c1116;   /* 7.1:1 sur --danger-bg */

  /* Alerte douce : bandeau de connexion, question bonus, bouton « son ».
     Fond clair + texte foncé, plutôt qu'un aplat orange agressif. */
  --warn-bg: #fff1d6;
  --warn-border: #e0a83c;
  --warn-text: #5a3600;

  /* Couleurs des quatre réponses. Assombries pour rester lisibles en blanc
     sur fond clair (toutes ≥ 5:1) et associées à une forme, afin de rester
     distinguables sans percevoir la couleur. */
  --choice-a: #cc2b31;
  --choice-b: #1e5fd8;
  --choice-c: #a85a00;
  --choice-d: #1d7a4c;
  --on-choice: #ffffff;
  --ring-on-choice: #ffffff;
  --ring-on-choice-soft: rgba(255, 255, 255, 0.45);

  /* Le QR code doit rester sur un blanc pur pour être lu de loin. */
  --qr-bg: #ffffff;

  --radius: 12px;
  --tap: 44px;
}

* { box-sizing: border-box; }

/* Une règle `display` de ce fichier l'emporterait sinon sur l'attribut
   `hidden`, que le JavaScript utilise pour montrer et cacher les sections. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
a { color: var(--accent); }

.wrap { max-width: 60rem; margin: 0 auto; padding: 1rem; }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.muted { color: var(--muted); font-size: 0.9rem; }
.hidden-form { display: none; }

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

/* --- Contrôles --------------------------------------------------------- */

button, .button {
  min-height: var(--tap);
  padding: 0 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.ghost { background: transparent; }
button.small { min-height: 2rem; padding: 0 0.6rem; font-size: 0.85rem; }

input, textarea, select {
  min-height: var(--tap);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  width: 100%;
}
textarea { min-height: 5rem; resize: vertical; }
input[type="checkbox"] { width: auto; min-height: auto; }
input[type="file"] { padding: 0.4rem; }

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

label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 0.5rem; }

.error {
  padding: 0.75rem 1rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-bg);
  color: var(--danger-text);
}

/* --- Espace animateur -------------------------------------------------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.page-login { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.page-login .card { width: min(24rem, 100%); }
.page-login .subtitle { color: var(--muted); margin-top: -0.25rem; }

.list { list-style: none; margin: 1.5rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.list-title { font-weight: 600; font-size: 1.05rem; margin-right: 0.5rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.question-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.grid > label:first-child { grid-column: 1 / -1; }

/* Les quatre formes sont dessinées, pas écrites : aucun glyphe Unicode à
   installer sur le téléviseur ou le téléphone. Elles doublent la couleur pour
   rester distinguables sans la percevoir. */
.shape {
  display: inline-block;
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  background: currentColor;
}
.shape-a { clip-path: polygon(50% 0%, 100% 100%, 0% 100%); }
.shape-b { clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); }
.shape-c { border-radius: 50%; }
.shape-d { border-radius: 2px; }

/* Dans le formulaire d'édition, la forme est colorée sur fond clair.
   Sur un bouton de réponse, elle reprend la couleur du texte du bouton :
   la teinte du fond est déjà celle de la réponse. */
label.choice > .shape { margin-right: 0.25rem; }
label.choice-a > .shape { color: var(--choice-a); }
label.choice-b > .shape { color: var(--choice-b); }
label.choice-c > .shape { color: var(--choice-c); }
label.choice-d > .shape { color: var(--choice-d); }

.medias { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; }
.medias legend { color: var(--muted); font-size: 0.9rem; padding: 0 0.4rem; }
.media-field { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding: 0.35rem 0; }
.media-label { min-width: 4rem; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Pages joueur et écran TV (complétées à l'étape 6) ----------------- */

.page-center { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.page-center .card { width: min(26rem, 100%); text-align: center; }
.page-center .subtitle { color: var(--muted); margin-top: -0.25rem; }

button.big { min-height: 3.5rem; font-size: 1.1rem; }

.code-input {
  text-align: center;
  font-size: 2rem;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

/* L'écran TV est souvent projeté dans une salle sombre : un blanc pur
   éblouit, on garde un gris très clair. */
.page-screen { background: var(--bg-stage); }
.page-screen { display: grid; place-items: center; min-height: 100dvh; padding: 2rem; }
.page-screen .lobby { text-align: center; }
.page-screen .qr { display: inline-block; background: var(--qr-bg); padding: 1rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.page-screen .qr svg { display: block; width: min(40vh, 22rem); height: auto; }

.code-big {
  font-size: clamp(3rem, 12vw, 7rem);
  font-weight: 800;
  letter-spacing: 0.15em;
  margin: 0.5rem 0 0;
  font-variant-numeric: tabular-nums;
}

.players {
  list-style: none; padding: 0;
  margin: 1.5rem auto 0;
  display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center;
  max-width: 60rem;
}
.players li {
  padding: 0.4rem 0.9rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-weight: 600;
}

/* --- Bandeau de connexion (commun aux trois écrans) -------------------- */

.connection {
  margin: 0;
  padding: 0.5rem 1rem;
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn-text);
  font-weight: 600;
  text-align: center;
}

/* --- Écran du joueur --------------------------------------------------- */

.page-play { min-height: 100dvh; }

#play { display: flex; flex-direction: column; min-height: 100dvh; }

.player-bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.player-name { font-weight: 700; flex: 1; overflow-wrap: anywhere; }
.player-score { font-variant-numeric: tabular-nums; font-weight: 700; }
.player-rank { color: var(--muted); font-size: 0.9rem; }

.player-main {
  flex: 1;
  display: flex; flex-direction: column; gap: 1rem;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

.question-body { font-size: 1.35rem; margin: 0; }
.question-image {
  max-width: 100%; max-height: 32vh;
  object-fit: contain;
  border-radius: var(--radius);
  align-self: center;
}

.chrono {
  margin: 0; text-align: center;
  font-size: 1.5rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.chrono.urgent { color: var(--danger); }

.big-message { font-size: 1.5rem; font-weight: 700; text-align: center; margin: auto 0 0.25rem; }
.verdict { font-size: 2rem; font-weight: 800; text-align: center; margin: auto 0 0; }
.verdict.juste { color: var(--ok); }
.verdict.rate { color: var(--danger); }
.points {
  font-size: 2.5rem; font-weight: 800; text-align: center;
  margin: 0 0 0.5rem; font-variant-numeric: tabular-nums;
}
.verdict + .points { margin-bottom: 0.25rem; }
.points ~ .muted { text-align: center; margin: 0; }
.points ~ .muted:last-child { margin-bottom: auto; }
.bonus-flag {
  align-self: center;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  font-weight: 800;
  margin: 0;
}

/* --- Boutons de réponse ------------------------------------------------ */

.choices { display: grid; gap: 0.75rem; margin-top: auto; }
.choices-2 { grid-template-columns: 1fr; }
.choices-4 { grid-template-columns: repeat(2, 1fr); }

.choice-button, .choice-card {
  display: flex; align-items: center; gap: 0.6rem;
  min-height: 5rem;
  padding: 0.75rem 1rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--on-choice);
  font-size: 1.05rem; font-weight: 700;
  text-align: left;
}
.choice-button .shape, .choice-card .shape { width: 1.75rem; height: 1.75rem; }
.choice-button .label, .choice-card .label { overflow-wrap: anywhere; }

.choice-a { background: var(--choice-a); }
.choice-b { background: var(--choice-b); }
.choice-c { background: var(--choice-c); }
.choice-d { background: var(--choice-d); }

.choice-button:disabled { opacity: 0.45; }
.choice-button.picked { opacity: 1; border-color: var(--ring-on-choice); box-shadow: 0 0 0 3px var(--ring-on-choice-soft); }

/* --- Écran TV ---------------------------------------------------------- */

.page-screen { display: block; min-height: 100dvh; padding: 0; place-items: initial; }
#screen { min-height: 100dvh; display: flex; flex-direction: column; }

.sound-button {
  position: fixed; top: 1rem; right: 1rem; z-index: 5;
  background: var(--warn-bg); color: var(--warn-text);
  border-color: var(--warn-border); font-weight: 700;
}

.lobby { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5rem; padding: 2rem; text-align: center; }
.lobby h1 { font-size: clamp(1.75rem, 4vw, 3rem); }
.lobby-grid { display: flex; align-items: center; gap: 2.5rem; flex-wrap: wrap; justify-content: center; }
.lobby-count { color: var(--muted); font-size: 1.25rem; margin: 0; }

.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 1.25rem; padding: 2rem; }
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.stage-index { color: var(--muted); font-size: 1.1rem; font-weight: 600; }
.stage-question { font-size: clamp(1.5rem, 3.5vw, 3rem); margin: 0; text-align: center; }
.stage-media { display: flex; justify-content: center; }
.stage-image, .stage-video { max-height: 38vh; max-width: 100%; border-radius: var(--radius); }
.stage-audio { width: min(30rem, 100%); }

.page-screen .choices { margin-top: auto; }
.page-screen .choice-card { min-height: 6rem; font-size: clamp(1rem, 2vw, 1.6rem); }
/* À la révélation, plus de médias ni de chrono : les cartes se recentrent. */
.choices.revealed { margin-top: 0; }
.choices.revealed .wrong { opacity: 0.3; }
.choices.revealed .correct { border-color: var(--ring-on-choice); box-shadow: 0 0 0 4px var(--ring-on-choice-soft); }
.choice-card .count { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 1.5rem; }

.answered-count { text-align: center; font-size: 1.5rem; margin: 0; }

.podium { text-align: center; }
.podium-list { list-style: none; padding: 0; margin: 0.5rem 0 0; display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.podium-list li { display: flex; gap: 0.5rem; align-items: baseline; padding: 0.5rem 1rem; background: var(--surface-2); border-radius: 999px; }
.podium-name { font-weight: 700; }
.podium-points { color: var(--ok); font-variant-numeric: tabular-nums; }

/* --- Chrono circulaire ------------------------------------------------- */

.chrono-ring { width: 6rem; height: 6rem; flex: none; transform: rotate(-90deg); }
.chrono-track { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.chrono-arc {
  fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  transition: stroke-dashoffset 0.1s linear;
}
.chrono-ring.urgent .chrono-arc { stroke: var(--danger); }
.chrono-text {
  fill: var(--text); font-size: 2.4rem; font-weight: 800;
  transform: rotate(90deg); transform-origin: 60px 60px;
  font-variant-numeric: tabular-nums;
}

/* --- Classement -------------------------------------------------------- */

.ranking { list-style: none; counter-reset: none; padding: 0; margin: 0 auto; width: min(44rem, 100%); display: flex; flex-direction: column; gap: 0.5rem; }
.ranking li {
  display: flex; align-items: center; gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.rank-pos { min-width: 2.5rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--muted); }
.rank-name { flex: 1; font-weight: 700; overflow-wrap: anywhere; }
.rank-score { font-variant-numeric: tabular-nums; font-weight: 700; }
.ranking .rank-1 .rank-pos { color: var(--choice-c); }

/* --- Pupitre de l'animateur -------------------------------------------- */

.host-state { color: var(--muted); font-weight: 600; }
.host-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.host-choices { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: 0.5rem; }
.host-choices li {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.9rem; border-radius: var(--radius);
  border: 1px solid var(--border);
}
.host-choices .tag { margin-left: auto; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.host-choices .correct { border-color: var(--ok); }
.ranking.compact li { padding: 0.4rem 0.75rem; }

/* Sous 24rem, quatre boutons côte à côte deviennent illisibles. */
@media (max-width: 24rem) {
  .choices-4 { grid-template-columns: 1fr; }
  .choice-button { min-height: 4rem; }
}
