*{ box-sizing:border-box; }
html,body{ height:100%; margin:0; }

:root{
  --bg: #020617;
  --fg: #e5e7eb;
  --panel: rgba(255,255,255,.07);
  --panelBd: rgba(255,255,255,.12);
  --btn: rgba(255,255,255,.09);
  --btnBd: rgba(255,255,255,.18);
  --btnActive: rgba(255,255,255,.14);

  /* Largeur des marges pour les contrôles */
  --ctrlW: clamp(68px, 14vw, 112px);
}

body{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
}

#app{
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------------- HUD compact ---------------- */
.topbarCompact{
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(6px + env(safe-area-inset-top))
           calc(8px + env(safe-area-inset-right))
           6px
           calc(8px + env(safe-area-inset-left));
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.02));
}

.hudLeft{ flex: 0 0 auto; }
.hudCenter{
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.hudRight{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill{
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  font-weight: 900;
}
.pillLabel{ opacity:.85; font-size: 12px; }
.pillValue{ font-variant-numeric: tabular-nums; letter-spacing: .3px; }

.playerHud{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.10);
  min-width: 0;
  max-width: 46vw;
}
.playerHud .tag{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  font-weight: 900;
  font-size: 12px;
}
.playerHud .pseudo{
  font-weight: 900;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 16vw;
}
.playerHud .score{
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.playerHud .eval{
  opacity: .92;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.playerHud .unit{ opacity: .8; margin-left: 2px; }

.iconBtn{
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid var(--btnBd);
  background: var(--btn);
  color: var(--fg);
  font-weight: 900;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.iconBtn:active{ background: var(--btnActive); transform: translateY(1px); }

/* ---------------- Stage mobile : marges + aire de jeu ---------------- */
.stageMobile{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 0;
  padding: 0;
}

.controls{
  width: calc(var(--ctrlW) + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 6px;
  background: rgba(0,0,0,.10);
  border-right: 1px solid rgba(255,255,255,.06);
}
.controlsRight{
  width: calc(var(--ctrlW) + env(safe-area-inset-right));
  border-right: none;
  border-left: 1px solid rgba(255,255,255,.06);
}

.controlsTitle{
  font-weight: 900;
  opacity: .85;
  letter-spacing: .5px;
}

.dpad{
  width: 100%;
  max-width: 112px;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
}

.padBtn{
  border-radius: 14px;
  border: 1px solid var(--btnBd);
  background: var(--btn);
  color: var(--fg);
  font-weight: 900;
  font-size: 18px;
  touch-action: none;
}
.padBtn:active{ background: var(--btnActive); transform: translateY(1px); }

.padBtn.up   { grid-column: 2; grid-row: 1; }
.padBtn.left { grid-column: 1; grid-row: 2; }
.padBtn.right{ grid-column: 3; grid-row: 2; }
.padBtn.down { grid-column: 2; grid-row: 3; }

/* Aire de jeu */
.gameWrap{
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: #050a18;
}

#game{
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------------- Overlay ---------------- */
.overlay{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.58);
  padding: 16px;
  z-index: 4;
}
.overlay.hidden{ display:none; }

.overlayCard{
  width: min(720px, 100%);
  background: #0b1224;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  padding: 16px 16px 14px;
  box-shadow: 0 18px 60px rgba(0,0,0,.45);
}

.overlayCard.compactCard{ width: min(560px, 100%); }

.overlayTitle{
  font-weight: 900;
  font-size: 18px;
  margin-bottom: 8px;
}

.overlayText{
  font-size: 14px;
  line-height: 1.45;
  opacity: .95;
}

.overlayActions{
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn{
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: var(--fg);
  font-weight: 900;
  cursor: pointer;
}
.btn:active{ background: rgba(255,255,255,.10); transform: translateY(1px); }
.btn.primary{
  background: rgba(59,130,246,.35);
  border-color: rgba(59,130,246,.55);
}

.muted{ opacity:.78; font-size:12px; }

.endSummary{
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  font-size: 14px;
  line-height: 1.5;
}

/* Form pseudos */
.formGrid{
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 760px){
  .formGrid{ grid-template-columns: 1fr; }
}

.field label{
  display: block;
  font-size: 12px;
  opacity: .85;
  margin-bottom: 6px;
}

.field input{
  width: 100%;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: var(--fg);
  outline: none;
  font-weight: 900;
  user-select: text;
  touch-action: manipulation;
}

.inlineRow{ margin-top: 10px; }

/* ---------------- Mode 1 joueur : aire de jeu maximisée ---------------- */
#app.mode1 #controlsRight,
#app.mode1 #p1HudBlock,
#app.mode1 #fieldPseudoR{
  display: none !important;
}
