:root {
  --bg: #0b0b0f;
  --surface: #141419;
  --surface-2: #1c1c23;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f4f6;
  --muted: #9a9aa8;
  --faint: #5f5f6c;
  --accent: #d9bb7e;
  --accent-soft: rgba(217, 187, 126, 0.12);
  --on-accent: #17120a;
  --good: #43d690;
  --good-soft: rgba(67, 214, 144, 0.12);
  --bad: #ff6b6b;
  --bad-soft: rgba(255, 107, 107, 0.12);
  --gold: #d9bb7e;
  --silver: #c3c7cf;
  --bronze: #c58c5c;
  --radius: 16px;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Halo très discret en haut de page */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(900px 480px at 50% -12%, rgba(217, 187, 126, 0.09), transparent 65%),
    radial-gradient(700px 400px at 100% 110%, rgba(120, 120, 255, 0.05), transparent 60%);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 32px);
}

sup { font-size: 0.55em; vertical-align: 0.55em; line-height: 0; margin-left: 1px; }

/* ------------------------------------------------ typographie */

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.eyebrow b { color: var(--text); font-weight: 600; }

.display {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(42px, 12vw, 58px);
  line-height: 1.02;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.display em { font-style: italic; color: var(--accent); }

.lead { margin: 0 0 28px; font-size: 17px; color: var(--muted); }
.hint { margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.center { text-align: center; }
.err { margin: 12px 0 0; min-height: 1.5em; font-size: 14px; font-weight: 500; color: var(--bad); }
.err:empty { min-height: 0; margin: 0; }

/* ------------------------------------------------ mise en page */

.screen { animation: rise 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.center-v {
  min-height: calc(100vh - 140px);
  min-height: calc(100svh - 140px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 18px;
}
.panel + .panel { margin-top: 12px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel-head .count { font-size: 15px; letter-spacing: 0; color: var(--text); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------ barre du haut */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: linear-gradient(var(--bg) 65%, rgba(11, 11, 15, 0));
}
.brand { font-family: var(--serif); font-size: 26px; line-height: 1; }
.who {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 65%;
  height: 38px;
  padding: 0 12px 0 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}
.who-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--good); }
.who #whoName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .sep { width: 1px; height: 16px; flex: none; background: var(--border-strong); }
.who svg { flex: none; color: var(--muted); }

/* ------------------------------------------------ boutons & champs */

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 20px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.12s, background 0.2s, opacity 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:disabled { background: var(--surface-2); color: var(--faint); }
.btn.secondary { background: var(--surface-2); border: 1px solid var(--border); }
.btn.ghost { color: var(--muted); }
.btn.danger { background: var(--bad); color: #1b0808; }
.btn.danger-text { color: var(--bad); font-weight: 500; }
.btn .sub { font-weight: 500; opacity: 0.65; }

.form { display: grid; gap: 12px; }
.input {
  width: 100%;
  height: 56px;
  padding: 0 18px;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input::placeholder { color: var(--faint); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ------------------------------------------------ salle d'attente */

.waiting { display: inline-flex; align-items: baseline; }
.dots { display: inline-flex; gap: 3px; margin-left: 3px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: blink 1.4s infinite both; }
.dots i:nth-child(2) { animation-delay: 0.2s; }
.dots i:nth-child(3) { animation-delay: 0.4s; }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips li {
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  animation: pop 0.3s ease-out both;
}
.chips li.me { border-color: var(--accent); color: var(--accent); }

.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: 12px; min-height: 48px; border-top: 1px solid var(--border); }
.plist li:first-child { border-top: 0; }
.plist li.empty { justify-content: center; color: var(--muted); font-size: 15px; }
.plist .nm { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.off { background: var(--faint); }
.kick { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--faint); }
.kick:active { background: var(--surface-2); color: var(--bad); }

.join-url { margin: 4px 0 0; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }

/* ------------------------------------------------ question */

.qhead { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.qhead .eyebrow { margin: 0; }
.qhead-right { display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  animation: pop 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.hairline { height: 2px; margin: 14px 0 0; border-radius: 2px; background: var(--border); overflow: hidden; }
#hair { height: 100%; background: var(--accent); transform-origin: left; transform: scaleX(1); }
.ring { position: relative; width: 48px; height: 48px; flex: none; }
.ring > svg { display: block; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3; }
.ring .track { stroke: var(--border-strong); }
.ring .arc { stroke: var(--accent); stroke-linecap: round; transition: stroke 0.3s; }
.ring span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hurry .ring .arc, .hurry #hair { stroke: var(--bad); background: var(--bad); }
.revealing .ring .arc, .revealing #hair { stroke: var(--faint); background: var(--faint); }
.revealing .ring span { color: var(--muted); }
.paused .ring .arc { stroke: var(--accent); opacity: 0.45; }
.paused .ring span { color: var(--accent); }
.paused #hair { background: var(--accent); opacity: 0.45; }

.question {
  margin: 26px 0 24px;
  font-size: clamp(22px, 6vw, 27px);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.qimg {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(38vh, 360px);
  max-height: min(38svh, 360px);
  margin: -4px auto 22px;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
  animation: pop 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

/* Question avec image : tout doit tenir sur un écran de téléphone, sans défiler. */
.has-img .question { margin: 20px 0 16px; }
.has-img .qimg { max-height: min(28vh, 300px); max-height: min(28svh, 300px); margin-bottom: 16px; }
.has-img .choices { gap: 8px; }
.has-img .choice { min-height: 52px; padding-top: 8px; padding-bottom: 8px; }
.has-img .status { margin-top: 12px; }

.choices { display: grid; gap: 10px; }
.choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 62px;
  padding: 12px 16px 12px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: left;
  font-size: 17px;
  font-weight: 500;
  transition: transform 0.12s, border-color 0.2s, background 0.2s, opacity 0.25s;
}
.choice:active:not(:disabled) { transform: scale(0.985); border-color: var(--border-strong); }
.choice .label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.key {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.mark { display: grid; place-items: center; flex: none; width: 22px; }

.choice.picked { border-color: var(--accent); background: var(--accent-soft); }
.choice.picked .key { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.choice.dim { opacity: 0.38; }
.choice.good { border-color: var(--good); background: var(--good-soft); opacity: 1; }
.choice.good .key { background: var(--good); border-color: var(--good); color: #06180f; }
.choice.good .mark { color: var(--good); }
.choice.bad { border-color: var(--bad); background: var(--bad-soft); opacity: 1; }
.choice.bad .key { background: var(--bad); border-color: var(--bad); color: #1b0808; }
.choice.bad .mark { color: var(--bad); }

.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  margin: 18px 0 0;
  padding: 0 16px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
  text-align: center;
}
.status.saved { color: var(--accent); }
.status.ok { background: var(--good-soft); color: var(--good); font-size: 17px; font-weight: 600; }
.status.ko { background: var(--bad-soft); color: var(--bad); font-size: 17px; font-weight: 600; }
.status.none { background: var(--surface); color: var(--muted); font-size: 17px; font-weight: 600; }
.status.ok, .status.ko, .status.none { animation: pop 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.scoreline { margin: 12px 0 0; text-align: center; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Explication de la bonne réponse : petite, pour tenir sur l'écran avec la correction. */
.why {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.45;
  color: #c9c9d3;
  animation: rise 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.why b {
  display: block;
  margin-bottom: 3px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.hopts + .why { margin-top: 12px; }

/* Pendant la révélation, tout se resserre pour laisser la place à l'explication. */
.revealing .question { margin: 20px 0 16px; }
.revealing .choices { gap: 8px; }
.revealing .choice { min-height: 50px; padding-top: 7px; padding-bottom: 7px; }
.revealing .status { min-height: 46px; margin-top: 12px; }
.scoreline b { color: var(--text); font-weight: 600; }

/* ------------------------------------------------ vue maître du jeu */

.hopts { display: grid; gap: 8px; }
.hopt {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 10px 16px 10px 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 500;
  transition: opacity 0.25s, border-color 0.25s;
}
.hopt .fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: rgba(255, 255, 255, 0.05);
  transition: width 0.7s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.hopt .key, .hopt .label, .hopt .n { position: relative; }
.hopt .key { width: 32px; height: 32px; }
.hopt .label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.hopt .n { font-weight: 600; font-variant-numeric: tabular-nums; }
.hopt.good { border-color: var(--good); }
.hopt.good .fill { background: var(--good-soft); }
.hopt.good .key { background: var(--good); border-color: var(--good); color: #06180f; }
.hopt.dim { opacity: 0.5; }

.meter { margin: 18px 0 0; }
.meter-head { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-head b { color: var(--text); font-weight: 600; }
.track { height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.track > div { height: 100%; width: 0; border-radius: 6px; background: var(--accent); transition: width 0.4s ease-out; }

.actions-stack { display: grid; gap: 10px; margin-top: 22px; }
.section-title { margin: 30px 0 12px; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

/* ------------------------------------------------ classement */

.me-card {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 8px 0 18px;
  padding: 20px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(217, 187, 126, 0.16), rgba(217, 187, 126, 0.04));
  border: 1px solid rgba(217, 187, 126, 0.35);
}
.me-rank { font-family: var(--serif); font-size: 60px; line-height: 0.9; color: var(--accent); }
.me-detail { font-size: 16px; font-weight: 500; }
.me-detail small { display: block; margin-top: 2px; font-size: 14px; font-weight: 400; color: var(--muted); }

.ranking { list-style: none; margin: 0; padding: 4px 0; }
.ranking li {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  padding: 0 4px;
  border-top: 1px solid var(--border);
  animation: rise 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.ranking li:first-child { border-top: 0; }
.ranking .pos {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.ranking .r1 .pos { background: var(--gold); color: #17120a; }
.ranking .r2 .pos { background: var(--silver); color: #121316; }
.ranking .r3 .pos { background: var(--bronze); color: #170d05; }
.ranking .nm { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.ranking .pts { font-weight: 600; font-variant-numeric: tabular-nums; }
.ranking .pts small { font-weight: 400; color: var(--muted); }
.ranking li.me .nm { color: var(--accent); }

/* ------------------------------------------------ fenêtre de confirmation */

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  background: rgba(5, 5, 8, 0.6);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fade 0.2s ease-out both;
}
.sheet {
  width: 100%;
  max-width: 420px;
  padding: 24px 20px 20px;
  border-radius: 24px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.sheet h3 { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.sheet p { margin: 0 0 22px; color: var(--muted); }
.sheet .actions { display: grid; gap: 10px; }
@media (min-width: 600px) { .modal { align-items: center; } }

/* ------------------------------------------------ réseau, chargement */

#net {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  left: 50%;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 0.25s, transform 0.25s;
}
body.offline #net { opacity: 1; transform: translate(-50%, 0); transition-delay: 1s; }

.spinner, .spin-sm {
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.spinner { width: 32px; height: 32px; margin: 40vh auto 0; }
.spin-sm { width: 12px; height: 12px; }

/* ------------------------------------------------ animations */

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
