:root {
  --fond: #06080d;
  --verre: rgba(10, 16, 27, 0.86);
  --verre2: rgba(16, 26, 42, 0.92);
  --bord: rgba(110, 170, 230, 0.28);
  --bordF: rgba(110, 170, 230, 0.55);
  --texte: #e8f0fa;
  --doux: #8fa3bd;
  --accent: #4db4ff;
  --accent2: #9be0ff;
  --essaim: #d26bff;
  --vert: #3ddc84;
  --rouge: #ff5d5d;
  --cristal: #6fe6ff;
  --gaz: #7dff6a;
  --titre: 'Chakra Petch', 'Rajdhani', system-ui, sans-serif;
  --chiffre: 'Rajdhani', system-ui, sans-serif;
  --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);
  --biseau: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}

* { 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: var(--titre);
  position: fixed; inset: 0; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}

button {
  font: inherit; color: inherit; cursor: pointer; touch-action: manipulation;
  background: linear-gradient(180deg, rgba(40, 62, 92, 0.9), rgba(16, 26, 42, 0.95));
  border: 1px solid var(--bord); border-radius: 8px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 2px 6px rgba(0, 0, 0, 0.35);
}
button:active { filter: brightness(1.35); transform: translateY(1px); }
img { -webkit-user-drag: none; }

.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(180deg, rgba(6, 10, 18, 0.95), rgba(8, 14, 24, 0.72));
  border-bottom: 1px solid var(--bord);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
}
#hud::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: 0.6; }
.res {
  display: flex; align-items: center; gap: 5px; padding: 3px 10px 3px 6px; border-radius: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.25)); border: 1px solid rgba(255, 255, 255, 0.07);
  font-family: var(--chiffre); font-size: 17px; font-weight: 700;
}
.res b { font-variant-numeric: tabular-nums; min-width: 2ch; }
.res.temps { margin-left: auto; color: var(--doux); font-size: 15px; padding-left: 10px; }
.ico { width: 20px; height: 20px; display: inline-block; flex: 0 0 auto; }
.ic-c, .ic-g { display: inline-block; background-size: contain; background-repeat: no-repeat; background-position: center; }
.ic-c { background-image: var(--ic-cri); }
.ic-g { background-image: var(--ic-gaz); }
.res .ic-c, .res .ic-g { width: 22px; height: 22px; }
#bPause { width: 40px; height: 34px; display: grid; place-items: center; padding: 0; }
#bPause svg { width: 16px; height: 16px; }

/* ---------- Minicarte ---------- */
#mmCadre {
  position: fixed; z-index: 4; left: calc(8px + var(--sl)); top: calc(56px + var(--st));
  width: 128px; height: 128px; padding: 3px; border-radius: 10px;
  background: linear-gradient(145deg, rgba(90, 140, 200, 0.5), rgba(20, 30, 46, 0.9));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
}
#minicarte { width: 100%; height: 100%; display: block; border-radius: 7px; background: #000; touch-action: none; }

/* ---------- Boutons latéraux ---------- */
#cote {
  position: fixed; z-index: 4; right: calc(8px + var(--sr)); top: calc(56px + var(--st));
  display: flex; flex-direction: column; gap: 6px;
}
#cote > button {
  width: 64px; height: 50px; padding: 4px 2px 3px; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase; color: #cfe3f7;
  background: linear-gradient(180deg, rgba(30, 48, 74, 0.92), rgba(10, 16, 27, 0.92));
}
#cote > button svg { width: 20px; height: 20px; color: var(--accent2); }
#cote > button.arme { background: linear-gradient(180deg, #8a2020, #4a0f0f); border-color: var(--rouge); color: #fff; box-shadow: 0 0 14px rgba(255, 70, 70, 0.6); }
#cote > button.arme svg { color: #fff; }
#nInactifs { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: #ffb020; color: #1a1000; font-style: normal; font-size: 11px; font-weight: 700; line-height: 18px; font-family: var(--chiffre); }
#nInactifs:empty { display: none; }
.groupes { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.grp { width: 64px; height: 40px; font-weight: 700; font-size: 17px; position: relative; font-family: var(--chiffre); background: linear-gradient(180deg, rgba(30, 48, 74, 0.85), rgba(10, 16, 27, 0.9)); }
.grp.plein { border-color: var(--bordF); color: var(--accent2); }
.grp.plein::after { content: attr(data-n); position: absolute; right: 5px; bottom: 1px; font-size: 10px; color: var(--doux); font-weight: 600; }

/* ---------- Panneau du bas ---------- */
#panneau {
  position: fixed; z-index: 5; left: 0; right: 0; bottom: 0;
  background: linear-gradient(180deg, rgba(12, 20, 33, 0.9), rgba(6, 10, 18, 0.97));
  border-top: 1px solid var(--bordF);
  box-shadow: 0 -6px 22px rgba(0, 0, 0, 0.5);
  padding: 8px calc(8px + var(--sr)) calc(8px + var(--sb)) calc(8px + var(--sl));
  display: flex; flex-direction: column; gap: 7px; min-height: 136px;
}
#panneau::before { content: ''; position: absolute; left: 0; right: 0; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--accent), transparent); }
#pInfo { display: flex; align-items: center; gap: 9px; min-height: 40px; font-size: 13px; }
#pInfo .portrait { flex: 0 0 auto; width: 42px; height: 42px; border-radius: 8px; overflow: hidden; border: 1px solid var(--bordF); box-shadow: 0 0 10px rgba(77, 180, 255, 0.25); }
#pInfo .portrait.ennemi { border-color: rgba(255, 90, 90, 0.7); box-shadow: 0 0 10px rgba(255, 70, 70, 0.3); }
#pInfo .portrait img { width: 100%; height: 100%; display: block; }
#pInfo .bloc { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
#pInfo .nom { font-weight: 700; font-size: 14px; white-space: nowrap; letter-spacing: 0.4px; }
#pInfo .nom em { font-style: normal; color: #ff8a80; font-size: 11px; text-transform: uppercase; margin-left: 4px; }
#pInfo .ligne { display: flex; align-items: center; gap: 6px; }
#pInfo .pv { font-family: var(--chiffre); font-size: 12px; color: var(--doux); font-weight: 600; }
#pInfo .det { color: var(--doux); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
#pInfo .barre { flex: 0 0 110px; height: 7px; background: rgba(0, 0, 0, 0.6); border-radius: 4px; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.08); }
#pInfo .barre.bouc { height: 5px; }
#pInfo .barre.bouc i { background: #6fd0ff; }
#pInfo .barre i { display: block; height: 100%; background: var(--vert); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3); }
#pInfo .indice { color: var(--doux); font-size: 12.5px; }
#pInfo .x { margin-left: auto; width: 36px; height: 32px; flex: 0 0 auto; }

#pActions { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 1px 3px; }
#pActions::-webkit-scrollbar { display: none; }
.act {
  flex: 0 0 auto; width: 76px; min-height: 76px; padding: 4px 3px 5px; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 1px;
  font-size: 11px; line-height: 1.1; text-align: center; overflow: hidden;
  clip-path: var(--biseau); border-radius: 0;
  background: linear-gradient(180deg, rgba(34, 54, 82, 0.95), rgba(12, 19, 31, 0.98));
  border: 1px solid var(--bord);
}
.act img { width: 42px; height: 42px; border-radius: 6px; display: block; margin-bottom: 1px; }
.act .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.act .ct { color: var(--doux); font-size: 11px; white-space: nowrap; display: flex; gap: 5px; justify-content: center; font-family: var(--chiffre); font-weight: 700; }
.act .ct .c { color: var(--cristal); display: flex; align-items: center; gap: 1px; }
.act .ct .g { color: var(--gaz); display: flex; align-items: center; gap: 1px; }
.act .ct i { width: 12px; height: 12px; }
.act.off { filter: grayscale(0.7) brightness(0.65); }
.act.off .ct .c, .act.off .ct .g { color: #ff8a80; }
.act.lock { opacity: 0.45; filter: grayscale(1); }
.act.on { border-color: var(--vert); color: var(--vert); box-shadow: inset 0 0 12px rgba(61, 220, 132, 0.35); }
.act.boucle .sym { font-size: 28px; line-height: 42px; height: 43px; color: var(--accent2); }
.act.boucle.on .sym { color: var(--vert); }
.act.puce { width: 64px; min-height: 70px; }
.act.puce .nb { position: absolute; top: 34px; right: 6px; font-family: var(--chiffre); font-weight: 700; font-size: 13px; color: #fff; text-shadow: 0 1px 3px #000; }
.qi { width: 60px; }
.qi img { width: 38px; height: 38px; }
.qi .qp { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--vert); width: 0; box-shadow: 0 0 6px var(--vert); }
.sep { flex: 0 0 1px; background: var(--bord); margin: 6px 2px; }

/* ---------- Placement ---------- */
#placement {
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  top: calc(56px + var(--st)); background: var(--verre2); 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% - 300px); min-width: 190px; box-shadow: 0 0 16px rgba(61, 220, 132, 0.25);
}
#placement button { height: 36px; padding: 0 10px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; z-index: 7; left: 50%; bottom: calc(150px + var(--sb)); transform: translateX(-50%);
  background: rgba(4, 8, 14, 0.88); border: 1px solid var(--bordF); border-radius: 8px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; letter-spacing: 0.3px; opacity: 0; transition: opacity 0.25s; pointer-events: none;
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
#toast.vu { opacity: 1; }
#toast.alerte { border-color: var(--rouge); color: #ffd0d0; box-shadow: 0 0 18px rgba(255, 60, 60, 0.45); }

/* ---------- Écrans ---------- */
.ecran {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto;
  display: flex; justify-content: center; align-items: flex-start;
  padding: calc(20px + var(--st)) 16px calc(20px + var(--sb));
}
#menu { background: radial-gradient(ellipse at 50% 30%, rgba(6, 10, 20, 0.25), rgba(3, 5, 10, 0.8) 80%); }
#pauseEcran, #finEcran { background: rgba(3, 6, 12, 0.78); align-items: center; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.boite { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 10px; }
.boite.petite {
  max-width: 340px; padding: 20px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(18, 30, 48, 0.95), rgba(8, 13, 22, 0.97));
  border: 1px solid var(--bordF); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6), 0 0 30px rgba(77, 180, 255, 0.12);
}
.logo { display: flex; flex-direction: column; align-items: center; margin: 18px 0 2px; filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.8)); }
.logo .l1 { font-family: var(--titre); font-weight: 700; font-size: 46px; letter-spacing: 12px; line-height: 1; margin-right: -12px;
  background: linear-gradient(180deg, #ffffff 20%, #9fd6ff 60%, #3d86c9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo .l2 { font-family: var(--titre); font-weight: 600; font-size: 17px; letter-spacing: 13px; margin-right: -13px; color: var(--accent); text-shadow: 0 0 14px rgba(77, 180, 255, 0.7); margin-top: 4px; }
.logo .trait { width: 220px; height: 2px; margin-top: 10px; background: linear-gradient(90deg, transparent, var(--accent), #fff, var(--accent), transparent); box-shadow: 0 0 10px var(--accent); }
h1 { margin: 4px 0 6px; font-size: 30px; letter-spacing: 6px; text-align: center; font-weight: 700; }
h2 { margin: 10px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 3px; color: var(--accent2); font-weight: 600; text-shadow: 0 1px 4px #000; }
.sous { text-align: center; color: #b6c6da; margin: 0; font-size: 13px; letter-spacing: 0.5px; text-shadow: 0 1px 4px #000; }
.factions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.fac {
  text-align: left; padding: 8px; display: flex; flex-direction: column; gap: 4px; min-height: 140px;
  background: linear-gradient(180deg, rgba(20, 32, 52, 0.88), rgba(8, 12, 20, 0.92)); clip-path: var(--biseau); border-radius: 0;
}
.fac .visuels { display: flex; gap: 3px; }
.fac .visuels img { width: 33%; min-width: 0; max-width: 46px; aspect-ratio: 1; border-radius: 5px; border: 1px solid rgba(255, 255, 255, 0.1); }
.fac b { font-size: 14.5px; letter-spacing: 0.3px; }
.fac .desc { font-size: 11.5px; color: var(--doux); line-height: 1.35; font-family: var(--chiffre); font-weight: 500; }
.fac[data-fac="C"].choisi { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), inset 0 0 24px rgba(77, 180, 255, 0.25); }
.fac[data-fac="L"].choisi { border-color: #e8c25a; box-shadow: inset 0 0 0 1px #e8c25a, inset 0 0 24px rgba(232, 194, 90, 0.25); }
.fac[data-fac="E"].choisi { border-color: var(--essaim); box-shadow: inset 0 0 0 1px var(--essaim), inset 0 0 24px rgba(210, 107, 255, 0.25); }
.fac:not(.choisi) { opacity: 0.72; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; min-width: 0; height: 42px; font-size: 13px; padding: 0 4px; font-weight: 600; background: linear-gradient(180deg, rgba(20, 32, 52, 0.88), rgba(8, 12, 20, 0.92)); }
.seg button.choisi { border-color: var(--vert); color: var(--vert); box-shadow: inset 0 0 14px rgba(61, 220, 132, 0.22); }
.gros {
  height: 58px; font-size: 20px; font-weight: 700; letter-spacing: 6px; margin-top: 10px; color: #fff;
  background: linear-gradient(180deg, #2f8fe0, #11508f); border-color: #8fd0ff; clip-path: var(--biseau); border-radius: 0;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 0 22px rgba(77, 180, 255, 0.35);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { filter: brightness(1.18); } }
.boite.petite .gros { letter-spacing: 2px; font-size: 18px; animation: none; }
.boite > button:not(.gros) { height: 46px; font-weight: 600; }
details { background: rgba(8, 12, 20, 0.85); border: 1px solid var(--bord); border-radius: 10px; padding: 10px 12px; font-size: 13px; font-family: var(--chiffre); font-weight: 500; }
summary { cursor: pointer; font-weight: 700; font-family: var(--titre); }
details ul { padding-left: 18px; margin: 8px 0 0; line-height: 1.5; color: #c9d4e2; }
#finTitre { font-size: 38px; text-shadow: 0 0 20px currentColor; }
#finStats { width: 100%; border-collapse: collapse; font-size: 15px; margin: 6px 0; font-family: var(--chiffre); font-weight: 600; }
#finStats th, #finStats td { padding: 6px 4px; border-bottom: 1px solid var(--bord); text-align: right; }
#finStats th { color: var(--accent2); font-family: var(--titre); font-size: 13px; }
#finStats th:first-child, #finStats td:first-child { text-align: left; color: var(--doux); font-weight: 500; }

.version { margin: 4px 0 0; text-align: center; font-size: 11px; letter-spacing: 1px; color: var(--doux); font-family: var(--chiffre); font-weight: 600; opacity: 0.8; }

/* ---------- Taille de l'interface (Auto = selon l'écran) ---------- */
#hud, #panneau, #cote, #mmCadre, #placement, #toast, .ecran > .boite { zoom: var(--ui, 1); }
kbd { display: none; }

/* ---------- Ordinateur : souris et grand écran ---------- */
body.pc kbd {
  display: block; position: absolute; top: 3px; left: 4px; min-width: 15px; padding: 0 3px; border-radius: 3px;
  font: 700 10px/14px var(--chiffre); color: #cfe3f7; background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.18); text-align: center;
}
body.pc #cote > button kbd { left: auto; right: 3px; top: 3px; }
body.pc #mmCadre { top: auto; bottom: 8px; left: 8px; width: 214px; height: 214px; z-index: 6; }
body.pc #panneau {
  left: 230px; right: 8px; bottom: 8px; flex-direction: row; align-items: center; gap: 12px;
  min-height: 0; height: 120px; padding: 10px 12px; border: 1px solid var(--bordF); border-radius: 12px;
}
body.pc #pInfo { flex: 0 0 300px; min-height: 0; align-self: stretch; }
body.pc #pInfo .portrait { width: 56px; height: 56px; }
body.pc #pInfo .barre { flex-basis: 120px; }
body.pc #pInfo .indice { white-space: normal; }
body.pc #pActions { flex: 1; padding: 0; overflow-x: auto; }
body.pc .act { min-height: 96px; width: 84px; }
body.pc .act img { width: 48px; height: 48px; }
body.pc .act:hover:not(.lock) { border-color: var(--accent); filter: brightness(1.2); }
body.pc #cote > button:hover, body.pc .grp:hover, body.pc .seg button:hover, body.pc .fac:hover { filter: brightness(1.25); }
body.pc #toast { bottom: 150px; }
body.pc .boite { max-width: 520px; }
body.pc .factions .fac { min-height: 160px; }
details .sousTitre { margin: 10px 0 0; font-weight: 700; font-family: var(--titre); color: var(--accent2); }

/* Paysage sur téléphone : panneau en une seule rangée, boutons latéraux sur deux colonnes */
@media (orientation: landscape) and (max-height: 500px) {
  #hud { padding-top: calc(3px + var(--st)); padding-bottom: 3px; }
  .res { font-size: 15px; padding: 1px 8px 1px 5px; }
  .res .ic-c, .res .ic-g, .ico { width: 18px; height: 18px; }
  #bPause { height: 30px; }
  #panneau { flex-direction: row; align-items: center; min-height: 0; padding-top: 5px; padding-bottom: calc(5px + var(--sb)); gap: 8px; }
  #pInfo { flex: 0 0 232px; min-height: 0; align-self: stretch; }
  #pInfo .barre { flex-basis: 80px; }
  #pInfo .indice { white-space: normal; font-size: 12px; }
  #pActions { flex: 1; padding: 0; }
  .act { min-height: 66px; width: 66px; font-size: 10.5px; }
  .act img { width: 34px; height: 34px; }
  .act.puce { width: 58px; min-height: 60px; }
  .act.puce .nb { top: 26px; }
  .act.boucle .sym { line-height: 34px; height: 35px; font-size: 24px; }
  #cote, #mmCadre, #placement { top: calc(44px + var(--st)); }
  #cote { display: grid; grid-template-columns: 54px 54px; gap: 4px; }
  #cote > button { height: 40px; width: 54px; font-size: 9px; }
  #cote > button svg { width: 15px; height: 15px; }
  .groupes { grid-column: 1 / span 2; flex-direction: row; gap: 4px; margin-top: 0; }
  .grp { flex: 1; width: auto; height: 32px; font-size: 14px; }
  .grp.plein::after { display: none; }
  #mmCadre { width: 104px; height: 104px; }
  #toast { bottom: calc(92px + var(--sb)); }
  .ecran { align-items: flex-start; }
}
