:root {
  --bg: #14202b;
  --panel: rgba(20, 30, 42, 0.92);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f4efe6;
  --muted: #a9b4bf;
  --accent: #ffb43b;
  --accent2: #ff7a2f;
  --danger: #e5484d;
  --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; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; touch-action: none;
  overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- écrans ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
}
.screen.modal { background: rgba(5, 10, 16, 0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); z-index: 40; }

#splash {
  flex-direction: column; gap: 18px; z-index: 60;
  background: radial-gradient(ellipse at 50% 30%, #2b5d4a 0%, #14202b 70%);
}
.logo { text-align: center; }
.logo-monkey { font-size: 72px; animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }
h1 { margin: 0; font-size: 42px; letter-spacing: 1px; text-shadow: 0 3px 0 #000a, 0 0 18px #ffb43b55; font-weight: 900; }
h1 span { color: var(--accent); }
h2 { margin: 0 0 10px; font-size: 18px; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; }
.version { font-size: 12px; color: var(--muted); opacity: 0.9; letter-spacing: 1px; }
.loader { width: 180px; height: 6px; border-radius: 3px; background: #ffffff1a; overflow: hidden; }
.loader div { width: 40%; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); animation: load 1s ease-in-out infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ---------- menu ---------- */
#menu {
  background: radial-gradient(ellipse at 20% 0%, #2d6b50 0%, transparent 55%),
              radial-gradient(ellipse at 100% 100%, #6b3a20 0%, transparent 55%), var(--bg);
  overflow-y: auto; align-items: flex-start;
}
.menu-wrap { width: 100%; max-width: 980px; margin: auto; display: flex; flex-direction: column; gap: 12px; }
.menu-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.menu-head h1 { font-size: 32px; }
.menu-grid { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(260px, 1.4fr); gap: 12px; }
@media (max-width: 640px) { .menu-grid { grid-template-columns: 1fr; } }
.panel {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 16px;
  padding: 14px; box-shadow: 0 10px 30px #0006;
}
.row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.team-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.team-row .swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff8; flex: none; cursor: pointer; }
.team-row input {
  flex: 1; min-width: 0; background: #0006; border: 1px solid var(--panel-border); color: var(--text);
  border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 14px;
}
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; font-size: 14px; color: var(--muted); }
.field.check { justify-content: flex-start; cursor: pointer; }
.field.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--panel-border); background: #ffffff12; font-size: 18px; }
.stepper span { min-width: 54px; text-align: center; color: var(--text); font-weight: bold; }

.map-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.map-card {
  border: 2px solid transparent; border-radius: 12px; overflow: hidden; background: #0005; padding: 0;
  text-align: left; transition: transform .1s, border-color .1s;
}
.map-card:active { transform: scale(0.97); }
.map-card.sel { border-color: var(--accent); box-shadow: 0 0 0 3px #ffb43b33; }
.map-card canvas, .map-card .ph { width: 100%; aspect-ratio: 2 / 1; display: block; background: #000; }
.map-card .ph { display: flex; align-items: center; justify-content: center; font-size: 34px; background: linear-gradient(135deg,#3a4a5a,#1b2530); }
.map-card .mname { padding: 6px 8px 2px; font-weight: bold; font-size: 13px; }
.map-card .mdesc { padding: 0 8px 7px; font-size: 11px; color: var(--muted); }

.menu-actions { display: flex; gap: 10px; justify-content: center; padding-bottom: 8px; }
.btn {
  border: none; border-radius: 12px; padding: 11px 18px; font-size: 16px; font-weight: bold;
  background: linear-gradient(180deg, #ffc65c, #ff8f2f); color: #2a1404; box-shadow: 0 4px 0 #a6501a, 0 6px 14px #0005;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a6501a; }
.btn.big { font-size: 20px; padding: 13px 34px; }
.btn.small { font-size: 13px; padding: 7px 12px; box-shadow: 0 3px 0 #a6501a; }
.btn.ghost { background: #ffffff18; color: var(--text); box-shadow: 0 3px 0 #0006; }
.btn.danger { background: linear-gradient(180deg, #ff6a6f, #c92f35); color: #fff; box-shadow: 0 4px 0 #7a1b1f; }

.help-panel { max-width: 640px; max-height: 100%; overflow-y: auto; font-size: 14px; line-height: 1.45; }
.help-panel ul { padding-left: 18px; margin: 0 0 12px; }
.help-panel li { margin-bottom: 6px; }
.pause-panel { display: flex; flex-direction: column; gap: 10px; min-width: 260px; text-align: center; align-items: stretch; }
.pause-panel p { margin: 0 0 6px; color: var(--muted); }
.rotate-icon { font-size: 46px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top {
  position: absolute; top: calc(6px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r));
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
}
.team-bars { display: flex; flex-direction: column; gap: 3px; min-width: 120px; max-width: 34%; }
.tbar { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: bold; text-shadow: 0 1px 2px #000; }
.tbar .tname { width: 74px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tbar .ttrack { flex: 1; height: 8px; background: #0007; border-radius: 4px; overflow: hidden; min-width: 40px; border: 1px solid #fff3; }
.tbar .tfill { display: block; height: 100%; border-radius: 4px; transition: width .5s; }
.tbar.active .tname::before { content: "▶ "; }
.timer {
  width: 54px; height: 54px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, #1d2c3a, #0d151d); border: 3px solid var(--accent); font-size: 22px; font-weight: 900;
  box-shadow: 0 4px 14px #0007; transition: border-color .2s;
}
.timer.warn { border-color: var(--danger); color: #ffb1b3; animation: pulse .5s ease-in-out infinite alternate; }
.timer.retreat { border-color: #49c2ff; }
@keyframes pulse { to { transform: scale(1.08); } }
.hud-right { display: flex; align-items: center; gap: 8px; }
.wind { background: #0008; padding: 4px 6px; border-radius: 8px; border: 1px solid #fff2; }
.wind-label { font-size: 9px; color: var(--muted); text-align: center; letter-spacing: 2px; }
.wind-bar { width: 96px; height: 8px; background: #fff1; border-radius: 4px; position: relative; overflow: hidden; }
.wind-bar::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: #fff8; }
#windFill { position: absolute; top: 0; bottom: 0; background: linear-gradient(90deg, #8fd3ff, #fff); }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid #fff3; background: #000a; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.banner {
  position: absolute; top: 24%; left: 50%; transform: translateX(-50%);
  padding: 10px 22px; border-radius: 14px; background: #000b; border: 2px solid #fff3;
  font-size: 20px; font-weight: 900; text-align: center; text-shadow: 0 2px 0 #000; white-space: nowrap;
  animation: bannerIn .35s ease-out;
}
.banner small { display: block; font-size: 13px; color: var(--muted); font-weight: normal; }
@keyframes bannerIn { from { opacity: 0; transform: translate(-50%, -12px) scale(.9); } }
.hint {
  position: absolute; bottom: calc(96px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: #000a; padding: 6px 12px; border-radius: 10px; font-size: 13px; white-space: nowrap;
}

.controls { position: absolute; bottom: calc(10px + var(--safe-b)); display: flex; align-items: flex-end; gap: 8px; }
.controls.left { left: calc(10px + var(--safe-l)); }
.controls.right { right: calc(10px + var(--safe-r)); }
.ctl {
  width: 62px; height: 62px; border-radius: 50%; border: 2px solid #ffffff40; background: #0b141d99;
  font-size: 24px; color: #fff; display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); box-shadow: 0 4px 10px #0006;
}
.ctl.on { background: #ffb43b88; border-color: #ffd28a; }
.ctl.fire { width: 76px; height: 76px; font-size: 32px; background: radial-gradient(circle, #ff8a3c99, #b3290099); border-color: #ffc28a; }
.aim-col { display: flex; flex-direction: column; gap: 6px; }
.aim-col .ctl { width: 50px; height: 50px; font-size: 18px; }
.weapon-btn {
  min-width: 72px; height: 62px; border-radius: 14px; border: 2px solid #ffffff40; background: #0b141dcc;
  display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; padding: 2px 6px;
}
.weapon-btn span { font-size: 24px; line-height: 1; }
.weapon-btn small { font-size: 10px; max-width: 80px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.weapon-btn em { position: absolute; top: -6px; right: -6px; font-style: normal; font-size: 11px; background: var(--accent); color: #241000; border-radius: 9px; padding: 1px 6px; font-weight: bold; }
.chip { align-self: center; border: 1px solid #fff4; background: #000b; border-radius: 16px; padding: 6px 10px; font-size: 13px; }
@media (max-height: 380px) {
  .ctl { width: 52px; height: 52px; font-size: 20px; }
  .ctl.fire { width: 64px; height: 64px; }
  .aim-col .ctl { width: 42px; height: 42px; }
  .weapon-btn { height: 52px; }
  .timer { width: 46px; height: 46px; font-size: 18px; }
}

/* ---------- arsenal ---------- */
.weapon-panel { width: min(720px, 100%); max-height: 100%; display: flex; flex-direction: column; }
.wp-head { display: flex; align-items: center; justify-content: space-between; }
.weapon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; overflow-y: auto; padding: 2px; }
.wcell {
  position: relative; border: 1px solid #fff2; background: #ffffff0d; border-radius: 10px; padding: 6px 2px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 64px;
}
.wcell .wi { font-size: 26px; line-height: 1.1; }
.wcell .wn { font-size: 10px; text-align: center; line-height: 1.1; }
.wcell .wa { position: absolute; top: 2px; right: 4px; font-size: 10px; color: var(--accent); font-weight: bold; }
.wcell.sel { border-color: var(--accent); background: #ffb43b26; }
.wcell.off { opacity: 0.35; }
.wcell .wl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: bold; background: #000a; border-radius: 10px; color: #ffd28a; }
.wcell .cat { position: absolute; top: 2px; left: 4px; font-size: 8px; color: var(--muted); }
.weapon-info { margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 32px; }

/* ---------- réseau local ---------- */
.btn.lan { background: linear-gradient(180deg, #6fd3ff, #2f8cff); color: #04203d; box-shadow: 0 4px 0 #1a4f99, 0 6px 14px #0005; }
.menu-actions { flex-wrap: wrap; }
#lan { background: radial-gradient(ellipse at 30% 0%, #1f4a7a 0%, transparent 60%), var(--bg); overflow-y: auto; align-items: flex-start; }
.lan-panel { width: min(560px, 100%); margin: auto; display: flex; flex-direction: column; gap: 8px; }
.lan-panel h3 { margin: 10px 0 4px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.lan-panel .field input, .lan-panel select {
  flex: 1; max-width: 240px; background: #0006; border: 1px solid var(--panel-border); color: var(--text);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 15px;
}
.lan-note { color: var(--muted); font-size: 13px; margin: 4px 0; line-height: 1.4; }
.lan-rooms { display: flex; flex-direction: column; gap: 6px; }
.lan-room { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #ffffff10; border: 1px solid #fff2; border-radius: 10px; padding: 8px 10px; }
.lan-room b { font-size: 15px; }
.lan-room small { color: var(--muted); display: block; }
.lan-code { font-size: 15px; margin: 0; color: var(--muted); }
.lan-code b { color: var(--accent); font-size: 22px; letter-spacing: 3px; }
.lan-players { display: flex; flex-direction: column; gap: 4px; }
.lan-player { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; background: #ffffff0d; font-weight: bold; }
.lan-player .dot { width: 14px; height: 14px; border-radius: 50%; }
.lan-player .tag { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: normal; }
.lan-error { color: #ffb1b3; background: #e5484d22; border-radius: 8px; padding: 8px; margin: 0; }
#hud.spectator .controls { opacity: 0.3; pointer-events: none; }
#hud.spectator .controls button { pointer-events: none; }
.turn-owner { position: absolute; top: calc(66px + var(--safe-t)); left: 50%; transform: translateX(-50%); font-size: 12px; background: #000a; padding: 3px 10px; border-radius: 10px; white-space: nowrap; }
.join-row { align-items: center; }
#lanJoinCode {
  width: 130px; text-transform: uppercase; letter-spacing: 6px; text-align: center; font-size: 22px; font-weight: bold;
  background: #0006; border: 1px solid var(--panel-border); color: var(--accent); border-radius: 10px; padding: 8px; font-family: inherit;
}
.net-status { position: absolute; top: calc(92px + var(--safe-t)); left: 50%; transform: translateX(-50%); font-size: 12px; background: #e5484dcc; padding: 3px 10px; border-radius: 10px; white-space: nowrap; }
.fire-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.fire-col .ctl.jump { width: 54px; height: 54px; font-size: 22px; background: #2f8cff66; border-color: #9fd0ff; }
@media (max-height: 380px) { .fire-col .ctl.jump { width: 46px; height: 46px; font-size: 18px; } }
