:root {
  --fond: #13200f;
  --panneau: rgba(20, 28, 18, 0.88);
  --bord: rgba(255, 255, 255, 0.12);
  --texte: #f1eee2;
  --discret: #a9b39c;
  --accent: #e8a33d;
  --accent-fonce: #b9761b;
  --danger: #e25b4b;
  --ok: #7cc96b;
  --bois: #b07a45;
  --or: #f2c94c;
}
* { 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; -webkit-user-select: none; user-select: none; }
canvas#jeu { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.cache { display: none !important; }

.ecran { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at center, rgba(40, 70, 30, 0.75), rgba(10, 16, 8, 0.95)); overflow-y: auto; z-index: 10; }
.ecran.visible { display: flex; }
.carte-ui { background: var(--panneau); border: 1px solid var(--bord); border-radius: 16px; padding: 22px; width: min(440px, 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; gap: 12px; margin: auto; }
h1 { margin: 0; font-size: 56px; letter-spacing: 10px; text-align: center; color: var(--accent);
  text-shadow: 0 4px 0 #6b3f12, 0 8px 18px rgba(0, 0, 0, 0.6); }
h2, h3 { margin: 0; }
h2 small { font-size: 13px; color: var(--discret); font-weight: normal; }
.sous-titre { margin: -6px 0 6px; text-align: center; color: var(--discret); }
.discret { color: var(--discret); font-size: 13px; margin: 0; text-align: center; }
.champ { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--discret); }
input { font: inherit; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--bord); background: rgba(0, 0, 0, 0.35);
  color: var(--texte); outline: none; min-width: 0; -webkit-user-select: text; user-select: text; }
input:focus { border-color: var(--accent); }
.ligne { display: flex; gap: 8px; }
.ligne > * { flex: 1; }
.btn { font: inherit; font-weight: 600; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--bord); cursor: pointer;
  background: rgba(255, 255, 255, 0.08); color: var(--texte); transition: transform 0.08s, background 0.15s; touch-action: manipulation; }
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn:active { transform: scale(0.97); }
.btn.principal { background: linear-gradient(var(--accent), var(--accent-fonce)); color: #2b1600; border-color: #f5c06f; }
.btn.principal:hover { filter: brightness(1.08); }
.btn.petit { padding: 8px 10px; font-size: 13px; flex: none; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.actif { background: var(--ok); color: #102a0b; }
.btn.coupe { background: var(--danger); color: #fff; }
.regles { font-size: 14px; color: var(--discret); }
.regles summary { cursor: pointer; color: var(--texte); }
.regles ul { padding-left: 18px; margin: 8px 0 0; display: flex; flex-direction: column; gap: 4px; }
.invitation { display: flex; gap: 8px; }
.invitation input { flex: 1; font-size: 13px; }
.case { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.case input { width: 18px; height: 18px; }

.liste-joueurs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.liste-joueurs li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: rgba(0, 0, 0, 0.25); border-radius: 8px; }
.liste-joueurs .pastille { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.4); transition: box-shadow 0.1s; }
.liste-joueurs .parle .pastille { box-shadow: 0 0 0 3px var(--ok), 0 0 10px var(--ok); }
.liste-joueurs .nom { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.liste-joueurs .etiq { font-size: 11px; color: var(--discret); }
.liste-joueurs .mort .nom { opacity: 0.5; text-decoration: line-through; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#hud-haut, #annonce, #toasts, #hud-ressources, #hud-joueurs, #fil { pointer-events: none !important; }
#hud-haut { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 12px;
  background: var(--panneau); border: 1px solid var(--bord); border-radius: 12px; padding: 7px 14px; font-weight: 700; white-space: nowrap; font-size: 15px; }
#hud-minuteur { color: var(--accent); font-variant-numeric: tabular-nums; }
#hud-kodos { color: #e9a08f; }
#hud-ressources { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); display: flex; gap: 8px; }
.res { display: flex; align-items: center; gap: 6px; background: var(--panneau); border: 1px solid var(--bord); border-radius: 10px; padding: 6px 10px;
  font-weight: 700; font-variant-numeric: tabular-nums; min-width: 64px; }
.res i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.res.bois i { background: var(--bois); }
.res.or i { background: var(--or); border-radius: 50%; }
#hud-joueurs { position: absolute; top: calc(52px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); width: 170px; gap: 4px; }
#hud-joueurs li { padding: 4px 8px; background: rgba(0, 0, 0, 0.45); font-size: 13px; }
#colonne-droite { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 6px; width: 192px; pointer-events: none; }
#colonne-droite > * { pointer-events: auto; }
#minicarte { width: 192px; height: 128px; border: 1px solid var(--bord); border-radius: 8px; background: #000; }
#hud-boutons { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(208px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; }
.btn.rond { width: 46px; height: 46px; padding: 0; border-radius: 50%; font-size: 20px; background: var(--panneau); }
.btn.rond.actif { background: var(--ok); }
.btn.rond.coupe { background: var(--danger); }
#barre-construction { position: absolute; bottom: calc(10px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 6px;
  background: var(--panneau); border: 1px solid var(--bord); border-radius: 14px; padding: 6px; }
.bat { position: relative; width: 74px; padding: 4px 2px 5px; border-radius: 10px; border: 2px solid transparent; background: rgba(255, 255, 255, 0.06);
  color: var(--texte); font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; touch-action: manipulation; }
.bat canvas { width: 36px; height: 36px; }
.bat .n { font-size: 12px; font-weight: 700; }
.bat .c { font-size: 11px; color: var(--discret); white-space: nowrap; }
.bat .c .b { color: #e0a46b; } .bat .c .o { color: var(--or); }
.bat .touche { position: absolute; top: 2px; left: 5px; font-size: 10px; color: var(--discret); }
.bat.choisi { border-color: var(--accent); background: rgba(232, 163, 61, 0.2); }
.bat.trop-cher { opacity: 0.45; }
#bandeau-mort { position: absolute; top: calc(56px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(520px, calc(100% - 32px));
  text-align: center; background: rgba(120, 30, 25, 0.85); border-radius: 10px; padding: 8px 12px; font-size: 14px; }
#annonce { position: absolute; top: 30%; left: 0; right: 0; text-align: center; font-size: 44px; font-weight: 900; color: var(--accent);
  text-shadow: 0 3px 0 #5a2f08, 0 6px 20px #000; opacity: 0; transition: opacity 0.4s; padding: 0 16px; }
#annonce.visible { opacity: 1; }
#annonce small { display: block; font-size: 18px; color: var(--texte); font-weight: 600; }
#toasts { position: absolute; bottom: calc(110px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column;
  align-items: center; gap: 6px; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--panneau); border: 1px solid var(--bord); border-radius: 8px; padding: 6px 12px; font-size: 14px; animation: toast 2.6s forwards; text-align: center; }
.toast.erreur { border-color: var(--danger); }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }
#menu-jeu { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(320px, calc(100% - 32px)); z-index: 6; }

#fin-titre { text-align: center; font-size: 34px; }
#fin-titre.victoire { color: var(--ok); }
#fin-titre.defaite { color: var(--danger); }
#fin-resume { text-align: center; margin: 0; color: var(--discret); }
#fin-stats { width: 100%; border-collapse: collapse; font-size: 13px; }
#fin-stats th, #fin-stats td { padding: 5px 4px; text-align: center; border-bottom: 1px solid var(--bord); }
#fin-stats td:first-child, #fin-stats th:first-child { text-align: left; }
#ad-slot { min-height: 0; }


.btn.enorme { font-size: 26px; padding: 18px; letter-spacing: 2px; }
.secondaire { font-size: 14px; color: var(--discret); }
.secondaire summary { cursor: pointer; text-align: center; }
.pile { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.discret-case { color: var(--discret); font-size: 13px; }
.res.bats i { background: #9ea4aa; border-radius: 2px; }

#fil { position: absolute; top: calc(52px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; }
#fil div { background: rgba(0,0,0,.45); padding: 3px 10px; border-radius: 12px; font-size: 12px; white-space: nowrap; animation: fil 5s forwards; }
#fil b { color: var(--accent); }
@keyframes fil { 0% { opacity: 0; } 8%, 75% { opacity: 1; } 100% { opacity: 0; } }

#classement { background: var(--panneau); border: 1px solid var(--bord); border-radius: 8px; font-size: 12px; overflow: hidden; }
#classement-titre { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 5px 8px; font-weight: 700; cursor: pointer; }
#classement.replie #classement-corps { display: none; }
#classement-corps { padding: 0 8px 6px; }
#classement-corps h4 { margin: 4px 0 2px; font-size: 11px; color: var(--discret); font-weight: 600; }
#classement-corps ol { margin: 0; padding-left: 18px; }
#classement-corps li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#classement-corps li.moi { color: var(--accent); font-weight: 700; }

#bandeau-mort { position: absolute; top: calc(90px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(520px, calc(100% - 32px));
  text-align: center; background: rgba(60, 30, 80, 0.88); border-radius: 10px; padding: 10px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }

#panneau-bat { position: absolute; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--panneau);
  border: 1px solid var(--bord); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-width: 240px; font-size: 13px; }
#panneau-bat h4 { margin: 0; font-size: 15px; display: flex; justify-content: space-between; gap: 10px; }
#panneau-bat .stats { color: var(--discret); }
#panneau-bat .ligne .btn { padding: 8px 10px; font-size: 13px; }
.niv { color: var(--or); letter-spacing: 1px; }

/* Commandes tactiles : joystick fixe en bas à gauche, boutons ronds en bas à droite */
.tactile { display: none; position: absolute; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 2; }
body.tactile-on .tactile { display: flex; }
body.tactile-on #actions { display: grid; }
#stick { left: calc(22px + env(safe-area-inset-left)); width: 136px; height: 136px; border-radius: 50%; background: rgba(255,255,255,.12);
  border: 2px solid rgba(255,255,255,.3); align-items: center; justify-content: center; touch-action: none; }
#nub { width: 56px; height: 56px; border-radius: 50%; background: rgba(255,255,255,.45); pointer-events: none; }
#actions { right: calc(18px + env(safe-area-inset-right)); grid-template-columns: repeat(2, 66px); gap: 10px; direction: rtl; }
.act { direction: ltr; width: 66px; height: 66px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45); background: rgba(20,28,18,.75); color: #fff;
  font-size: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; touch-action: manipulation; padding: 0; }
.act small { font-size: 9px; font-weight: 600; margin-top: 3px; opacity: .85; }
.act.choisi, #act-poser { background: rgba(232,163,61,.85); color: #2b1600; }
#act-ameliorer { background: rgba(124,201,107,.85); color: #102a0b; }
.act.actif { background: var(--ok); } .act.coupe { background: var(--danger); }
body.gaucher #stick { left: auto; right: calc(22px + env(safe-area-inset-right)); }
body.gaucher #actions { right: auto; left: calc(18px + env(safe-area-inset-left)); direction: ltr; }
body.tactile-on .pc-seulement { display: none; }
body.tactile-on #barre-construction { display: none; }
body.tactile-on.menu-constr #barre-construction { display: flex; bottom: calc(176px + env(safe-area-inset-bottom)); }
body.tactile-on #panneau-bat { bottom: calc(176px + env(safe-area-inset-bottom)); }
body.tactile-on #toasts { bottom: calc(250px + env(safe-area-inset-bottom)); }

/* Petits écrans */
@media (max-width: 700px), (max-height: 500px) {
  h1 { font-size: 44px; }
  #hud-haut { font-size: 12px; gap: 6px; padding: 5px 9px; top: calc(48px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left));
    transform: none; flex-wrap: wrap; max-width: calc(100% - 140px); white-space: normal; }
  #fil { top: calc(100px + env(safe-area-inset-top)); left: 8px; transform: none; align-items: flex-start; }
  #hud-joueurs { display: none; }
  #colonne-droite { width: 120px; }
  #minicarte { width: 120px; height: 80px; }
  #hud-boutons { right: calc(136px + env(safe-area-inset-right)); }
  .res { min-width: 50px; padding: 5px 7px; font-size: 13px; }
  #barre-construction { left: 8px; right: 8px; transform: none; justify-content: space-between; gap: 4px; padding: 4px; }
  .bat { flex: 1; width: auto; min-width: 0; }
  .bat .touche { display: none; }
  .bat .n { font-size: 11px; }
  .bat .c { font-size: 10px; }
  #annonce { font-size: 32px; }
  #bandeau-mort { top: calc(150px + env(safe-area-inset-top)); font-size: 13px; }
  #classement { font-size: 11px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #hud-haut { top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); max-width: none; white-space: nowrap; }
  #fil { top: calc(44px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); align-items: center; }
  #bandeau-mort { top: calc(70px + env(safe-area-inset-top)); }
  body.tactile-on.menu-constr #barre-construction { left: 50%; right: auto; transform: translateX(-50%); width: min(440px, 60%); bottom: calc(10px + env(safe-area-inset-bottom)); }
  body.tactile-on #panneau-bat { bottom: calc(10px + env(safe-area-inset-bottom)); }
  body.tactile-on #toasts { bottom: calc(90px + env(safe-area-inset-bottom)); }
}
