:root {
  --fond: #0c2b3c;
  --panneau: rgba(14, 26, 34, 0.86);
  --bord: rgba(255, 255, 255, 0.13);
  --texte: #f3efe2;
  --discret: #a8b7bd;
  --accent: #f0b23e;
  --accent-fonce: #b97a16;
  --danger: #e25b4b;
  --ok: #7cc96b;
  --bois: #b07a45;
  --pierre: #9aa3ab;
  --or: #f2c94c;
  --titan: #e0583a;
}
* { 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(20, 80, 100, 0.55), rgba(5, 18, 26, 0.92)); overflow-y: auto; z-index: 10; }
.ecran.visible { display: flex; }
.ecran.voile { background: rgba(5, 14, 20, 0.72); }
.carte-ui { background: var(--panneau); border: 1px solid var(--bord); border-radius: 16px; padding: 20px; width: min(440px, 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; gap: 12px; margin: auto; }
.carte-ui.large { width: min(640px, 100%); }
h1 { margin: 0; font-size: 50px; line-height: 0.95; 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; }
.sous-titre { margin: -4px 0 4px; text-align: center; color: var(--discret); }
.discret { color: var(--discret); font-size: 13px; margin: 0; text-align: center; }
.regle-jour { margin: 0; text-align: center; font-size: 13px; color: #cfe6ef; background: rgba(255,255,255,.06); border-radius: 8px; padding: 6px 8px; }
.regle-jour:empty { display: none; }
.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.enorme { font-size: 28px; padding: 18px; letter-spacing: 2px; }
.btn:disabled { opacity: 0.45; cursor: default; }
.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); }
.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, #hud-gauche, #fil, #bandeau { pointer-events: none !important; }
#hud-haut { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; gap: 10px; align-items: center;
  background: var(--panneau); border: 1px solid var(--bord); border-radius: 12px; padding: 6px 13px; font-weight: 700; white-space: nowrap; font-size: 15px; }
#hud-minuteur { color: var(--accent); font-variant-numeric: tabular-nums; }
#hud-compte { font-size: 13px; color: var(--discret); font-weight: 600; }
#hud-compte .t { color: #ff9a80; }
#hud-gauche { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 6px; width: 230px; }
#hud-ressources { display: flex; gap: 6px; }
.res { display: flex; align-items: center; gap: 5px; background: var(--panneau); border: 1px solid var(--bord); border-radius: 10px; padding: 5px 9px;
  font-weight: 700; font-variant-numeric: tabular-nums; min-width: 58px; }
.res i { width: 13px; height: 13px; border-radius: 3px; display: inline-block; flex: none; }
.res.bois i { background: var(--bois); }
.res.pierre i { background: var(--pierre); border-radius: 50% 30%; }
.res.or i { background: var(--or); border-radius: 50%; }
#hud-titan { background: var(--panneau); border: 1px solid var(--bord); border-radius: 10px; padding: 6px 8px; display: flex; flex-direction: column; gap: 5px; }
.titan-ligne { display: flex; justify-content: space-between; align-items: center; color: #ffb39e; }
.titan-ligne .res { border: 0; padding: 0; background: none; min-width: 0; }
.jauge { position: relative; height: 12px; border-radius: 6px; background: rgba(0,0,0,.55); border: 1px solid var(--bord); overflow: hidden; }
.jauge i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: linear-gradient(#8de07a, #4ca33b); transition: width .2s; }
.jauge.xp { height: 7px; } .jauge.xp i { background: linear-gradient(#ffe08a, #e0a52a); }
.jauge span { position: absolute; inset: 0; font-size: 9px; line-height: 11px; text-align: center; font-weight: 700; text-shadow: 0 1px 2px #000; }
#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: 4px; width: 150px; align-items: flex-end; }
#minicarte { width: 150px; height: 150px; border: 1px solid var(--bord); border-radius: 10px; background: #0c3a52; }
.discret-mini { font-size: 11px; color: var(--discret); text-align: right; text-shadow: 0 1px 2px #000; line-height: 1.3; }
#hud-boutons { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(166px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; }

#fil { position: absolute; top: calc(50px + 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 6s forwards; }
#fil b { color: var(--accent); } #fil .t { color: #ff9a80; }
@keyframes fil { 0% { opacity: 0; } 6%, 80% { opacity: 1; } 100% { opacity: 0; } }

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

/* Barre de construction */
#barre-construction, #barre-sorts { position: absolute; bottom: calc(10px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 5px;
  background: var(--panneau); border: 1px solid var(--bord); border-radius: 14px; padding: 5px; max-width: calc(100% - 16px); }
.bat { position: relative; width: 66px; padding: 3px 1px 4px; 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: 32px; height: 32px; }
.bat .n { font-size: 11px; font-weight: 700; white-space: nowrap; }
.bat .c { font-size: 10px; color: var(--discret); white-space: nowrap; }
.bat .c .b { color: #e0a46b; } .bat .c .p { color: #c4ccd2; } .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(240, 178, 62, 0.2); }
.bat.trop-cher { opacity: 0.42; }
.sort { position: relative; width: 74px; height: 64px; border-radius: 12px; border: 2px solid rgba(255,255,255,.2); background: rgba(120, 40, 20, .55); color: #fff;
  font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; touch-action: manipulation; padding: 0; }
.sort .i { font-size: 22px; line-height: 1; } .sort .n { font-size: 10px; font-weight: 700; margin-top: 3px; }
.sort .touche { position: absolute; top: 2px; left: 5px; font-size: 10px; color: #ddd; }
.sort .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.65); }
.sort .cdt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 800; text-shadow: 0 1px 3px #000; }
.sort.boutique-btn { background: rgba(120, 90, 20, .6); }

#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: 250px; max-width: calc(100% - 16px); 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; }

#boutique { position: absolute; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); width: min(380px, calc(100% - 16px)); gap: 8px; padding: 14px; }
#boutique h3 { display: flex; justify-content: space-between; }
.objet { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.05); border-radius: 10px; padding: 6px 8px; }
.objet .i { font-size: 22px; width: 28px; text-align: center; }
.objet .d { flex: 1; font-size: 12px; color: var(--discret); } .objet .d b { color: var(--texte); font-size: 13px; }
.objet .btn { padding: 7px 10px; font-size: 12px; flex: none; }

#annonce { position: absolute; top: 28%; left: 0; right: 0; text-align: center; font-size: 42px; 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.rouge { color: #ff6a4a; }
#annonce small { display: block; font-size: 18px; color: var(--texte); font-weight: 600; margin-top: 4px; }
#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 de manche */
#fin-titre { text-align: center; font-size: 30px; }
#fin-titre.bleu { color: #8fd7ff; } #fin-titre.rouge { color: #ff7a5a; }
#fin-resume { text-align: center; margin: 0; color: var(--discret); }
#fin-classements { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#fin-classements h4 { margin: 0 0 4px; font-size: 13px; color: var(--discret); }
#fin-classements ol { margin: 0; padding-left: 20px; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
#fin-classements li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#fin-classements li.moi { color: var(--accent); font-weight: 700; }
#fin-classements .v { color: var(--discret); font-size: 11px; }
#ad-slot { min-height: 0; }

/* Commandes tactiles */
.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: 132px; height: 132px; 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: 54px; height: 54px; 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(2, 64px); gap: 9px; direction: rtl; align-items: end; }
.act { position: relative; direction: ltr; width: 64px; height: 64px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45); background: rgba(14,26,34,.78); color: #fff;
  font-size: 23px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; touch-action: manipulation; padding: 0; overflow: hidden; font-family: inherit; }
.act small { font-size: 9px; font-weight: 600; margin-top: 3px; opacity: .9; }
.act .cd { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.6); pointer-events: none; }
.act .cdt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 800; pointer-events: none; }
.act.choisi, .act.poser { background: rgba(240,178,62,.88); color: #2b1600; }
.act.ameliorer { background: rgba(124,201,107,.88); color: #102a0b; }
.act.sort { background: rgba(140,45,25,.82); }
.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(16px + env(safe-area-inset-left)); direction: ltr; }
body.tactile-on .pc-seulement { display: none; }
body.tactile-on #barre-sorts { display: none !important; }
body.tactile-on:not(.menu-constr) #barre-construction { display: none !important; }
body.tactile-on.menu-constr #barre-construction { bottom: calc(240px + env(safe-area-inset-bottom)); flex-wrap: wrap; justify-content: center; width: min(360px, calc(100% - 16px)); }
body.tactile-on #panneau-bat, body.tactile-on #boutique { bottom: calc(240px + env(safe-area-inset-bottom)); }
body.tactile-on #toasts { bottom: calc(250px + env(safe-area-inset-bottom)); }

@media (max-width: 700px), (max-height: 500px) {
  h1 { font-size: 40px; }
  #hud-haut { font-size: 12px; gap: 6px; padding: 4px 8px; top: calc(8px + env(safe-area-inset-top)); flex-wrap: wrap; justify-content: center; max-width: calc(100% - 250px); white-space: normal; }
  #hud-compte { font-size: 11px; }
  #hud-gauche { width: 150px; }
  #hud-ressources { flex-wrap: wrap; gap: 4px; }
  .res { min-width: 44px; padding: 4px 6px; font-size: 12px; }
  #colonne-droite { width: 92px; }
  #minicarte { width: 92px; height: 92px; }
  #hud-boutons { right: calc(104px + env(safe-area-inset-right)); top: calc(8px + env(safe-area-inset-top)); flex-direction: row; }
  #hud-haut { left: 50%; top: calc(108px + env(safe-area-inset-top)); max-width: calc(100% - 16px); }
  #fil { top: calc(150px + env(safe-area-inset-top)); }
  .discret-mini { font-size: 10px; max-width: 92px; }
  .suffixe { display: none; }
  #hud-haut { flex-wrap: nowrap; white-space: nowrap; }
  #fil div { font-size: 11px; }
  #bandeau { top: calc(200px + env(safe-area-inset-top)); font-size: 13px; }
  .bat { width: 62px; }
  #annonce { font-size: 30px; }
  #fin-classements { grid-template-columns: 1fr; }
}
@media (max-width: 380px) { .btn.rond { width: 38px; height: 38px; font-size: 16px; } #hud-boutons { right: calc(102px + env(safe-area-inset-right)); } }
@media (max-height: 500px) and (orientation: landscape) {
  #hud-haut { top: calc(8px + env(safe-area-inset-top)); max-width: calc(100% - 420px); }
  #fil { top: calc(42px + env(safe-area-inset-top)); }
  #bandeau { top: calc(70px + env(safe-area-inset-top)); }
  body.tactile-on.menu-constr #barre-construction { bottom: calc(10px + env(safe-area-inset-bottom)); width: min(440px, 52%); }
  body.tactile-on #panneau-bat, body.tactile-on #boutique { bottom: calc(10px + env(safe-area-inset-bottom)); }
  body.tactile-on #toasts { bottom: calc(90px + 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; }
