:root {
  --bg: #14102a; --bg2: #1d1740; --card: #231c4a; --line: #3a3170;
  --text: #f4f1ff; --muted: #a9a2cf; --accent: #ffc23d; --accent2: #ff5d8f; --ok: #3ddc97; --bad: #ff5d6c;
  --c0: #e84a6f; --c1: #3b82f6; --c2: #f0a92b; --c3: #22b07d;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(900px 500px at 15% -10%, #3b1d7a 0%, transparent 60%), radial-gradient(800px 500px at 110% 10%, #1b3d7a 0%, transparent 55%), var(--bg);
  overflow: hidden; height: 100dvh;
}
[hidden] { display: none !important; }
button, input { font-family: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.big { font-size: 20px; font-weight: 800; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.scroll { overflow-y: auto; }
.wrap { width: 100%; max-width: 520px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 90px; display: flex; flex-direction: column; gap: 14px; }
.hero { text-align: center; margin: 6px 0 2px; }
.logo { font-size: 50px; line-height: 1; filter: drop-shadow(0 6px 14px rgba(0,0,0,.4)); }
h1 { margin: 8px 0 4px; font-size: 36px; font-weight: 900; background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { margin: 0; }

.box { background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.boxtitle { font-weight: 800; font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.boxtitle.small { font-size: 14px; margin-top: 14px; color: var(--muted); }
.pill { background: #2f2760; border-radius: 999px; padding: 2px 9px; font-size: 13px; }
.lbl { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 12px 0 6px; }
.lbl:first-child { margin-top: 0; }
input { width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: #120e28; color: var(--text); font-size: 16px; padding: 0 14px; outline: none; }
input:focus { border-color: var(--accent); }
.code-in { text-transform: uppercase; letter-spacing: 6px; font-weight: 900; text-align: center; flex: 1; }
.check { display: flex; gap: 10px; align-items: center; margin: 14px 0 4px; font-size: 15px; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex: none; }
.err { color: var(--bad); font-weight: 700; min-height: 1em; margin: 8px 0 0; text-align: center; }

.btn { min-height: 46px; padding: 0 14px; border: 0; border-radius: 12px; font-weight: 800; font-size: 15px; cursor: pointer; color: var(--text); background: #2f2760; box-shadow: 0 3px 0 #1a1540; white-space: nowrap; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #1a1540; }
.btn.main { color: #1b1300; background: linear-gradient(180deg, #ffd56b, var(--accent)); box-shadow: 0 3px 0 #b27d00; }
.btn.red { color: #fff; background: linear-gradient(180deg, #ff6b8f, #e0456b); box-shadow: 0 3px 0 #8f2440; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn:disabled { opacity: .45; }
.btn.wide { width: 100%; margin-top: 10px; }
.big-btn { min-height: 58px; font-size: 19px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }
.iconbtn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: #2a2257; color: var(--text); font-size: 18px; cursor: pointer; flex: none; }

.seg { display: flex; gap: 6px; background: #120e28; padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 800; font-size: 14px; cursor: pointer; }
.seg button.sel { background: linear-gradient(180deg, #ffd56b, var(--accent)); color: #1b1300; }
.seg.locked button { cursor: default; }
.seg.locked button:not(.sel) { opacity: .5; }

.avatars { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.avatars button { height: 44px; font-size: 24px; border-radius: 12px; border: 2px solid transparent; background: #120e28; cursor: pointer; }
.avatars button.sel { border-color: var(--accent); background: #2f2760; }
.avatars button:disabled { opacity: .25; }

/* salon */
.code { font-size: 52px; font-weight: 900; letter-spacing: 10px; margin: 2px 0 12px; color: var(--accent); }
.plist { display: flex; flex-direction: column; gap: 6px; }
.pl { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: #1a1538; border-left: 4px solid var(--c, #888); }
.pl .av { font-size: 26px; width: 34px; text-align: center; }
.pl .nm { font-weight: 800; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl .tag { font-size: 12px; color: var(--muted); }
.pl.off { opacity: .45; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 2px; }

/* jeu */
#game { background: #0b0820; }
.topbar { display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 10px 8px; background: linear-gradient(180deg, #1d1740, #16112f); border-bottom: 1px solid var(--line); flex: none; }
.qnum { font-weight: 900; font-size: 14px; background: #2f2760; border-radius: 9px; padding: 6px 9px; white-space: nowrap; }
.turn { flex: 1; min-width: 0; font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn small { color: var(--muted); font-weight: 700; }
.timer { height: 5px; background: #120e28; flex: none; }
.timer div { height: 100%; width: 0; background: linear-gradient(90deg, var(--ok), var(--accent), var(--bad)); background-size: 300% 100%; border-radius: 0 3px 3px 0; }
.strip { display: flex; gap: 6px; padding: 6px 8px; overflow-x: auto; flex: none; background: #120e28; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.chip { display: flex; align-items: center; gap: 5px; padding: 4px 9px 4px 6px; border-radius: 999px; background: #221b48; border: 2px solid transparent; flex: none; font-size: 14px; }
.chip .av { font-size: 18px; }
.chip .sc { font-weight: 900; color: var(--accent); }
.chip .nm { font-weight: 700; max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .dots { display: flex; gap: 2px; }
.chip .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); display: block; }
.chip.cur { border-color: var(--c); background: #2f2760; }
.chip.off { opacity: .5; }
.chip.team { padding: 5px 12px; font-size: 15px; }
.chip.team .sc { font-size: 18px; }
.stage { flex: 1; position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.spect-badge { position: absolute; left: 10px; top: 10px; font-size: 13px; font-weight: 800; background: rgba(20,16,42,.8); color: var(--muted); padding: 4px 12px; border-radius: 999px; z-index: 3; }
.banner { position: absolute; left: 50%; top: 21%; transform: translate(-50%, -50%); width: min(92%, 460px); text-align: center; z-index: 4; pointer-events: none;
  background: rgba(20,16,42,.88); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; font-size: 20px; font-weight: 900; box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: popc .3s ease; }
.banner small { display: block; margin-top: 4px; font-size: 14px; color: var(--muted); font-weight: 700; }
.banner.big { font-size: 30px; }
@keyframes popc { from { transform: translate(-50%, -50%) scale(.8); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
.endbox { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); width: min(92%, 440px); max-height: 54%; overflow-y: auto; z-index: 5; background: rgba(20,16,42,.94); border: 1px solid var(--line); border-radius: 18px; padding: 14px; box-shadow: 0 14px 40px rgba(0,0,0,.5); animation: popd .3s ease; }
@keyframes popd { from { transform: translateX(-50%) scale(.85); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
.endbox h3 { margin: 0 0 4px; text-align: center; font-size: 22px; }
.endbox .sub { text-align: center; color: var(--muted); margin-bottom: 10px; font-size: 14px; }
.br { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: #1a1538; margin-bottom: 5px; border-left: 5px solid var(--c, #888); }
.br .rk { width: 22px; font-weight: 900; color: var(--muted); text-align: center; }
.br .av { font-size: 22px; }
.br .nm { flex: 1; font-weight: 800; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.br .gain { color: var(--ok); font-weight: 900; font-size: 15px; }
.br .gain.z { color: var(--muted); font-weight: 700; }
.br .sc { font-weight: 900; color: var(--accent); min-width: 34px; text-align: right; }
.br.me { background: #2b2360; }
.teamscore { display: flex; justify-content: center; gap: 18px; font-size: 34px; font-weight: 900; margin: 6px 0; }
.hostbar { position: absolute; left: 0; right: 76px; bottom: 0; padding: 10px 14px max(10px, env(safe-area-inset-bottom)); display: flex; z-index: 6; pointer-events: none; }
.hostbar .btn { flex: 0 1 auto; pointer-events: auto; }
#game .hostbar { bottom: 0; }

/* salon : équipes, robots, règles */
.pl .team { font-size: 16px; }
.pl .kick { border: 0; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; padding: 0 4px; }
.pl .tsw { border: 0; background: #2f2760; color: var(--text); border-radius: 8px; font-size: 14px; padding: 4px 6px; cursor: pointer; }
.teampick { margin-top: 10px; }
.teampick .btn.sel { outline: 3px solid var(--accent); outline-offset: -3px; }
.botbox { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.botbox .btn { flex: 1 1 auto; }
.small-seg { flex: 1 1 200px; }
.small-seg button { min-height: 36px; font-size: 13px; }
.rules summary { font-weight: 800; cursor: pointer; }
.rules ul, .rules-sheet ul { margin: 10px 0 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.rules li, .rules-sheet li { margin-bottom: 6px; }
.rules b, .rules-sheet b { color: var(--text); }
.rules-sheet { max-height: 80dvh; overflow-y: auto; }
.seg button { white-space: normal; line-height: 1.15; padding: 4px; }

/* fin */
.endtitle { font-size: 28px; margin: 6px 0 0; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; min-height: 200px; }
.pod { flex: 1; max-width: 140px; text-align: center; }
.pod .av { font-size: 40px; }
.pod .nm { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pod .sc { color: var(--accent); font-weight: 900; }
.pod .step { margin-top: 6px; border-radius: 12px 12px 0 0; font-size: 28px; font-weight: 900; display: flex; align-items: flex-start; justify-content: center; padding-top: 8px; }
.pod.p1 .step { height: 110px; background: linear-gradient(180deg, #ffd56b, #c99112); color: #3b2a00; }
.pod.p2 .step { height: 80px; background: linear-gradient(180deg, #e3e6f0, #9aa0b5); color: #2a2d3a; }
.pod.p3 .step { height: 60px; background: linear-gradient(180deg, #f0b27a, #a8642c); color: #3a1f08; }
.er { display: flex; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.er:last-child { border-bottom: 0; }
.er .rk { font-weight: 900; width: 28px; color: var(--muted); padding-top: 3px; }
.er .av { font-size: 26px; }
.er .info { flex: 1; min-width: 0; }
.er .nm { font-weight: 800; }
.er .cm { color: var(--muted); font-size: 14px; margin-top: 2px; }
.er .sc { font-weight: 900; color: var(--accent); }
.er .st { font-size: 12px; color: var(--muted); }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i { position: absolute; top: -20px; width: 9px; height: 14px; border-radius: 2px; animation: fall 3.2s linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* menu */
.sheet-bg { position: fixed; inset: 0; background: rgba(5,3,15,.6); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; background: var(--bg2); border-radius: 20px 20px 0 0; padding: 12px 16px max(16px, env(safe-area-inset-bottom)); border: 1px solid var(--line); }

/* chat */
.chat-btn { position: fixed; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 15; width: 54px; height: 54px; border-radius: 50%; border: 1px solid var(--line); background: #2f2760; font-size: 24px; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.4); }
.chat-badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent2); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }
.chat-feed { position: fixed; right: 14px; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 64px); z-index: 14; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; max-width: 75vw; }
.chat-feed > div { background: rgba(20,16,42,.92); border: 1px solid var(--line); border-radius: 14px; padding: 6px 10px; animation: pop .25s ease; }
.chat-feed .gif { max-height: 90px; }
.chat-feed .mini .gif { max-height: 44px; }
.chat-panel { position: fixed; z-index: 25; left: 0; right: 0; bottom: 0; height: min(72dvh, 560px); max-width: 520px; margin: 0 auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 20px 20px 0 0; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -10px 40px rgba(0,0,0,.5); }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: 15px; line-height: 1.35; word-wrap: break-word; }
.msg b { margin-right: 6px; }
.msg .gif { display: block; max-width: 200px; max-height: 160px; border-radius: 10px; margin-top: 4px; }
.emojis { display: flex; gap: 4px; padding: 6px 10px; overflow-x: auto; border-top: 1px solid var(--line); }
.emojis button { font-size: 22px; background: #120e28; border: 0; border-radius: 10px; min-width: 42px; height: 40px; cursor: pointer; }
.emojis .gif-btn { font-size: 13px; font-weight: 900; color: var(--accent); }
.chat-form { display: flex; gap: 6px; padding: 8px 10px; }
.chat-form input { flex: 1; }
.gif-picker { border-top: 1px solid var(--line); padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; max-height: 46%; }
.gif-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; overflow-y: auto; }
.gif-grid button { padding: 0; border: 0; background: #120e28; border-radius: 8px; overflow: hidden; height: 80px; cursor: pointer; }
.gif-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gif-grid .hint { grid-column: 1 / -1; }
.gif-credit { font-size: 11px; color: var(--muted); text-align: right; }
.hint { color: var(--muted); font-size: 14px; }

.toast { position: fixed; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translate(-50%, -250%); visibility: hidden; background: #2f2760; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-weight: 700; z-index: 40; transition: transform .25s; max-width: 90vw; text-align: center; }
.toast.on { transform: translate(-50%, 0); visibility: visible; }
.conn { position: fixed; left: 0; right: 0; top: 0; background: var(--bad); color: #fff; text-align: center; font-weight: 800; padding: 6px; z-index: 50; font-size: 14px; }

/* ---- Auto-tamponneuses ---------------------------------------------------- */
#game { background: #090616; }
.feed { position: absolute; left: 8px; top: 8px; right: 70px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; z-index: 3; }
.feed div { align-self: flex-start; max-width: 100%; font-size: 13px; font-weight: 800; background: rgba(15,11,34,.82); border: 1px solid var(--line); border-radius: 10px; padding: 4px 9px; animation: feedin .25s ease-out, feedout .5s ease-in 3.4s forwards; }
.feed div.me { border-color: var(--accent); }
@keyframes feedin { from { transform: translateX(-20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes feedout { to { opacity: 0; transform: translateY(-4px); } }
.spect-badge { top: auto !important; bottom: 12px; }
.count { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); font-size: 96px; font-weight: 900; color: #fff; pointer-events: none; z-index: 4;
  text-shadow: 0 6px 0 #b8325a, 0 10px 30px rgba(0,0,0,.6); animation: countpop .9s ease-out both; white-space: nowrap; }
.count.go { color: var(--accent); font-size: 64px; text-shadow: 0 5px 0 #a8580f, 0 10px 30px rgba(0,0,0,.6); }
@keyframes countpop { 0% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1); opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%) scale(.9); } }
.drivehint { position: absolute; left: 12px; right: 120px; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 58px); font-size: 14px; font-weight: 800; text-align: center; color: #fff;
  background: rgba(15,11,34,.8); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; pointer-events: none; z-index: 3; animation: pulse 1.6s ease-in-out infinite; }
body.lefty .drivehint { left: 120px; right: 12px; }
@keyframes pulse { 50% { opacity: .55; } }
.turbo { position: absolute; right: 16px; bottom: max(18px, env(safe-area-inset-bottom)); width: 96px; height: 96px; border-radius: 50%; border: 0; z-index: 4;
  color: #2b1600; font-weight: 900; display: flex; flex-direction: column; align-items: center; justify-content: center; touch-action: none; user-select: none; -webkit-user-select: none;
  background: radial-gradient(circle at 50% 35%, #fff3b0, #ffc23d 55%, #ff8a3d); box-shadow: 0 6px 0 #a8580f, 0 0 0 6px rgba(255,194,61,.25), 0 10px 30px rgba(0,0,0,.5); }
body.lefty .turbo { right: auto; left: 16px; }
.turbo span { font-size: 38px; line-height: 1; }
.turbo small { font-size: 12px; letter-spacing: 1px; }
.turbo:active, .turbo.on { transform: translateY(4px); box-shadow: 0 2px 0 #a8580f, 0 0 0 10px rgba(255,194,61,.35); }
.turbo.wait { background: conic-gradient(#ffc23d calc(var(--p, 0) * 1turn), #3a3170 0); color: #cfc8ff; box-shadow: 0 6px 0 #1a1540, 0 10px 30px rgba(0,0,0,.5); }
.turbo.wait span { filter: grayscale(1); opacity: .7; }
.chat-btn.ingame { bottom: auto; width: 44px; height: 44px; font-size: 20px; }
.chip.out { opacity: .4; text-decoration: line-through; }
.chip .x { font-size: 13px; }
