:root {
  --fond: #10141c;
  --panneau: rgba(16, 20, 28, 0.86);
  --bord: rgba(255, 255, 255, 0.12);
  --texte: #eee8da;
  --discret: #a3a9b5;
  --accent: #e0a443;
  --accent-fonce: #a86f1c;
  --danger: #e25b4b;
  --ok: #7cc96b;
}
* { 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, 50, 70, 0.55), rgba(6, 8, 12, 0.92)); overflow-y: auto; z-index: 10; }
.ecran.visible { display: flex; }
.carte-ui { background: var(--panneau); border: 1px solid var(--bord); border-radius: 16px; padding: 20px; 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); font-family: Georgia, "Times New Roman", serif;
  text-shadow: 0 3px 0 #5b3a10, 0 8px 18px rgba(0, 0, 0, 0.7); }
h2, h3, h4 { margin: 0; }
.sous-titre { margin: -6px 0 4px; text-align: center; color: var(--discret); }
.discret { color: var(--discret); font-size: 13px; margin: 0; text-align: center; }
.regle-jour { font-style: italic; }
.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: #261400; border-color: #f2c47a; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.enorme { font-size: 26px; padding: 16px; letter-spacing: 2px; }
.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; }
.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; }

.choix-classe { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.choix-classe button { font: inherit; color: var(--texte); background: rgba(255, 255, 255, 0.06); border: 2px solid transparent; border-radius: 10px;
  padding: 8px 2px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; touch-action: manipulation; }
.choix-classe button i { width: 22px; height: 22px; border-radius: 50%; display: block; box-shadow: 0 0 0 2px rgba(0,0,0,.4); }
.choix-classe button b { font-size: 12px; }
.choix-classe button small { font-size: 10px; color: var(--discret); line-height: 1.2; text-align: center; padding: 0 2px; }
.choix-classe button.choisi { border-color: var(--accent); background: rgba(224, 164, 67, 0.18); }
.choix-classe.mini button small { display: none; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#hud-haut, #annonce, #toasts, #fil, #hud-moi { pointer-events: none !important; }
#hud-haut { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); background: var(--panneau);
  border: 1px solid var(--bord); border-radius: 12px; padding: 5px 14px; font-weight: 700; white-space: nowrap; text-align: center; }
.ligne-haut { display: flex; gap: 12px; justify-content: center; font-size: 15px; }
.ligne-haut.petite { font-size: 12px; font-weight: 600; color: var(--discret); }
#hud-chrono { color: var(--accent); font-variant-numeric: tabular-nums; }
#hud-prochaine { color: var(--discret); font-weight: 600; }
.alerte { color: var(--danger) !important; }
.moyen { color: #f0c05a !important; }
#hud-moi { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); width: 220px; background: var(--panneau);
  border: 1px solid var(--bord); border-radius: 10px; padding: 6px 8px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.moi-ligne { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.moi-ligne #moi-mat { margin-left: auto; font-variant-numeric: tabular-nums; }
.pastille-classe { width: 14px; height: 14px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 2px rgba(0,0,0,.4); }
.barre { height: 7px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; }
.barre i { display: block; height: 100%; width: 0; transition: width .2s; }
.barre.pv i { background: linear-gradient(90deg, #d64535, #7cc96b); }
.barre.xp { height: 4px; } .barre.xp i { background: #8ab4ff; }
.barre.releve { width: 200px; margin: 0 auto; } .barre.releve i { background: #f4d35e; }
.discret-mini { font-size: 11px; color: var(--discret); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#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: 200px; }
#minicarte { width: 200px; height: 140px; border: 1px solid var(--bord); border-radius: 8px; background: #000; }
#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 ol { margin: 0; padding-left: 20px; }
#classement-corps li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#classement-corps li.moi { color: var(--accent); font-weight: 700; }
#classement-corps .rang { color: var(--discret); margin-top: 3px; }
#hud-boutons { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(216px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; }
.btn.rond { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 19px; background: var(--panneau); }
.btn.rond.actif { background: var(--ok); } .btn.rond.coupe { background: var(--danger); }

#fil { position: absolute; top: calc(64px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; width: max-content; max-width: calc(100% - 440px); }
#fil div { background: rgba(0,0,0,.5); padding: 3px 10px; border-radius: 12px; font-size: 12px; animation: fil 6s forwards; text-align: center; }
#fil div.alerte { color: #ffb3a7 !important; background: rgba(110, 20, 15, .6); }
#fil div.heros { color: #ffe08a; }
@keyframes fil { 0% { opacity: 0; } 6%, 80% { opacity: 1; } 100% { opacity: 0; } }

#barre-pc { 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: 12px; padding: 6px; pointer-events: none !important; }
.touche-pc { position: relative; display: flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 8px; background: rgba(255,255,255,.06); font-size: 13px; overflow: hidden; }
.touche-pc kbd { font: inherit; font-weight: 800; color: var(--accent); }
.recharge { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); width: 0; }
body:not(.classe-ingenieur) .ingenieur-seul { display: none !important; }

#bandeau-mort { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(400px, calc(100% - 32px)); text-align: center;
  background: rgba(70, 20, 20, 0.9); border: 1px solid rgba(255,255,255,.15); border-radius: 12px; padding: 12px; font-size: 14px; display: flex; flex-direction: column; gap: 8px; }
#bandeau-mort b { font-size: 18px; }
#annonce { position: absolute; top: 26%; left: 0; right: 0; text-align: center; font-size: 42px; font-weight: 900; color: var(--accent); font-family: Georgia, serif;
  text-shadow: 0 3px 0 #4a2a06, 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; font-family: system-ui, sans-serif; }
#toasts { position: absolute; bottom: calc(70px + 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(380px, calc(100% - 32px)); z-index: 6; max-height: calc(100% - 32px); overflow-y: auto; }
#ecran-fin { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100% - 24px)); z-index: 7; max-height: calc(100% - 24px); overflow-y: auto; }
#fin-titre { text-align: center; font-size: 34px; font-family: Georgia, serif; }
#fin-titre.victoire { color: var(--ok); } #fin-titre.defaite { color: var(--danger); }
.tableau { max-height: 300px; overflow-y: auto; }
#fin-heros { width: 100%; border-collapse: collapse; font-size: 13px; }
#fin-heros th, #fin-heros td { padding: 4px; text-align: center; border-bottom: 1px solid var(--bord); }
#fin-heros td:nth-child(2), #fin-heros th:nth-child(2) { text-align: left; }
#fin-heros tr.moi { color: var(--accent); font-weight: 700; }

/* 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,.1);
  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(16px + env(safe-area-inset-right)); grid-template-columns: repeat(3, 62px); grid-template-rows: repeat(2, 62px); gap: 8px; direction: rtl; align-items: end; }
.act { position: relative; direction: ltr; width: 62px; height: 62px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45); background: rgba(16,20,28,.78); color: #fff;
  font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; touch-action: none; padding: 0; overflow: hidden; }
.act small { font-size: 8.5px; font-weight: 600; margin-top: 3px; opacity: .9; white-space: nowrap; }
.act.gros { background: rgba(200, 70, 50, .85); grid-row: span 2; width: 76px; height: 76px; align-self: center; justify-self: center; font-size: 28px; }
.act.enfonce { filter: brightness(1.4); transform: scale(.95); }
.act.actif { background: var(--ok); } .act.coupe { background: var(--danger); }
.act .recharge { height: 100%; bottom: 0; background: rgba(0,0,0,.55); width: 100%; transform-origin: bottom; transform: scaleY(0); }
#act-comp { background: rgba(70, 90, 160, .85); }
#act-reparer { background: rgba(160, 110, 40, .85); }
#menu-constr { position: absolute; right: calc(16px + env(safe-area-inset-right)); bottom: calc(170px + env(safe-area-inset-bottom)); display: flex; gap: 8px; z-index: 3; }
.act.petit { width: 58px; height: 58px; font-size: 20px; background: rgba(160, 110, 40, .9); }
body.gaucher #stick { left: auto; right: calc(22px + env(safe-area-inset-right)); }
body.gaucher #actions { right: auto; left: calc(16px + env(safe-area-inset-left)); direction: ltr; }
body.gaucher #menu-constr { right: auto; left: calc(16px + env(safe-area-inset-left)); }
body.tactile-on .pc-seulement { display: none !important; }
body.tactile-on #toasts { bottom: calc(180px + env(safe-area-inset-bottom)); }

/* Petits écrans */
@media (max-width: 760px), (max-height: 520px) {
  h1 { font-size: 40px; letter-spacing: 4px; }
  #hud-haut { padding: 4px 8px; top: calc(6px + env(safe-area-inset-top)); left: calc(6px + env(safe-area-inset-left)); transform: none; max-width: calc(100% - 150px); }
  .ligne-haut { font-size: 13px; gap: 8px; justify-content: flex-start; } .ligne-haut.petite { font-size: 10.5px; gap: 6px; flex-wrap: wrap; }
  #hud-prochaine { display: none; }
  #hud-moi { top: auto; bottom: calc(176px + env(safe-area-inset-bottom)); width: 160px; font-size: 12px; padding: 4px 6px; }
  body.gaucher #hud-moi { left: auto; right: calc(8px + env(safe-area-inset-right)); }
  #fil { top: calc(60px + env(safe-area-inset-top)); left: 8px; transform: none; align-items: flex-start; max-width: calc(100% - 150px); }
  #fil div { font-size: 11px; }
  #colonne-droite { width: 128px; top: calc(6px + env(safe-area-inset-top)); right: calc(6px + env(safe-area-inset-right)); }
  #minicarte { width: 128px; height: 90px; }
  #classement { font-size: 11px; }
  #hud-boutons { right: calc(6px + env(safe-area-inset-right)); top: auto; bottom: calc(176px + env(safe-area-inset-bottom)); }
  body.gaucher #hud-boutons { right: auto; left: calc(6px + env(safe-area-inset-left)); }
  #annonce { font-size: 28px; }
  .choix-classe button small { display: none; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #hud-moi { bottom: auto; top: calc(56px + env(safe-area-inset-top)); }
  #hud-boutons { top: calc(110px + env(safe-area-inset-top)); bottom: auto; right: calc(140px + env(safe-area-inset-right)); }
  #fil { left: 50%; transform: translateX(-50%); align-items: center; top: calc(8px + env(safe-area-inset-top)); max-width: 40%; }
  #hud-haut { left: calc(164px + env(safe-area-inset-left)); }
  #menu-constr { bottom: calc(160px + 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; }
