:root {
  --bg: #0b0b12;
  --panel: #161622;
  --panel-2: #20202e;
  --line: #2c2c3d;
  --text: #f4f4fa;
  --muted: #9a9ab0;
  --accent: #ff2d55;
  --danger: #ff5a5a;
  --radius: 18px;

  --rouge: #ff2d46;
  --bleu: #2f7bff;
  --vert: #22e06b;
  --jaune: #ffd60a;
  --violet: #b14dff;
  --orange: #ff8a00;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { touch-action: manipulation; }

[hidden] { display: none !important; }

.view { display: none; min-height: 100dvh; }
.view.active { display: block; }

.wrap {
  max-width: 440px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.wrap.center { text-align: center; align-items: stretch; justify-content: center; min-height: 100dvh; }

h1 { font-size: 44px; margin: 0; letter-spacing: -1px; }
h2 { font-size: 28px; margin: 4px 0 4px; }
h3 { margin: 0; }
.muted { color: var(--muted); margin: 0; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.center-text { text-align: center; }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.logo {
  width: 120px; height: 120px; margin: 0 auto 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff7a8e, var(--accent) 55%, #a80022);
  box-shadow: 0 14px 0 #6d0016, 0 24px 60px rgba(255, 45, 85, .45);
  display: grid; place-items: center;
}
.logo span { width: 46px; height: 18px; border-radius: 50%; background: rgba(255,255,255,.35); transform: translate(-14px, -22px) rotate(-20deg); }

/* ---------- Boutons */
.btn {
  appearance: none; border: 0; cursor: pointer;
  font: inherit; font-weight: 700;
  padding: 14px 18px; border-radius: 14px;
  color: var(--text); background: var(--panel-2);
}
.btn.big { padding: 18px; font-size: 19px; }
.btn.small { padding: 8px 12px; font-size: 14px; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 6px 0 #8c0020; }
.btn.primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #8c0020; }
.btn.ghost { background: transparent; border: 2px solid var(--line); }
.btn.link { background: none; color: var(--muted); text-decoration: underline; padding: 8px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .4; cursor: default; }
.btn kbd { font: 12px/1 inherit; opacity: .7; border: 1px solid rgba(255,255,255,.5); border-radius: 5px; padding: 2px 5px; margin-left: 6px; vertical-align: middle; }

.back { align-self: flex-start; background: none; border: 0; color: var(--muted); font: inherit; padding: 4px 0; cursor: pointer; }

/* ---------- Formulaires */
label, .label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; color: var(--muted); font-size: 14px; }
input:not([type=checkbox]) {
  font: inherit; font-size: 24px; font-weight: 700; letter-spacing: 2px;
  padding: 14px 16px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--panel); color: var(--text);
  outline: none;
}
#player-name { letter-spacing: 0; font-size: 20px; }
input:focus { border-color: var(--accent); }

.seg { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.seg button {
  font: inherit; font-size: 20px; font-weight: 800; padding: 14px 0;
  border-radius: 12px; border: 2px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
}
.seg button.on { background: var(--accent); border-color: var(--accent); }

.color-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.color-swatch {
  aspect-ratio: 1; border-radius: 50%; border: 4px solid transparent; cursor: pointer;
  background: var(--c); box-shadow: inset 0 -8px 0 rgba(0,0,0,.25);
  display: grid; place-items: center; color: rgba(0,0,0,.65); font-weight: 800; font-size: 13px;
  padding: 6px; text-align: center; overflow: hidden;
}
.color-swatch.on { border-color: #fff; transform: scale(1.06); box-shadow: 0 0 28px var(--c); }
.color-swatch.taken {
  cursor: not-allowed; color: rgba(255,255,255,.75);
  background: color-mix(in srgb, var(--c) 18%, #111); box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--c) 45%, transparent);
}

/* ---------- Buzzer (joueur) */
.buzzer-view {
  --c: var(--rouge);
  position: fixed; inset: 0;
  min-height: 0; overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  background: radial-gradient(circle at 50% 45%, color-mix(in srgb, var(--c) 35%, #000), #050508 75%);
  transition: background .25s, filter .25s;
}
.buzzer-view.active { display: flex; flex-direction: column; }

.buzz-top {
  position: relative; z-index: 2;
  display: flex; gap: 8px; align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 16px 0;
}
.pill {
  font: inherit; font-size: 13px; font-weight: 700;
  background: rgba(0,0,0,.45); color: #fff; border: 0; border-radius: 99px; padding: 6px 12px;
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pill.quit { margin-left: auto; cursor: pointer; }

.buzz-zone {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px;
  touch-action: none; cursor: pointer;
  padding: 0 16px max(24px, env(safe-area-inset-bottom));
}
.buzz-button {
  width: min(72vw, 52vh, 380px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, color-mix(in srgb, var(--c) 55%, #fff), var(--c) 55%, color-mix(in srgb, var(--c) 60%, #000));
  box-shadow: 0 18px 0 color-mix(in srgb, var(--c) 45%, #000), 0 30px 80px color-mix(in srgb, var(--c) 55%, transparent);
  display: grid; place-items: center;
  transition: transform .08s, box-shadow .08s, opacity .25s;
}
.buzz-button span { font-size: clamp(40px, 13vw, 72px); font-weight: 900; color: rgba(255,255,255,.92); text-shadow: 0 3px 0 rgba(0,0,0,.25); letter-spacing: 2px; }
.buzz-status { margin: 0; font-size: 20px; font-weight: 700; text-align: center; color: rgba(255,255,255,.85); }

/* Appuyé / envoyé, en attente de l'arbitrage */
.buzzer-view[data-state=sent] .buzz-button { transform: translateY(14px); box-shadow: 0 4px 0 color-mix(in srgb, var(--c) 45%, #000), 0 10px 40px color-mix(in srgb, var(--c) 40%, transparent); }

/* GAGNÉ : tout l'écran s'illumine dans la couleur du joueur */
.buzzer-view::after {
  content: ''; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 3;
}
.buzzer-view[data-state=win] {
  background: var(--c);
  animation: winglow 1.4s ease-in-out 1.4s infinite alternate;
}
.buzzer-view[data-state=win]::after { animation: winflash .45s ease-out 3; }
.buzzer-view[data-state=win] .buzz-button {
  background: radial-gradient(circle, #fff, color-mix(in srgb, var(--c) 40%, #fff) 60%, var(--c));
  box-shadow: none;
  transform: scale(1.08);
}
.buzzer-view[data-state=win] .buzz-zone { background: radial-gradient(circle at 50% 47%, rgba(255,255,255,.85), rgba(255,255,255,0) 62%); }
.buzzer-view[data-state=win] .buzz-button span { color: var(--c); text-shadow: none; }
.buzzer-view[data-state=win] .buzz-status { color: #000; font-size: 26px; font-weight: 900; }
.buzzer-view[data-state=win] .pill { background: rgba(0,0,0,.25); }
@keyframes winflash { 0% { opacity: .9; } 100% { opacity: 0; } }
@keyframes winglow { from { background: var(--c); } to { background: color-mix(in srgb, var(--c) 72%, #fff); } }

/* PERDU : l'écran baisse drastiquement sa luminosité */
.buzzer-view[data-state=lose] { background: #000; }
.buzzer-view[data-state=lose] .buzz-zone,
.buzzer-view[data-state=lose] .buzz-top { filter: brightness(.18) saturate(.5); }
.buzzer-view[data-state=lose] .buzz-button { transform: scale(.85); box-shadow: none; }

/* En pause */
.buzzer-view[data-state=locked] { background: #0a0a0f; }
.buzzer-view[data-state=locked] .buzz-button { filter: grayscale(1) brightness(.45); box-shadow: none; }
.buzzer-view[data-state=locked] .buzz-status { color: var(--muted); }

/* ---------- Animateur */
.admin-view { padding: max(16px, env(safe-area-inset-top)) 16px 32px; max-width: 1100px; margin: 0 auto; }
.admin-view.active { display: flex; flex-direction: column; gap: 16px; }
.admin-head { display: flex; gap: 24px; align-items: flex-end; flex-wrap: wrap; }
.admin-head-actions { margin-left: auto; display: flex; gap: 8px; }
.kicker { font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); font-weight: 700; }
.code-big { font-size: 40px; font-weight: 900; letter-spacing: 4px; line-height: 1; font-variant-numeric: tabular-nums; }

.stage {
  --c: var(--panel);
  border-radius: 24px; min-height: 42vh;
  background: var(--panel); border: 2px solid var(--line);
  display: grid; place-items: center; text-align: center; padding: 24px 16px;
  transition: background .2s;
}
.stage-kicker { font-size: 16px; font-weight: 800; letter-spacing: 3px; text-transform: uppercase; color: var(--muted); }
.stage-title { font-size: clamp(36px, 9vw, 96px); font-weight: 900; line-height: 1.05; margin-top: 8px; word-break: break-word; }
.stage-order { list-style: none; padding: 0; margin: 20px 0 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.stage-order li { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.35); color: #fff; padding: 6px 12px 6px 6px; border-radius: 99px; font-weight: 700; font-size: 15px; }
.stage-order .dot { width: 22px; height: 22px; border-radius: 50%; background: var(--c); border: 2px solid rgba(255,255,255,.8); }
.stage-order .rank { opacity: .7; }

.stage[data-state=open] .stage-title { animation: pulse 1.4s ease-in-out infinite; }
.stage[data-state=buzzed] { background: var(--c); border-color: var(--c); box-shadow: 0 0 80px color-mix(in srgb, var(--c) 60%, transparent); animation: stageflash .45s ease-out 2; }
.stage[data-state=buzzed] .stage-kicker { color: rgba(0,0,0,.6); }
.stage[data-state=buzzed] .stage-title { color: #000; }
.stage[data-state=locked] .stage-title { color: var(--muted); }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes stageflash { 0% { filter: brightness(2); } 100% { filter: brightness(1); } }

.admin-controls { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }

.players-title { color: var(--muted); font-size: 15px; text-transform: uppercase; letter-spacing: 2px; }
.players-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.player-card {
  --c: var(--line);
  border-radius: 16px; padding: 14px; background: var(--panel);
  border: 2px solid var(--line); display: flex; align-items: center; gap: 12px; position: relative;
}
.player-card .dot { width: 34px; height: 34px; border-radius: 50%; background: var(--c); flex: none; box-shadow: 0 0 14px color-mix(in srgb, var(--c) 60%, transparent); }
.player-card .name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-card .sub { font-size: 13px; color: var(--muted); }
.player-card .sub.on { color: #4ee38a; }
.player-card .sub.off { color: var(--danger); }
.player-card.empty { border-style: dashed; color: var(--muted); justify-content: center; min-height: 66px; }
.player-card.first { border-color: var(--c); box-shadow: 0 0 24px color-mix(in srgb, var(--c) 55%, transparent); }
.player-card .kick { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; padding: 4px 6px; }
.player-card .info { min-width: 0; }

.admin-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.check { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Plein écran : la scène prend toute la place */
.admin-view.fullstage .stage { min-height: 70vh; }
.admin-view.fullstage .stage-title { font-size: clamp(48px, 12vw, 160px); }

/* ---------- Divers */
.dialog {
  border: 2px solid var(--line); border-radius: 22px; background: var(--panel); color: var(--text);
  padding: 22px; width: min(92vw, 380px);
}
.dialog::backdrop { background: rgba(0,0,0,.7); }
.dialog h3 { text-align: center; margin-bottom: 12px; }
.qr { background: #fff; border-radius: 14px; padding: 12px; margin: 0 auto 14px; width: fit-content; }
.qr img, .qr svg { display: block; width: 240px; height: 240px; }

.net {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 50;
  background: #3a2a00; color: #ffd60a; font-weight: 700; font-size: 13px; padding: 6px 14px; border-radius: 99px;
}
.toast {
  position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 50;
  background: #fff; color: #000; font-weight: 700; padding: 12px 18px; border-radius: 14px; max-width: calc(100vw - 32px);
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

@media (max-width: 560px) {
  .code-big { font-size: 30px; }
  .admin-head { gap: 16px; }
  .admin-head-actions { margin-left: 0; width: 100%; }
  .admin-head-actions .btn { flex: 1; }
  .admin-controls { grid-template-columns: 1fr; }
  .btn kbd { display: none; }
  .stage { min-height: 36vh; }
}
