:root {
  color-scheme: dark;
  --bg: #12121a;
  --bg-2: #1c1c28;
  --bg-3: #262636;
  --fg: #f4f4f8;
  --fg-2: #a9a9bd;
  --fg-3: #6f6f86;
  --line: #34344a;
  --accent: #ff70a6;
  --accent-2: #ffd166;
  --ok: #06d6a0;
  --ko: #ef476f;
  --radius: 16px;
  --radius-s: 10px;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f6f6fa;
    --bg-2: #ffffff;
    --bg-3: #ececf4;
    --fg: #16161f;
    --fg-2: #4d4d64;
    --fg-3: #8a8aa3;
    --line: #d9d9e6;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; color: var(--fg-2); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0; }
.muted { color: var(--fg-2); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.hidden { display: none !important; }

/* Mise en page */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.screen {
  flex: 1; display: flex; flex-direction: column; gap: 14px;
  width: 100%; max-width: 520px; margin: 0 auto;
  padding: calc(var(--pad) + var(--safe-t)) var(--pad) calc(var(--pad) + var(--safe-b));
}
.screen-wide { max-width: 900px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding-bottom: 4px;
}
.topbar .brand { font-weight: 800; letter-spacing: -.01em; }
.topbar .code { font-weight: 800; letter-spacing: .12em; color: var(--accent-2); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--fg-3); display: inline-block; }
.conn.online { background: var(--ok); }
.conn.reconnecting, .conn.connecting { background: var(--accent-2); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .3; } }

.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.card.flat { background: transparent; border-style: dashed; }
.stack-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 12px 18px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--fg); font-weight: 700; cursor: pointer;
  width: 100%; text-decoration: none; transition: transform .06s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a0a12; }
.btn-secondary { background: var(--accent-2); border-color: var(--accent-2); color: #241c00; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--ko); color: var(--ko); }
.btn-inline { width: auto; min-height: 40px; padding: 8px 14px; font-size: 14px; }
.btn-icon { width: 40px; min-height: 40px; padding: 0; border-radius: 10px; }

/* Champs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--fg-2); font-weight: 600; }
.input, textarea.input {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--fg); outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 120px; resize: vertical; }
.input.code-input { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; font-size: 24px; text-align: center; }
.error { color: var(--ko); font-size: 14px; }
.notice { background: rgba(255, 209, 102, .12); border: 1px solid rgba(255, 209, 102, .5); border-radius: var(--radius-s); padding: 10px 12px; font-size: 14px; }

/* Avatars */
.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; color: #14141c; font-size: 16px; position: relative;
  text-transform: uppercase;
}
.avatar.lg { width: 64px; height: 64px; font-size: 24px; }
.avatar.xl { width: 92px; height: 92px; font-size: 34px; }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar .badge {
  position: absolute; right: -4px; bottom: -4px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg-2); border: 1px solid var(--line); font-size: 11px;
  display: flex; align-items: center; justify-content: center; color: var(--fg);
}
.avatar.sm .badge { width: 14px; height: 14px; font-size: 8px; right: -3px; bottom: -3px; }
.avatar.xl .badge { width: 28px; height: 28px; font-size: 15px; }
.avatar.offline { opacity: .45; }
.player-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.player-row:last-child { border-bottom: none; }
.player-row .name { font-weight: 700; }
.player-row .state { font-size: 13px; color: var(--fg-2); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg-3); color: var(--fg-2); white-space: nowrap; }
.tag.ok { background: rgba(6, 214, 160, .18); color: var(--ok); }
.tag.warn { background: rgba(255, 209, 102, .18); color: var(--accent-2); }
.tag.ko { background: rgba(239, 71, 111, .18); color: var(--ko); }

.color-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; }
.color-swatch {
  aspect-ratio: 1; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0;
  background: none;
}
.color-swatch span { display: block; width: 100%; height: 100%; border-radius: 50%; }
.color-swatch.selected { border-color: var(--fg); }

/* Code géant + QR */
.big-code {
  font-size: 56px; font-weight: 900; letter-spacing: .25em; text-align: center; color: var(--accent-2);
  padding-left: .25em;
}
.qr { width: 100%; max-width: 220px; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #fff; padding: 8px; }
.qr svg { display: block; width: 100%; height: auto; }
.url { text-align: center; font-size: 13px; color: var(--fg-2); word-break: break-all; }

/* Plateformes */
.platform-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.platform-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 84px;
  padding: 12px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--bg-2);
  text-align: left; cursor: pointer;
}
.platform-card .p-name { font-weight: 800; }
.platform-card .p-sub { font-size: 12px; color: var(--fg-2); }
.platform-card.selected { border-color: var(--accent); }

/* Titres */
.track-list { display: flex; flex-direction: column; gap: 8px; }
.track {
  display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line); text-align: left; width: 100%; cursor: pointer;
}
.track.static { cursor: default; }
.track.selected { border-color: var(--accent); background: rgba(255, 112, 166, .12); }
.track .cover { width: 48px; height: 48px; border-radius: 8px; background: var(--bg-3); flex: none; object-fit: cover; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.track .t-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track .t-artist { font-size: 13px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track .t-body { flex: 1; min-width: 0; }
.track .check {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800;
}
.track.selected .check { background: var(--accent); border-color: var(--accent); color: #1a0a12; }
.counter { font-weight: 800; font-size: 18px; }

/* Manche */
.now-playing { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.now-playing .cover-lg {
  width: min(56vw, 240px); height: min(56vw, 240px); border-radius: 18px; background: var(--bg-3); object-fit: cover;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .35); display: flex; align-items: center; justify-content: center; font-size: 64px;
}
.now-playing .title { font-size: 22px; font-weight: 800; }
.now-playing .artist { color: var(--fg-2); }
.round-label { font-size: 13px; color: var(--fg-2); font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }

.timer { display: flex; flex-direction: column; gap: 6px; align-items: center; }
.timer .num { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.timer .num.urgent { color: var(--ko); }
.timer .bar { width: 100%; height: 6px; border-radius: 3px; background: var(--bg-3); overflow: hidden; }
.timer .bar > div { height: 100%; background: var(--accent); transition: width .2s linear; }

.vote-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.vote-btn {
  min-height: 64px; display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-radius: 14px; border: 2px solid var(--line); background: var(--bg-2); cursor: pointer; text-align: left;
}
.vote-btn .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vote-btn.selected { border-color: var(--accent); background: rgba(255, 112, 166, .14); }
.vote-btn[disabled] { opacity: .55; cursor: default; }
.vote-btn.owner { border-color: var(--ok); background: rgba(6, 214, 160, .14); }

.reveal-owner { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0; }
.reveal-owner .who { font-size: 22px; font-weight: 900; }
.result-banner { border-radius: var(--radius); padding: 14px; text-align: center; font-weight: 800; font-size: 18px; }
.result-banner.ok { background: rgba(6, 214, 160, .18); color: var(--ok); }
.result-banner.ko { background: rgba(239, 71, 111, .18); color: var(--ko); }
.result-banner.owner { background: rgba(255, 209, 102, .18); color: var(--accent-2); }
.vote-line { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.vote-line:last-child { border-bottom: none; }
.vote-line .arrow { color: var(--fg-3); }
.vote-line .pts { margin-left: auto; font-weight: 800; font-variant-numeric: tabular-nums; }
.vote-line .pts.ok { color: var(--ok); }
.vote-line .pts.ko { color: var(--fg-3); }
.ranking { display: flex; flex-direction: column; }
.rank-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border-bottom: none; }
.rank-row .pos { width: 24px; font-weight: 800; color: var(--fg-2); text-align: right; }
.rank-row .name { font-weight: 700; flex: 1; }
.rank-row .score { font-weight: 900; font-variant-numeric: tabular-nums; }
.rank-row.me .name { color: var(--accent); }

/* Fin */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: end; padding: 10px 0; }
.podium .step { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.podium .block { width: 100%; border-radius: 10px 10px 0 0; background: var(--bg-3); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; font-weight: 900; }
.podium .first .block { height: 84px; background: rgba(255, 209, 102, .35); }
.podium .second .block { height: 60px; background: rgba(169, 169, 189, .35); }
.podium .third .block { height: 44px; background: rgba(205, 127, 50, .35); }
.podium .name { font-weight: 800; font-size: 14px; text-align: center; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--bg-3); border-radius: var(--radius-s); padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.stat .s-label { font-size: 12px; color: var(--fg-2); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.stat .s-value { font-weight: 800; display: flex; align-items: center; gap: 8px; }
.stat .s-sub { font-size: 12px; color: var(--fg-2); }

/* Options */
.opt-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.opt-row:last-child { border-bottom: none; }
.opt-row label { font-weight: 600; }
.opt-row .input { width: 90px; min-height: 40px; padding: 6px 10px; text-align: center; }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--bg-3); border: 1px solid var(--line); position: relative; cursor: pointer; padding: 0; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--fg-3); transition: left .15s; }
.switch.on { background: var(--ok); border-color: var(--ok); }
.switch.on::after { left: 25px; background: #fff; }
details summary { cursor: pointer; font-weight: 700; color: var(--fg-2); list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: "▸ "; }
details[open] summary::before { content: "▾ "; }

/* Toasts */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 50; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; max-width: 90vw; box-shadow: 0 6px 24px rgba(0, 0, 0, .35); animation: pop .2s ease; }
.toast.error { background: var(--ko); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.pulse { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 0 8px; text-align: center; }
.hero .logo { width: 84px; height: 84px; }
.hero h1 { font-size: 30px; }
.hero p { color: var(--fg-2); }

.steps { display: flex; flex-direction: column; gap: 8px; }
.step-item { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--fg-2); }
.step-item b { color: var(--fg); }
.step-item .n { width: 24px; height: 24px; border-radius: 50%; background: var(--bg-3); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12px; flex: none; color: var(--fg); }

/* Mode un seul téléphone */
.handoff { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 24px 0; text-align: center; }
.handoff .who { font-size: 30px; font-weight: 900; }
.check-big { width: 84px; height: 84px; border-radius: 50%; background: rgba(6, 214, 160, .18); color: var(--ok); font-size: 44px; font-weight: 900; display: flex; align-items: center; justify-content: center; }
.add-player { display: flex; flex-direction: column; gap: 10px; }

.yt-frame { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 12px; background: #000; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--fg-2); }

/* Début / Milieu du morceau (E5) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: none; }
.seg > span { padding: 4px 9px; font-size: 12px; font-weight: 600; color: var(--fg-2); cursor: pointer; user-select: none; }
.seg > span.on { background: var(--accent); color: #1a0a12; }
