/* Le monde est dans le canvas, le HUD est en DOM par-dessus.
   Les deux ne communiquent que par appels de fonction explicites. */

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #10161d;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #f3f6f4;
  /* Coupe le pull-to-refresh et le rebond élastique iOS, qui
     interfèrent avec le pan du canvas. */
  overscroll-behavior: none;
}

#stage {
  position: relative;
  width: 100%;
  height: 100%;
}

#world {
  display: block;
  width: 100%;
  height: 100%;
  /* Indispensable : sans ça le navigateur mobile intercepte le geste
     avant que pointermove ne soit émis. */
  touch-action: none;
  user-select: none;
}

#hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 12px
           max(12px, env(safe-area-inset-bottom));
  /* Le HUD laisse passer les gestes ; seuls les boutons les captent. */
  pointer-events: none;
}

.top, .bottom {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Bandeau de ressources ─────────────────────────────────────────── */

.resources {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(12, 20, 28, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 6px 12px 6px 6px;
  backdrop-filter: blur(6px);
  width: fit-content;
}

.avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background-repeat: no-repeat;
  /* Portrait recadré à la main dans artisan-homme-sprite-HID-test.png,
     rangée 5 colonne 0 (face caméra pure, choisie pour un avatar — voir
     tools/slice_sprites.py et la discussion sur les rangées 4/5). Recalculer
     ces trois valeurs si la planche est réexportée : rect source
     [84,1402,103,199], recadré aux ~46 % hauts (tête + épaules), mis à
     l'échelle pour couvrir un cercle de 40 px. */
  background-image: url('assets/atlas/artisan-homme-sprite-HID-test.png');
  background-size: 308px 741px;
  background-position: -39px -613px;
}

.level {
  display: flex;
  align-items: center;
  gap: 6px;
}

.level-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #7c4dff;
  font-size: 11px;
  font-weight: 700;
}

.xp-track {
  width: 64px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  background: #7c4dff;
}

.stat {
  font-size: 12px;
  white-space: nowrap;
}

/* ── Panneaux (inventaire pour l'instant) ─────────────────────────── */

.panel {
  pointer-events: auto;
  align-self: center;
  width: min(240px, 80vw);
  background: rgba(12, 20, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(6px);
}

.panel-title {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.7;
  margin-bottom: 6px;
}

.inv-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}

.inv-label { flex: 1; }
.inv-count { font-variant-numeric: tabular-nums; }

.icon {
  flex: none;
  display: inline-block;
  width: 28px;
  height: 28px;
  background-repeat: no-repeat;
}

/* Recadrages à la main dans landscape-items-HD.png — mêmes coordonnées que
   le manifeste de l'atlas (r1c5 bûches, r4c1 fleur, r2c2 champignons —
   identique au sprite "crop-ready" du monde), recalculer si la planche est
   réexportée. */
.icon-bois {
  background-image: url('assets/atlas/landscape-items-HD.png');
  background-size: 267px 178px;
  background-position: -150px -36px;
}

.icon-fleurs {
  background-image: url('assets/atlas/landscape-items-HD.png');
  background-size: 768px 512px;
  background-position: -60px -367px;
}

.icon-herbes {
  background-image: url('assets/atlas/landscape-items-HD.png');
  background-size: 295px 196px;
  background-position: -79px -72px;
}

.panel-hint {
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.85;
}

/* ── Nav du bas ────────────────────────────────────────────────────── */

.nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav {
  pointer-events: auto;
  display: flex;
  flex: 1;
  gap: 8px;
  justify-content: center;
  /* Défensif : un enfant flex:1 peut refuser de rétrécir sous sa largeur de
     contenu et déborder sur un petit écran, sans cette remise à zéro. */
  min-width: 0;
}

.nav-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  background: rgba(22, 34, 44, 0.9);
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  min-height: 44px;
  cursor: pointer;
}

.nav-btn span { font-size: 11px; }

.nav-btn:active, .nav-btn.active {
  background: rgba(124, 77, 255, 0.35);
  border-color: rgba(124, 77, 255, 0.6);
}

.map-btn {
  pointer-events: auto;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(22, 34, 44, 0.9);
  font-size: 18px;
  cursor: pointer;
}

.tag {
  background: rgba(12, 20, 28, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  backdrop-filter: blur(6px);
}

.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.actions button {
  pointer-events: auto;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(22, 34, 44, 0.9);
  color: inherit;
  font: inherit;
  font-size: 13px;
  padding: 10px 18px;
  /* 44 px : cible tactile minimale confortable au pouce. */
  min-height: 44px;
  cursor: pointer;
}

.actions button:active { background: rgba(40, 60, 76, 0.95); }

/* ── Chargement initial ────────────────────────────────────────────── */

.boot-loader {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(120% 120% at 50% 20%, #1b2735 0%, #10161d 60%, #0a0e13 100%);
  color: #f3f6f4;
  text-align: center;
  padding: 24px;
}

body.boot-active .boot-loader { display: flex; }
body.boot-active #stage { visibility: hidden; }

.boot-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.15) 0%, transparent 40%, rgba(0, 0, 0, 0.25) 100%);
}

.boot-title {
  position: relative;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 10px rgba(124, 77, 255, 0.5);
}

.boot-bar {
  position: relative;
  width: min(220px, 60vw);
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.boot-bar-fill {
  height: 100%;
  width: 40%;
  background: #7c4dff;
  border-radius: inherit;
  animation: bootBarSlide 1.1s ease-in-out infinite;
}

@keyframes bootBarSlide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

.boot-label {
  position: relative;
  font-size: 12px;
  opacity: 0.75;
}

/* ── Verrou d'accès (Google OAuth) ─────────────────────────────────── */

.overlay-auth {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 12, 17, 0.86);
  backdrop-filter: blur(4px);
}

.overlay-auth[hidden] { display: none !important; }

.auth-card {
  width: min(90%, 340px);
  text-align: center;
  padding: 28px 22px;
  background: rgba(16, 24, 32, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.auth-title {
  font-size: 24px;
  font-weight: 800;
  margin: 0 0 12px;
}

.auth-subtitle {
  font-size: 14px;
  font-weight: 600;
  color: #d6dde3;
  margin: 0 0 16px;
}

.auth-desc {
  font-size: 13px;
  color: #a9b2ba;
  margin: 0 0 10px;
}

.auth-hint {
  font-size: 12px;
  line-height: 1.4;
  color: #8b949c;
  margin: 0 0 14px;
}

.btn-google {
  appearance: none;
  background: #ffffff;
  border: none;
  border-radius: 999px;
  color: #202124;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  height: 48px;
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease;
}

.btn-google:hover { background: #f1f3f4; }
.btn-google:active { transform: scale(0.97); }

.btn-secondary {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(22, 34, 44, 0.9);
  color: inherit;
  font: inherit;
  font-size: 13px;
  padding: 10px 18px;
  min-height: 44px;
  cursor: pointer;
  margin-top: 6px;
}

.btn-secondary:active { background: rgba(40, 60, 76, 0.95); }

.auth-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #7c4dff;
  border-radius: 50%;
  animation: bootSpin 0.8s linear infinite;
  margin: 12px auto;
}

@keyframes bootSpin {
  to { transform: rotate(360deg); }
}

.auth-badge-wait {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(124, 77, 255, 0.18);
  color: #c9b8ff;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

/* Bandeau d'alerte — repli de l'atlas. Volontairement voyant : son intérêt
   est justement qu'on ne puisse pas le rater. */
#alert {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  max-width: min(90vw, 44rem);
  padding: 0.6rem 0.9rem;
  border-radius: 0.5rem;
  background: #b3261e;
  color: #fff;
  font: 500 0.82rem/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
  box-shadow: 0 2px 12px rgb(0 0 0 / 35%);
  z-index: 10;
}
