:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --surface-3: #e8eaf3;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e3e6f0;
  --primary: #5b5bf6;
  --primary-2: #9b5cf6;
  --primary-soft: color-mix(in srgb, var(--primary) 12%, transparent);
  --success: #10b981;
  --success-soft: color-mix(in srgb, var(--success) 14%, transparent);
  --danger: #ef4444;
  --danger-soft: color-mix(in srgb, var(--danger) 12%, transparent);
  --warning: #f59e0b;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 10px 30px -12px rgba(15, 23, 42, .16);
  --shadow-lg: 0 2px 4px rgba(15, 23, 42, .04), 0 24px 60px -20px rgba(15, 23, 42, .28);
  --c0: #6366f1; --c1: #f59e0b; --c2: #10b981; --c3: #f43f5e; --c4: #0ea5e9; --c5: #a855f7;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0c16;
    --surface: #121528;
    --surface-2: #191d35;
    --surface-3: #232846;
    --text: #e9ebf8;
    --muted: #949cbc;
    --border: #252a48;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 12px 32px -12px rgba(0, 0, 0, .7);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, .3), 0 30px 70px -20px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 0% -10%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 60%),
    radial-gradient(900px 520px at 100% 0%, color-mix(in srgb, var(--primary-2) 14%, transparent), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.02em; line-height: 1.2; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
button { font: inherit; color: inherit; }
pre, code { font-family: var(--mono); }
[hidden] { display: none !important; }

/* ───── Layout ───── */
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.narrow { max-width: 520px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mt { margin-top: 24px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.topbar .container { display: flex; align-items: center; gap: 16px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.02em; color: var(--text); }
.logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: 16px; font-weight: 800;
  box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--primary) 70%, transparent);
}

/* ───── Cards ───── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.card.lg { padding: 32px; }
.card-hover { transition: transform .18s ease, box-shadow .18s ease, border-color .18s; }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--primary) 35%, var(--border)); }
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

/* ───── Buttons ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; font-size: 14px; cursor: pointer;
  transition: transform .12s ease, box-shadow .15s, background .15s, opacity .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary {
  border: 0; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 8px 22px -8px color-mix(in srgb, var(--primary) 75%, transparent);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary), var(--primary-2)); filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-lg { height: 54px; padding: 0 28px; font-size: 16px; border-radius: 14px; }
.btn-xl { height: 64px; padding: 0 36px; font-size: 19px; border-radius: 16px; }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.icon-btn { width: 36px; height: 36px; padding: 0; }

/* ───── Forms ───── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.input, textarea.input, select.input {
  width: 100%; min-height: 46px; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 16px; outline: none; transition: border-color .15s, box-shadow .15s, background .15s;
}
textarea.input { resize: vertical; min-height: 80px; }
textarea.code-input { font-family: var(--mono); font-size: 13px; }
.input:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px var(--primary-soft); }
.input.lg { font-size: 22px; font-weight: 700; letter-spacing: .25em; text-align: center; text-transform: uppercase; }
.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }

/* ───── Badges, chips ───── */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.live { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.live::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite; }
.badge.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-weight: 600;
}
.chip.pop { animation: pop .45s cubic-bezier(.2, 1.6, .4, 1); }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 12px; font-weight: 800; color: #fff;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }

/* ───── Tabs ───── */
.tabs { display: inline-flex; padding: 4px; gap: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.tab { border: 0; background: transparent; height: 34px; padding: 0 14px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ───── Tables ───── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }

/* ───── Choices (réponses) ───── */
.choices { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .choices.two { grid-template-columns: 1fr 1fr; } }
.choice {
  --c: var(--c0);
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; min-height: 64px;
  padding: 14px 16px; text-align: left; border-radius: 16px; cursor: pointer; overflow: hidden;
  border: 2px solid color-mix(in srgb, var(--c) 30%, var(--border));
  background: color-mix(in srgb, var(--c) 8%, var(--surface));
  font-weight: 600; font-size: 16px; transition: transform .12s, border-color .15s, background .15s, opacity .2s;
}
.choice:hover:not(:disabled) { border-color: var(--c); }
.choice:active:not(:disabled) { transform: scale(.98); }
.choice:disabled { cursor: default; }
.choice .letter {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none;
  background: var(--c); color: #fff; font-weight: 800; font-size: 16px; position: relative; z-index: 1;
}
.choice .label { flex: 1; position: relative; z-index: 1; }
.choice .count { position: relative; z-index: 1; font-weight: 800; font-variant-numeric: tabular-nums; }
.choice .bar { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--c) 22%, transparent); transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.choice.selected { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface)); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 18%, transparent); }
.choice.selected .letter::after { content: '✓'; position: absolute; inset: 0; display: grid; place-items: center; background: var(--c); border-radius: inherit; }
.choice.correct { border-color: var(--success); background: color-mix(in srgb, var(--success) 14%, var(--surface)); }
.choice.correct .label::after { content: ' ✓'; color: var(--success); font-weight: 800; }
.choice.correct .bar { background: color-mix(in srgb, var(--success) 26%, transparent); }
.choice.dim { opacity: .45; }
.choice.wrong { border-color: var(--danger); }
.c0 { --c: var(--c0); } .c1 { --c: var(--c1); } .c2 { --c: var(--c2); }
.c3 { --c: var(--c3); } .c4 { --c: var(--c4); } .c5 { --c: var(--c5); }

.code-block {
  margin: 0; padding: 16px 18px; border-radius: 14px; overflow-x: auto;
  background: #0f1226; color: #e2e6ff; font-size: 14px; line-height: 1.6;
  border: 1px solid #262b4e;
}

/* ───── Timer ───── */
.timer-bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.timer-bar > div { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .25s linear; }
.timer-bar.low > div { background: linear-gradient(90deg, var(--warning), var(--danger)); }
.ring { position: relative; width: 96px; height: 96px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: grid; place-items: center; font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ring circle { fill: none; stroke-width: 9; }
.ring .track { stroke: var(--surface-3); }
.ring .prog { stroke: url(#ringGrad); stroke-linecap: round; transition: stroke-dashoffset .25s linear; }
.ring.low .prog { stroke: var(--danger); }

/* ───── Stats ───── */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 28px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

/* ───── Podium ───── */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 14px; max-width: 720px; margin: 0 auto; }
.podium .place { display: flex; flex-direction: column; align-items: center; gap: 10px; animation: rise .8s cubic-bezier(.2, 1.2, .4, 1) both; }
.podium .place:nth-child(1) { animation-delay: .5s; }
.podium .place:nth-child(2) { animation-delay: .9s; }
.podium .place:nth-child(3) { animation-delay: .2s; }
.podium .name { font-weight: 800; font-size: 17px; text-align: center; word-break: break-word; }
.podium .block {
  width: 100%; border-radius: 16px 16px 6px 6px; display: grid; place-items: center; color: #fff; font-weight: 900; font-size: 40px;
  box-shadow: var(--shadow-lg);
}
.podium .p1 .block { height: 190px; background: linear-gradient(180deg, #fbbf24, #f59e0b); }
.podium .p2 .block { height: 140px; background: linear-gradient(180deg, #cbd5e1, #94a3b8); }
.podium .p3 .block { height: 105px; background: linear-gradient(180deg, #fdba74, #ea8a3c); }

/* ───── Divers ───── */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty .emoji { font-size: 44px; margin-bottom: 8px; }
.hero-icon {
  width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center; margin: 0 auto; font-size: 34px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  box-shadow: 0 16px 40px -14px color-mix(in srgb, var(--primary) 80%, transparent);
}
.hero-icon.ok { background: linear-gradient(135deg, #34d399, #10b981); box-shadow: 0 16px 40px -14px rgba(16, 185, 129, .8); }
.hero-icon.ko { background: linear-gradient(135deg, #fb7185, #ef4444); box-shadow: 0 16px 40px -14px rgba(239, 68, 68, .8); }
.loader { display: inline-flex; gap: 6px; }
.loader i { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); animation: bounce 1.2s infinite ease-in-out; }
.loader i:nth-child(2) { animation-delay: .15s; } .loader i:nth-child(3) { animation-delay: .3s; }
.alert { padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 500; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.divider { height: 1px; background: var(--border); margin: 4px 0; }
.kbd { font-family: var(--mono); font-size: 12px; padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); }

.toast-host { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 12px 18px; border-radius: 12px; background: #111427; color: #fff; font-weight: 600; font-size: 14px; box-shadow: var(--shadow-lg); animation: toastIn .25s ease; }
.toast.error { background: var(--danger); }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 24, .55); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.modal { width: 100%; max-width: 560px; max-height: calc(100dvh - 40px); overflow: auto; }

.fade-in { animation: fadeUp .35s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes blink { 50% { opacity: .3; } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.shake { animation: shake .4s; }

@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .card { padding: 18px; }
  .card.lg { padding: 22px; }
  .hide-sm { display: none !important; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ───── Choix du mode de session ───── */
.mode-picker { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .mode-picker { grid-template-columns: 1fr; } }
.mode-option { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 16px; cursor: pointer; box-shadow: none; transition: border-color .15s, background .15s, box-shadow .15s; }
.mode-option input { position: absolute; opacity: 0; pointer-events: none; }
.mode-option .mode-icon { font-size: 24px; }
.mode-option:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 7%, var(--surface)); box-shadow: 0 0 0 4px var(--primary-soft); }
.mode-option:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ───── Progression (mode continu) ───── */
.progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > div { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .4s ease; }
.progress.done > div { background: var(--success); }
.voters { display: flex; flex-wrap: wrap; gap: 6px; }
.voters .chip { padding: 4px 10px 4px 4px; font-size: 13px; box-shadow: none; }
.voters .chip .avatar { width: 22px !important; height: 22px !important; font-size: 10px !important; }
