/* ============================================================
   Olisé — système de design
   Grille 8 pt (pas de 4) · cibles tactiles ≥ 44 px (Apple HIG)
   et 48 px pour les actions clés (Material 3) · 2 élévations
   Échelle typo : 12 / 13 / 14 / 16 / 19 / 24
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* couleurs */
  --cream: #fdf3e3;
  --cream2: #fff9ef;
  --ink: #3c332e;          /* texte courant — contraste AA sur crème */
  --ink-strong: #2e2a33;   /* titres */
  --ink-soft: #7a6a5f;     /* texte secondaire */
  --pink: #f5a8bc;
  --pink-deep: #e87f9c;
  --pink-press: #c95f7e;
  --green: #6fae58;
  --green-press: #47883a;
  --danger: #a84848;
  --line: #f0dfc8;

  /* espacement (grille 8 pt, pas de 4) */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 20px;
  --s6: 24px;

  /* typo */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-base: 16px;
  --fs-lg: 19px;
  --fs-xl: 24px;

  /* rayons */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-full: 999px;

  /* élévations */
  --elev-1: 0 2px 8px rgba(120, 90, 60, .14);
  --elev-2: 0 6px 24px rgba(120, 90, 60, .18);

  /* cibles tactiles */
  --tap: 44px;
  --tap-lg: 48px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', 'Quicksand', -apple-system, system-ui, sans-serif;
  font-size: var(--fs-base);
  background: var(--cream);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.screen { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* focus clavier visible partout */
button:focus-visible, input:focus-visible, select:focus-visible, .swatch:focus-visible {
  outline: 3px solid var(--pink-deep);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ============================================================
   ÉCRAN CRÉATEUR / ACCUEIL
   ============================================================ */
#screen-creator {
  overflow-y: auto;
  touch-action: pan-y;
  background:
    radial-gradient(1200px 500px at 50% -150px, #ffe4ec 0%, transparent 60%),
    radial-gradient(900px 400px at 10% 110%, #dcf0d2 0%, transparent 60%),
    radial-gradient(900px 400px at 95% 105%, #d8ecf7 0%, transparent 55%),
    var(--cream);
}

.creator-wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: var(--s6) var(--s4) 64px;
}

/* ---- bannière hero (onboarding) ---- */
#hero-banner {
  position: relative;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--elev-2);
  margin-bottom: var(--s4);
  aspect-ratio: 16 / 7;
  max-height: 260px;
  background: linear-gradient(#8fd4f2, #cdeede);
}
#hero-scene { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
#hero-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: var(--s5) var(--s5) var(--s4);
  background: linear-gradient(transparent, rgba(30, 40, 30, .55));
  color: #fff;
}
#hero-overlay h1 {
  font-weight: 900;
  font-size: clamp(34px, 6vw, 52px);
  letter-spacing: 1px;
  text-shadow: 0 2px 0 rgba(0,0,0,.25), 0 0 18px rgba(0,0,0,.3);
  line-height: 1;
}
#hero-overlay p {
  font-weight: 700;
  font-size: var(--fs-md);
  margin-top: var(--s2);
  max-width: 42ch;
  text-shadow: 0 1px 4px rgba(0,0,0,.5);
}

/* ---- carte d'authentification ---- */
#auth-card {
  background: var(--cream2);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
  padding: var(--s5);
  margin-bottom: var(--s4);
}
.btn-instant {
  width: 100%;
  min-height: 56px;
  padding: 0 var(--s5);
  font: inherit;
  font-size: var(--fs-lg);
  font-weight: 900;
  color: #fff;
  background: linear-gradient(#8fd07a, #5fa84c);
  border: none;
  border-radius: var(--r-md);
  box-shadow: 0 4px 0 var(--green-press), var(--elev-1);
  cursor: pointer;
  transition: transform .1s;
}
.btn-instant:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--green-press); }
.auth-sep {
  text-align: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--ink-soft);
  margin: var(--s4) 0 var(--s3);
}
.auth-row { display: flex; gap: var(--s2); margin-bottom: var(--s2); }
.auth-row input {
  flex: 1;
  min-width: 0;
  height: var(--tap-lg);
  padding: 0 var(--s4);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: #fff;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--ink);
  outline: none;
}
.auth-row input:focus { border-color: var(--pink); }
.auth-row .btn-soft { flex: 1; }
.auth-error {
  background: #fdeaea;
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: 700;
  border-radius: var(--r-sm);
  padding: var(--s2) var(--s3);
}
#auth-hello {
  display: block;
  font-weight: 700;
  font-size: var(--fs-md);
  line-height: 1.5;
  margin-bottom: var(--s3);
}
#auth-hello b { color: var(--pink-deep); }

/* ---- panneau créateur ---- */
.creator-panel {
  display: flex;
  gap: var(--s6);
  background: var(--cream2);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
  padding: var(--s6);
}

.creator-left {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s3);
}

.preview-box {
  background:
    radial-gradient(160px 60px at 50% 105%, #c2e3ad 0%, transparent 70%),
    linear-gradient(#cfeef7 0%, #e8f7ee 100%);
  border-radius: var(--r-lg);
  padding: var(--s3);
  box-shadow: inset 0 0 0 4px #fff, var(--elev-1);
}
#avatar-preview { display: block; image-rendering: pixelated; }

.preview-controls { display: flex; gap: var(--s2); align-items: center; }

.creator-right { flex: 1; min-width: 0; }

.field { margin-bottom: var(--s4); }
.field label {
  display: block;
  font-weight: 800;
  font-size: var(--fs-sm);
  letter-spacing: .01em;
  color: var(--ink-strong);
  margin-bottom: var(--s2);
}
.field .hint { font-weight: 600; font-size: var(--fs-xs); color: var(--ink-soft); }

#inp-name, #inp-region {
  width: 100%;
  height: var(--tap-lg);
  padding: 0 var(--s4);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: #fff;
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--ink);
  outline: none;
}
#inp-name:focus, #inp-region:focus { border-color: var(--pink); }
#inp-name:disabled { background: var(--cream); color: var(--ink-soft); }

.swatches { display: flex; flex-wrap: wrap; gap: var(--s2); }
.swatch {
  width: 38px;
  height: 38px;
  border-radius: var(--r-sm);
  border: 3px solid rgba(255, 255, 255, .9);
  box-shadow: var(--elev-1);
  cursor: pointer;
  transition: transform .12s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.sel { outline: 3px solid var(--pink-deep); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  height: 38px;
  padding: 0 var(--s4);
  background: #fff;
  border: 2px solid var(--line);
  border-radius: var(--r-full);
  font: inherit;
  font-weight: 800;
  font-size: var(--fs-sm);
  color: var(--ink);
  cursor: pointer;
  transition: transform .12s;
}
.chip:hover { transform: translateY(-2px); }
.chip.sel { background: var(--pink); border-color: var(--pink-deep); color: #fff; }

.btn-play {
  width: 100%;
  min-height: 56px;
  margin-top: var(--s2);
  padding: 0 var(--s5);
  font: inherit;
  font-size: var(--fs-lg);
  font-weight: 900;
  color: #fff;
  background: linear-gradient(#f7b3c6, #e87f9c);
  border: none;
  border-radius: var(--r-md);
  box-shadow: 0 4px 0 var(--pink-press), var(--elev-1);
  cursor: pointer;
  transition: transform .1s;
}
.btn-play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--pink-press); }

.btn-soft, .btn-round {
  min-height: var(--tap);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 800;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: var(--r-full);
  padding: 0 var(--s4);
  cursor: pointer;
}
.btn-round { width: var(--tap); padding: 0; font-size: var(--fs-lg); }
.btn-soft:hover, .btn-round:hover { border-color: var(--pink); }

@media (max-width: 640px) {
  .creator-panel { flex-direction: column; align-items: center; }
  .creator-right { width: 100%; }
}

/* ============================================================
   JEU
   ============================================================ */
#screen-game { background: #7ec97e; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }

#overlay { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }

/* minimap (haut-gauche) */
#minimap-box {
  position: absolute;
  top: calc(var(--s3) + env(safe-area-inset-top));
  left: var(--s3);
  background: rgba(255, 252, 245, .9);
  border-radius: var(--r-md);
  padding: 5px;
  box-shadow: var(--elev-1);
  z-index: 6;
}
#minimap-title {
  font-size: 11px;
  font-weight: 900;
  color: #7a5c46;
  text-align: center;
  margin-bottom: 3px;
  letter-spacing: .02em;
}
#minimap {
  display: block;
  image-rendering: pixelated;
  border-radius: 6px;
  width: 150px; height: 112px;
}
@media (max-width: 520px) {
  #minimap { width: 108px; height: 80px; }
  #minimap-title { font-size: 10px; }
}

/* étiquettes de nom — texte flottant façon MMORPG (sans fond) */
.tag {
  position: absolute;
  transform: translate(-50%, -100%);
  font-size: 12px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: .01em;
  white-space: nowrap;
  pointer-events: none;
  text-shadow:
    -1px -1px 0 rgba(20,16,14,.95), 1px -1px 0 rgba(20,16,14,.95),
    -1px 1px 0 rgba(20,16,14,.95), 1px 1px 0 rgba(20,16,14,.95),
    0 2px 3px rgba(0,0,0,.55);
}
.tag.me { color: #ffe08a; }    /* soi = doré */
.tag.live { color: #8ef0a0; }  /* autres vrais joueurs = vert clair */

/* icônes pixel (remplacent les émojis) */
.picon {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  vertical-align: -3px;
  margin-right: var(--s1);
}
.picon-big {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto;
}

/* bulles BD */
.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  max-width: 200px;
  background: #fff;
  border: 2px solid var(--ink-strong);
  border-radius: var(--r-md);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-md);
  line-height: 1.35;
  font-weight: 700;
  color: var(--ink-strong);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .1);
  animation: pop .18s ease-out;
  text-align: center;
  word-wrap: break-word;
}
.bubble::after {
  content: '';
  position: absolute;
  left: 50%; bottom: -10px;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top: 8px solid var(--ink-strong);
}
.bubble::before {
  content: '';
  position: absolute;
  left: 50%; bottom: -5px;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top: 7px solid #fff;
  z-index: 1;
}
.bubble.emote { padding: var(--s2); }
.bubble.fading { opacity: 0; transition: opacity .4s; }
@keyframes pop { from { transform: translate(-50%, -90%) scale(.6); opacity: 0; } }

/* invite d'interaction */
#prompt {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(46, 42, 51, .92);
  color: #fff;
  font-size: var(--fs-sm);
  font-weight: 800;
  padding: 6px 12px;
  border-radius: var(--r-full);
  white-space: nowrap;
  box-shadow: var(--elev-1);
  animation: bob 1s ease-in-out infinite;
}
#prompt b {
  display: inline-block;
  background: #fff;
  color: var(--ink-strong);
  border-radius: 5px;
  padding: 0 5px;
  margin-right: 2px;
  font-size: var(--fs-xs);
}
@keyframes bob { 50% { margin-top: -4px; } }

/* bannière de zone */
#zone-banner {
  position: absolute;
  top: calc(var(--s4) + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 252, 245, .95);
  padding: var(--s2) var(--s6);
  border-radius: var(--r-full);
  font-size: var(--fs-base);
  font-weight: 900;
  color: #7a5c46;
  box-shadow: var(--elev-2);
  animation: zonein .5s ease-out;
  pointer-events: none;
  z-index: 5;
}
@keyframes zonein { from { transform: translate(-50%, -30px); opacity: 0; } }
#zone-banner.out { opacity: 0; transition: opacity .8s; }

/* HUD haut droite */
#hud-top-right {
  position: absolute;
  top: calc(var(--s3) + env(safe-area-inset-top));
  right: var(--s3);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--s2);
  z-index: 6;
}
#presence {
  display: flex;
  align-items: center;
  height: 32px;
  background: rgba(255, 252, 245, .92);
  padding: 0 var(--s3);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 900;
  color: #2e7a42;
  box-shadow: var(--elev-1);
}
#presence.off { color: #b05a5a; }
#stats {
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: 36px;
  background: rgba(255, 252, 245, .92);
  padding: 0 var(--s3);
  border-radius: var(--r-full);
  box-shadow: var(--elev-1);
}
.stat {
  display: inline-flex;
  align-items: center;
  font-size: var(--fs-sm);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.hud-btns { display: flex; gap: var(--s2); }
.btn-hud {
  position: relative;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--r-md);
  background: rgba(255, 252, 245, .92);
  cursor: pointer;
  box-shadow: var(--elev-1);
}
.btn-hud:active { transform: scale(.92); }
.btn-hud.on { background: #ffe1b0; box-shadow: 0 0 0 2px #f0a54e, var(--elev-1); }
.btn-hud.on svg [stroke] { stroke: #b45f1e; }
.btn-hud.muted { opacity: .45; }
.btn-hud.muted::after {
  content: "";
  position: absolute;
  left: 9px; top: 21px;
  width: 26px; height: 2.5px;
  background: #c05454;
  transform: rotate(-38deg);
  border-radius: 2px;
}

/* chat en bas à gauche */
#chat-box {
  position: absolute;
  left: var(--s3);
  bottom: calc(var(--s3) + env(safe-area-inset-bottom));
  width: min(360px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  z-index: 6;
}
#chat-log {
  max-height: 160px;
  overflow-y: auto;
  background: rgba(255, 252, 245, .9);
  border-radius: var(--r-md);
  padding: var(--s2) var(--s3);
  font-size: var(--fs-sm);
  line-height: 1.5;
  box-shadow: var(--elev-1);
  scrollbar-width: thin;
}
#chat-log .line b { color: #c46a87; }
#chat-log .line .live-name { color: #2e7a42; }
#chat-log .line .reg { font-size: 10px; color: var(--ink-soft); font-weight: 800; margin-right: 2px; }
#chat-log .line.sys { color: #5e8a4f; font-style: italic; font-weight: 700; }
#emote-bar { display: flex; gap: var(--s2); flex-wrap: wrap; }
.emote, .quickchat {
  height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 13px 0 10px;
  border: none;
  border-radius: var(--r-full);
  background: rgba(255, 252, 245, .94);
  font: inherit;
  font-size: var(--fs-xs);
  font-weight: 800;
  color: #6b5a52;
  cursor: pointer;
  box-shadow: var(--elev-1);
  white-space: nowrap;
}
.emote .e-ico, .quickchat .e-ico { font-size: 15px; line-height: 1; }
.emote:active, .quickchat:active { transform: scale(.94); }
#chat-input-row { display: flex; gap: var(--s2); pointer-events: auto; }
#btn-chat-toggle {
  display: none;
  width: var(--tap);
  height: var(--tap);
  place-items: center;
  border: none;
  border-radius: var(--r-md);
  background: rgba(255, 252, 245, .95);
  box-shadow: var(--elev-1);
}
#chat-input {
  flex: 1;
  min-width: 0;
  height: var(--tap-lg);
  padding: 0 var(--s4);
  border: 2px solid rgba(240, 223, 200, .9);
  border-radius: var(--r-full);
  background: rgba(255, 255, 255, .95);
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--ink);
  outline: none;
}
#chat-input:focus { border-color: var(--pink); }
#btn-send {
  width: var(--tap-lg);
  height: var(--tap-lg);
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: linear-gradient(#f7b3c6, #e87f9c);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--pink-press);
}
#btn-send:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--pink-press); }

/* toasts */
#toasts {
  position: absolute;
  top: calc(72px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  align-items: center;
  z-index: 7;
  pointer-events: none;
}
.toast {
  background: #fff;
  border: 2px solid var(--pink);
  color: #b04a68;
  font-weight: 900;
  font-size: var(--fs-md);
  padding: var(--s2) var(--s5);
  border-radius: var(--r-full);
  box-shadow: var(--elev-2);
  animation: pop .25s ease-out;
}
.toast.fading { opacity: 0; transition: opacity .5s; }

/* contrôles tactiles */
#touch-controls { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
#joystick {
  position: absolute;
  right: var(--s6);
  bottom: calc(96px + env(safe-area-inset-bottom));
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255, 252, 245, .3);
  border: 3px solid rgba(255, 252, 245, .5);
  pointer-events: auto;
  touch-action: none;
}
#joy-thumb {
  position: absolute;
  left: 50%; top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 252, 245, .85);
  box-shadow: var(--elev-1);
  transform: translate(-50%, -50%);
}
#btn-action {
  position: absolute;
  left: var(--s5);
  bottom: calc(104px + env(safe-area-inset-bottom));
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: none;
  background: linear-gradient(#f7b3c6, #e87f9c);
  box-shadow: 0 5px 0 var(--pink-press), var(--elev-2);
  pointer-events: auto;
  transition: transform .1s;
}
#btn-action:active { transform: scale(.92); }
#btn-action.glow { animation: glow 1s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 4px 0 var(--pink-press), 0 0 22px 6px rgba(255, 200, 120, .85); } }
/* le « A » du bouton d'action */
#btn-action { color: #fff; font-family: var(--sans); font-size: 32px; font-weight: 900; line-height: 1; text-shadow: 0 2px 0 rgba(0, 0, 0, .18); }

/* HUD : ligne présence + argent */
.hud-row { display: flex; align-items: center; gap: var(--s2); }

/* menu ☰ (aide, modifier avatar) */
#burger-menu {
  position: absolute;
  top: calc(var(--s3) + 96px + env(safe-area-inset-top));
  right: var(--s3);
  display: flex; flex-direction: column; gap: 2px;
  background: rgba(255, 252, 245, .98);
  border-radius: var(--r-md);
  box-shadow: var(--elev-2);
  padding: 6px;
  z-index: 14;
  opacity: 0; pointer-events: none; transform: translateY(-8px) scale(.97);
  transition: opacity .15s ease, transform .15s ease;
}
#burger-menu.open { opacity: 1; pointer-events: auto; transform: none; }
#burger-menu button {
  text-align: left; white-space: nowrap;
  border: none; background: none; font: inherit; font-weight: 800; font-size: var(--fs-sm);
  color: #6b5a52; padding: 11px 16px; border-radius: var(--r-sm); cursor: pointer;
}
#burger-menu button:active { background: #f3ebdd; }

/* aide */
#help-modal {
  position: absolute;
  inset: 0;
  background: rgba(46, 42, 51, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: var(--s4);
}
.help-card {
  background: var(--cream2);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2);
  padding: var(--s6);
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
}
.help-card h2 {
  color: var(--pink-deep);
  font-size: var(--fs-xl);
  font-weight: 900;
  margin-bottom: var(--s4);
}
.help-card ul { list-style: none; }
.help-card li {
  margin-bottom: var(--s3);
  font-weight: 700;
  font-size: var(--fs-md);
  line-height: 1.5;
}
.help-note {
  margin-top: var(--s3);
  font-size: var(--fs-sm);
  line-height: 1.5;
  font-weight: 700;
  background: #fdeedd;
  border-radius: var(--r-sm);
  padding: var(--s3);
  color: #9a7048;
}

/* mobile */
@media (pointer: coarse) {
  #hud-top-right { top: calc(var(--s2) + env(safe-area-inset-top)); right: var(--s2); gap: 6px; }
  #burger-menu { top: calc(100px + env(safe-area-inset-top)); right: var(--s2); }
  #btn-chat-toggle { display: none; }

  /* le chat occupe TOUT le bas + toute la largeur ; on laisse passer les touches sauf sur les zones utiles */
  #chat-box {
    left: 0; right: 0; width: auto;
    bottom: env(safe-area-inset-bottom);
    padding: 0 8px 8px;
    gap: 6px;
    z-index: 8;
    pointer-events: none;
  }
  #emote-bar, #chat-input-row { pointer-events: auto; }

  /* journal toujours visible mais TRANSPARENT : on voit le jeu derrière */
  #chat-log {
    display: block;
    max-height: 24vh;
    background: linear-gradient(180deg, transparent, rgba(24, 20, 28, .30));
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .85);
    box-shadow: none;
    padding-top: 22px;
    pointer-events: none;
    -webkit-mask-image: linear-gradient(180deg, transparent, #000 26px);
    mask-image: linear-gradient(180deg, transparent, #000 26px);
  }
  #chat-log .line b { color: #ffd0e2; }
  #chat-log .line .live-name { color: #9ff0b4; }
  #chat-log .line .reg { color: #e6ddd2; }
  #chat-log .line.sys { color: #e6f2d8; font-style: normal; }

  /* émotes sur UNE seule ligne qui défile horizontalement */
  #emote-bar {
    display: flex; flex-wrap: nowrap; overflow-x: auto;
    gap: 6px; padding: 2px 0;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  #emote-bar::-webkit-scrollbar { display: none; }

  /* barre d'écriture pleine largeur, de bord à bord */
  #chat-input-row { width: 100%; }

  /* on remonte les contrôles au-dessus du chat */
  #joystick { right: var(--s4); bottom: calc(148px + env(safe-area-inset-bottom)); }
  #btn-action { left: var(--s4); bottom: calc(156px + env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) {
  .picon { width: 14px; height: 14px; }
}

/* ============ BOUTON SAC + PASTILLE ============ */
#btn-bag { position: relative; }
.bag-n {
  position: absolute;
  top: -5px; right: -5px;
  min-width: 16px; height: 16px;
  padding: 0 3px;
  border-radius: var(--r-full);
  background: var(--pink-deep);
  color: #fff;
  font-size: 10px; font-weight: 900;
  line-height: 16px; text-align: center;
  box-shadow: var(--elev-1);
}
#btn-bag.bump { animation: bag-bump .35s ease; }
@keyframes bag-bump { 30% { transform: scale(1.22) rotate(-6deg); } 60% { transform: scale(.95); } }

/* ============ INVENTAIRE ============ */
#inventory {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -46%) scale(.96);
  width: min(440px, calc(100vw - 32px));
  max-height: min(74vh, 560px);
  overflow-y: auto;
  background: linear-gradient(180deg, #fffdf8, var(--cream));
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2), inset 0 0 0 3px #fff;
  padding: var(--s4);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
#inventory.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
.inv-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: var(--fs-lg); font-weight: 900; color: var(--ink-strong);
  margin-bottom: var(--s3);
}
#inv-close-x {
  width: 32px; height: 32px; border: none; border-radius: var(--r-full);
  background: #f0e5d5; color: var(--ink-soft); font-size: 16px; font-weight: 900;
  cursor: pointer;
}
#inv-close-x:hover { background: var(--pink); color: #fff; }
#inv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: var(--s2);
}
.inv-empty { grid-column: 1 / -1; color: var(--ink-soft); font-weight: 700; text-align: center; padding: var(--s5) var(--s3); line-height: 1.5; }
.inv-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px;
  border: 2px solid #eaddc8;
  border-radius: var(--r-md);
  background: #fffdf8;
  cursor: pointer;
  position: relative;
  transition: transform .1s, border-color .1s;
}
.inv-item:hover { border-color: var(--pink); transform: translateY(-2px); }
.inv-item.equipped { border-color: var(--green); background: #f1f8ec; }
.inv-item img { width: 34px; height: 34px; image-rendering: pixelated; }
.inv-item .inv-n { position: absolute; top: 3px; right: 5px; font-size: 11px; font-weight: 900; color: var(--pink-deep); }
.inv-item .inv-name { font-size: 10px; font-weight: 700; color: var(--ink-soft); }
#inv-actions { display: none; }
#inv-actions.open {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: var(--s3); padding-top: var(--s3);
  border-top: 2px dashed #eaddc8;
}
.inv-act-title { display: flex; align-items: center; gap: 8px; font-weight: 900; color: var(--ink-strong); margin-bottom: 2px; }
.inv-act-title img { width: 22px; height: 22px; image-rendering: pixelated; }
#inv-actions button {
  height: var(--tap); border: none; border-radius: var(--r-md);
  background: var(--green); color: #fff; font-weight: 800; font-size: var(--fs-sm);
  cursor: pointer; font-family: inherit;
}
#inv-actions button:hover { filter: brightness(1.05); }
#inv-actions .inv-close { background: #f0e5d5; color: var(--ink-soft); }
.inv-tip { margin-top: var(--s3); font-size: var(--fs-xs); color: var(--ink-soft); line-height: 1.5; text-align: center; }

/* — argent (badge HUD) — */
#coin-hud {
  display: inline-flex; align-items: center; gap: 4px;
  align-self: flex-end; margin-top: 4px;
  padding: 3px 11px 3px 8px;
  background: linear-gradient(180deg, #fff6df, #ffe9b8);
  border-radius: var(--r-full);
  box-shadow: var(--elev-1), inset 0 0 0 1.5px #f0c96a;
  font-weight: 900; color: #8a5a12; font-size: var(--fs-sm);
}
#coin-hud .coin-ico { font-size: 13px; line-height: 1; }
#coin-hud.bump { animation: coinBump .4s ease; }
@keyframes coinBump { 0%,100%{ transform: scale(1); } 40%{ transform: scale(1.22); } }

/* — boutique / marché (même esprit que le sac) — */
#shop {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -46%) scale(.96);
  width: min(460px, calc(100vw - 32px));
  max-height: min(78vh, 600px); overflow-y: auto;
  background: linear-gradient(180deg, #fffdf8, var(--cream));
  border-radius: var(--r-lg);
  box-shadow: var(--elev-2), inset 0 0 0 3px #fff;
  padding: var(--s4); z-index: 31;
  opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
#shop.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
#shop-coins-badge {
  margin-left: auto; margin-right: 6px;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: var(--r-full);
  background: #fff2d2; box-shadow: inset 0 0 0 1.5px #f0c96a;
  font-size: var(--fs-sm); color: #8a5a12;
}
#shop-close-x {
  width: 32px; height: 32px; border: none; border-radius: var(--r-full);
  background: #f0e5d5; color: var(--ink-soft); font-size: 16px; font-weight: 900; cursor: pointer;
}
#shop-close-x:hover { background: var(--pink); color: #fff; }
.shop-tabs { display: flex; gap: 6px; margin-bottom: var(--s3); }
.shop-tab {
  flex: 1; height: 38px; border: 2px solid #eaddc8; border-radius: var(--r-md);
  background: #fffdf8; color: var(--ink-soft); font-weight: 800; font-size: var(--fs-sm);
  cursor: pointer; font-family: inherit;
}
.shop-tab.active { background: var(--pink); color: #fff; border-color: var(--pink); }
#shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: var(--s2); }
.shop-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 4px 6px; border: 2px solid #eaddc8; border-radius: var(--r-md);
  background: #fffdf8; cursor: pointer; position: relative; font-family: inherit;
  transition: transform .1s, border-color .1s;
}
.shop-item:hover { border-color: var(--pink); transform: translateY(-2px); }
.shop-item img { width: 34px; height: 34px; image-rendering: pixelated; }
.shop-name { font-size: 10px; font-weight: 800; color: var(--ink-soft); text-align: center; line-height: 1.2; }
.shop-price { font-size: 11px; font-weight: 900; }
.shop-price.sell { color: #b06a12; }
.shop-price.sell small { color: var(--ink-soft); font-weight: 700; }
.shop-price.buy { color: #2e9a4a; }
.shop-item.owned { opacity: .6; cursor: default; }
.shop-item.owned .shop-price { color: var(--green); }
.shop-item.locked { opacity: .55; }
.shop-item.locked .shop-price.buy { color: #c05454; }

/* ============ CLAVIER INTÉGRÉ (mobile) ============ */
#kbd {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  background: linear-gradient(180deg, #efe2cd, #e6d7bd);
  border-top: 3px solid #fff;
  box-shadow: 0 -6px 24px rgba(120, 90, 60, .22);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  transform: translateY(102%);
  transition: transform .22s cubic-bezier(.2, .8, .3, 1);
  touch-action: manipulation;
  user-select: none;
}
#kbd.open { transform: translateY(0); }
.kbd-bar {
  display: flex; align-items: center; gap: 6px;
  background: #fffdf8;
  border: 2px solid #d8c9ad;
  border-radius: var(--r-md);
  padding: 8px 10px;
  margin: 0 2px 8px;
  min-height: 40px;
  font-size: 16px; font-weight: 700; color: var(--ink);
}
.kbd-text { flex: 1; white-space: pre-wrap; word-break: break-word; line-height: 1.3; }
#kbd.empty .kbd-text::after { content: 'Tape ton message…'; color: var(--ink-soft); font-weight: 600; }
.kbd-caret { width: 2px; height: 20px; background: var(--pink-deep); animation: caret 1s steps(1) infinite; }
#kbd.empty .kbd-caret { display: none; }
@keyframes caret { 50% { opacity: 0; } }
.kbd-hide {
  width: 34px; height: 34px; flex: none; border: none; border-radius: var(--r-sm);
  background: #f0e5d5; color: var(--ink-soft); font-size: 20px; font-weight: 900; line-height: 1; cursor: pointer;
}
.kbd-keys { display: flex; flex-direction: column; gap: 6px; }
.kbd-row { display: flex; gap: 5px; justify-content: center; }
.kbd-key {
  flex: 1 1 0;
  min-width: 0;
  height: 46px;
  border: none;
  border-radius: 9px;
  background: #fffdf8;
  box-shadow: 0 2px 0 #c9b78f;
  font-family: inherit; font-size: 18px; font-weight: 800; color: var(--ink-strong);
  cursor: pointer;
  transition: transform .05s, background .05s;
}
.kbd-key:active { transform: translateY(2px); box-shadow: 0 0 0 #c9b78f; background: #f3e8d2; }
.kbd-sp { font-size: 15px; font-weight: 800; background: #e7d8bd; box-shadow: 0 2px 0 #b9a67e; }
.kbd-space { flex: 5 1 0; }
.kbd-send { flex: 2.4 1 0; background: var(--green); color: #fff; box-shadow: 0 2px 0 var(--green-press); }
.kbd-shift.kbd-key, .kbd-back.kbd-key { flex: 1.4 1 0; }
.kbd-123, .kbd-abc { flex: 1.6 1 0; }
/* pendant la frappe, on masque le joystick et les boutons d'action */
#touch-controls.typing { opacity: 0; pointer-events: none; }
@media (min-width: 900px) and (pointer: fine) {
  #kbd { display: none; } /* jamais de clavier intégré au clavier physique */
}

/* ============ INVITE D'INSTALLATION (PWA) ============ */
#btn-install {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  height: 46px;
  padding: 0 var(--s5);
  border: none;
  border-radius: var(--r-full);
  background: var(--green);
  color: #fff;
  font-family: inherit;
  font-weight: 800;
  font-size: var(--fs-md);
  box-shadow: 0 4px 0 var(--green-press), var(--elev-2);
  cursor: pointer;
  animation: install-pop .3s ease;
}
#btn-install:active { transform: translateX(-50%) translateY(3px); box-shadow: 0 1px 0 var(--green-press), var(--elev-1); }
@keyframes install-pop { from { opacity: 0; transform: translateX(-50%) translateY(12px); } }

/* ============ CONNEXION GOOGLE / EMAIL ============ */
.btn-google {
  width: 100%;
  min-height: 48px;
  margin-top: var(--s3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: #fff;
  color: #3c4043;
  font: inherit;
  font-weight: 800;
  font-size: var(--fs-md);
  cursor: pointer;
  box-shadow: var(--elev-1);
  transition: transform .1s, border-color .1s;
}
.btn-google:hover { border-color: #cdc6b6; }
.btn-google:active { transform: translateY(1px); }
.btn-apple {
  width: 100%;
  min-height: 48px;
  margin-top: var(--s2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  border: 2px solid #000;
  border-radius: var(--r-md);
  background: #000;
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: var(--fs-md);
  cursor: pointer;
  box-shadow: var(--elev-1);
  transition: transform .1s, filter .1s;
}
.btn-apple:hover { filter: brightness(1.25); }
.btn-apple:active { transform: translateY(1px); }
.auth-hint {
  font-size: var(--fs-xs);
  color: var(--ink-soft);
  font-weight: 600;
  margin-top: var(--s3);
  line-height: 1.45;
}

/* ============ PAGE DE CONNEXION + TABLEAU DE BORD ============ */
#screen-login {
  overflow-y: auto;
  touch-action: pan-y;
  background:
    radial-gradient(1200px 500px at 50% -150px, #ffe4ec 0%, transparent 60%),
    radial-gradient(900px 400px at 10% 110%, #dcf0d2 0%, transparent 60%),
    radial-gradient(900px 400px at 95% 105%, #d8ecf7 0%, transparent 55%),
    var(--cream);
}
.login-wrap {
  max-width: 460px;
  margin: 0 auto;
  padding: var(--s6) var(--s4) 40px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-title {
  font-size: var(--fs-lg);
  font-weight: 900;
  color: var(--ink-strong);
  text-align: center;
  margin-bottom: var(--s4);
}
.btn-guest {
  background: none;
  border: none;
  color: var(--pink-deep);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.btn-guest:hover { color: var(--pink-press); }
#dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s4);
  flex-wrap: wrap;
}
#dash-hello { display: block; font-size: var(--fs-xl); font-weight: 900; color: var(--ink-strong); line-height: 1.1; }
#dash-sub { display: block; font-size: var(--fs-sm); color: var(--ink-soft); font-weight: 700; margin-top: 3px; }
