:root {
  --fond: #0b0f16;
  --panneau: rgba(14, 20, 31, 0.92);
  --bord: #2a3a52;
  --texte: #e6edf6;
  --doux: #8fa1b8;
  --accent: #4da3ff;
  --essaim: #c25be3;
  --vert: #3ddc84;
  --rouge: #ff5d5d;
  --cristal: #5fe3ff;
  --gaz: #7dff6a;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--fond);
  color: var(--texte); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  position: fixed; inset: 0; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}

button {
  font: inherit; color: inherit; background: #18243a; border: 1px solid var(--bord);
  border-radius: 10px; cursor: pointer; touch-action: manipulation;
}
button:active { filter: brightness(1.3); }

.cache { display: none !important; }

#jeu { position: fixed; inset: 0; touch-action: none; display: block; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: center; gap: 6px;
  padding: calc(6px + var(--st)) calc(8px + var(--sr)) 6px calc(8px + var(--sl));
  background: linear-gradient(var(--panneau), rgba(14,20,31,0.75));
  border-bottom: 1px solid var(--bord); font-size: 14px;
}
.res { display: flex; align-items: center; gap: 5px; background: rgba(0,0,0,0.3); padding: 4px 8px; border-radius: 8px; }
.res b { font-variant-numeric: tabular-nums; }
.res.temps { margin-left: auto; color: var(--doux); font-variant-numeric: tabular-nums; }
.ico { width: 11px; height: 11px; display: inline-block; }
.ico.cri { background: var(--cristal); transform: rotate(45deg); }
.ico.gaz { background: var(--gaz); border-radius: 50%; }
.ico.pop { border: 2px solid #ffd166; border-radius: 3px; }
#bPause { width: 40px; height: 34px; font-size: 13px; }

/* ---------- Minicarte ---------- */
#minicarte {
  position: fixed; z-index: 4; left: calc(8px + var(--sl)); top: calc(54px + var(--st));
  width: 124px; height: 124px; border: 1px solid var(--bord); border-radius: 8px;
  background: #000; touch-action: none;
}

/* ---------- Boutons latéraux ---------- */
#cote {
  position: fixed; z-index: 4; right: calc(8px + var(--sr)); top: calc(54px + var(--st));
  display: flex; flex-direction: column; gap: 6px;
}
#cote > button {
  min-width: 72px; height: 44px; font-size: 13px; background: var(--panneau); padding: 0 8px;
}
#cote > button.arme { background: #5a1d1d; border-color: var(--rouge); color: #fff; }
#nInactifs { color: #ffd166; font-weight: 700; }
.groupes { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.grp { height: 44px; background: var(--panneau); font-weight: 700; position: relative; }
.grp.plein::after { content: attr(data-n); position: absolute; right: 5px; bottom: 2px; font-size: 10px; color: var(--doux); font-weight: 400; }

/* ---------- Panneau du bas ---------- */
#panneau {
  position: fixed; z-index: 5; left: 0; right: 0; bottom: 0;
  background: var(--panneau); border-top: 1px solid var(--bord);
  padding: 8px calc(8px + var(--sr)) calc(8px + var(--sb)) calc(8px + var(--sl));
  display: flex; flex-direction: column; gap: 6px; min-height: 118px;
}
#pInfo { display: flex; align-items: center; gap: 8px; min-height: 28px; font-size: 13px; }
#pInfo .nom { font-weight: 700; font-size: 14px; white-space: nowrap; }
#pInfo .det { color: var(--doux); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pInfo .barre { flex: 0 0 90px; height: 7px; background: #333; border-radius: 4px; overflow: hidden; }
#pInfo .barre i { display: block; height: 100%; background: var(--vert); }
#pInfo .indice { color: var(--doux); }
#pInfo .x { margin-left: auto; width: 36px; height: 30px; flex: 0 0 auto; }

#pActions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
#pActions::-webkit-scrollbar { display: none; }
.act {
  flex: 0 0 auto; min-width: 78px; min-height: 56px; padding: 6px 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; line-height: 1.1; text-align: center;
}
.act .nm { font-weight: 600; }
.act .ct { color: var(--doux); font-size: 11px; white-space: nowrap; }
.act .ct .c { color: var(--cristal); }
.act .ct .g { color: var(--gaz); }
.act.off { opacity: 0.45; }
.act.lock { opacity: 0.35; }
.act.on { border-color: var(--vert); color: var(--vert); }
.act.puce { min-width: 64px; }
.qi { position: relative; overflow: hidden; min-width: 64px; }
.qi .qp { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--vert); width: 0; }
.sep { flex: 0 0 1px; background: var(--bord); margin: 4px 2px; }

/* ---------- Placement ---------- */
#placement {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  top: calc(54px + var(--st)); background: var(--panneau); border: 1px solid var(--vert);
  border-radius: 10px; padding: 6px 6px 6px 12px; display: flex; gap: 10px; align-items: center;
  font-size: 13px; max-width: calc(100% - 280px); min-width: 200px;
}
#placement button { height: 36px; padding: 0 10px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 7; left: 50%; bottom: calc(130px + var(--sb)); transform: translateX(-50%);
  background: rgba(0,0,0,0.8); border: 1px solid var(--bord); border-radius: 10px;
  padding: 8px 14px; font-size: 13px; opacity: 0; transition: opacity 0.25s; pointer-events: none;
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.vu { opacity: 1; }
#toast.alerte { border-color: var(--rouge); color: #ffd0d0; }

/* ---------- Écrans ---------- */
.ecran {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto;
  background: radial-gradient(ellipse at 50% 20%, #17243a, #06080c 70%);
  display: flex; justify-content: center; align-items: flex-start;
  padding: calc(20px + var(--st)) 16px calc(20px + var(--sb));
}
#pauseEcran, #finEcran { background: rgba(4,6,10,0.82); align-items: center; }
.boite { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 10px; }
.boite.petite { max-width: 340px; }
h1 { margin: 10px 0 0; font-size: 30px; letter-spacing: 6px; text-align: center; font-weight: 800; }
h1 span { display: block; font-size: 15px; letter-spacing: 11px; color: var(--accent); font-weight: 600; }
h2 { margin: 10px 0 0; font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--doux); }
.sous { text-align: center; color: var(--doux); margin: 0; font-size: 13px; }
.factions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fac { text-align: left; padding: 12px; display: flex; flex-direction: column; gap: 6px; min-height: 120px; }
.fac b { font-size: 16px; }
.fac span { font-size: 12px; color: var(--doux); line-height: 1.35; }
.fac[data-fac="C"].choisi { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.fac[data-fac="E"].choisi { border-color: var(--essaim); box-shadow: 0 0 0 1px var(--essaim) inset; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; height: 44px; }
.seg button.choisi { border-color: var(--vert); color: var(--vert); }
.gros { height: 54px; font-size: 18px; font-weight: 700; background: #1e4f86; border-color: var(--accent); margin-top: 8px; }
.boite > button:not(.gros) { height: 46px; }
details { background: rgba(255,255,255,0.03); border: 1px solid var(--bord); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
summary { cursor: pointer; font-weight: 600; }
details ul { padding-left: 18px; margin: 8px 0 0; line-height: 1.5; color: #c9d4e2; }
#finStats { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0; }
#finStats th, #finStats td { padding: 6px 4px; border-bottom: 1px solid var(--bord); text-align: right; }
#finStats th:first-child, #finStats td:first-child { text-align: left; color: var(--doux); font-weight: 400; }

/* Paysage sur téléphone : panneau plus compact */
@media (orientation: landscape) and (max-height: 500px) {
  #panneau { min-height: 96px; padding-top: 5px; gap: 4px; }
  .act { min-height: 48px; }
  #cote > button, .grp { height: 34px; font-size: 12px; }
  #cote { gap: 3px; top: calc(48px + var(--st)); }
  #minicarte { top: calc(48px + var(--st)); }
  #hud { padding-top: calc(4px + var(--st)); padding-bottom: 4px; }
  #placement { top: calc(48px + var(--st)); }
  .groupes { flex-direction: row; gap: 4px; }
  .grp { flex: 1; min-width: 0; }
  #minicarte { width: 104px; height: 104px; }
  #toast { bottom: calc(108px + var(--sb)); }
}
