:root {
  --ui: 1; --joy: 1;
  --pine: #1f2f27; --pine-2: #2a3f34; --amber: #f2b84b; --cream: #f6efdc; --ink: #263029; --red: #e0503f; --blue: #4da3ff;
  --panel: rgba(31, 47, 39, 0.82);
  --font: 'Nunito', system-ui, -apple-system, sans-serif;
  --display: 'Lilita One', 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2e3b2c; font-family: var(--font); color: var(--cream); user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; display: block; }
button { font-family: var(--font); font-weight: 800; cursor: pointer; border: 0; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
.hidden { display: none !important; }

/* ---------- Accueil / mort ---------- */
#home, #death { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(31,47,39,0.25), rgba(20,30,24,0.78)); z-index: 20; padding: 16px; }
.homeCard { width: min(560px, 100%); background: var(--pine); border: 5px solid var(--ink); border-radius: 26px; padding: 28px 28px 22px; box-shadow: 0 10px 0 var(--ink); text-align: center; }
h1 { font-family: var(--display); font-weight: 400; font-size: clamp(54px, 11vw, 84px); line-height: 0.95; margin: 0 0 8px; color: var(--amber); text-shadow: 0 5px 0 var(--ink), 4px 0 0 var(--ink), -4px 0 0 var(--ink), 0 -4px 0 var(--ink); letter-spacing: 0.5px; }
h1 span { color: var(--cream); font-size: 0.55em; }
h2 { font-family: var(--display); font-weight: 400; font-size: 44px; margin: 0 0 6px; color: var(--amber); }
.tag { margin: 0 0 20px; font-size: 17px; opacity: 0.9; }
#nameInput { width: 100%; font: 800 22px var(--font); text-align: center; padding: 14px; border-radius: 14px; border: 4px solid var(--ink); background: var(--cream); color: var(--ink); }
#skins { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 16px 0; }
.skin { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--pine-2); border: 3px solid transparent; border-radius: 14px; padding: 4px 4px 6px; color: var(--cream); font-size: 11px; width: 76px; }
.skin.on { border-color: var(--amber); background: #34503f; }
.skin.locked canvas { filter: grayscale(0.85) brightness(0.7); }
.skin.locked span { color: var(--amber); }
.big { width: 100%; font: 400 34px var(--display); padding: 12px; border-radius: 16px; background: var(--amber); color: var(--ink); border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink); margin-top: 4px; }
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.big:disabled { opacity: 0.55; cursor: wait; }
.ghost { background: transparent; color: var(--cream); border: 3px solid rgba(246,239,220,0.35); border-radius: 12px; padding: 8px 14px; font-size: 15px; }
.homeRow { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; gap: 10px; }
#status { font-size: 13px; opacity: 0.85; }
#status.ok::before { content: '● '; color: #7ee06a; }
#status.ko { color: #ff9a8a; }
.keysHelp { font-size: 13px; opacity: 0.7; margin: 14px 0 0; line-height: 1.45; }
#death .homeCard { display: grid; gap: 10px; }
#deathBy { margin: 0 0 6px; opacity: 0.9; }

/* ---------- HUD ---------- */
#hud > * { position: fixed; z-index: 5; }
.panel { background: var(--panel); border: 3px solid var(--ink); border-radius: 16px; padding: 10px 12px; }
#topLeft { top: calc(12px + env(safe-area-inset-top)); left: 12px; display: flex; gap: 8px; align-items: center; transform: scale(var(--ui)); transform-origin: top left; }
#topLeft button { background: var(--panel); color: var(--cream); border: 3px solid var(--ink); border-radius: 12px; padding: 8px 14px; font-size: 15px; }
#stats { font-size: 13px; font-weight: 800; text-shadow: 0 2px 0 var(--ink); }
#clanPanel { top: calc(62px + env(safe-area-inset-top)); left: 12px; width: 300px; max-height: 60vh; overflow: auto; transform: scale(var(--ui)); transform-origin: top left; }
#clanPanel h3 { margin: 0 0 8px; font: 400 24px var(--display); color: var(--amber); }
#clanPanel ul { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 6px; }
#clanPanel li { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 800; }
#clanPanel li small { display: block; font-weight: 600; opacity: 0.75; }
#clanPanel li.empty { opacity: 0.7; font-weight: 600; }
#clanPanel .row { display: flex; gap: 6px; }
#clanPanel input { flex: 1; min-width: 0; padding: 8px; border-radius: 10px; border: 3px solid var(--ink); font: 800 14px var(--font); }
#clanPanel button { background: var(--amber); color: var(--ink); border-radius: 10px; padding: 7px 10px; border: 3px solid var(--ink); }
#clanPanel button.danger { background: var(--red); color: #fff; width: 100%; }
#clanPanel .hint { font-size: 12px; opacity: 0.8; }
#leaderboard { top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 230px; font-size: 14px; transform: scale(var(--ui)); transform-origin: top right; }
#leaderboard h4 { margin: 0 0 6px; font: 400 20px var(--display); color: var(--amber); }
#leaderboard div { display: flex; justify-content: space-between; gap: 6px; padding: 1px 0; }
#leaderboard div span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#leaderboard div.me { color: var(--amber); }
#minimapBox { left: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); transform: scale(var(--ui)); transform-origin: bottom left; }
#minimap { width: 200px; height: 200px; border-radius: 16px; border: 4px solid var(--ink); display: block; }
#biome, #bossTimer { font-size: 13px; font-weight: 800; text-shadow: 0 2px 0 var(--ink); margin-top: 3px; }
#bossTimer { color: #ffb3e9; }
#resources { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); display: grid; gap: 6px; transform: scale(var(--ui)); transform-origin: bottom right; }
.res { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 3px solid var(--ink); border-radius: 12px; padding: 5px 12px; min-width: 175px; }
.res i { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--ink); }
.res span { flex: 1; font-size: 14px; opacity: 0.85; }
.res b { font-size: 18px; }
#bottomCenter { left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateX(-50%) scale(var(--ui)); transform-origin: bottom center; display: grid; gap: 8px; justify-items: center; }
#buff { color: var(--amber); font-weight: 900; text-shadow: 0 2px 0 var(--ink); min-height: 0; }
#ageRow { display: flex; align-items: center; gap: 10px; }
#ageLabel { font: 400 24px var(--display); color: var(--amber); text-shadow: 0 3px 0 var(--ink); }
#xpBar { position: relative; width: 340px; height: 24px; background: var(--panel); border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; }
#xpFill { height: 100%; width: 0; background: linear-gradient(#ffd774, #e8a52c); transition: width 0.2s; }
#xpText { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; font-weight: 900; text-shadow: 0 1px 0 var(--ink); }
#hotbar { display: flex; gap: 6px; }
.slot { position: relative; width: 62px; height: 62px; display: grid; place-items: center; background: var(--panel); border: 3px solid var(--ink); border-radius: 14px; padding: 0; }
.slot.on { background: #4a6b52; border-color: var(--amber); box-shadow: 0 0 0 3px var(--ink); }
.slot kbd { position: absolute; top: 2px; left: 6px; font: 900 12px var(--font); color: var(--cream); text-shadow: 0 1px 0 var(--ink); }
#upgrades { top: 50%; left: 50%; transform: translate(-50%, -62%) scale(var(--ui)); width: min(760px, 94vw); background: var(--pine); border: 5px solid var(--ink); border-radius: 22px; padding: 16px; box-shadow: 0 8px 0 var(--ink); text-align: center; z-index: 8; }
#upgrades h3 { margin: 0 0 12px; font: 400 26px var(--display); color: var(--amber); }
#upgrades p { margin: 10px 0 0; font-size: 13px; opacity: 0.75; }
#upgrades .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.card { display: grid; justify-items: center; gap: 6px; background: var(--pine-2); color: var(--cream); border: 3px solid var(--ink); border-radius: 16px; padding: 12px 10px; text-align: center; }
.card:hover { border-color: var(--amber); background: #34503f; }
.card strong { display: block; font-size: 16px; }
.card small { display: block; font-weight: 600; font-size: 13px; opacity: 0.85; line-height: 1.35; margin-top: 3px; }
.card em { display: block; font-style: normal; color: var(--amber); font-size: 12px; margin-top: 4px; }
#chatInput { left: 50%; bottom: 190px; transform: translateX(-50%); width: min(420px, 90vw); padding: 12px; border-radius: 12px; border: 4px solid var(--ink); font: 800 16px var(--font); z-index: 9; }
#toasts { left: 50%; bottom: 175px; transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; pointer-events: none; }
.toast { background: var(--panel); border: 3px solid var(--ink); border-radius: 12px; padding: 7px 14px; font-weight: 800; font-size: 14px; animation: toast 2.8s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateY(8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
#announce { top: 18%; left: 50%; transform: translateX(-50%); width: min(720px, 92vw); text-align: center; font: 400 28px var(--display); color: var(--amber); text-shadow: 0 3px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink); opacity: 0; pointer-events: none; }
#announce.show { animation: announce 6s forwards; }
@keyframes announce { 0% { opacity: 0; transform: translate(-50%, -10px); } 6%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ---------- Mobile ---------- */
#mobile { display: none; }
body.touch #mobile { display: block; position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.joy { position: fixed; width: calc(130px * var(--joy)); height: calc(130px * var(--joy)); margin: calc(-65px * var(--joy)) 0 0 calc(-65px * var(--joy)); border-radius: 50%; background: rgba(31,47,39,0.35); border: 3px solid rgba(246,239,220,0.4); display: none; }
.joy.active { display: grid; place-items: center; }
.knob { width: 56px; height: 56px; border-radius: 50%; background: rgba(246,239,220,0.75); border: 3px solid var(--ink); }
#mBtns { position: fixed; right: 12px; bottom: calc(185px + env(safe-area-inset-bottom)); display: grid; gap: 8px; pointer-events: auto; }
#mBtns button { width: 76px; padding: 10px 0; border-radius: 14px; background: var(--panel); color: var(--cream); border: 3px solid var(--ink); font-size: 13px; }
#mBtns button.on { background: var(--amber); color: var(--ink); }
body.touch #resources { grid-template-columns: repeat(2, auto); }
body.touch .res { min-width: 0; padding: 3px 8px; }
body.touch .res span { display: none; }
@media (max-width: 760px) {
  #xpBar { width: 200px; }
  .slot { width: 48px; height: 48px; }
  #minimap { width: 120px; height: 120px; }
  #leaderboard { width: 170px; font-size: 12px; }
  #bottomCenter { bottom: calc(96px + env(safe-area-inset-bottom)); }
}

/* ---------- Paramètres (inspiration Epic Games) ---------- */
#settings { position: fixed; inset: 0; z-index: 30; background: linear-gradient(160deg, #0f1730 0%, #18224a 60%, #1d2b5c 100%); color: #eef2ff; display: grid; grid-template-rows: auto 1fr auto; font-family: var(--font); }
#settings header { display: flex; align-items: center; gap: 18px; padding: 18px 28px 0; border-bottom: 2px solid rgba(255,255,255,0.08); flex-wrap: wrap; }
#settings h2 { color: #fff; font-size: 34px; margin: 0 12px 10px 0; }
#setTabs { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
#setTabs button { background: transparent; color: rgba(238,242,255,0.65); font-size: 16px; padding: 12px 16px; border-bottom: 4px solid transparent; border-radius: 0; }
#setTabs button.on { color: #fff; border-bottom-color: #f2d14b; }
#setTabs button:hover { color: #fff; }
#setClose { background: rgba(255,255,255,0.08); color: #fff; width: 44px; height: 44px; border-radius: 50%; font-size: 18px; margin-bottom: 10px; }
#setList { overflow: auto; padding: 18px 28px; display: grid; gap: 6px; align-content: start; max-width: 980px; width: 100%; margin: 0 auto; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 16px; background: rgba(255,255,255,0.05); border-left: 4px solid transparent; padding: 12px 16px; border-radius: 4px; }
.srow:hover { background: rgba(255,255,255,0.09); border-left-color: #f2d14b; }
.srow label { font-size: 16px; font-weight: 700; }
.sctl { display: flex; align-items: center; gap: 6px; min-width: 260px; justify-content: space-between; }
.sctl span { flex: 1; text-align: center; font-weight: 800; }
.sctl .arr { background: rgba(255,255,255,0.1); color: #fff; width: 36px; height: 36px; border-radius: 6px; font-size: 22px; line-height: 1; }
.sctl .arr:hover { background: #f2d14b; color: #10162b; }
.sctl input[type=range] { flex: 1; accent-color: #f2d14b; }
.sctl .num { flex: 0 0 40px; }
.keybtn { width: 100%; background: rgba(255,255,255,0.1); color: #fff; padding: 9px; border-radius: 6px; font-size: 15px; }
.keybtn.wait { background: #f2d14b; color: #10162b; }
#settings footer { display: flex; align-items: center; gap: 16px; padding: 14px 28px; border-top: 2px solid rgba(255,255,255,0.08); font-size: 13px; opacity: 0.85; }
@media (max-width: 600px) { .srow { flex-direction: column; align-items: stretch; } .sctl { min-width: 0; } }
@media (prefers-reduced-motion: reduce) { #xpFill { transition: none; } }
