:root {
  --fond: #1d2614;
  --panneau: rgba(22, 24, 30, 0.86);
  --bord: rgba(255, 255, 255, 0.13);
  --texte: #f2eee4;
  --discret: #aab0a0;
  --accent: #e8b23d;
  --accent-fonce: #b9821b;
  --danger: #e25b4b;
  --ok: #7cc96b;
  --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(60, 70, 30, 0.7), rgba(12, 14, 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(460px, 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: 50px; letter-spacing: 6px; 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; text-align: center; }
.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); }
.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:disabled { opacity: 0.45; cursor: default; }
.btn.enorme { font-size: 28px; padding: 18px; letter-spacing: 2px; }
.btn.petit { padding: 6px 10px; font-size: 13px; }
.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: 5px; }
.case { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.case input { width: 18px; height: 18px; }
.discret-case { color: var(--discret); font-size: 13px; justify-content: center; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#hud-haut, #annonce, #toasts, #fil, #hud-gauche { pointer-events: none !important; }
#hud-gauche { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); width: 200px;
  display: flex; flex-direction: column; gap: 5px; }
.ligne-res { display: flex; gap: 6px; }
.res { display: flex; align-items: center; gap: 6px; background: var(--panneau); border: 1px solid var(--bord); border-radius: 10px; padding: 5px 9px;
  font-weight: 700; font-variant-numeric: tabular-nums; flex: 1; }
.res i { width: 13px; height: 13px; border-radius: 50%; display: inline-block; background: var(--or); }
.res.armee i { background: #c9ccd2; border-radius: 3px; transform: rotate(45deg); width: 10px; height: 10px; }
.jauge { display: flex; align-items: center; gap: 6px; background: var(--panneau); border: 1px solid var(--bord); border-radius: 10px; padding: 4px 8px; font-size: 13px; }
.jauge > span { width: 20px; text-align: center; font-weight: 800; color: var(--accent); }
.jauge small { font-size: 11px; color: var(--discret); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.barre { position: relative; flex: 1; height: 9px; background: rgba(0, 0, 0, .5); border-radius: 5px; overflow: hidden; }
.barre > div { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--ok); border-radius: 5px; transition: width .2s; }
#barre-xp { top: auto; height: 3px; background: #8fb7ff; }
.petit-txt { font-size: 12px; color: var(--discret); text-shadow: 0 1px 2px #000; padding-left: 4px; }

#hud-haut { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 10px;
  font-size: 12px; color: var(--discret); background: rgba(0, 0, 0, .35); border-radius: 10px; padding: 3px 10px; white-space: nowrap; }
#hud-haut b { color: var(--texte); }
#fil { position: absolute; top: calc(34px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column;
  align-items: center; gap: 3px; width: min(520px, 50%); }
#fil div { background: rgba(0, 0, 0, .45); padding: 3px 10px; border-radius: 12px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  animation: fil 7s forwards; }
#fil b { font-weight: 700; filter: brightness(1.35); }
@keyframes fil { 0% { opacity: 0; } 6%, 80% { opacity: 1; } 100% { opacity: 0; } }

#invitations { position: absolute; top: calc(150px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 6px; width: 220px; }
.invit { background: rgba(30, 60, 30, .92); border: 1px solid var(--ok); border-radius: 10px; padding: 6px 8px; font-size: 12px; display: flex; flex-direction: column; gap: 5px; }
.invit .ligne { display: flex; gap: 6px; }
.invit .btn { padding: 5px 8px; font-size: 12px; flex: 1; }

#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: 180px; }
#minicarte { width: 180px; height: 180px; border: 1px solid var(--bord); border-radius: 8px; background: #26331a; touch-action: none; }
#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 h5 { margin: 4px 0 1px; 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; }
#classement-corps .vous { color: var(--accent); margin-top: 4px; }
#hud-boutons { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(196px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 7px; }
.btn.rond { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 18px; background: var(--panneau); }
.btn.rond.actif, .act.actif, .act-pc.actif { background: var(--ok); color: #102a0b; }
.btn.rond.coupe, .act.coupe, .act-pc.coupe { background: var(--danger); }

#barre { position: absolute; bottom: calc(10px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 6px; align-items: center;
  background: var(--panneau); border: 1px solid var(--bord); border-radius: 14px; padding: 6px; }
#barre .sep { width: 1px; align-self: stretch; background: var(--bord); margin: 0 3px; }
.act-pc { position: relative; width: 70px; height: 60px; border-radius: 10px; border: 2px solid transparent; background: rgba(255, 255, 255, .07); color: var(--texte);
  font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; overflow: hidden; }
.act-pc:hover { background: rgba(255, 255, 255, .14); }
.act-pc .ic { font-size: 20px; line-height: 1; }
.act-pc small { font-size: 11px; font-weight: 600; }
.act-pc kbd { position: absolute; top: 2px; right: 4px; font: 9px system-ui; color: var(--discret); }
.act-pc.choisi { border-color: var(--accent); }
.cd { position: absolute; inset: 0; background: rgba(0, 0, 0, .62); color: #fff; font-style: normal; font-weight: 800; font-size: 18px; display: none; align-items: center; justify-content: center; border-radius: inherit; }
.cd.on { display: flex; }

.panneau { position: absolute; background: var(--panneau); border: 1px solid var(--bord); border-radius: 12px; padding: 10px 12px; font-size: 13px; z-index: 3; }
.panneau h4 { margin: 0 0 8px; font-size: 15px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.fermer { all: unset; cursor: pointer; padding: 2px 8px; font-size: 16px; }
#panneau-amel { bottom: calc(86px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(560px, calc(100% - 16px)); max-height: calc(100% - 200px); overflow-y: auto; }
#liste-amel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.amel { font: inherit; text-align: left; color: var(--texte); background: rgba(255, 255, 255, .07); border: 1px solid var(--bord); border-radius: 9px; padding: 6px 8px;
  cursor: pointer; display: flex; flex-direction: column; gap: 2px; touch-action: manipulation; }
.amel:hover { background: rgba(255, 255, 255, .14); }
.amel .t { font-weight: 700; display: flex; justify-content: space-between; gap: 4px; }
.amel .p { color: var(--or); font-size: 12px; font-weight: 700; }
.amel .d { color: var(--discret); font-size: 11px; line-height: 1.25; }
.amel .niv { color: var(--or); letter-spacing: 1px; font-size: 11px; }
.amel.trop-cher { opacity: .55; }
.amel.max { opacity: .45; cursor: default; }
#panneau-joueur { top: calc(120px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(300px, calc(100% - 16px)); display: flex; flex-direction: column; gap: 7px; }
#panneau-joueur .pastille { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
#panneau-joueur .etat { color: var(--discret); }
#panneau-joueur .ligne { display: flex; gap: 6px; }
#panneau-joueur .ligne .btn { flex: 1; padding: 8px; font-size: 13px; }

#ecran-elimine { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(380px, calc(100% - 24px)); z-index: 8; }
#ecran-elimine h2 { color: var(--danger); }
#elimine-stats { width: 100%; border-collapse: collapse; font-size: 14px; }
#elimine-stats td { padding: 5px 4px; border-bottom: 1px solid var(--bord); }
#elimine-stats td:last-child { text-align: right; font-weight: 700; }
#annonce { position: absolute; top: 28%; left: 0; right: 0; text-align: center; font-size: 40px; 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: 17px; color: var(--texte); font-weight: 600; }
#toasts { position: absolute; bottom: calc(100px + 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.8s 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: 9; }

/* Commandes tactiles : joystick fixe en bas à gauche, boutons ronds en bas à droite */
.tactile { display: none; position: absolute; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 2; }
body.tactile-on .tactile { display: flex; }
body.tactile-on #actions { display: grid; }
body.tactile-on .pc-seulement { display: none !important; }
#stick { left: calc(18px + env(safe-area-inset-left)); width: 128px; height: 128px; 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: 52px; height: 52px; border-radius: 50%; background: rgba(255, 255, 255, .45); pointer-events: none; }
#actions { right: calc(12px + env(safe-area-inset-right)); grid-template-columns: repeat(3, 56px); gap: 8px; }
.act { position: relative; width: 56px; height: 56px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .45); background: rgba(22, 24, 30, .78); color: #fff;
  font-size: 21px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; touch-action: manipulation; padding: 0; }
.act small { font-size: 8.5px; font-weight: 600; margin-top: 3px; opacity: .9; max-width: 52px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.act.rouge { background: rgba(190, 55, 40, .85); }
.act.choisi { border-color: var(--accent); }
body.gaucher #stick { left: auto; right: calc(18px + env(safe-area-inset-right)); }
body.gaucher #actions { right: auto; left: calc(12px + env(safe-area-inset-left)); }
body.tactile-on #panneau-amel { bottom: auto; top: calc(60px + env(safe-area-inset-top)); max-height: calc(100% - 290px); }
body.tactile-on #toasts { bottom: calc(215px + env(safe-area-inset-bottom)); }

/* Petits écrans */
@media (max-width: 700px), (max-height: 520px) {
  h1 { font-size: 38px; letter-spacing: 3px; }
  #hud-gauche { width: 150px; gap: 4px; }
  .res { padding: 4px 7px; font-size: 13px; }
  .jauge { padding: 3px 6px; font-size: 12px; }
  .jauge small { display: none; }
  #colonne-droite { width: 116px; }
  #minicarte { width: 116px; height: 116px; }
  #hud-boutons { right: calc(130px + env(safe-area-inset-right)); gap: 6px; }
  .btn.rond { width: 38px; height: 38px; font-size: 16px; }
  #hud-haut { top: auto; bottom: calc(206px + env(safe-area-inset-bottom)); font-size: 11px; }
  #fil { top: calc(128px + env(safe-area-inset-top)); left: 8px; transform: none; width: calc(100% - 16px); align-items: flex-start; }
  #fil div { font-size: 11px; }
  #invitations { top: calc(190px + env(safe-area-inset-top)); width: 200px; }
  #classement { font-size: 11px; }
  .replie-mobile #classement-corps { display: none; }
  .replie-mobile.ouvert #classement-corps { display: block; }
  #liste-amel { grid-template-columns: repeat(2, 1fr); }
  #panneau-joueur { top: calc(150px + env(safe-area-inset-top)); }
  #annonce { font-size: 30px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #hud-haut { bottom: auto; top: calc(8px + env(safe-area-inset-top)); }
  #fil { top: calc(30px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: 40%; align-items: center; }
  #minicarte { width: 96px; height: 96px; }
  #colonne-droite { width: 96px; }
  #hud-boutons { right: calc(110px + env(safe-area-inset-right)); }
  body.tactile-on #toasts { bottom: calc(20px + env(safe-area-inset-bottom)); }
  #panneau-joueur { top: calc(40px + env(safe-area-inset-top)); }
}
@media (max-width: 700px) {
  .amel .d { display: none; }
  .amel { padding: 5px 7px; }
  #panneau-amel h4 { margin-bottom: 5px; }
  #txt-selection { display: none; }
  body.tactile-on #toasts { bottom: calc(236px + env(safe-area-inset-bottom)); }
}

#ecran-micro { background: rgba(0, 0, 0, 0.45); z-index: 30; }
#ecran-micro h2 { text-align: center; }
.micro-choix { display: flex; gap: 8px; }
.micro-choix .btn { flex: 1; }
