:root {
  --encre: #2a241c;
  --creme: #f6efdf;
  --creme-t: rgba(246, 239, 223, 0.92);
  --vert: #3f7d4f;
  --vert-f: #2c5c39;
  --bois: #8a6440;
  --rouge: #b5493a;
  --ombre: 0 2px 10px rgba(30, 22, 12, 0.35);
  --marge: max(12px, env(safe-area-inset-left));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #24382c;
  font: 600 17px/1.3 "Trebuchet MS", "Segoe UI", system-ui, sans-serif; color: var(--encre);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none;
}
canvas#vue { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }
button {
  font: inherit; color: var(--encre); background: var(--creme-t); border: 0; border-radius: 12px; padding: 10px 14px; min-height: 48px;
  box-shadow: var(--ombre); cursor: pointer; touch-action: manipulation;
}
button:active { transform: scale(0.96); filter: brightness(0.92); }
button.vert { background: var(--vert); color: #fff; }
button[disabled] { opacity: 0.45; }

#jeu { position: fixed; inset: 0; pointer-events: none; }
#jeu button, #palette { pointer-events: auto; }

#haut { position: absolute; top: max(10px, env(safe-area-inset-top)); left: var(--marge); display: flex; gap: 8px; flex-wrap: wrap; max-width: 46vw; }
.pastille { background: var(--creme-t); border-radius: 10px; padding: 6px 12px; box-shadow: var(--ombre); font-size: 16px; white-space: nowrap; }
.pastille.alerte { background: var(--rouge); color: #fff; }

#but {
  position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(42vw, 520px);
  background: rgba(42, 36, 28, 0.82); color: #fff; border-radius: 12px; padding: 8px 14px; font-size: 17px; text-align: center; box-shadow: var(--ombre);
}
#but:empty { display: none; }
#barres { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 84px); left: var(--marge); width: 170px; display: grid; gap: 5px; }
.barre { position: relative; height: 22px; background: rgba(42, 36, 28, 0.6); border-radius: 8px; overflow: hidden; }
.barre i { position: absolute; inset: 0 auto 0 0; background: #6da544; width: 50%; transition: width 0.4s; }
.barre:nth-child(2) i { background: #4f9fc4; }
.barre span { position: absolute; z-index: 1; left: 8px; top: 1px; color: #fff; font-size: 14px; text-shadow: 0 1px 2px #000; }
#menus { position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; }
#menus button { font-size: 15px; padding: 8px 12px; min-height: 44px; }

#manette { position: absolute; left: calc(var(--marge) + 12px); bottom: calc(max(10px, env(safe-area-inset-bottom)) + 12px); width: 150px; height: 150px; border-radius: 50%; background: rgba(246, 239, 223, 0.22); border: 3px solid rgba(246, 239, 223, 0.55); }
#bouton-manette { position: absolute; left: 50%; top: 50%; width: 64px; height: 64px; margin: -32px; border-radius: 50%; background: rgba(246, 239, 223, 0.9); box-shadow: var(--ombre); }
@media (hover: hover) and (pointer: fine) { #manette { opacity: 0.45; } }

#ordres { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); width: 232px; display: grid; gap: 7px; }
.titre-ordres { justify-self: center; color: #fff; text-shadow: 0 1px 3px #000; font-size: 16px; }
.ligne { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.ordre { display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 54px; padding: 6px; font-size: 17px; }
.ordre svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.ordre.grand { background: var(--vert); color: #fff; font-size: 20px; min-height: 62px; }
.ordre.actif { outline: 4px solid #e2b93b; }
.appel { background: #e8d39a; min-height: 50px; }

#action {
  position: absolute; right: calc(max(12px, env(safe-area-inset-right)) + 244px); bottom: calc(max(10px, env(safe-area-inset-bottom)) + 62px); max-width: 26vw; min-height: 76px;
  background: #e2b93b; font-size: 19px; border-radius: 16px; padding: 10px 18px; animation: appelle 1.4s ease-in-out infinite;
}
@keyframes appelle { 50% { transform: scale(1.04); } }
#nom-bete { position: absolute; transform: translate(-50%, -100%); color: #fff; font-size: 16px; text-shadow: 0 1px 3px #000, 0 0 6px #000; white-space: nowrap; }
#bulle-ordre { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); font-size: 26px; color: #fff; text-shadow: 0 2px 6px #000; opacity: 0; transition: opacity 0.2s; white-space: nowrap; }
#bulle-ordre.vu { opacity: 1; }
#annonces { position: absolute; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 110px); transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; width: 54vw; }
.annonce { background: rgba(42, 36, 28, 0.85); color: #fff; padding: 7px 14px; border-radius: 10px; font-size: 16px; text-align: center; animation: entre 0.25s ease-out; }
.annonce.fort { background: var(--rouge); font-size: 19px; }
@keyframes entre { from { opacity: 0; transform: translateY(-8px); } }

#palette { position: absolute; left: 0; right: 0; bottom: 0; background: var(--creme); box-shadow: 0 -2px 14px rgba(0,0,0,0.4); padding: 8px max(10px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-bottom)); }
#pieces { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 6px; touch-action: pan-x; -webkit-overflow-scrolling: touch; }
#pieces button { flex: 0 0 auto; min-width: 104px; padding: 6px 8px; background: #fff; box-shadow: none; border: 2px solid #d9cfb7; font-size: 15px; }
#pieces button small { display: block; font-size: 14px; color: var(--bois); font-weight: 700; }
#pieces button.choisi { border-color: var(--vert); background: #e6f1dd; }
#outils { display: flex; gap: 8px; align-items: center; }
#outils button { min-width: 96px; }
#outils button.actif { background: var(--rouge); color: #fff; }
#info-piece { font-size: 15px; padding-top: 5px; min-height: 26px; }
#info-piece.non { color: var(--rouge); }
body.construction #ordres, body.construction #menus, body.construction #action, body.construction #barres { display: none; }
body.construction #manette { bottom: 158px; width: 120px; height: 120px; }
body.construction #but { display: none; }

#dialogue { position: fixed; inset: auto 0 calc(max(10px, env(safe-area-inset-bottom)) + 60px) 0; display: flex; justify-content: center; z-index: 20; pointer-events: none; }
.carte-dialogue { pointer-events: auto; width: min(560px, 50vw); background: var(--creme); border-radius: 18px; padding: 14px 18px; box-shadow: 0 4px 20px rgba(0,0,0,0.5); display: grid; gap: 8px; }
.qui { color: var(--vert-f); font-size: 15px; font-weight: 800; }
#dlg-texte { font-size: 20px; line-height: 1.32; }
#dlg-suite { justify-self: end; background: var(--vert); color: #fff; min-width: 130px; }

#panneau { position: fixed; inset: 0; background: rgba(20, 16, 10, 0.5); display: flex; align-items: center; justify-content: center; z-index: 30; }
#panneau-contenu { width: min(760px, 94vw); max-height: 88vh; overflow-y: auto; background: var(--creme); border-radius: 18px; padding: 18px 22px; box-shadow: 0 4px 24px rgba(0,0,0,0.5); touch-action: pan-y; -webkit-overflow-scrolling: touch; }
#panneau h2 { margin: 0 0 8px; font-size: 25px; color: var(--vert-f); }
#panneau p { margin: 6px 0; font-size: 18px; font-weight: 500; }
.bas-panneau { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.etoiles { font-size: 40px; letter-spacing: 6px; color: #d9a521; text-align: center; }
.etoiles b { color: #cfc6ae; font-weight: 400; }
.liste-achats { display: grid; gap: 8px; }
.achat { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; background: #fff; border-radius: 10px; padding: 8px 12px; }
.achat em { color: var(--bois); font-style: normal; font-size: 15px; display: block; font-weight: 500; }
.betes { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.bete { background: #fff; border-radius: 10px; padding: 7px 10px; font-size: 16px; }
.bete input { font: inherit; width: 100%; border: 0; border-bottom: 1px dashed #bbb; background: transparent; padding: 0; user-select: text; -webkit-user-select: text; color: inherit; }
.bete small { display: block; font-size: 14px; color: #6d6455; font-weight: 500; }
.bete .mal { color: var(--rouge); font-weight: 700; }
.reglage { display: grid; grid-template-columns: 1fr 200px; align-items: center; gap: 10px; margin: 8px 0; }
.reglage input { width: 100%; height: 34px; touch-action: none; }
#carte-jeu { display: block; width: min(58vh, 88vw); max-width: 100%; margin: 0 auto; border-radius: 12px; touch-action: none; }
.legende { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; font-size: 15px; padding-top: 6px; }
.legende i { display: inline-block; width: 13px; height: 13px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

#titre { position: fixed; inset: 0; background: rgba(28, 44, 34, 0.45); display: flex; align-items: center; justify-content: center; z-index: 40; }
.fond-titre { width: min(480px, 92vw); text-align: center; background: var(--creme-t); border-radius: 22px; padding: 22px 26px; box-shadow: 0 6px 30px rgba(0,0,0,0.45); }
h1 { margin: 0; font-size: 56px; letter-spacing: 1px; color: var(--vert-f); font-weight: 800; }
.sous-titre { margin: 2px 0 16px; font-size: 18px; font-weight: 500; }
#choix-titre, #formulaire { display: grid; gap: 10px; }
#formulaire label { display: grid; gap: 4px; text-align: left; }
#formulaire input { font: inherit; font-size: 20px; padding: 10px 12px; border-radius: 10px; border: 2px solid #cfc4a8; background: #fff; user-select: text; -webkit-user-select: text; touch-action: manipulation; }
#barre-chargement { height: 16px; background: #d9cfb7; border-radius: 8px; overflow: hidden; margin-bottom: 6px; }
#barre-chargement i { display: block; height: 100%; width: 0; background: var(--vert); transition: width 0.2s; }
#erreur { color: var(--rouge); font-size: 17px; }

#tourne { display: none; position: fixed; inset: 0; z-index: 60; background: #24382c; color: #fff; font-size: 28px; text-align: center; align-items: center; justify-content: center; padding: 20px; }
@media (orientation: portrait) { #tourne { display: flex; } }

/* petites tablettes et téléphones couchés */
@media (max-height: 560px) {
  #barres { top: 72px; width: 140px; }
  #ordres { width: 208px; gap: 5px; }
  .ordre { min-height: 44px; font-size: 15px; }
  .ordre.grand { min-height: 48px; font-size: 17px; }
  .appel { min-height: 42px; font-size: 15px; }
  .titre-ordres { display: none; }
  #manette { width: 124px; height: 124px; }
  #action { right: 224px; min-height: 60px; font-size: 16px; }
  #dlg-texte { font-size: 17px; }
  h1 { font-size: 40px; }
}

#boussole { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 72px); left: calc(50% - 170px); display: flex; align-items: center; gap: 6px; color: #fff; text-shadow: 0 1px 3px #000; font-size: 16px; }
#boussole svg { width: 34px; height: 34px; fill: #e2b93b; stroke: #2a241c; stroke-width: 1.2; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }

#qr { display: block; width: min(52vh, 320px); height: auto; margin: 6px auto; border-radius: 12px; background: #fff; image-rendering: pixelated; }
#panneau .centre { text-align: center; }
#panneau .petit { font-size: 15px; color: #6d6455; word-break: break-all; }
.pastille.tel { background: #3f7d4f; color: #fff; }
