:root {
  --fond: #1a1424;
  --panneau: rgba(22, 18, 32, 0.86);
  --bord: rgba(255, 255, 255, 0.13);
  --texte: #f3eee4;
  --discret: #b3a9c2;
  --accent: #f2b544;
  --accent-fonce: #b9761b;
  --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: flex-start; justify-content: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 0%, rgba(90, 60, 120, 0.7), rgba(12, 9, 18, 0.96)); 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(480px, 100%);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; gap: 11px; margin: auto; }
h1 { margin: 0; font-size: 46px; 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: -6px 0 0; 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: #e8d3ff; }
.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); }
input[type=range] { padding: 0; 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.principal:disabled { filter: grayscale(0.7); opacity: 0.6; cursor: default; }
.btn.enorme { font-size: 28px; padding: 18px; letter-spacing: 2px; }
.btn.petit { padding: 6px 10px; font-size: 13px; }
.btn.actif { background: var(--ok); color: #102a0b; }
.lien { all: unset; cursor: pointer; text-align: center; font-size: 13px; color: var(--discret); text-decoration: underline; }
.case { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.case input[type=checkbox] { width: 18px; height: 18px; }
.discret-case { color: var(--discret); font-size: 13px; justify-content: center; }
.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; }

.classes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.classe { font: inherit; color: var(--texte); text-align: left; padding: 9px 10px; border-radius: 12px; border: 2px solid var(--bord);
  background: rgba(255, 255, 255, 0.05); cursor: pointer; display: flex; flex-direction: column; gap: 3px; touch-action: manipulation; }
.classe .nom { font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.classe .nom i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.classe .role { font-size: 12px; color: var(--accent); font-weight: 700; }
.classe .desc { font-size: 12px; color: var(--discret); }
.classe .ics { font-size: 15px; letter-spacing: 2px; }
.classe.choisie { border-color: var(--accent); background: rgba(242, 181, 68, 0.14); }
#pantheon { text-align: left; }
#pantheon b { color: var(--accent); }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#haut, #fil, #annonce, #toasts { pointer-events: none !important; }
#haut { position: absolute; top: calc(6px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(420px, calc(100% - 330px));
  display: flex; flex-direction: column; gap: 3px; align-items: stretch; }
#boss { display: flex; align-items: center; gap: 8px; background: var(--panneau); border: 1px solid var(--bord); border-radius: 10px; padding: 5px 10px; font-size: 13px; font-weight: 700; }
#boss-nom { color: #e3b8ff; white-space: nowrap; }
#boss-barre { flex: 1; height: 10px; background: rgba(0, 0, 0, 0.5); border-radius: 5px; overflow: hidden; min-width: 40px; }
#boss-barre i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #a01e5e, #e2445b); transition: width 0.5s; }
#boss-pct { font-variant-numeric: tabular-nums; min-width: 46px; text-align: right; }
#ligne-cycle { display: flex; justify-content: center; gap: 10px; font-size: 12px; color: var(--discret); text-shadow: 0 1px 2px #000; flex-wrap: wrap; }
#cycle { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
#regle-jour { color: #e8d3ff; }
#fil { position: absolute; top: calc(66px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; width: min(520px, calc(100% - 24px)); }
#fil div { background: rgba(0, 0, 0, 0.45); padding: 3px 10px; border-radius: 12px; font-size: 12px; animation: fil 6s forwards; text-align: center; }
@keyframes fil { 0% { opacity: 0; } 6%, 78% { opacity: 1; } 100% { opacity: 0; } }

#perso { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: calc(8px + env(safe-area-inset-left)); width: 200px;
  background: var(--panneau); border: 1px solid var(--bord); border-radius: 12px; padding: 7px 9px; display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.ligne-perso { display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.ligne-perso.petit { font-size: 12px; color: var(--discret); }
#p-zone { color: var(--discret); font-size: 11px; }
#p-or { color: var(--or); font-weight: 700; }
#p-or::before { content: '● '; }
#p-ral { color: var(--ok); font-weight: 700; }
.jauge { position: relative; height: 12px; background: rgba(0, 0, 0, 0.5); border-radius: 6px; overflow: hidden; }
.jauge i { display: block; height: 100%; width: 0; transition: width 0.15s; }
.jauge.pv { height: 15px; }
.jauge.pv i { background: linear-gradient(#5fd35a, #2f9e3a); }
.jauge.pv span { position: absolute; inset: 0; font-size: 11px; text-align: center; line-height: 15px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.jauge.xp { height: 6px; }
.jauge.xp i { background: #8f6cff; }
.jauge.rel { width: 100%; height: 8px; }
.jauge.rel i { background: #ffe37a; }

#droite { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(8px + env(safe-area-inset-right)); display: flex; gap: 6px; align-items: flex-start; flex-direction: row-reverse; pointer-events: none; }
#droite > * { pointer-events: auto; }
#minicarte { width: 64px; height: 250px; border: 1px solid var(--bord); border-radius: 8px; background: #0d0a12; }
#classement { background: var(--panneau); border: 1px solid var(--bord); border-radius: 8px; font-size: 12px; overflow: hidden; width: 172px; }
#classement-titre { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 5px 8px; font-weight: 700; cursor: pointer; }
#classement.replie { width: auto; }
#classement.replie #classement-corps { display: none; }
#classement-corps { padding: 0 8px 6px; }
#classement-corps h4 { margin: 5px 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 span { color: var(--discret); }
#classement-corps li.moi { color: var(--accent); font-weight: 700; }
#boutons-haut { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: calc(82px + env(safe-area-inset-right)); display: flex; flex-direction: column; gap: 8px; }
#boutons-haut.decale { right: calc(260px + env(safe-area-inset-right)); }
.btn.rond { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 19px; background: var(--panneau); }
.btn.rond.actif { background: var(--ok); }
.btn.rond.coupe { background: var(--danger); }

#bandeau-mort { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); width: min(380px, calc(100% - 32px));
  text-align: center; background: rgba(60, 22, 32, 0.92); border: 1px solid rgba(255,255,255,.2); border-radius: 14px; padding: 14px; font-size: 14px; display: flex; flex-direction: column; gap: 9px; align-items: center; }
#mort-titre { font-size: 22px; color: #ff9d8f; }

/* Compétences : barre en bas au centre sur ordi */
#actions { position: absolute; bottom: calc(12px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: flex-end; }
.comp { position: relative; width: 58px; height: 58px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.45); background: rgba(22, 18, 32, 0.8);
  color: #fff; font-size: 24px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; padding: 0; cursor: pointer; touch-action: none; overflow: hidden; }
.comp .ic { position: relative; z-index: 1; }
.comp em { position: absolute; bottom: 2px; right: 50%; transform: translateX(50%); font-size: 10px; font-style: normal; font-weight: 800; opacity: .75; z-index: 2; }
.comp small { font-size: 9px; font-weight: 700; margin-top: 2px; z-index: 1; }
.comp .cd { position: absolute; inset: 0; border-radius: 50%; background: conic-gradient(rgba(0, 0, 0, 0.72) calc(var(--f, 0) * 360deg), transparent 0); pointer-events: none; z-index: 1; }
.comp.verrou { opacity: 0.35; }
.comp.ult { border-color: #f2b544; }
.comp.attaque { width: 70px; height: 70px; background: rgba(160, 50, 40, 0.8); }
.comp.appui { transform: scale(0.93); background: rgba(242, 181, 68, 0.5); }
.comp.vide { opacity: 0.4; }
body.pc #actions .comp.attaque small { display: none; }

#stick { display: none; position: absolute; bottom: calc(26px + env(safe-area-inset-bottom)); left: calc(22px + env(safe-area-inset-left)); width: 136px; height: 136px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.3); align-items: center; justify-content: center; touch-action: none; }
#nub { width: 56px; height: 56px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); pointer-events: none; }
body.tactile-on #stick { display: flex; }
/* Mobile : joystick fixe en bas à gauche, boutons ronds en bas à droite (gaucher : inversé) */
body.tactile-on #actions { left: auto; transform: none; right: calc(14px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 190px; height: 190px; display: block; }
body.tactile-on .comp { position: absolute; width: 56px; height: 56px; }
body.tactile-on .comp em { display: none; }
body.tactile-on .comp.attaque { width: 80px; height: 80px; right: 0; bottom: 0; }
body.tactile-on .comp[data-k="0"] { right: 92px; bottom: 0; }
body.tactile-on .comp[data-k="1"] { right: 84px; bottom: 64px; }
body.tactile-on .comp[data-k="2"] { right: 30px; bottom: 98px; }
body.tactile-on .comp[data-k="3"] { right: 136px; bottom: 112px; width: 50px; height: 50px; }
body.tactile-on .comp.potion { right: 0; bottom: 152px; width: 46px; height: 46px; font-size: 20px; }
body.tactile-on.gaucher #stick { left: auto; right: calc(22px + env(safe-area-inset-right)); }
body.tactile-on.gaucher #actions { right: auto; left: calc(14px + env(safe-area-inset-left)); transform: scaleX(-1); }
body.tactile-on.gaucher #actions .comp > * { transform: scaleX(-1); }
body.tactile-on #toasts { bottom: calc(230px + env(safe-area-inset-bottom)); }

#annonce { position: absolute; top: 26%; left: 0; right: 0; text-align: center; font-size: 38px; 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(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column;
  align-items: center; gap: 6px; width: min(440px, calc(100% - 32px)); }
.toast { background: var(--panneau); border: 1px solid var(--bord); border-radius: 8px; padding: 6px 12px; font-size: 14px; animation: toast 3s forwards; text-align: center; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 8%, 82% { opacity: 1; transform: none; } 100% { opacity: 0; } }
#menu { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(360px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto; z-index: 6; }
#menu-perso { font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
#menu-perso .obj { padding: 5px 8px; background: rgba(0,0,0,.25); border-radius: 8px; }
#menu-perso .obj small { color: var(--discret); display: block; }
#victoire { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 32px)); max-height: calc(100% - 40px); overflow-y: auto; z-index: 7; text-align: center; }
#victoire h2 { color: var(--accent); font-size: 30px; }
#vic-liste { text-align: left; font-size: 13px; margin: 0; padding-left: 26px; columns: 2; }

/* Petits écrans */
@media (max-width: 760px) {
  h1 { font-size: 36px; letter-spacing: 3px; }
  .classe .desc { display: none; }
  #haut { left: calc(8px + env(safe-area-inset-left)); transform: none; top: calc(6px + env(safe-area-inset-top)); width: calc(100% - 74px - env(safe-area-inset-right)); }
  #boss { padding: 4px 8px; font-size: 12px; }
  #ligne-cycle { justify-content: flex-start; font-size: 11px; gap: 8px; }
  #perso { top: calc(62px + env(safe-area-inset-top)); width: min(230px, calc(100% - 136px)); padding: 6px 8px; gap: 4px; font-size: 12px; }
  #droite { flex-direction: column; align-items: flex-end; }
  #minicarte { width: 46px; height: 190px; }
  #boutons-haut, #boutons-haut.decale { top: calc(62px + env(safe-area-inset-top)); right: calc(62px + env(safe-area-inset-right)); }
  #classement { width: 172px; }
  #classement.replie { width: 46px; }
  #classement.replie #classement-titre { font-size: 0; text-align: center; }
  #classement.replie #classement-titre .ico { width: 18px; height: 18px; }
  #classement-titre { padding: 4px 6px; }
  #fil { top: calc(176px + env(safe-area-inset-top)); left: 8px; transform: none; width: calc(100% - 74px); align-items: flex-start; }
  #annonce { font-size: 28px; }
  .comp { width: 50px; height: 50px; font-size: 21px; }
  .comp.attaque { width: 60px; height: 60px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #haut { top: calc(6px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: min(360px, calc(100% - 420px)); }
  #fil { top: calc(56px + env(safe-area-inset-top)); }
  #minicarte { height: 150px; }
  body.tactile-on #actions { transform: scale(0.85); transform-origin: bottom right; }
}

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