/* Habillage rétro : panneaux sombres, bordures dorées, police pixel. */

:root {
  --panel-bg: rgba(18, 14, 24, 0.92);
  --panel-border: #8a6d3b;
  --gold: #e8c56a;
  --text: #e8e0d0;
  --hp: #c0392b;
  --mp: #2e6da4;
  --xp: #8e7cc3;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%; overflow: hidden;
  background: #0a0810;
  font-family: 'Courier New', monospace;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* pas de loupe/menu iOS sur appui long */
}

/* touch-action:none : sans ça le navigateur confisque le glissement (scroll)
   et coupe le maintien-pour-se-déplacer par un pointercancel. */
#game { position: absolute; inset: 0; image-rendering: pixelated; cursor: crosshair; touch-action: none; }

.hidden { display: none !important; }

/* Le HUD laisse passer les clics vers le jeu, sauf ses éléments interactifs. */
#hud { pointer-events: none; }
#hud .panel, #hotbar, #activebuffs, #chatin, #chatlog, #npcwin, #tradewin { pointer-events: auto; }

/* --- HUD --- */
#topleft { position: absolute; top: 10px; left: 10px; width: 230px; }
#charline { font-weight: bold; text-shadow: 1px 1px 0 #000; margin-bottom: 4px; }
#charname { color: var(--gold); }

.bar {
  position: relative; height: 16px; margin-bottom: 3px;
  background: rgba(0,0,0,.6); border: 1px solid #000; border-radius: 2px;
}
.bar > div { height: 100%; transition: width .15s; border-radius: 1px; }
.bar > span {
  position: absolute; inset: 0; text-align: center; font-size: 11px;
  line-height: 15px; text-shadow: 1px 1px 0 #000;
}
#hpfill { background: linear-gradient(#e74c3c, var(--hp)); }
#mpfill { background: linear-gradient(#3f8fd4, var(--mp)); }
#xpfill { background: linear-gradient(#a794d4, var(--xp)); }
.xpbar { height: 8px; }
.xpbar > span { font-size: 8px; line-height: 8px; }
#zonename { margin-top: 4px; font-size: 12px; color: var(--gold); text-shadow: 1px 1px 0 #000; }
#ammoline { margin-top: 2px; font-size: 12px; color: #c9b08a; text-shadow: 1px 1px 0 #000; }
#ammoline.empty { color: #e05050; }
#activebuffs { display: flex; gap: 4px; margin-top: 6px; min-height: 30px; }
.bufficon {
  width: 30px; height: 30px; position: relative; border: 1px solid var(--panel-border);
  border-radius: 3px; background: var(--panel-bg); box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.bufficon canvas { position: absolute; inset: 3px; width: 22px; height: 22px; image-rendering: pixelated; }
.bufficon .btime {
  position: absolute; left: 0; right: 0; bottom: -10px; text-align: center;
  font-size: 8px; color: #f4e09a; text-shadow: 1px 1px 0 #000;
}

/* --- Groupe --- */
#partybar { margin-top: 8px; pointer-events: auto; }
#partybar .ptitle { font-size: 11px; color: var(--gold); text-shadow: 1px 1px 0 #000; }
#partybar .prow { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
#partybar .pname { font-size: 11px; width: 80px; text-shadow: 1px 1px 0 #000; overflow: hidden; }
#partybar .pbar { flex: 1; height: 8px; background: rgba(0,0,0,.6); border: 1px solid #000; border-radius: 2px; }
#partybar .pbar > div { height: 100%; background: #5cb85c; }
#partybar .pleave {
  margin-top: 3px; font-size: 10px; background: none; color: #aaa;
  border: 1px solid #555; border-radius: 3px; cursor: pointer; font-family: inherit; padding: 1px 6px;
}
#partybar .pleave:hover { color: #fff; }

/* --- Hauts faits --- */
.achrow { font-size: 11px; color: #777; margin: 2px 0; }
.achrow.got { color: var(--gold); }
#statrows h3 { margin-top: 10px; }

/* --- Classements --- */
#panel-board { left: 50%; top: 90px; transform: translateX(-50%); width: 320px; }
#boardtabs { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 8px; }
#boardtabs button {
  background: none; border: 1px solid var(--panel-border); color: #bbb;
  font-size: 10px; padding: 2px 6px; border-radius: 3px; cursor: pointer; font-family: inherit;
}
#boardtabs button.active { background: var(--panel-border); color: #000; font-weight: bold; }
.brow { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 2px 4px; border-radius: 3px; }
.brow:nth-child(odd) { background: rgba(255,255,255,.04); }
.brow .brank { width: 20px; color: var(--gold); text-align: right; }
.brow .bname { flex: 1; }
.brow .bname.me { color: var(--gold); font-weight: bold; }
.brow .bon { color: #7bd17b; font-size: 9px; }
.brow .bval { color: #cdc4ae; }
.brow.top1 .brank { color: #f4e09a; }
#boardlist .bempty { color: #888; font-size: 12px; padding: 6px; }
#boardfoot { margin-top: 6px; font-size: 10px; color: #888; text-align: center; }

/* --- Guilde --- */
#panel-guild { left: 50%; top: 100px; transform: translateX(-50%); width: 300px; }
#guildbody input {
  width: 100%; margin-bottom: 6px; padding: 5px; background: rgba(0,0,0,.5);
  border: 1px solid var(--panel-border); color: var(--text); font-family: inherit;
  font-size: 12px; border-radius: 3px;
}
#guildbody .gtag { display: inline-block; color: #9ad17b; font-weight: bold; }
#guildbody .gname { color: var(--gold); font-size: 14px; }
#guildbody .gtreasury { color: var(--gold); font-size: 12px; margin: 6px 0; }
#guildbody h4 { color: var(--gold); font-size: 12px; margin: 8px 0 4px; }
#guildbody .gmember { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 1px 2px; }
#guildbody .gmember .gon { color: #7bd17b; }
#guildbody .gmember .goff { color: #777; }
#guildbody .gmember .glead { color: var(--gold); font-size: 9px; }
#guildbody .grow { display: flex; gap: 6px; margin-top: 6px; }
#guildbody .grow input { margin-bottom: 0; }
#guildbody button {
  background: #5a4423; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 3px; padding: 4px 10px; cursor: pointer; font-family: inherit; font-size: 12px;
}
#guildbody button:hover { background: #7a5c30; }
#guildbody .gcost { font-size: 10px; color: #888; margin-bottom: 8px; }
#guildbody .gleave { margin-top: 10px; width: 100%; }

/* --- Joueurs --- */
#panel-players { left: 50%; top: 86px; transform: translateX(-50%); width: 390px; max-width: calc(100vw - 24px); }
#playerscount { color: #888; font-size: 10px; margin: -2px 0 8px; text-align: center; }
#playerslist { max-height: min(420px, calc(100vh - 170px)); overflow-y: auto; }
#playerslist .pempty { color: #888; font-size: 12px; padding: 6px; text-align: center; }
.playerrow {
  display: flex; align-items: center; gap: 8px; padding: 4px;
  border-radius: 3px; font-size: 12px;
}
.playerrow:nth-child(odd) { background: rgba(255,255,255,.04); }
.playerrow.self .plname { color: var(--gold); font-weight: bold; }
.playerinfo { flex: 1; min-width: 0; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.plname { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pllevel { color: #cdc4ae; font-size: 10px; }
.plguild { color: #9ad17b; font-weight: bold; font-size: 10px; }
.plbadge {
  color: #8fb6da; border: 1px solid rgba(143,182,218,.35);
  border-radius: 3px; padding: 0 4px; font-size: 9px;
}
.playeractions { display: flex; gap: 4px; }
.playeractions button {
  background: #5a4423; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 3px; padding: 3px 7px; cursor: pointer; font-family: inherit; font-size: 10px;
}
.playeractions button:hover:not(:disabled) { background: #7a5c30; }
.playeractions button:disabled { opacity: .4; cursor: default; }

/* --- Échange --- */
#tradewin { left: 50%; top: 44%; transform: translate(-50%, -50%); width: 420px; }
#tradewin .tcols { display: flex; gap: 12px; }
#tradewin .tcol { flex: 1; }
#tradewin .tcol h4 { color: var(--gold); font-size: 12px; margin-bottom: 4px; }
#tradewin .tcol.ok h4::after { content: ' ✓'; color: #7bd17b; }
#tradewin .tgrid { display: grid; grid-template-columns: repeat(3, 38px); gap: 3px; min-height: 80px; }
#tradewin .tgold { margin-top: 6px; font-size: 12px; color: var(--gold); display: flex; align-items: center; gap: 4px; }
#tradewin .tgold input {
  width: 70px; background: rgba(0,0,0,.5); border: 1px solid var(--panel-border);
  color: var(--text); font-family: inherit; font-size: 12px; padding: 2px 4px; border-radius: 3px;
}
#tradewin .tbtns { display: flex; gap: 8px; margin-top: 10px; justify-content: center; }
#tradewin .tbtns button {
  background: #5a4423; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 3px; padding: 4px 14px; cursor: pointer; font-family: inherit; font-size: 12px;
}
#tradewin .tbtns button.confirmed { background: #2e5a2e; border-color: #7bd17b; }
#tradewin .thint { font-size: 10px; color: #888; margin-top: 8px; text-align: center; }

#minimap {
  position: absolute; top: 10px; right: 10px;
  border: 2px solid var(--panel-border); background: #000;
  image-rendering: pixelated;
}
#online { position: absolute; top: 166px; right: 10px; font-size: 11px; text-shadow: 1px 1px 0 #000; }

/* --- Boutons de menu (panneaux sans clavier, indispensables au tactile) --- */
#menubtns {
  position: absolute; top: 186px; right: 10px;
  display: flex; gap: 4px; pointer-events: auto;
}
#menubtns button {
  width: 28px; height: 28px; font-size: 14px; line-height: 1; padding: 0;
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  border-radius: 4px; cursor: pointer;
}
#menubtns button:hover { border-color: var(--gold); }

/* --- Barre de raccourcis --- */
#hotbar {
  position: absolute; bottom: calc(12px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px;
}
.hotslot {
  width: 46px; height: 46px; position: relative;
  background: var(--panel-bg); border: 2px solid var(--panel-border); border-radius: 4px;
  cursor: pointer; overflow: hidden;
}
.hotslot[draggable="true"] { cursor: grab; }
.hotslot.dragging { opacity: .6; border-color: #f4e09a; cursor: grabbing; }
.hotslot.dropok { box-shadow: 0 0 0 2px #f4e09a, 0 0 12px rgba(244,224,154,.45); }
.hotslot canvas { position: absolute; inset: 4px; width: 36px; height: 36px; image-rendering: pixelated; }
.hotslot .key {
  position: absolute; top: 1px; left: 3px; font-size: 10px; color: var(--gold);
  text-shadow: 1px 1px 0 #000; z-index: 2;
}
.hotslot .count {
  position: absolute; bottom: 1px; right: 3px; font-size: 11px; font-weight: bold;
  text-shadow: 1px 1px 0 #000; z-index: 2;
}
.hotslot .cd {
  position: absolute; inset: 0; background: rgba(0,0,0,.65); z-index: 1;
  transform-origin: bottom;
}
.hotslot.empty { opacity: .35; }

#helpline {
  position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%);
  font-size: 10px; color: #aaa; text-shadow: 1px 1px 0 #000;
}

/* --- Chat --- */
#chat { position: absolute; bottom: 12px; left: 10px; width: 320px; }
#chatlog {
  max-height: 150px; overflow-y: auto; font-size: 12px;
  display: flex; flex-direction: column; justify-content: flex-end;
  text-shadow: 1px 1px 0 #000; padding: 4px;
  mask-image: linear-gradient(transparent, black 20%);
}
#chatlog .sys { color: #9ad17b; }
#chatlog .msg .who { color: var(--gold); }
#chatlog .cguild { color: #9ad17b; font-weight: bold; }
#chatlog .cparty { color: #5d9ed0; }
#chatlog .cwhisper { color: #c89ad0; font-style: italic; }
#chatin {
  width: 100%; background: rgba(0,0,0,.7); border: 1px solid var(--panel-border);
  color: var(--text); padding: 4px 6px; font-family: inherit; font-size: 12px;
  border-radius: 3px; opacity: .35;
}
#chatin:focus { opacity: 1; outline: none; }

/* --- Toasts / annonces --- */
#toasts {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  pointer-events: none; z-index: 20;
}
.toast {
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  padding: 4px 14px; border-radius: 4px; font-size: 13px;
  animation: toastfade 4s forwards;
}
.toast.gold { color: var(--gold); }
@keyframes toastfade {
  0% { opacity: 0; transform: translateY(-6px); }
  8% { opacity: 1; transform: none; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* --- Panneaux --- */
.panel {
  position: absolute; background: var(--panel-bg);
  border: 2px solid var(--panel-border); border-radius: 6px;
  padding: 12px; min-width: 230px;
  box-shadow: 0 4px 18px rgba(0,0,0,.6);
}
.panel h3 {
  color: var(--gold); font-size: 14px; margin-bottom: 8px;
  border-bottom: 1px solid var(--panel-border); padding-bottom: 4px;
}
#panel-inv { right: 10px; top: 224px; }
#panel-stats { left: 10px; top: 140px; }
#panel-quests {
  right: 10px; bottom: 84px;
  max-width: 360px; max-height: calc(100vh - 118px);
  overflow-y: auto;
}

#invgrid { display: grid; grid-template-columns: repeat(6, 38px); gap: 3px; margin-top: 8px; }
#equipgrid { display: grid; grid-template-columns: repeat(4, 48px); gap: 4px; }
.islot {
  width: 38px; height: 38px; background: rgba(0,0,0,.45);
  border: 1px solid #555; border-radius: 3px; position: relative; cursor: pointer;
}
.islot canvas { position: absolute; inset: 3px; width: 30px; height: 30px; image-rendering: pixelated; }
.islot:hover { border-color: var(--gold); }
.islot .stackcount {
  position: absolute; right: -2px; bottom: -2px; min-width: 16px; height: 14px;
  padding: 0 3px; border: 1px solid #000; border-radius: 3px;
  background: rgba(18, 14, 24, .96); color: #f4e09a;
  font-size: 10px; font-weight: bold; line-height: 12px; text-align: center;
  text-shadow: 1px 1px 0 #000; z-index: 3;
}
.eslot { width: 48px; height: 48px; border-color: var(--panel-border); }
.eslot canvas { inset: 6px; width: 34px; height: 34px; }
.eslot .slotlabel {
  position: absolute; bottom: -1px; left: 0; right: 0; font-size: 8px;
  text-align: center; color: #999;
}
#goldline { margin-top: 8px; color: var(--gold); font-size: 13px; }

.statrow { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: 13px; }
.statrow .nm { flex: 1; }
.statrow .val { color: var(--gold); width: 28px; text-align: right; }
.statrow.derived { margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid rgba(138,109,59,.55); }
.statrow.derived .val { width: 42px; }
.statrow button {
  width: 22px; height: 22px; background: #2c4; color: #fff; border: none;
  border-radius: 3px; cursor: pointer; font-weight: bold; font-family: inherit;
}
#statpoints { font-size: 12px; color: var(--gold); margin-bottom: 6px; }

.questrow { margin-bottom: 10px; font-size: 12px; }
.questrow .qt { color: var(--gold); font-weight: bold; }
.questrow .qd { color: #bbb; margin: 2px 0; }
.questrow .qp { color: #9ad17b; }

/* --- Fenêtre PNJ --- */
#npcwin { left: 50%; top: 50%; transform: translate(-50%, -50%); width: 380px; max-height: 70vh; overflow-y: auto; }
#npcwin .npcrole { font-size: 11px; color: #aaa; margin-bottom: 6px; }
#npcwin .npcsay { font-style: italic; font-size: 12px; color: #cdc4ae; margin-bottom: 10px; }
.shoprow {
  display: flex; align-items: center; gap: 8px; padding: 3px 4px;
  font-size: 12px; border-radius: 3px;
}
.shoprow:hover { background: rgba(255,255,255,.06); }
.shoprow canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.shoprow .inm { flex: 1; }
.shoprow .pr { color: var(--gold); }
.shoprow button, #npcwin > button, .qbtns button {
  background: #5a4423; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 3px; padding: 3px 10px; cursor: pointer; font-family: inherit; font-size: 12px;
}
.shoprow button:hover, #npcwin > button:hover, .qbtns button:hover { background: #7a5c30; }
#npcwin h4 { color: var(--gold); font-size: 12px; margin: 10px 0 4px; }
.closex {
  position: absolute; top: 6px; right: 8px; cursor: pointer; color: #aaa;
  background: none; border: none; font-size: 16px; font-family: inherit;
  line-height: 1; padding: 2px 4px;
}
.closex:hover { color: #fff; }
/* Laisse de la place au bouton ✕ pour ne pas chevaucher le titre. */
.panel > h3 { padding-right: 18px; }

/* --- Mort --- */
#deathveil {
  position: absolute; inset: 0; background: rgba(40, 0, 0, .55);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
#deathmsg { font-size: 32px; color: #e74c3c; text-shadow: 2px 2px 0 #000; }
#deathsub { font-size: 14px; margin-top: 8px; }

/* --- Tooltip --- */
#tooltip {
  position: absolute; pointer-events: none; z-index: 50;
  background: var(--panel-bg); border: 1px solid var(--panel-border);
  padding: 5px 8px; border-radius: 4px; font-size: 11px; max-width: 220px;
}
#tooltip .tt-name { color: var(--gold); font-weight: bold; }
#tooltip .tt-line { color: #bbb; }
/* Mini-menu tactile (appui long) : le tooltip devient cliquable et porte des actions. */
#tooltip.tt-touch { pointer-events: auto; }
#tooltip .tt-act {
  display: block; width: 100%; margin-top: 6px; min-height: 36px;
  background: #5a4423; color: var(--text); border: 1px solid var(--panel-border);
  border-radius: 3px; cursor: pointer; font-family: inherit; font-size: 12px;
}
#tooltip .tt-act:hover { background: #7a5c30; }

/* --- Connexion --- */
#login {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1a1430 0%, #0a0810 75%);
}
#loginbox {
  text-align: center; background: var(--panel-bg); border: 2px solid var(--panel-border);
  border-radius: 8px; padding: 32px 40px; width: 340px;
}
#logintitle { color: var(--gold); letter-spacing: 4px; font-size: 30px; text-shadow: 2px 2px 0 #000; }
#loginsub { color: #9a8db8; font-size: 12px; margin: 4px 0 16px; }
#langsel { margin-bottom: 16px; display: flex; gap: 6px; justify-content: center; }
#langsel button {
  background: none; border: 1px solid var(--panel-border); color: var(--text);
  padding: 3px 10px; border-radius: 3px; cursor: pointer; font-family: inherit; font-size: 11px;
}
#langsel button.active { background: var(--panel-border); color: #000; font-weight: bold; }
#loginbox input {
  display: block; width: 100%; margin-bottom: 10px; padding: 8px;
  background: rgba(0,0,0,.5); border: 1px solid var(--panel-border);
  color: var(--text); font-family: inherit; border-radius: 3px;
}
#loginbtn {
  width: 100%; padding: 9px; background: #5a4423; color: var(--gold);
  border: 1px solid var(--gold); border-radius: 4px; font-family: inherit;
  font-size: 15px; font-weight: bold; cursor: pointer; letter-spacing: 2px;
}
#loginbtn:hover { background: #7a5c30; }
#loginhint { font-size: 10px; color: #888; margin-top: 8px; }
#loginerr { color: #e74c3c; font-size: 12px; margin-top: 8px; min-height: 16px; }

#connoverlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: var(--gold); text-shadow: 2px 2px 0 #000; z-index: 100;
}

/* --- Ergonomie tactile : cibles ≥ 44 px quand le pointeur est un doigt --- */
@media (pointer: coarse) {
  .islot { width: 44px; height: 44px; }
  .islot canvas { inset: 4px; width: 36px; height: 36px; }
  #invgrid { grid-template-columns: repeat(6, 44px); }
  .closex { font-size: 20px; padding: 10px 12px; top: 0; right: 0; }
  .statrow button { width: 32px; height: 32px; }
  #menubtns button { width: 44px; height: 44px; font-size: 20px; }
  #panel-inv { top: 240px; }
  #chatin { font-size: 16px; } /* < 16px = zoom automatique iOS au focus */
  #helpline { display: none; } /* aide clavier, hors sujet au doigt */
}

/* --- Petits écrans : panneaux, hotbar et chat contenus dans la fenêtre --- */
@media (max-width: 480px) {
  .panel { max-width: calc(100vw - 16px); }
  #npcwin, #tradewin { width: calc(100vw - 16px); max-height: 60vh; }
  /* 9 slots de 40 px + 8 espaces de 2 px = 376 px : la barre tient en largeur */
  #hotbar { gap: 2px; }
  .hotslot { width: 40px; height: 40px; }
  .hotslot canvas { inset: 3px; width: 34px; height: 34px; }
  /* le chat passe au-dessus de la hotbar au lieu de la chevaucher */
  #chat { width: calc(100vw - 20px); bottom: calc(62px + env(safe-area-inset-bottom)); }
  #chatlog { max-height: 90px; }
  #topleft { width: 180px; }
  #minimap { width: 100px; height: 100px; } /* réduction CSS, rendu 150px inchangé */
}
