:root {
  --bg: #0b0d17;
  --panel: #1d2133;
  --panel2: #2a3048;
  --line: #000;
  --txt: #fff;
  --red: #ff3b3b;
  --blue: #2fa8ff;
  --green: #3ddc6a;
  --yellow: #ffd23f;
  --font: "Trebuchet MS", "Arial Rounded MT Bold", "Segoe UI", system-ui, sans-serif;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--txt); font-family: var(--font); overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
input { user-select: text; -webkit-user-select: text; touch-action: auto; }
button { font-family: var(--font); cursor: pointer; }
.hidden { display: none !important; }
#game { position: fixed; inset: 0; display: block; }

/* ---------- boutons ---------- */
.pill { background: #e8ecf5; color: #111; border: 3px solid #000; border-radius: 12px; padding: 8px 14px; font-weight: 800; font-size: 15px; box-shadow: 0 4px 0 #000; }
.pill:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.pill.go, .big.go { background: var(--green); }
.pill.danger { background: #ff6b6b; }
.pill.wide { display: block; width: 100%; margin: 8px 0; }
.pill:disabled { opacity: .45; }
.big { font-size: 26px; font-weight: 900; padding: 12px 30px; border: 4px solid #000; border-radius: 16px; box-shadow: 0 6px 0 #000; color: #111; letter-spacing: 1px; margin-top: 14px; width: 100%; }
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #000; }
.round { width: 48px; height: 48px; border-radius: 50%; border: 3px solid #000; background: #e8ecf5; font-size: 22px; box-shadow: 0 3px 0 #000; position: relative; padding: 0; }
.round.on { background: var(--green); }
.round.off { background: #ff6b6b; }
.badge { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; border: 2px solid #000; line-height: 14px; font-weight: 900; }
.close-x { position: absolute; top: 10px; left: 10px; width: 38px; height: 38px; border-radius: 8px; background: #ff4d4d; color: #fff; border: 3px solid #000; font-size: 20px; font-weight: 900; z-index: 3; }
.panel { background: var(--panel); border: 4px solid #000; border-radius: 18px; box-shadow: 0 8px 0 rgba(0,0,0,.5), inset 0 0 0 3px #3a4262; padding: 18px; position: relative; }

/* ---------- écrans ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 20%, #1c2140 0%, #07080f 70%); z-index: 50; overflow: auto; touch-action: pan-y; }
.stars { position: absolute; inset: 0; background-image: radial-gradient(1.5px 1.5px at 10% 20%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 30% 70%, #fff 50%, transparent 51%), radial-gradient(2px 2px at 70% 30%, #cde 50%, transparent 51%), radial-gradient(1px 1px at 85% 80%, #fff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 55% 55%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 45% 15%, #fff 50%, transparent 51%); background-size: 280px 280px; animation: drift 60s linear infinite; opacity: .7; pointer-events: none; }
@keyframes drift { to { background-position: -560px 280px; } }
.home-inner { position: relative; display: flex; gap: 28px; align-items: center; padding: 20px calc(16px + var(--safe-r)) 20px calc(16px + var(--safe-l)); max-width: 1000px; width: 100%; }
.home-left { flex: 1; text-align: center; }
.home-right { flex: 1.1; max-width: 460px; }
.logo { font-size: clamp(34px, 6.5vw, 72px); margin: 0; font-weight: 900; letter-spacing: 2px; color: #fff; -webkit-text-stroke: 3px #000; paint-order: stroke fill; text-shadow: 0 6px 0 #000; transform: rotate(-3deg); }
.logo span { color: var(--red); }
.tagline { font-size: 18px; opacity: .85; margin-top: 6px; font-style: italic; }
#preview { width: min(260px, 32vh); height: min(260px, 32vh); }
.status { font-weight: 700; font-size: 15px; color: var(--yellow); min-height: 22px; }
.field-label { display: block; font-weight: 800; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; opacity: .8; margin: 10px 0 6px; }
#in-name { width: 100%; font-size: 20px; padding: 10px 12px; border-radius: 10px; border: 3px solid #000; background: #f1f4fb; color: #111; font-weight: 800; font-family: var(--font); }
.grid { display: grid; gap: 6px; }
.grid.faces { grid-template-columns: repeat(9, 1fr); }
.grid.colors { grid-template-columns: repeat(8, 1fr); }
.grid.outfits { grid-template-columns: repeat(3, 1fr); }
.grid .cell.outfit { aspect-ratio: auto; height: 64px; background: #2a3048; display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: 800; font-size: 13px; }
.grid .cell.outfit canvas { width: 48px; height: 48px; }
.grid .cell { aspect-ratio: 1; border-radius: 10px; border: 3px solid #000; background-size: cover; background-position: center; position: relative; }
.grid .cell.sel { outline: 3px solid var(--yellow); outline-offset: 1px; transform: scale(1.08); }
.grid .cell.taken { opacity: .3; pointer-events: none; }
.grid .cell.none { background: linear-gradient(#c9f1fb, #4b7f96); }
.hint { font-size: 12px; opacity: .7; margin-top: 12px; line-height: 1.5; }
.back { display: inline-block; margin-top: 10px; color: #9fb4ff; font-size: 13px; text-decoration: none; }
.wait-panel { text-align: center; max-width: 640px; width: calc(100% - 32px); }
#wait-canvas { width: 100%; height: auto; }
#wait-players { font-size: 14px; opacity: .8; margin: 8px 0 14px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#taskbar { position: absolute; top: calc(8px + var(--safe-t)); left: calc(10px + var(--safe-l)); width: min(420px, 46vw); pointer-events: none; }
.tb-label { position: absolute; left: 10px; top: 4px; font-size: 11px; font-weight: 900; z-index: 1; -webkit-text-stroke: 2px #000; paint-order: stroke fill; letter-spacing: .5px; }
.tb-bar { height: 24px; background: #3d4250; border: 3px solid #000; border-radius: 4px; overflow: hidden; }
.tb-fill { height: 100%; width: 0; background: linear-gradient(#5be36f, #2ea84a); transition: width .6s; }
#tasklist { position: absolute; top: calc(42px + var(--safe-t)); left: calc(10px + var(--safe-l)); background: rgba(40,44,60,.82); border: 2px solid rgba(0,0,0,.6); border-radius: 6px; padding: 7px 10px; font-size: 13px; line-height: 1.45; max-width: min(340px, 40vw); max-height: 45vh; overflow: auto; pointer-events: auto; }
#tasklist.collapsed .tl-items { display: none; }
#tasklist .tl-head { font-weight: 900; font-size: 12px; opacity: .85; cursor: pointer; }
#tasklist .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tasklist .t.done { color: var(--green); }
#tasklist .t.part { color: var(--yellow); }
#tasklist .t.imp { color: #ff8080; }
#tasklist .t.sab { color: var(--red); font-weight: 800; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .4; } }
#sabo-banner { position: absolute; top: calc(52px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: rgba(160,0,0,.85); border: 3px solid #000; border-radius: 10px; padding: 6px 16px; font-weight: 900; font-size: 18px; animation: blink 1s infinite; pointer-events: none; white-space: nowrap; }
#room-label { position: absolute; bottom: calc(12px + var(--safe-b)); left: 50%; transform: translateX(-50%); font-weight: 900; font-size: 15px; opacity: .85; -webkit-text-stroke: 3px #000; paint-order: stroke fill; pointer-events: none; white-space: nowrap; }
#topright { position: absolute; top: calc(8px + var(--safe-t)); right: calc(10px + var(--safe-r)); display: flex; gap: 8px; }
#lobby-bar { position: absolute; bottom: calc(14px + var(--safe-b)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; }
#lobby-info { font-weight: 900; font-size: 18px; -webkit-text-stroke: 3px #000; paint-order: stroke fill; text-align: center; }
#lobby-host { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#lobby-wait { font-weight: 800; opacity: .8; -webkit-text-stroke: 2px #000; paint-order: stroke fill; }
#btn-start { font-size: 18px; padding: 8px 22px; }

#actions { position: absolute; right: calc(12px + var(--safe-r)); bottom: calc(12px + var(--safe-b)); display: grid; grid-template-columns: repeat(3, auto); gap: 10px; direction: rtl; }
.act { direction: ltr; width: 86px; height: 86px; border-radius: 18px; border: 3px solid rgba(0,0,0,.8); background: rgba(235,240,250,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative; color: #111; box-shadow: 0 4px 0 rgba(0,0,0,.6); padding: 0; }
.act .ico { font-size: 34px; line-height: 1; filter: drop-shadow(0 2px 0 rgba(0,0,0,.3)); }
.act .lbl { font-size: 11px; font-weight: 900; letter-spacing: .5px; }
.act .cd { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 900; color: #fff; -webkit-text-stroke: 3px #000; paint-order: stroke fill; }
.act.disabled { opacity: .35; filter: grayscale(1); }
.act:not(.disabled):active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.6); }
.act[data-act="kill"] { background: rgba(255,120,120,.95); }
.act[data-act="report"] { background: rgba(255,210,90,.95); }
.act[data-act="sabotage"], .act[data-act="vent"] { background: rgba(255,150,150,.9); }
#vent-arrows { position: absolute; inset: 0; pointer-events: none; }
#vent-arrows button { position: absolute; pointer-events: auto; width: 64px; height: 64px; border-radius: 50%; border: 3px solid #000; background: #ffcc00; font-size: 30px; font-weight: 900; transform: translate(-50%, -50%); box-shadow: 0 3px 0 #000; }
#joystick { position: absolute; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,.12); border: 3px solid rgba(255,255,255,.35); pointer-events: none; transform: translate(-50%, -50%); }
#joystick .knob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px; border-radius: 50%; background: rgba(255,255,255,.55); border: 3px solid rgba(0,0,0,.4); }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; }
.overlay > canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#ov-intro { background: #000; z-index: 40; }
.intro-text { position: relative; text-align: center; pointer-events: none; }
#ov-kill { background: rgba(0,0,0,.35); z-index: 45; }
#ov-splash { background: rgba(0,0,0,.55); z-index: 41; }
.splash-inner { text-align: center; animation: zoomin .35s cubic-bezier(.2,1.6,.4,1); }
.splash-inner .big-txt { font-size: clamp(36px, 8vw, 84px); font-weight: 900; -webkit-text-stroke: 4px #000; paint-order: stroke fill; color: #fff; text-shadow: 0 6px 0 #000; transform: rotate(-3deg); }
.splash-inner canvas { width: 220px; height: 220px; }
@keyframes zoomin { from { transform: scale(.2); opacity: 0; } }

#ov-meeting { background: rgba(0,0,0,.6); z-index: 35; padding: 8px calc(8px + var(--safe-r)) 8px calc(8px + var(--safe-l)); }
.tablet { width: min(1000px, 100%); height: min(680px, 100%); background: #aab8d4; border: 5px solid #000; border-radius: 22px; box-shadow: inset 0 0 0 6px #7f8fb0, 0 10px 0 rgba(0,0,0,.6); display: flex; flex-direction: column; padding: 10px; color: #111; }
.m-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 6px; }
.m-title { font-size: clamp(18px, 3.5vw, 30px); font-weight: 900; color: #fff; -webkit-text-stroke: 3px #000; paint-order: stroke fill; }
.m-timer { font-weight: 900; font-size: 15px; background: #1d2133; color: #fff; border: 3px solid #000; border-radius: 10px; padding: 4px 10px; }
.m-body { flex: 1; display: flex; gap: 8px; min-height: 0; }
.m-grid { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-content: start; overflow: auto; padding: 2px; }
.card { position: relative; display: flex; align-items: center; gap: 8px; background: #e8eef9; border: 3px solid #000; border-radius: 10px; padding: 4px 8px; height: 66px; cursor: pointer; overflow: hidden; }
.card canvas { width: 56px; height: 56px; flex: none; border-radius: 8px; background: rgba(0,0,0,.06); }
.card .nm { font-weight: 900; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .nm.imp { color: #d21; }
.card.dead { background: #8c8f99; cursor: default; }
.card.dead::after { content: '✕'; position: absolute; left: 6px; top: -6px; font-size: 54px; color: #e11; -webkit-text-stroke: 2px #000; paint-order: stroke fill; font-weight: 900; pointer-events: none; }
.card.me { box-shadow: inset 0 0 0 3px var(--yellow); }
.card.speaking { box-shadow: inset 0 0 0 4px #3ddc6a; }
.card .voted { position: absolute; right: 6px; top: 4px; background: #fff; border: 2px solid #000; border-radius: 6px; font-size: 10px; font-weight: 900; padding: 1px 4px; transform: rotate(8deg); color: #2a7; }
.card .caller { position: absolute; right: 6px; bottom: 2px; font-size: 18px; }
.card .confirm { position: absolute; right: 6px; display: flex; gap: 6px; }
.card .confirm button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #000; font-size: 20px; font-weight: 900; }
.card .confirm .yes { background: var(--green); }
.card .confirm .no { background: #ff6b6b; }
.card .votes, .m-skipvotes { display: flex; gap: 2px; flex-wrap: wrap; }
.card .votes { position: absolute; right: 6px; bottom: 3px; max-width: 55%; justify-content: flex-end; }
.vchip { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #000; background-size: cover; background-position: center; animation: zoomin .3s; }
.card.ejected { background: #ffd6d6; }
.m-chat { width: min(340px, 40%); display: flex; flex-direction: column; background: #f4f6fb; border: 3px solid #000; border-radius: 10px; min-height: 0; }
.chat-log { flex: 1; overflow: auto; padding: 6px; display: flex; flex-direction: column; gap: 4px; min-height: 0; }
.msg { display: flex; gap: 6px; align-items: flex-start; font-size: 14px; color: #111; }
.msg .av { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid #000; background-size: cover; background-position: center; }
.msg .bub { background: #fff; border: 2px solid #000; border-radius: 8px; padding: 3px 7px; word-break: break-word; }
.msg .bub b { display: block; font-size: 11px; }
.msg.ghost .bub { opacity: .6; font-style: italic; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .bub { background: #dff7e3; }
.chat-form { display: flex; gap: 4px; padding: 6px; border-top: 2px solid #000; }
.chat-form input { flex: 1; font-size: 16px; padding: 6px 8px; border: 2px solid #000; border-radius: 8px; min-width: 0; font-family: var(--font); }
.chat-form button { border: 2px solid #000; border-radius: 8px; background: var(--green); font-size: 18px; padding: 0 12px; }
.m-foot { display: flex; align-items: center; gap: 10px; padding-top: 8px; }
.m-skipvotes { flex: 1; }
.m-chat-btn { position: relative; }

#ov-eject { background: #000; z-index: 38; }
.eject-text { position: relative; font-size: clamp(18px, 3.4vw, 34px); font-weight: 900; text-align: center; padding: 0 20px; text-shadow: 0 3px 0 #000; }
#ov-end { background: #000; z-index: 39; flex-direction: column; }
.end-title { position: relative; font-size: clamp(44px, 10vw, 110px); font-weight: 900; -webkit-text-stroke: 4px #000; paint-order: stroke fill; margin-top: -32vh; animation: zoomin .5s; }
.end-reason { position: relative; font-size: 18px; font-weight: 800; margin-top: 4px; text-align: center; padding: 0 16px; }
.end-timer { position: absolute; bottom: calc(16px + var(--safe-b)); font-size: 14px; opacity: .7; }

#ov-map { background: rgba(0,0,0,.6); z-index: 25; }
.map-wrap { position: relative; padding: 14px; background: rgba(10,40,80,.85); border: 4px solid #6ad0ff; border-radius: 18px; box-shadow: 0 0 30px rgba(80,200,255,.4); max-width: 96vw; max-height: 94vh; }
.map-wrap canvas { display: block; }
.map-sabo { position: absolute; inset: 14px; pointer-events: none; }
.map-sabo button { position: absolute; pointer-events: auto; transform: translate(-50%, -50%); border-radius: 50%; width: 54px; height: 54px; border: 3px solid #000; background: #ff4d4d; font-size: 24px; box-shadow: 0 3px 0 #000; }
.map-sabo button:disabled { opacity: .4; }
.map-sabo .cdlbl { position: absolute; left: 50%; top: 6px; transform: translateX(-50%); background: #000a; padding: 3px 10px; border-radius: 8px; font-weight: 800; font-size: 13px; white-space: nowrap; }

#ov-settings, #ov-chat, #ov-menu { background: rgba(0,0,0,.55); z-index: 28; padding: 10px; }
.settings-panel { width: min(640px, 100%); max-height: 100%; overflow: auto; padding-top: 54px; touch-action: pan-y; }
.settings-panel h2, .menu-panel h2 { margin: -40px 0 12px 50px; font-size: 20px; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; }
.settings-grid label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; background: var(--panel2); padding: 6px 8px; border-radius: 8px; }
.settings-grid select { font-size: 14px; padding: 4px; border-radius: 6px; border: 2px solid #000; font-family: var(--font); font-weight: 700; max-width: 55%; }
.settings-grid .full { grid-column: 1 / -1; }
.chat-panel { width: min(520px, 100%); height: min(520px, 100%); display: flex; flex-direction: column; padding-top: 54px; background: #f4f6fb; color: #111; }
.chat-panel .chat-title { position: absolute; top: 12px; left: 60px; margin: 0; }
.menu-panel { width: min(420px, 100%); padding-top: 54px; }
.menu-help { font-size: 12px; opacity: .7; margin-top: 10px; line-height: 1.5; }

#task-container { position: fixed; inset: 0; z-index: 33; }
#toast { position: fixed; top: 18%; left: 50%; transform: translateX(-50%); background: #1d2133; border: 3px solid #000; border-radius: 12px; padding: 10px 18px; font-weight: 800; z-index: 60; text-align: center; max-width: 90vw; box-shadow: 0 5px 0 rgba(0,0,0,.5); }

#rotate-hint { display: none; position: fixed; inset: 0; z-index: 100; background: #0b0d17; flex-direction: column; align-items: center; justify-content: center; text-align: center; font-weight: 800; font-size: 20px; }
#rotate-hint div { font-size: 64px; animation: rot 2s infinite; }
@keyframes rot { 50% { transform: rotate(90deg); } }
body.ingame.touch #rotate-hint { }
@media (orientation: portrait) and (max-width: 820px) {
  body.ingame #rotate-hint { display: flex; }
}

/* ---------- petits écrans (téléphone en paysage) ---------- */
@media (max-height: 500px) {
  .act { width: 66px; height: 66px; border-radius: 14px; }
  .act .ico { font-size: 26px; }
  .act .lbl { font-size: 9px; }
  .round { width: 40px; height: 40px; font-size: 18px; }
  #tasklist { font-size: 11px; max-height: 38vh; top: calc(36px + var(--safe-t)); }
  .tb-bar { height: 20px; }
  .tb-label { font-size: 9px; top: 3px; }
  .card { height: 46px; }
  .card canvas { width: 40px; height: 40px; }
  .card .nm { font-size: 13px; }
  .m-title { font-size: 18px; }
  .home-inner { gap: 14px; }
  #preview { width: 140px; height: 140px; }
  .logo { font-size: 36px; }
  .big { font-size: 20px; padding: 8px 20px; margin-top: 8px; }
  .home-right { padding: 12px; }
  .field-label { margin: 6px 0 4px; }
  #in-name { font-size: 16px; padding: 6px 10px; }
  .grid { gap: 4px; }
  .hint { display: none; }
  .pill { font-size: 13px; padding: 6px 10px; }
  #lobby-info { font-size: 14px; }
  .settings-grid label { font-size: 12px; padding: 4px 6px; }
}
@media (max-width: 700px) and (orientation: portrait) {
  .home-inner { flex-direction: column; }
  .home-right { max-width: none; width: 100%; }
}
