:root {
  --bg: #15123a;
  --bg-2: #221c5c;
  --panel: #1e1a52;
  --panel-2: #2a2470;
  --line: rgba(255, 255, 255, .14);
  --text: #f6f4ff;
  --muted: #b3aedf;
  --accent: #ffd23f;
  --accent-ink: #2a1f00;
  --good: #3ddc97;
  --bad: #ff5d73;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 85% -10%, var(--bg-2), transparent 70%),
    radial-gradient(700px 500px at -10% 110%, #2b1a63, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.view { display: none; width: 100%; max-width: 980px; margin: 0 auto; }
.view.active { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

h1, h2, h3 { margin: 0; line-height: 1.1; letter-spacing: -.02em; }
h2 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 800; }
h3 { font-size: 1.05rem; font-weight: 600; }
.muted { color: var(--muted); margin: 8px 0 0; }

/* Accueil */
.hero { text-align: center; padding: 8vh 0; }
.logo {
  display: flex; flex-direction: column; align-items: center;
  font-size: clamp(3.2rem, 14vw, 8.5rem);
  font-weight: 800; letter-spacing: -.05em; line-height: .88;
}
.logo span:last-child { color: var(--accent); transform: rotate(-2deg); }
.lead { color: var(--muted); font-size: clamp(1.05rem, 2.6vw, 1.3rem); margin: 28px 0 36px; }

/* Cartes */
.card {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(20px, 4vw, 36px);
  box-shadow: 0 20px 50px rgba(5, 3, 30, .45);
}
.card.narrow { max-width: 480px; margin: 0 auto; }

/* Boutons */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 2px solid transparent; border-radius: 999px;
  padding: 12px 24px; color: var(--text); background: transparent;
  transition: transform .12s ease, background .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, .06); }
.btn-xl { font-size: 1.3rem; padding: 16px 44px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.row { display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap; margin-top: 28px; }
.row.end { justify-content: flex-end; min-height: 48px; }

/* Formulaire */
.input {
  width: 100%; margin-top: 20px; padding: 14px 16px; font: inherit; font-size: 1.1rem;
  color: var(--text); background: rgba(0, 0, 0, .25);
  border: 2px solid var(--line); border-radius: 12px;
}
.input:focus { outline: none; border-color: var(--accent); }
.error { color: var(--bad); min-height: 1.5em; margin: 10px 0 0; font-weight: 600; }

/* Lobby */
.count { margin: 22px 0 10px; color: var(--muted); }
.count strong { color: var(--accent); font-size: 1.4rem; }
.players { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px; }
.players li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 8px; border-radius: 999px;
  background: rgba(255, 255, 255, .07); border: 1px solid var(--line);
}
.players li.me { border-color: var(--accent); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; color: #1a1440; flex: none;
}

/* Quiz */
.quiz-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; }
.quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill { padding: 6px 14px; border-radius: 999px; background: rgba(255, 255, 255, .08); font-weight: 600; font-size: .95rem; }
.pill-part { background: var(--part); color: var(--part-ink); }
.pill-score strong { color: var(--accent); }
.bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .1); margin: 16px 0 26px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--part); border-radius: 99px; transition: width .4s ease; }
.question { font-size: clamp(1.25rem, 3.4vw, 1.9rem); margin-bottom: 22px; overflow-wrap: anywhere; }
.options { display: grid; gap: 12px; }
.opt {
  width: 100%; min-height: 56px;
  display: flex; align-items: center; gap: 14px; text-align: left;
  font: inherit; font-size: 1.05rem; color: var(--text); cursor: pointer;
  padding: 14px 16px; border-radius: 14px;
  background: rgba(255, 255, 255, .06); border: 2px solid var(--line);
  transition: border-color .15s ease, background .15s ease, transform .12s ease;
}
.opt:hover:not(:disabled) { border-color: var(--accent); transform: translateX(4px); }
.opt:disabled { cursor: default; }
.opt .letter {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: rgba(255, 255, 255, .12); font-weight: 800;
}
.opt.good { border-color: var(--good); background: rgba(61, 220, 151, .16); }
.opt.good .letter { background: var(--good); color: #04271a; }
.opt.bad { border-color: var(--bad); background: rgba(255, 93, 115, .16); }
.opt.bad .letter { background: var(--bad); color: #3a0510; }
.opt.dim { opacity: .5; }
.feedback { min-height: 1.6em; margin: 18px 0 0; font-weight: 600; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }


/* Réponses : texte, images, sons */
.optwrap { position: relative; min-width: 0; }
.opt-text { min-width: 0; overflow-wrap: anywhere; }
.opt-sound { padding-left: 72px; }
.play {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: inherit; font-size: 1.1rem; line-height: 1;
  display: grid; place-items: center; z-index: 2; padding: 0;
}
.play.playing { background: var(--good); color: #04271a; }
.play.broken { opacity: .4; }
.opt-sound .letter { order: 2; margin-left: auto; }

.options-images { grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
.opt-image { position: relative; display: block; padding: 8px; min-height: 0; }
.opt-image .letter { position: absolute; top: 14px; left: 14px; z-index: 1; box-shadow: 0 2px 8px rgba(0, 0, 0, .5); }
.opt-img {
  display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 9px; background: rgba(0, 0, 0, .3);
}
.opt-img.broken { object-fit: contain; font-size: .8rem; color: var(--muted); }
.opt-image:hover:not(:disabled) { transform: translateY(-3px); }

.explain {
  margin: 12px 0 0; padding: 12px 14px; border-radius: 12px;
  background: rgba(255, 255, 255, .07); border-left: 4px solid var(--accent);
  overflow-wrap: anywhere;
}
.endnote {
  margin: 22px 0 0; padding: 14px 16px; text-align: center; font-weight: 600;
  border-radius: 14px; background: rgba(255, 210, 63, .12); border: 1px solid var(--accent);
}

.live h3 { margin-bottom: 14px; }
.live-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.live-list li { font-size: .95rem; }
.live-list .line { display: flex; justify-content: space-between; gap: 8px; }
.live-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-list .mini { height: 5px; border-radius: 9px; background: rgba(255, 255, 255, .1); margin-top: 5px; overflow: hidden; }
.live-list .mini i { display: block; height: 100%; background: var(--good); transition: width .3s ease; }
.live-list li.me .nm { color: var(--accent); font-weight: 600; }

/* Classement */
.ranking { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; }
.rank {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center;
  padding: 14px 16px; border-radius: 14px;
  background: rgba(255, 255, 255, .06); border: 1px solid var(--line);
}
.rank.first { background: rgba(255, 210, 63, .12); border-color: var(--accent); }
.rank.me .who { color: var(--accent); }
.pos { font-size: 1.5rem; font-weight: 800; text-align: center; }
.who { font-weight: 600; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.meter { height: 6px; border-radius: 9px; background: rgba(255, 255, 255, .1); margin-top: 8px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 9px; }
.stats { text-align: right; white-space: nowrap; }
.stats .pct { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.stats .fr { color: var(--muted); font-size: .9rem; }

.conn {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; padding: 8px; text-align: center;
  background: var(--bad); color: #fff; font-weight: 600;
}

@media (max-width: 800px) {
  .quiz-layout { grid-template-columns: 1fr; }
  .live { order: 2; }
  .row .btn { flex: 1 1 auto; }
  .players li { max-width: 100%; }
}
@media (min-width: 1400px) {
  .view { max-width: 1120px; }
  .quiz-layout { grid-template-columns: 1fr 300px; }
  .options-images { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
  #app { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .opt { font-size: 1rem; padding: 12px; gap: 12px; }
  .opt-sound { padding-left: 68px; }
  .options-images { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .btn { padding: 12px 18px; }
  .row.end .btn { width: 100%; }
  .bar { margin: 14px 0 20px; }
}
@media (max-width: 340px) {
  .options-images { grid-template-columns: 1fr; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .hero { padding: 2vh 0; }
  .logo { font-size: clamp(2.4rem, 12vh, 4.5rem); }
  .lead { margin: 14px 0 18px; }
}
@media (hover: none) {
  .opt:hover:not(:disabled) { transform: none; }
  .btn:hover:not(:disabled) { transform: none; }
}
@media (max-width: 480px) {
  .rank { grid-template-columns: 36px 1fr; }
  .rank .stats { grid-column: 2; text-align: left; display: flex; gap: 10px; align-items: baseline; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}


/* ---------- Thème par partie ---------- */
#view-quiz, #part-intro { --part: #ffd23f; --part-ink: #2a1f00; }            /* 1 · Flo : jaune */
#view-quiz[data-part="2"], #part-intro[data-part="2"] { --part: #ff8fa3; --part-ink: #3a0516; } /* 2 · Martin : rose */
#view-quiz[data-part="3"], #part-intro[data-part="3"] { --part: #7fd3ff; --part-ink: #04202e; } /* 3 · Lucas : bleu */
#view-quiz .card.quiz { border-top: 4px solid var(--part); }
#view-quiz .opt:hover:not(:disabled) { border-color: var(--part); }
#view-quiz .explain { border-left-color: var(--part); }
#view-quiz .btn-primary { background: var(--part); color: var(--part-ink); }

/* Écran d'intro de partie */
#view-quiz { position: relative; }
.part-intro {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgba(21, 18, 58, .92); backdrop-filter: blur(6px);
  animation: introIn .3s ease;
}
.part-intro[hidden] { display: none; }
.part-intro-box {
  text-align: center; padding: 36px 40px; border-radius: 24px; max-width: 420px; width: 100%;
  background: var(--panel-2); border: 2px solid var(--part);
  box-shadow: 0 0 60px color-mix(in srgb, var(--part) 35%, transparent);
}
.part-intro-emoji { font-size: 3.5rem; line-height: 1; }
.part-intro-num { margin: 14px 0 0; color: var(--part); font-weight: 800; letter-spacing: .08em; text-transform: uppercase; font-size: .9rem; }
.part-intro-name { margin: 6px 0 4px; font-size: clamp(2.4rem, 9vw, 3.6rem); color: var(--part); }
.part-intro-sub { margin: 0 0 22px; color: var(--muted); }
@keyframes introIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
