:root {
  --bg: #14161c; --panel: #1d2029; --panel-2: #262a35; --line: #333847; --text: #eef0f5; --muted: #9aa1b2;
  --accent: #ff4d4d; --accent-2: #ffcb05; --ok: #4cd182; --warn: #ffb547; --error: #ff6b6b;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
code, kbd { font: 0.9em ui-monospace, Consolas, monospace; background: var(--panel-2); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 12px; max-width: 1200px; margin: 0 auto; padding: 14px 0 6px; }
.top h1 { margin: 0; font-size: 22px; letter-spacing: 0.5px; }
.top h1 span { color: var(--accent-2); }
.chip { margin-left: auto; background: var(--panel-2); color: var(--muted); padding: 3px 10px; border-radius: 99px; font-size: 13px; }

.status { max-width: 1200px; margin: 4px auto 10px; min-height: 1.4em; color: var(--muted); }
.status[data-kind="error"], .error { color: var(--error); }
[data-kind="ok"] { color: var(--ok); }
[data-kind="warn"] { color: var(--warn); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.layout { max-width: 1280px; margin: 0 auto; display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 1000px) { .layout:has(.side:not([hidden])) { grid-template-columns: minmax(0, 1fr) 360px; } }
.main-col { min-width: 0; }
.narrow { max-width: 560px; margin: 0 auto; width: 100%; }

.race-info { display: flex; align-items: center; gap: 8px; min-width: 0; }
.race-info b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#race-status[data-status="en-cours"] { background: #1f4d33; color: var(--ok); }
#race-status[data-status="pause"], #race-status[data-status="attente"] { background: #4d3a1a; color: var(--warn); }
.net { margin-left: 0; }
.net[data-on="true"] { color: var(--ok); }
@media (max-width: 640px) { .top { flex-wrap: wrap; } .race-info { order: 5; width: 100%; } }

.form { display: grid; gap: 12px; margin-top: 12px; }
.form label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.form input { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.form input:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
#join-code { text-transform: uppercase; letter-spacing: 3px; font-family: ui-monospace, Consolas, monospace; }
.link { background: none; color: var(--accent-2); padding: 0; text-decoration: underline; font-size: inherit; }

/* ---------- Panneau de la course ---------- */
.side { padding: 0; overflow: hidden; }
.side > section { padding: 12px 16px; max-height: min(70vh, 640px); overflow-y: auto; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; background: none; padding: 12px 6px; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.me-line { padding: 8px 16px 12px; margin: 0; border-top: 1px solid var(--line); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.feed { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.feed li { display: grid; grid-template-columns: 22px 1fr; gap: 0 8px; padding: 8px 4px; border-bottom: 1px solid #ffffff0d; font-size: 14px; }
.feed li.imp .txt { font-weight: 600; }
.feed .ico { grid-row: span 2; }
.feed time { grid-column: 2; font-size: 12px; color: var(--muted); }
.ranking { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; }
.ranking li { display: grid; grid-template-columns: 26px 1fr auto auto; gap: 10px; align-items: center; background: var(--panel-2); border-radius: 10px; padding: 9px 12px; }
.ranking li.me { outline: 1px solid var(--accent-2); }
.ranking .rank { color: var(--accent-2); }
.ranking .pts { min-width: 64px; text-align: right; }
.players { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.players li { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; }
.players .head { display: flex; align-items: center; gap: 4px; }
.players .head .muted { margin-left: auto; }
.mons { display: flex; flex-wrap: wrap; gap: 4px; }
.mons span { background: #0004; border-radius: 6px; padding: 2px 6px; font-size: 12px; }
.mons span.ko { opacity: 0.45; text-decoration: line-through; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; max-width: min(92vw, 520px);
  background: var(--accent-2); color: #000; font-weight: 700; padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 30px #000a; transition: opacity .6s, transform .6s; }
.toast.out { opacity: 0; transform: translate(-50%, 12px); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card h2 { margin: 0 0 8px; font-size: 18px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.rom { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--panel-2); border-radius: 10px; padding: 10px 12px; margin-top: 12px; }
.primary, .ghost { padding: 10px 16px; border-radius: 10px; font-weight: 600; }
.primary { background: var(--accent); color: #fff; }
.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.ghost { background: var(--panel-2); border: 1px solid var(--line); }
.ghost:hover { border-color: var(--muted); }
.help { margin-top: 16px; color: var(--muted); }
.help table { border-collapse: collapse; margin-top: 8px; }
.help th { text-align: left; padding: 4px 12px 4px 0; color: var(--text); vertical-align: top; }

/* ---------- Écran du jeu ---------- */
.game { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.screen-wrap { position: relative; width: 100%; max-width: 960px; aspect-ratio: 3 / 2; background: #000; border-radius: 10px; overflow: hidden; box-shadow: 0 8px 30px #0008; }
#screen { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.paused { position: absolute; inset: 0; display: grid; place-items: center; background: #000b; text-align: center; padding: 16px; }
.paused p { font-size: 20px; font-weight: 700; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.toolbar .ghost { padding: 8px 12px; font-size: 14px; }
.vol { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; }

/* ---------- Boutons tactiles (téléphones et tablettes) ---------- */
.pad { display: none; width: 100%; max-width: 520px; user-select: none; -webkit-user-select: none; touch-action: none;
  grid-template-areas: "sh sh" "dpad ab" "sys sys"; grid-template-columns: 1fr 1fr; gap: 14px 8px; }
@media (pointer: coarse) { .pad { display: grid; } }
.pad button { background: var(--panel-2); border: 1px solid var(--line); touch-action: none; -webkit-tap-highlight-color: transparent; }
.pad button.down { background: var(--accent); border-color: var(--accent); }
.shoulders { grid-area: sh; display: flex; justify-content: space-between; }
.shoulders button { width: 96px; height: 38px; border-radius: 12px 12px 6px 6px; font-weight: 700; }
.dpad { grid-area: dpad; position: relative; width: 150px; height: 150px; justify-self: center; touch-action: none; }
.dpad span { position: absolute; background: var(--panel-2); border: 1px solid var(--line); }
.dpad .u, .dpad .d { left: 50px; width: 50px; height: 52px; }
.dpad .l, .dpad .r { top: 50px; height: 50px; width: 52px; }
.dpad .u { top: 0; border-radius: 8px 8px 0 0; } .dpad .d { bottom: 0; border-radius: 0 0 8px 8px; }
.dpad .l { left: 0; border-radius: 8px 0 0 8px; } .dpad .r { right: 0; border-radius: 0 8px 8px 0; }
.dpad::after { content: ""; position: absolute; left: 50px; top: 50px; width: 50px; height: 50px; background: var(--panel-2); }
.dpad[data-dirs~="Up"] .u, .dpad[data-dirs~="Down"] .d, .dpad[data-dirs~="Left"] .l, .dpad[data-dirs~="Right"] .r { background: var(--accent); border-color: var(--accent); }
.ab { grid-area: ab; position: relative; width: 150px; height: 150px; justify-self: center; }
.ab button { position: absolute; width: 66px; height: 66px; border-radius: 50%; font-size: 20px; font-weight: 800; }
.ab .a { right: 0; top: 20px; } .ab .b { left: 0; bottom: 20px; }
.system { grid-area: sys; display: flex; justify-content: center; gap: 18px; }
.system button { padding: 6px 16px; border-radius: 99px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }

/* Plein écran : l'écran en haut, les boutons en dessous. */
.game:fullscreen { background: var(--bg); justify-content: space-between; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.game:fullscreen .toolbar { display: none; }
.game:fullscreen .screen-wrap { border-radius: 0; max-height: 60dvh; width: auto; max-width: 100%; }

/* ---------- Page organisateur ---------- */
.admin { max-width: 900px; margin: 0 auto; display: grid; gap: 16px; }
.admin #panel { display: grid; gap: 16px; }
.form.inline { grid-template-columns: 1fr auto auto; align-items: end; }
@media (max-width: 560px) { .form.inline { grid-template-columns: 1fr; } }
.form select, .sel select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; }
.sel { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px; }
.race header { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.race h3 { font-size: 15px; margin: 16px 0 8px; }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: 3px; font-size: 18px; color: var(--accent-2); }
.chip[data-status="en-cours"] { background: #1f4d33; color: var(--ok); }
a.chip { text-decoration: none; margin-left: 0; }
.plist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.plist li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px; background: var(--panel-2); border-radius: 8px; padding: 8px 12px; }
.danger { color: var(--error) !important; }

/* ---------- Panneau de test ---------- */
[data-pane="debug"] dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0; }
[data-pane="debug"] dt { color: var(--muted); }
[data-pane="debug"] dd { margin: 0; }
[data-pane="debug"] h3 { font-size: 15px; margin: 14px 0 6px; }
.badges { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.badge { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; background: var(--panel-2); color: var(--muted); }
.badge.on { background: var(--accent-2); color: #000; font-weight: 700; }
.party { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.party li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.party li.bad { outline: 1px solid var(--error); }
.hp { grid-column: 1; height: 6px; background: #0006; border-radius: 3px; overflow: hidden; align-self: center; }
.hp i { display: block; height: 100%; background: var(--ok); }
