* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Écran d'accueil et lobby immersifs ----------
   Piloté par la classe .menu-screen (posée sur <html> ET <body> par défaut,
   retirée en JS quand la partie démarre) plutôt que par :has(), pour rester
   fiable même quand le verrouillage plein écran tactile (plus bas) s'applique
   en même temps. Le <html> doit être réinitialisé lui aussi : sur mobile ce
   verrouillage met "overflow: hidden" sur <html> ET <body>, et un défilement
   tactile réel (contrairement à un scroll déclenché en JS) est bloqué si
   n'importe lequel des deux ancêtres a encore overflow: hidden. */

html.menu-screen {
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
  min-height: 100%;
}

body.menu-screen {
  position: static;
  inset: auto;
  display: block;
  width: 100%;
  height: auto;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  background: radial-gradient(circle at 18% 18%, rgba(255,230,109,.18), transparent 24rem), radial-gradient(circle at 82% 72%, rgba(111,184,201,.18), transparent 28rem), linear-gradient(145deg, #101e17, #1d3b29 48%, #13251b);
  scrollbar-color: #7bc95f #172a1e;
  scrollbar-width: thin;
}

body.menu-screen::before,
body.menu-screen::after {
  content: "";
  position: fixed;
  z-index: 0;
  width: 340px;
  height: 340px;
  border-radius: 48% 52% 44% 56%;
  pointer-events: none;
  opacity: .28;
  background: repeating-radial-gradient(ellipse at center, #7bc95f 0 6px, transparent 7px 24px);
  animation: menu-float 12s ease-in-out infinite alternate;
}

body.menu-screen::before { top: -130px; left: -100px; }
body.menu-screen::after { right: -120px; bottom: -150px; animation-delay: -5s; }
@keyframes menu-float { to { transform: translate3d(20px, 18px, 0) rotate(8deg); } }

#auth-screen, #lobby {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 18px max(34px, env(safe-area-inset-bottom));
  justify-content: center;
}

#auth-screen { width: min(500px, 100%); }
#lobby { width: min(820px, 100%); max-width: none; }
.menu-brand { text-align: center; filter: drop-shadow(0 8px 18px rgba(0,0,0,.32)); }
.menu-brand-icon { display: inline-block; font-size: clamp(54px, 9vw, 82px); line-height: 1; animation: brand-breathe 3.5s ease-in-out infinite; }
.menu-brand h1 { margin-top: 5px; font-size: clamp(29px, 6vw, 46px) !important; color: #fff8d9; letter-spacing: .5px; text-shadow: 0 3px 0 #496d38, 0 7px 18px rgba(0,0,0,.5) !important; }
.menu-brand p { margin-top: 7px; color: #cfe8c4; font-size: clamp(13px, 2.4vw, 16px); }
@keyframes brand-breathe { 50% { transform: translateY(-5px) scale(1.04); } }

#auth-form, #lobby-form {
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 20px 48px rgba(4,12,7,.46), inset 0 1px rgba(255,255,255,.1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#auth-form { padding: clamp(22px, 5vw, 34px); border-radius: 24px; background: linear-gradient(145deg, rgba(58,94,53,.94), rgba(33,61,39,.95)); }
#auth-form h2 { margin-bottom: 6px; color: #ffe66d; }
#auth-form label, #lobby-form label { font-weight: bold; color: #dff3d7; }
#auth-form input, #player-name-input, #room-code-input { outline: none; border-color: rgba(123,201,95,.65); box-shadow: inset 0 2px 5px rgba(31,58,29,.18); transition: border-color .2s, box-shadow .2s, transform .2s; }
#auth-form input:focus, #player-name-input:focus, #room-code-input:focus { border-color: #ffe66d; box-shadow: 0 0 0 4px rgba(255,230,109,.16); transform: translateY(-1px); }

#auth-form button, #lobby-form button, #btn-logout { box-shadow: 0 4px 0 rgba(31,72,32,.7); transition: transform .15s, filter .15s, box-shadow .15s; }
#auth-form button:hover, #lobby-form button:hover, #btn-logout:hover { filter: brightness(1.1); transform: translateY(-2px); }
#auth-form button:active, #lobby-form button:active, #btn-logout:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(31,72,32,.7); }

#account-bar { padding: 9px 12px 9px 16px; border: 1px solid rgba(255,255,255,.14); border-radius: 14px; background: rgba(30,57,38,.82); box-shadow: 0 8px 22px rgba(0,0,0,.25); }
#account-name { font-weight: bold; color: #ffe66d; }
#lobby-form { padding: clamp(18px, 4vw, 30px); border-radius: 24px; background: linear-gradient(145deg, rgba(52,84,47,.94), rgba(30,55,35,.96)); }
#lobby-emoji-options { grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 7px; width: 100%; max-width: none; }
#lobby-emoji-options .character-btn { min-width: 0; background: linear-gradient(#345b32, #29492a); box-shadow: 0 5px 10px rgba(0,0,0,.2); }
#lobby-emoji-options .character-btn.selected { border-color: #ffe66d; background: linear-gradient(#56834a, #3f6b39); box-shadow: 0 0 0 3px rgba(255,230,109,.15), 0 7px 14px rgba(0,0,0,.25); }
#rooms-section { padding: 14px; border: 1px solid rgba(255,255,255,.12); background: rgba(13,36,23,.5); box-shadow: inset 0 1px rgba(255,255,255,.08); }
#rooms-list { max-height: 240px; padding-right: 3px; }
.room-row { border-left: 5px solid #7bc95f; box-shadow: 0 4px 9px rgba(0,0,0,.2); }
.room-row button:disabled { cursor: not-allowed; filter: grayscale(.8); opacity: .65; transform: none; }

@media (max-width: 720px) {
  #auth-screen, #lobby { justify-content: flex-start; gap: 10px; }
  .menu-brand-icon { font-size: 38px; }
  .menu-brand h1 { font-size: 24px !important; margin-top: 2px; }
  .menu-brand p { font-size: 12px; margin-top: 2px; }
  #lobby-emoji-options { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  #lobby-emoji-options .character-btn { padding: 5px 2px; gap: 2px; }
  #lobby-emoji-options .avatar-sprite { width: 40px; height: 48px; }
  #lobby-form { padding: 16px 12px; gap: 10px; }
  #lobby-join-row { flex-wrap: wrap; }
  #room-code-input { width: 130px; }
  .room-row { align-items: flex-start; }
  .room-actions { flex-wrap: wrap; justify-content: flex-end; }
}

/* Installation sur l'écran d'accueil (voir pwa.js) : visible seulement sur les menus. */
#install-btn, #install-hint { position: fixed; z-index: 5; left: 50%; transform: translateX(-50%); }
body:not(.menu-screen) #install-btn, body:not(.menu-screen) #install-hint { display: none; }
body:has(#install-btn:not(.hidden)) #auth-screen, body:has(#install-btn:not(.hidden)) #lobby { padding-bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px); }
#install-btn { bottom: max(14px, env(safe-area-inset-bottom)); white-space: nowrap; padding: 9px 14px; border: 1px solid rgba(255,255,255,.2); border-radius: 999px; background: linear-gradient(#56834a, #3f6b39); color: #fff8d9; font: inherit; font-weight: bold; font-size: 14px; cursor: pointer; box-shadow: 0 4px 0 rgba(31,72,32,.7), 0 8px 18px rgba(0,0,0,.3); }
#install-hint { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 52px); width: max-content; max-width: min(300px, calc(100vw - 24px)); text-align: center; padding: 10px 14px; border-radius: 14px; background: rgba(16,30,23,.96); border: 1px solid rgba(255,230,109,.5); color: #dff3d7; font-size: 14px; line-height: 1.4; box-shadow: 0 8px 22px rgba(0,0,0,.4); }

@media (prefers-reduced-motion: reduce) {
  .menu-brand-icon,
  body.menu-screen::before,
  body.menu-screen::after { animation: none; }
}

/* Viewports bas (téléphone en paysage, petites tablettes) : le gros bandeau de
   marque à lui seul peut repousser le formulaire et ses boutons hors champ.
   On le compacte pour garder "Entrer" / "Rejoindre" visibles sans avoir à scroller. */
@media (max-height: 560px) {
  .menu-brand-icon { display: none; }
  .menu-brand p { display: none; }
  .menu-brand h1 { margin-top: 0; font-size: clamp(18px, 5vh, 24px) !important; }
  #auth-screen, #lobby { gap: 8px; justify-content: flex-start; padding: max(10px, env(safe-area-inset-top)) 18px max(10px, env(safe-area-inset-bottom)); }
  #auth-form, #lobby-form { padding: 14px; gap: 8px; }
}

html, body {
  height: 100%;
}

body {
  background: #1b2a1a;
  font-family: "Comic Sans MS", "Trebuchet MS", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

button {
  touch-action: manipulation;
}

/* ---------- Lobby ---------- */

#auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: min(430px, 92vw);
  color: #eafbe0;
  text-align: center;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 22px;
  border-radius: 16px;
  background: #2f4d2a;
}

#device-wait, #mfa-enroll { padding: 24px; border-radius: 24px; background: #213d27; display: flex; flex-direction: column; gap: 16px; }
#mfa-enroll ol { padding-left: 22px; text-align: left; display: flex; flex-direction: column; gap: 10px; line-height: 1.45; }
#mfa-secret { display: inline-block; margin-top: 4px; font-family: monospace; font-size: 1.15em; letter-spacing: .08em; color: #ffe66d; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
#mfa-link { color: #a8e08f; }
#mfa-enroll input, #auth-mfa-row input { padding: 11px 14px; border: 3px solid #3d5c2e; border-radius: 12px; font: inherit; font-size: 20px; letter-spacing: .2em; text-align: center; width: 100%; }
#mfa-enroll button { padding: 12px; cursor: pointer; }
#mfa-enroll-error { color: #ffcfbf; }
#auth-mfa-row { display: flex; flex-direction: column; gap: 6px; width: 100%; }
#device-wait-code { display: inline-block; font-size: 1.3em; letter-spacing: .1em; color: #ffe66d; }
#device-wait button { padding: 12px; cursor: pointer; }
#devices-error, #device-wait-error { color: #ffcfbf; }

/* Administration : une vue indépendante du formulaire de jeu. */
#btn-admin {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; min-height: 48px; padding: 12px 16px; border: 1px solid #8cb876;
  border-radius: 14px; background: #29492f; color: #f5f2dc; font: inherit; font-weight: bold; cursor: pointer;
}
#admin-pending-badge { padding: 4px 8px; border-radius: 20px; background: #f2d789; color: #423612; font-size: 12px; }
#admin-devices {
  position: relative; z-index: 1; width: min(1120px, 100%); margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  color: #f5f2dc; font-family: "Trebuchet MS", sans-serif; line-height: 1.5;
}
.admin-header, .admin-hero, .admin-section-heading, .admin-toolbar, .admin-results-bar, .device-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.admin-brand { display: flex; align-items: center; gap: 10px; font-size: 24px; }
.admin-brand span { font-size: 11px; font-weight: bold; letter-spacing: .12em; }
.admin-hero { padding: 36px 0 26px; align-items: flex-end; }
.admin-eyebrow { color: #bbd5a9; font-size: 11px; font-weight: bold; letter-spacing: .16em; margin-bottom: 8px; }
.admin-hero h1 { font-size: clamp(30px, 5vw, 44px); line-height: 1.12; letter-spacing: -.035em; margin-bottom: 12px; }
.admin-hero p:not(.admin-eyebrow) { color: #d0dec5; max-width: 540px; font-size: 15px; }
.admin-account { color: #c5d8b8; font-size: 12px; flex-shrink: 0; }
.admin-button { min-height: 44px; padding: 10px 16px; border: 1px solid transparent; border-radius: 10px; font: inherit; font-size: 13px; font-weight: bold; cursor: pointer; line-height: 1.3; }
.admin-button-outline { background: transparent; border-color: currentColor; color: inherit; }
.admin-button-primary { color: #fff; background: #345b3c; border-color: #345b3c; }
.admin-button-danger { color: #8a3430; background: #fff8f5; border-color: #d5aea5; }
.admin-button:hover:not(:disabled) { filter: brightness(.94); }
.admin-button:disabled { opacity: .55; cursor: wait; }
#admin-devices :focus-visible, #admin-confirm :focus-visible, #btn-admin:focus-visible { outline: 3px solid #daab49; outline-offset: 4px; }
.admin-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.admin-stat { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 20px; border-radius: 16px; border: 1px solid #d9ddcc; background: #f5f3e9; color: #243f2d; text-align: left; font: inherit; }
button.admin-stat { cursor: pointer; transition: background .15s; }
button.admin-stat:hover { background: #e8eddc; }
.admin-stat:first-child { background: #f4e5b9; border-color: #eed694; }
.admin-stat > span { font-size: 13px; font-weight: bold; }
.admin-stat strong { font-size: 36px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.admin-stat small { font-size: 12px; color: #53634d; }
.admin-security { display: flex; align-items: center; gap: 10px; padding: 16px 2px 22px; color: #cfdec6; font-size: 13px; }
.admin-security > span { font-size: 24px; color: #b8d9a0; }
.admin-workspace { padding: 24px; border-radius: 20px; background: #f7f6ef; color: #253d2c; box-shadow: 0 14px 40px #06170f40; }
.admin-section-heading h2 { font-size: 21px; letter-spacing: -.02em; }
#devices-updated { font-size: 12px; color: #63705d; margin-top: 4px; }
.admin-toolbar { padding: 22px 0 16px; align-items: flex-end; flex-wrap: wrap; }
.admin-filters { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: #e9ecdf; flex-wrap: wrap; }
.admin-filters button { padding: 9px 12px; min-height: 44px; border: 0; border-radius: 8px; color: #536149; background: transparent; font: inherit; font-size: 13px; font-weight: bold; cursor: pointer; }
.admin-filters button[aria-pressed="true"] { background: #345b3c; color: #fff; box-shadow: 0 2px 6px #1d3b2925; }
.admin-search { flex: 1 1 230px; max-width: 360px; }
.admin-search label { display: block; font-size: 12px; font-weight: bold; margin-bottom: 5px; color: #536149; }
.admin-search input { width: 100%; min-height: 46px; padding: 10px 14px; border: 1px solid #bbc5b0; border-radius: 10px; background: #fff; color: #253d2c; font: inherit; font-size: 16px; }
.admin-search input::placeholder { color: #697565; }
.admin-results-bar { min-height: 44px; margin-bottom: 14px; flex-wrap: wrap; font-size: 12px; color: #5a6752; }
#devices-error:not(:empty), #devices-feedback:not(:empty) { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
#devices-error { color: #8b3028; background: #fae7df; }
#devices-feedback { color: #2e5439; background: #e4eedb; }
#devices-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.device-row { min-width: 0; padding: 20px; border: 1px solid #d9dfd0; border-radius: 14px; background: #fffefa; display: flex; flex-direction: column; gap: 14px; }
.device-row.device-pending { border-top: 3px solid #cda545; padding-top: 18px; }
.device-heading { align-items: flex-start; gap: 10px; }
.device-identity { min-width: 0; overflow-wrap: anywhere; }
.device-owner { font-size: 12px; color: #69725f; margin-bottom: 2px; }
.device-name { font-size: 18px; line-height: 1.3; color: #243f2d; }
.device-status { flex-shrink: 0; border-radius: 20px; padding: 4px 9px; font-size: 11px; font-weight: bold; background: #eceee7; color: #626855; }
.status-pending { background: #f5e8bc; color: #745319; }
.status-approved { background: #e0edd8; color: #345b3c; }
.status-rejected, .status-revoked { background: #f6e5de; color: #88463d; }
.device-current { align-self: flex-start; font-size: 11px; color: #46623d; }
.device-code { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 8px; background: #f1f3e9; font-size: 11px; color: #63705d; }
.device-pending .device-code { background: #faf2d9; }
.device-code strong { font-family: ui-monospace, Consolas, monospace; font-size: 15px; letter-spacing: .07em; color: #3d492c; user-select: all; }
.device-dates { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; }
.device-dates dt { font-size: 11px; color: #69725f; }
.device-dates dd { font-size: 12px; color: #354b35; font-variant-numeric: tabular-nums; }
.device-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 2px; }
.device-actions:empty { display: none; }
.device-actions .admin-button { flex: 1; }
.admin-empty { grid-column: 1 / -1; padding: 40px 16px; text-align: center; color: #63705d; }
.admin-empty-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: #e7eddd; color: #496d38; font-size: 26px; margin-bottom: 12px; }
.admin-empty h3 { color: #345b3c; margin-bottom: 6px; }
.admin-empty p { font-size: 14px; }
.admin-footer { padding: 20px 4px 0; color: #b7caaa; font-size: 12px; text-align: center; }
#admin-confirm { margin: auto; width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 24px; border: 1px solid #becbb3; border-radius: 18px; background: #f7f6ef; color: #253d2c; font-family: "Trebuchet MS", sans-serif; line-height: 1.5; overflow-y: auto; }
#admin-confirm::backdrop { background: #07180dcc; }
#admin-confirm h2 { font-size: 23px; margin-bottom: 12px; }
#admin-confirm p { margin: 12px 0; font-size: 14px; }
#admin-confirm-devices { list-style: none; border: 1px solid #d9dfd0; border-radius: 10px; background: #fffefa; padding: 12px; font-size: 14px; overflow-wrap: anywhere; }
#admin-confirm-devices li + li { margin-top: 10px; border-top: 1px solid #d9dfd0; padding-top: 10px; }
#admin-confirm-note { color: #685c3b; }
.admin-confirm-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
@media (max-width: 760px) {
  #admin-devices { padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  .admin-brand span { max-width: 130px; font-size: 10px; }
  .admin-hero { padding: 26px 0 20px; align-items: flex-start; flex-direction: column; gap: 12px; }
  .admin-stats { gap: 8px; }
  .admin-stat { padding: 12px 10px; border-radius: 12px; }
  .admin-stat strong { font-size: 29px; }
  .admin-stat small { font-size: 10px; }
  .admin-workspace { padding: 16px; }
  #devices-list { grid-template-columns: minmax(0, 1fr); }
  .admin-search { max-width: none; }
  .admin-filters { width: 100%; }
  .admin-filters button { flex: 1; padding: 8px; font-size: 12px; }
  .device-row { padding: 16px; }
  .device-name { font-size: 17px; }
}
@media (max-width: 380px) {
  .admin-section-heading { align-items: flex-start; flex-direction: column; }
  .device-heading, .device-code { flex-wrap: wrap; }
  .admin-filters { display: grid; grid-template-columns: repeat(2, 1fr); }
}

#auth-form input {
  padding: 11px 14px;
  border: 3px solid #3d5c2e;
  border-radius: 10px;
  background: #eafbe0;
  font: 17px inherit;
}

#auth-form button,
#btn-logout,
#btn-refresh-rooms,
.room-row button {
  padding: 10px 14px;
  border: 0;
  border-radius: 9px;
  background: #7bc95f;
  font-family: inherit;
  cursor: pointer;
}

#btn-register {
  background: #6fb8c9 !important;
}

#auth-error {
  padding: 8px;
  border-radius: 8px;
  background: #a94442;
  color: #fff;
}

#lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  color: #eafbe0;
  text-align: center;
  padding: 20px;
  max-width: 480px;
}

#lobby h1 {
  font-size: 26px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#account-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  width: 100%;
}

#btn-logout {
  padding: 6px 10px;
  background: #d9e7d2;
}

#rooms-section {
  padding: 10px;
  border-radius: 12px;
  background: rgba(47, 77, 42, 0.75);
}

#rooms-title-row,
.room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#rooms-title-row h2 {
  font-size: 17px;
}

#btn-refresh-rooms {
  padding: 5px 10px;
}

#rooms-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 8px;
  max-height: 180px;
  overflow-y: auto;
}

.room-row {
  padding: 8px;
  border-radius: 8px;
  background: #eafbe0;
  color: #2b2b2b;
  font-size: 13px;
  text-align: left;
}

.room-row button {
  padding: 7px 10px;
}

.room-actions {
  display: flex;
  gap: 6px;
}

.room-row .room-delete-btn {
  background: #c95f5f;
  color: #fff;
}

.rooms-empty {
  padding: 10px;
  font-size: 13px;
  opacity: 0.85;
}

#lobby-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  width: 100%;
}

#lobby-form label {
  font-size: 14px;
  opacity: 0.9;
}

#player-name-input, #room-code-input {
  font-family: inherit;
  font-size: 18px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 3px solid #3d5c2e;
  background: #eafbe0;
  color: #2b2b2b;
  text-align: center;
}

#room-code-input {
  text-transform: uppercase;
  letter-spacing: 4px;
  width: 140px;
}

#lobby-emoji-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  max-width: 420px;
  margin: 0 auto;
}

#btn-create-room {
  font-family: inherit;
  font-size: 18px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: #7bc95f;
  cursor: pointer;
  font-weight: bold;
}

#btn-create-room:hover {
  background: #5aa845;
}

#lobby-divider {
  font-size: 13px;
  opacity: 0.7;
}

#lobby-join-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

#btn-join-room {
  font-family: inherit;
  font-size: 15px;
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: #6fb8c9;
  cursor: pointer;
}

#btn-join-room:hover {
  background: #4f98a9;
}

#lobby-error {
  background: #a94442;
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.character-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 8px 4px;
  border: 3px solid #3d5c2e;
  border-radius: 12px;
  background: #2f4d2a;
  color: #eafbe0;
  font-size: 10px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.character-btn:hover {
  background: #416a37;
  transform: translateY(-2px);
  border-color: #7bc95f;
}

.character-btn.selected {
  background: #416a37;
  border-color: #7bc95f;
}

.character-emoji {
  font-size: 32px;
}

.avatar-sprite {
  display: inline-block;
  width: 58px;
  height: 68px;
  background-image: url("assets/avatars-chibi.png");
  background-repeat: no-repeat;
  /* Chaque rangée a son propre cadrage car les espacements de la source diffèrent. */
  background-size: 500% var(--avatar-size-y, 374%);
  background-position: var(--avatar-x) var(--avatar-y);
}

.entity-emoji.avatar-sprite {
  width: 34px;
  height: 44px;
  transform: scaleX(var(--avatar-facing, 1));
  transform-origin: center bottom;
}

#player::before,
.remote-player::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  z-index: -1;
  width: 28px;
  height: 8px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(25, 35, 20, 0.28);
}

#player.moving .avatar-sprite,
.remote-player.moving .avatar-sprite {
  animation: avatar-walk 0.36s ease-in-out infinite;
}

#player.moving::before,
.remote-player.moving::before {
  animation: avatar-shadow 0.36s ease-in-out infinite;
}

@keyframes avatar-walk {
  0%, 100% { transform: translateY(0) rotate(-2deg) scaleX(var(--avatar-facing, 1)); }
  50% { transform: translateY(-4px) rotate(2deg) scaleX(var(--avatar-facing, 1)); }
}

@keyframes avatar-shadow {
  0%, 100% { transform: translateX(-50%) scaleX(1); opacity: 0.8; }
  50% { transform: translateX(-50%) scaleX(0.72); opacity: 0.5; }
}

/* Sur un plateau d'eau, l'avatar reste reconnaissable mais son bas est
   immergé. Les deux pseudo-éléments dessinent la vague avant et le sillage. */
#player.swimming,
.remote-player.swimming {
  --swim-facing: 1;
  height: 39px;
  margin-top: 8px;
  filter: drop-shadow(0 4px 3px rgba(13, 68, 86, .28));
}

#player.swimming .avatar-sprite,
.remote-player.swimming .avatar-sprite {
  clip-path: inset(0 0 25% 0 round 0 0 45% 45%);
  transform-origin: 50% 65%;
  animation: avatar-float 1.5s ease-in-out infinite;
}

#player.swimming::before,
.remote-player.swimming::before {
  left: 50%;
  bottom: -2px;
  z-index: 2;
  width: 48px;
  height: 13px;
  border: 3px solid rgba(218, 249, 255, .92);
  border-top-color: transparent;
  border-radius: 50%;
  background: rgba(73, 174, 199, .28);
  box-shadow: 0 0 0 4px rgba(129, 220, 235, .18);
}

#player.swimming::after,
.remote-player.swimming::after {
  content: "○  ·  ○";
  position: absolute;
  left: 24%;
  bottom: -8px;
  z-index: 1;
  color: rgba(224, 252, 255, .9);
  font-size: 12px;
  letter-spacing: 1px;
  white-space: nowrap;
  transform: translateX(-50%) scaleX(var(--swim-facing));
  opacity: .65;
}

#player.swimming.swim-facing-left::after,
.remote-player.swimming.swim-facing-left::after { left: 76%; }

#player.swimming.moving .avatar-sprite,
.remote-player.swimming.moving .avatar-sprite {
  animation: avatar-swim .56s ease-in-out infinite;
}

#player.swimming.moving::before,
.remote-player.swimming.moving::before {
  animation: swim-ripple .7s ease-out infinite;
}

#player.swimming.moving::after,
.remote-player.swimming.moving::after {
  animation: swim-bubbles .9s linear infinite;
}

@keyframes avatar-float {
  0%, 100% { transform: translateY(1px) rotate(-1deg) scaleX(var(--avatar-facing, 1)); }
  50% { transform: translateY(-2px) rotate(1deg) scaleX(var(--avatar-facing, 1)); }
}

@keyframes avatar-swim {
  0%, 100% { transform: translateY(1px) rotate(-7deg) scaleX(var(--avatar-facing, 1)); }
  50% { transform: translateY(-3px) rotate(5deg) scaleX(var(--avatar-facing, 1)); }
}

@keyframes swim-ripple {
  from { transform: translateX(-50%) scale(.75); opacity: .95; }
  to { transform: translateX(-50%) scale(1.25); opacity: .18; }
}

@keyframes swim-bubbles {
  from { transform: translateX(-30%) scaleX(var(--swim-facing)); opacity: .9; }
  to { transform: translateX(-75%) scaleX(var(--swim-facing)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #player.moving .avatar-sprite,
  .remote-player.moving .avatar-sprite,
  #player.moving::before,
  .remote-player.moving::before {
    animation: none;
  }
  #player.swimming .avatar-sprite,
  .remote-player.swimming .avatar-sprite,
  #player.swimming::before,
  .remote-player.swimming::before,
  #player.swimming::after,
  .remote-player.swimming::after { animation: none !important; }
}

/* ---------- Backpack ---------- */

#backpack-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 10, 0.85);
}

#backpack-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 22px;
  border-radius: 16px;
  background: #2f4d2a;
  color: #eafbe0;
  text-align: center;
  max-height: 90vh;
  overflow-y: auto;
}

#backpack-content h2 {
  font-size: 22px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#backpack-grid {
  display: grid;
  grid-template-columns: repeat(5, 46px);
  grid-auto-rows: 46px;
  gap: 6px;
}

.backpack-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  overflow: hidden;
  box-sizing: border-box;
  border: 2px solid #3d5c2e;
  border-radius: 8px;
  background: #1b2a1a;
  touch-action: none;
}

.backpack-slot.multi-cell .backpack-slot-emoji {
  font-size: 32px;
}

.backpack-slot.multi-cell .backpack-slot-count {
  font-size: 11px;
}

.backpack-slot.filled {
  background: #eafbe0;
  border-color: #7bc95f;
  cursor: grab;
}

.backpack-slot.selected-for-sale {
  background: #fff3c4;
  border-color: #e0a83f;
  box-shadow: inset 0 0 0 2px #e0a83f;
}

.backpack-slot.awaiting-use {
  border-color: #ffe66d;
  box-shadow: inset 0 0 0 2px rgba(255,230,109,.75), 0 0 7px rgba(255,230,109,.5);
}

#container-sell-selection {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(224, 168, 63, 0.18);
  border: 1px solid #e0a83f;
}

#container-sell-selection-summary {
  font-weight: bold;
  font-size: 13px;
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  transform: translate(-50%, -50%);
  font-size: 28px;
  pointer-events: none;
  z-index: 999;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.5));
}

.drag-ghost-big {
  font-size: 46px;
}

.drop-preview {
  pointer-events: none;
  border-radius: 8px;
  z-index: 5;
}

.drop-preview-ok {
  background: rgba(90, 220, 90, 0.5);
  border: 2px solid #3fae3f;
}

.drop-preview-bad {
  background: rgba(220, 90, 90, 0.5);
  border: 2px solid #ae3f3f;
}

.backpack-slot-emoji {
  width: 100%;
  height: 27px;
  flex: 0 0 27px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

.backpack-slot-count {
  width: 100%;
  height: 10px;
  flex: 0 0 10px;
  font-size: 9px;
  line-height: 10px;
  color: #2b2b2b;
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

#inventory-tooltip {
  position: fixed;
  z-index: 10000;
  max-width: 220px;
  padding: 7px 11px;
  border: 2px solid #d4b060;
  border-radius: 9px;
  background: linear-gradient(145deg, rgba(47, 65, 43, .97), rgba(25, 40, 27, .98));
  color: #fff5cf;
  font: bold 12px/1.25 "Comic Sans MS", "Trebuchet MS", sans-serif;
  letter-spacing: .2px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 7px 18px rgba(0, 0, 0, .45), inset 0 1px rgba(255,255,255,.12);
  animation: inventory-tooltip-in .12s ease-out;
}

#inventory-tooltip::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 12px;
  width: 8px;
  height: 8px;
  transform: rotate(45deg);
  border-top: 2px solid #d4b060;
  border-left: 2px solid #d4b060;
  background: #2f412b;
}

@keyframes inventory-tooltip-in {
  from { opacity: 0; transform: translateY(3px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  #inventory-tooltip { animation: none; }
}

#backpack-close-btn {
  font-family: inherit;
  font-size: 15px;
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: #7bc95f;
  cursor: pointer;
}

#backpack-close-btn:hover {
  background: #5aa845;
}

/* ---------- Container (coffre / frigo) ---------- */

#container-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 20, 10, 0.85);
}

#container-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 22px;
  border-radius: 16px;
  background: #2f4d2a;
  color: #eafbe0;
  text-align: center;
  max-width: 92vw;
  max-height: 94vh;
  overflow: auto;
}

#container-content h2 {
  font-size: 22px;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#container-columns {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.container-column h3 {
  font-size: 14px;
  margin-bottom: 8px;
  opacity: 0.9;
}

.bag-grid {
  display: grid;
  grid-template-columns: repeat(5, 46px);
  grid-auto-rows: 46px;
  gap: 6px;
}

.bag-grid.compact-grid .backpack-slot {
  border-radius: 6px;
}

.bag-grid.compact-grid .backpack-slot-emoji {
  height: 21px;
  flex-basis: 21px;
  font-size: 15px;
}

.bag-grid.compact-grid .backpack-slot.multi-cell .backpack-slot-emoji {
  font-size: 26px;
}

.bag-grid.compact-grid .backpack-slot-count {
  height: 8px;
  flex-basis: 8px;
  font-size: 8px;
  line-height: 8px;
}

.bag-grid.compact-grid .backpack-slot.multi-cell .backpack-slot-count {
  font-size: 9px;
}

#container-hint {
  font-size: 12px;
  opacity: 0.8;
}

.backpack-slot-count.merchant-price {
  padding: 2px 5px;
  border-radius: 7px;
  background: #5b431f;
  color: #ffe66d;
  font-weight: bold;
}

.price-missing {
  color: #ff6b6b;
}

.backpack-slot-count.construction-slot-done {
  padding: 1px 4px;
  border-radius: 6px;
  background: #2f7d32;
  color: #eafbe0;
  font-weight: bold;
}

.merchant-sold-message {
  grid-column: 1 / -1;
  padding: 14px;
  border-radius: 10px;
  background: rgba(123, 201, 95, 0.18);
  color: #cfe8c4;
  font-size: 13px;
  text-align: center;
}

#container-close-btn {
  font-family: inherit;
  font-size: 15px;
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: #7bc95f;
  cursor: pointer;
}

#container-close-btn:hover {
  background: #5aa845;
}

/* ---------- Tableau des talents ---------- */

#talent-panel, #mason-panel {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(10, 20, 10, 0.88);
}

#talent-content, #mason-content {
  width: min(680px, 94vw);
  max-height: 94vh;
  overflow: auto;
  padding: 22px;
  border: 4px solid #c69152;
  border-radius: 18px;
  background: linear-gradient(145deg, #3c5b32, #243d25);
  color: #fff8e7;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.55);
}

#mason-content { width: min(1040px, 96vw); }

#mason-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.plan-card {
  min-height: 270px;
  padding: 12px 10px;
  cursor: default;
}

.plan-style-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  margin: 9px 0 5px;
}

.plan-style-gallery[data-kind="small"],
.plan-style-gallery[data-kind="medium"],
.plan-style-gallery[data-kind="large"] {
  grid-template-columns: repeat(5, minmax(58px, 1fr));
  max-height: 184px;
  padding: 3px 4px 3px 3px;
  overflow-y: auto;
  scrollbar-color: #ffe66d rgba(0,0,0,.2);
}

.plan-style-gallery[data-kind="small"] .plan-style-choice,
.plan-style-gallery[data-kind="medium"] .plan-style-choice,
.plan-style-gallery[data-kind="large"] .plan-style-choice { height: 82px; }

.plan-style-choice {
  min-width: 0;
  height: 82px;
  padding: 4px;
  border: 2px solid rgba(255,255,255,.25);
  border-radius: 10px;
  background: linear-gradient(#bce7ef 0 68%, #91b96c 69%);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.plan-style-choice:hover { transform: translateY(-2px); }
.plan-style-choice.selected { border-color: #ffe66d; box-shadow: 0 0 0 2px rgba(255,230,109,.28), inset 0 -7px 12px rgba(45,83,39,.2); }
.plan-style-choice:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.plan-style-name {
  min-height: 28px;
  color: #ffeaa0;
  font-size: 12px;
  font-weight: 700;
}

.plan-style-price {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: #ffe99b;
}

.building-preview {
  --wall-color: #e7c689;
  --wall-shadow: #c49a5c;
  --roof-color: #5c8050;
  --roof-shadow: #3f603b;
  position: relative;
  display: block;
  width: 64px;
  height: 67px;
  margin: 2px auto 0;
  filter: drop-shadow(0 4px 2px rgba(35,54,31,.28));
}

.building-preview i, .building-preview b { position: absolute; display: block; box-sizing: border-box; }
.building-body { left: 9px; bottom: 2px; width: 48px; height: 38px; border: 2px solid #725336; border-radius: 4px; background: linear-gradient(90deg, var(--wall-shadow), var(--wall-color) 25% 75%, var(--wall-shadow)); }
.building-roof { left: 2px; top: 7px; z-index: 2; width: 60px; height: 30px; clip-path: polygon(50% 0,100% 80%,92% 100%,8% 100%,0 80%); background: linear-gradient(150deg,var(--roof-color),var(--roof-shadow)); }
.building-door { left: 20px; bottom: 0; width: 13px; height: 22px; border: 2px solid #6e4932; border-bottom: 0; border-radius: 7px 7px 0 0; background: #9a653d; }
.building-window { top: 9px; width: 10px; height: 11px; border: 2px solid #77563b; background: #a8e8ec; }
.building-window.one { left: 5px; }
.building-window.two { right: 5px; }

/* Chaque forme conserve les mêmes couches, prêtes à recevoir des variables de peinture. */
.building-preview[data-style="1"] .building-roof { top: 2px; height: 38px; clip-path: polygon(12% 28%,50% 0,88% 28%,100% 100%,0 100%); }
.building-preview[data-style="1"] .building-body { left: 13px; width: 40px; height: 43px; }
.building-preview[data-style="2"] .building-body { left: 8px; width: 50px; border-radius: 45% 45% 6px 6px; }
.building-preview[data-style="2"] .building-roof { left: 5px; width: 56px; height: 26px; border-radius: 50% 50% 15% 15%; clip-path: none; }

/* Les modèles 4 à 20 combinent des volumes, toits et détails vraiment distincts. */
.building-preview[data-style="3"] .building-roof { clip-path: polygon(50% 0,100% 48%,82% 48%,94% 100%,6% 100%,18% 48%,0 48%); }
.building-preview[data-style="3"] .building-detail { right: 1px; top: 5px; width: 13px; height: 18px; border-radius: 50%; background: var(--roof-color); }
.building-preview[data-style="4"] .building-roof { top: 8px; border-radius: 70% 5% 70% 5%; clip-path: none; transform: rotate(-5deg); }
.building-preview[data-style="5"] .building-body { transform: skewX(-6deg); }
.building-preview[data-style="5"] .building-roof { clip-path: polygon(4% 20%,50% 5%,96% 20%,90% 38%,100% 54%,92% 70%,100% 88%,4% 100%,10% 82%,0 65%,10% 48%,0 32%); }
.building-preview[data-style="6"] .building-body { border-radius: 45% 45% 12% 12%; }
.building-preview[data-style="6"] .building-roof { border-radius: 60% 60% 8px 8px; clip-path: none; background: repeating-linear-gradient(60deg,var(--roof-color) 0 6px,var(--roof-shadow) 7px 10px); }
.building-preview[data-style="7"] .building-detail { left: 2px; top: 4px; width: 16px; height: 16px; border: 4px dotted #e7d8a1; border-radius: 50%; background: var(--roof-shadow); }
.building-preview[data-style="7"] .building-roof { clip-path: polygon(30% 0,70% 0,100% 100%,0 100%); }
.building-preview[data-style="8"] .building-body { border-radius: 50% 8px 50% 8px; }
.building-preview[data-style="8"] .building-roof { border-radius: 80% 10% 80% 10%; clip-path: none; }
.building-preview[data-style="9"] .building-detail { right: 3px; top: 0; width: 18px; height: 18px; clip-path: polygon(50% 0,62% 36%,100% 38%,70% 60%,82% 100%,50% 76%,18% 100%,30% 60%,0 38%,38% 36%); background: #ffe66d; }
.building-preview[data-style="10"] .building-roof { border-radius: 50% 50% 0 0; clip-path: circle(58% at 50% 100%); }
.building-preview[data-style="10"] .building-detail { left: 3px; top: 3px; width: 13px; height: 13px; border-radius: 50%; background: #ffe890; }
.building-preview[data-style="11"] .building-body { transform: rotate(2deg); }
.building-preview[data-style="11"] .building-roof { transform: rotate(-4deg); background: repeating-linear-gradient(90deg,var(--roof-color) 0 8px,var(--roof-shadow) 9px 12px); }
.building-preview[data-style="12"] .building-roof { border-radius: 80% 0 80% 0; clip-path: none; transform: rotate(-8deg); }
.building-preview[data-style="12"] .building-detail { left: 1px; bottom: 4px; width: 12px; height: 34px; border-radius: 90% 0; background: #759d4e; }
.building-preview[data-style="13"] .building-body { left: 13px; width: 40px; border-radius: 18px; }
.building-preview[data-style="13"] .building-roof { left: 13px; width: 40px; border-radius: 50%; clip-path: none; }
.building-preview[data-style="14"] .building-body { left: 19px; width: 29px; height: 52px; }
.building-preview[data-style="14"] .building-roof { left: 13px; width: 41px; clip-path: polygon(50% 0,100% 100%,0 100%); }
.building-preview[data-style="14"] .building-detail { left: 27px; top: 12px; z-index: 3; width: 12px; height: 12px; border: 2px solid #725336; border-radius: 50%; background: #b7edf2; }
.building-preview[data-style="15"] .building-body { border-radius: 50% 50% 5px 5px; }
.building-preview[data-style="15"] .building-roof { border-radius: 50%; clip-path: none; transform: rotate(8deg); }
.building-preview[data-style="15"] .building-detail { right: 0; top: 1px; width: 16px; height: 24px; border-radius: 3px 80% 3px 80%; background: #9bbd66; }
.building-preview[data-style="16"] .building-roof { clip-path: polygon(25% 0,75% 0,100% 100%,0 100%); }
.building-preview[data-style="16"] .building-detail { left: 25px; top: 1px; width: 17px; height: 17px; border-radius: 50% 50% 0 50%; background: #e9d39b; transform: rotate(45deg); }
.building-preview[data-style="17"] .building-roof { clip-path: polygon(0 70%,12% 20%,25% 70%,38% 20%,50% 70%,63% 20%,76% 70%,89% 20%,100% 70%,95% 100%,5% 100%); }
.building-preview[data-style="18"] .building-body { border-radius: 50% 50% 10% 10%; background: linear-gradient(90deg,#88806b,#c4b998 45%,#88806b); }
.building-preview[data-style="18"] .building-roof { border-radius: 50% 50% 25% 25%; clip-path: none; background: #77705e; }
.building-preview[data-style="19"] .building-roof { clip-path: polygon(0 60%,18% 15%,33% 60%,50% 0,67% 60%,82% 15%,100% 60%,92% 100%,8% 100%); }
.building-preview[data-style="19"] .building-detail { right: 0; bottom: 2px; width: 13px; height: 30px; border-radius: 50% 50% 3px 3px; background: #85633f; }

.building-preview[data-kind="medium"] { transform: scale(1.05); }
.building-preview[data-kind="medium"][data-style="0"] .building-detail { left: 2px; bottom: 1px; width: 10px; height: 49px; border-radius: 50%; background: #715335; }
.building-preview[data-kind="medium"][data-style="1"] .building-roof { clip-path: polygon(0 50%,18% 18%,38% 50%,62% 18%,82% 50%,100% 18%,94% 100%,5% 100%); }
.building-preview[data-kind="medium"][data-style="2"] .building-body { left: 18px; width: 32px; height: 54px; }
.building-preview[data-kind="medium"][data-style="2"] .building-roof { left: 13px; width: 42px; border-radius: 50% 50% 8px 8px; }

.building-preview[data-kind="large"] { transform: scale(1.08); }
.building-preview[data-kind="large"] .building-body { left: 3px; width: 60px; }
.building-preview[data-kind="large"][data-style="0"] .building-detail { left: 24px; top: 0; width: 14px; height: 28px; background: #8b5b3b; }
.building-preview[data-kind="large"][data-style="1"] .building-body { border-radius: 18px 18px 3px 3px; }
.building-preview[data-kind="large"][data-style="2"] .building-roof { clip-path: polygon(0 75%,18% 30%,34% 75%,50% 5%,66% 75%,82% 30%,100% 75%,94% 100%,6% 100%); }

.building-preview[data-kind="serre"] { --wall-color: rgba(196,244,237,.78); --wall-shadow: rgba(106,190,183,.75); --roof-color: #bdf0e6; --roof-shadow: #72b9a8; }
.building-preview[data-kind="serre"] .building-body { border-color: #477f71; }
.building-preview[data-kind="serre"] .building-roof { border-radius: 50% 50% 0 0; clip-path: none; opacity: .85; }
.building-preview[data-kind="serre"] .building-window { border-color: #579589; background: rgba(255,255,255,.55); }
.building-preview[data-kind="serre"] .building-detail { left: 8px; bottom: 2px; width: 48px; height: 8px; background: repeating-linear-gradient(90deg,#4e9b55 0 6px,#77bd5d 7px 11px); }

.building-preview[data-kind="terrarium"] { --wall-color: #9d9474; --wall-shadow: #706a54; --roof-color: #728453; --roof-shadow: #536541; }
.building-preview[data-kind="terrarium"] .building-body { height: 31px; border-radius: 45% 45% 4px 4px; }
.building-preview[data-kind="terrarium"] .building-roof { top: 14px; border-radius: 50% 50% 20% 20%; clip-path: none; }
.building-preview[data-kind="terrarium"] .building-door { background: #426b51; }
.building-preview[data-kind="terrarium"] .building-detail { right: 1px; bottom: 2px; width: 17px; height: 25px; border-radius: 70% 0; background: #78a554; transform: rotate(-18deg); }

.building-preview[data-kind="voliere"] { --wall-color: #d6ba79; --wall-shadow: #a7874e; --roof-color: #727d9a; --roof-shadow: #505b78; }
.building-preview[data-kind="voliere"] .building-body { left: 13px; width: 40px; height: 44px; background: repeating-linear-gradient(90deg,var(--wall-shadow) 0 2px,rgba(218,239,231,.7) 3px 8px); }
.building-preview[data-kind="voliere"] .building-roof { left: 8px; width: 50px; }
.building-preview[data-kind="voliere"] .building-detail { left: 29px; top: 26px; z-index: 3; width: 9px; height: 7px; border-radius: 60% 10% 60% 10%; background: #f2cf4d; }

.building-preview[data-kind="aquarium"] { --wall-color: rgba(129,218,229,.82); --wall-shadow: rgba(58,144,178,.86); --roof-color: #6bc3d1; --roof-shadow: #397f9c; }
.building-preview[data-kind="aquarium"] .building-body { height: 35px; border-color: #326c86; border-radius: 18px 18px 5px 5px; overflow: hidden; }
.building-preview[data-kind="aquarium"] .building-roof { top: 10px; height: 23px; border-radius: 50% 50% 5px 5px; clip-path: none; opacity: .88; }
.building-preview[data-kind="aquarium"] .building-door { background: rgba(38,112,142,.65); }
.building-preview[data-kind="aquarium"] .building-window { border: 0; border-radius: 50%; background: #ffe66d; }
.building-preview[data-kind="aquarium"] .building-detail { left: 5px; bottom: 3px; width: 14px; height: 19px; border-radius: 70% 0; background: #e87766; transform: rotate(-15deg); }

.plan-action {
  width: calc(100% - 12px);
  padding: 8px 6px;
  border: 0;
  border-radius: 8px;
  background: #557b47;
  color: #fff8e7;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.plan-action:hover { background: #6b9659; }

@media (max-width: 720px) {
  #mason-grid { grid-template-columns: 1fr; }
  .plan-card { min-height: 245px; }
  .plan-style-gallery[data-kind="small"], .plan-style-gallery[data-kind="medium"], .plan-style-gallery[data-kind="large"] { grid-template-columns: repeat(4, minmax(58px, 1fr)); }
}

.plan-card-resources {
  font-size: 11px;
  line-height: 1.5;
  opacity: 0.9;
}

#mason-message {
  min-height: 58px;
  margin: 16px 0;
  padding: 12px 14px;
  border-left: 5px solid #ffe66d;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
  line-height: 1.45;
}

#mason-close-btn {
  display: block;
  margin: auto;
  padding: 9px 22px;
  border: 0;
  border-radius: 10px;
  background: #7bc95f;
  font: inherit;
  cursor: pointer;
}

.talent-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 18px;
}

.talent-heading h2 { font-size: 24px; }
.talent-heading p { margin-top: 3px; font-size: 13px; color: #cfe8c4; }
.talent-advisor-avatar { font-size: 52px; }

#talent-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.talent-card {
  min-height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 3px solid #6f875f;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff8e7;
  cursor: pointer;
  font-family: inherit;
}

.talent-card:hover,
.talent-card.selected {
  transform: translateY(-2px);
  border-color: #ffe66d;
  background: rgba(255, 230, 109, 0.16);
}

.talent-card.unlocked { border-color: #7bc95f; background: rgba(123, 201, 95, 0.2); }
.talent-card.locked .talent-icon { filter: grayscale(0.65); opacity: 0.72; }
.talent-icon { font-size: 42px; }
.talent-status { font-size: 11px; color: #d9e7d2; }

#talent-quest-message {
  min-height: 58px;
  margin: 16px 0;
  padding: 12px 14px;
  border-left: 5px solid #ffe66d;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.24);
  line-height: 1.45;
}

.swim-test-course { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.swim-test-target { padding: 10px 8px; border: 2px solid #4c8ea1; border-radius: 10px; background: #dff6fb; color: #214b56; font-weight: bold; cursor: pointer; }
.swim-test-target:disabled { opacity: .45; cursor: default; }
.swim-test-target.reached { opacity: 1; border-color: #4f8b51; background: #dff3dc; color: #28542a; }
.swim-mastermind-controls { display: flex; justify-content: center; gap: 6px; margin: 12px 0; }
.swim-mastermind-controls select { min-width: 54px; padding: 7px; border: 2px solid #4c8ea1; border-radius: 8px; background: #effbff; font-size: 20px; }
.swim-mastermind-history { display: grid; gap: 4px; margin-top: 10px; font-size: 12px; }
.swim-quest-beacon .entity-emoji { filter: drop-shadow(0 0 12px #fff) drop-shadow(0 0 18px #4fc3f7); animation: future-quest-float 1s ease-in-out infinite alternate; }

#special-items-heading {
  margin: 4px 0 12px;
  font-size: 16px;
  color: #ffe66d;
}

#advisor-challenge-section {
  display: grid;
  grid-template-columns: 48px minmax(0,1fr) auto;
  align-items: center;
  gap: 11px;
  margin: 14px 0;
  padding: 12px;
  border: 2px solid #d6aa43;
  border-radius: 12px;
  background: linear-gradient(110deg,rgba(255,231,139,.22),rgba(88,63,24,.18));
  text-align: left;
}
.advisor-challenge-icon { font-size: 34px; text-align: center; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.advisor-challenge-copy h3 { margin: 0 0 3px; color: #ffe38a; font-size: 15px; }
.advisor-challenge-copy p { margin: 0; color: #e8dfc7; font-size: 11px; line-height: 1.35; }
#advisor-challenge-section #challenge-btn { position: static; width: auto; min-width: 130px; margin: 0; padding: 9px 12px; }
@media (max-width: 560px) {
  #advisor-challenge-section { grid-template-columns: 38px 1fr; }
  #advisor-challenge-section #challenge-btn { grid-column: 1 / -1; width: 100%; }
}

#special-items-grid {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

.special-item-section-heading {
  margin: 12px 0 6px;
  font-size: 13px;
  color: #ffe66d;
  opacity: 0.9;
  border-top: 1px solid rgba(255, 230, 109, 0.25);
  padding-top: 8px;
}

.special-item-section-heading:first-child {
  margin-top: 0;
  border-top: none;
  padding-top: 0;
}

.special-item-section-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.special-item-card .talent-status {
  color: #ffe66d;
  font-weight: bold;
}

/* ---------- Potions (taille = durée, couleur = effet) ---------- */

.potion-icon {
  position: relative;
  display: inline-block;
  width: 20px;
  height: 28px;
}

.potion-cork {
  position: absolute;
  top: 0;
  left: 50%;
  width: 8px;
  height: 6px;
  transform: translateX(-50%);
  background: linear-gradient(#a9764a, #7a4f28);
  border: 1px solid #4a2f18;
  border-radius: 2px 2px 1px 1px;
}

.potion-neck {
  position: absolute;
  top: 5px;
  left: 50%;
  width: 8px;
  height: 7px;
  transform: translateX(-50%);
  background: rgba(220, 235, 240, 0.55);
  border-left: 2px solid rgba(0, 0, 0, 0.35);
  border-right: 2px solid rgba(0, 0, 0, 0.35);
}

.potion-body {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 20px;
  height: 18px;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.4);
  box-shadow:
    inset -3px -4px 5px rgba(0, 0, 0, 0.3),
    inset 3px 3px 5px rgba(255, 255, 255, 0.4),
    0 2px 4px rgba(0, 0, 0, 0.35);
}

.potion-icon-small { transform: scale(0.72); }
.potion-icon-medium { transform: scale(1); }
.potion-icon-large { transform: scale(1.4); }

/* Dans une case de 46px, l'icône doit laisser la place au compteur. La grande
   potion reste reconnaissable, mais ne déborde plus sur les cases voisines. */
.backpack-slot-emoji > .potion-icon-small { transform: scale(.58); }
.backpack-slot-emoji > .potion-icon-medium { transform: scale(.74); }
.backpack-slot-emoji > .potion-icon-large {
  transform: scale(.9);
  transform-origin: 50% 55%;
}

.bag-grid.compact-grid .backpack-slot-emoji > .potion-icon-small { transform: scale(.46); }
.bag-grid.compact-grid .backpack-slot-emoji > .potion-icon-medium { transform: scale(.6); }
.bag-grid.compact-grid .backpack-slot-emoji > .potion-icon-large { transform: scale(.74); }

.special-item-card .potion-icon {
  width: 26px;
  height: 36px;
}

.special-item-card .potion-cork { width: 10px; height: 7px; }
.special-item-card .potion-neck { top: 6px; width: 10px; height: 9px; }
.special-item-card .potion-body { width: 26px; height: 24px; }

#talent-close-btn {
  display: block;
  margin: auto;
  padding: 9px 22px;
  border: 0;
  border-radius: 10px;
  background: #7bc95f;
  font: inherit;
  cursor: pointer;
}

@media (max-width: 520px) {
  #talent-content { padding: 14px; }
  #talent-grid { gap: 8px; }
  .talent-card { min-height: 105px; }
  .plan-card { min-height: 245px; }
}

/* ---------- Record board (village bulletin board) ---------- */

.record-board {
  width: 70px;
  height: 84px;
  z-index: 4;
  cursor: pointer;
}

.record-board-post {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 10px;
  height: 46px;
  transform: translateX(-50%);
  background: linear-gradient(#8a5a2f, #5c3b1e);
  border-radius: 2px;
  box-shadow: inset -2px 0 0 rgba(0, 0, 0, 0.2);
}

.record-board-plank {
  position: absolute;
  top: 0;
  left: 0;
  width: 70px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(90deg, #a9723f 0px, #a9723f 10px, #966339 10px, #966339 20px);
  border: 3px solid #6b4423;
  border-radius: 5px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
}

.record-board-paper {
  width: 42px;
  height: 28px;
  background: #f3e6c8;
  border: 1px solid #cbb98a;
  border-radius: 2px;
  transform: rotate(-3deg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

#record-panel {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(10, 20, 10, 0.88);
}

#record-board-display {
  position: relative;
  width: min(380px, 92vw);
  padding: 30px 22px 22px;
  border: 6px solid #6b4423;
  border-radius: 10px;
  background: repeating-linear-gradient(90deg, #a9723f 0px, #a9723f 14px, #96633a 14px, #96633a 28px);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.55), inset 0 0 0 3px rgba(0, 0, 0, 0.15);
  text-align: center;
  color: #3a2712;
}

#record-board-hook {
  position: absolute;
  top: -14px;
  left: 50%;
  width: 16px;
  height: 16px;
  transform: translateX(-50%);
  background: radial-gradient(circle at 35% 30%, #e2c98a, #8a6b3a);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

#record-board-display h2 {
  margin-bottom: 16px;
  font-size: 20px;
  color: #fff8e7;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
}

#record-board-paper {
  padding: 18px 14px;
  margin-bottom: 18px;
  background: #f6ecd4;
  border: 1px solid #d8c396;
  border-radius: 4px;
  transform: rotate(-1deg);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  font-size: 15px;
  line-height: 1.6;
  color: #4a3520;
}

#record-board-paper .record-line-main {
  font-size: 19px;
  font-weight: bold;
  margin-bottom: 4px;
}

#record-close-btn {
  padding: 9px 22px;
  border: 0;
  border-radius: 10px;
  background: #7bc95f;
  font: inherit;
  cursor: pointer;
}

/* ---------- Price board (étal de la marchande) ---------- */

.price-board {
  width: 78px;
  height: 58px;
  z-index: 4;
  cursor: pointer;
}

.price-board-post {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 8px;
  height: 22px;
  transform: translateX(-50%);
  background: linear-gradient(#8a5a2f, #5c3b1e);
  border-radius: 2px;
}

.price-board-plank {
  position: absolute;
  top: 0;
  left: 0;
  width: 78px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: repeating-linear-gradient(90deg, #a9723f 0px, #a9723f 10px, #966339 10px, #966339 20px);
  border: 3px solid #6b4423;
  border-radius: 5px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
  font-size: 20px;
}

#price-panel {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(10, 20, 10, 0.88);
}

#price-board-display {
  width: min(400px, 92vw);
  max-height: 90vh;
  overflow: auto;
  padding: 22px;
  border: 8px solid #6b4423;
  border-radius: 10px;
  background: linear-gradient(160deg, #7a4f28, #5c3b1e);
  box-shadow: 0 14px 35px rgba(0, 0, 0, 0.55);
  text-align: center;
}

#price-board-display h2 {
  margin-bottom: 14px;
  font-size: 20px;
  color: #fff8e7;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
}

#price-board-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 16px 10px;
  margin-bottom: 16px;
  background: #16321f;
  border: 4px solid #0c1f13;
  border-radius: 6px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
}

.price-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  color: #eafbe0;
  font-family: "Comic Sans MS", "Trebuchet MS", cursive, sans-serif;
}

.price-row-emoji {
  font-size: 20px;
}

.price-row-value {
  font-size: 13px;
  font-weight: bold;
  color: #ffe66d;
}

#price-close-btn {
  padding: 9px 22px;
  border: 0;
  border-radius: 10px;
  background: #7bc95f;
  font: inherit;
  cursor: pointer;
}

/* ---------- Game shell & responsive scaling ---------- */

#game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#stage-outer {
  position: relative;
}

#stage {
  width: 900px;
  transform-origin: top left;
}

#hud {
  position: relative;
  width: 900px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: #fff;
  background: linear-gradient(180deg, #3b5d34 0%, #2f4d2a 55%, #253f21 100%);
  padding: 10px 16px 40px;
  border-radius: 10px 10px 0 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 2px 6px rgba(0, 0, 0, 0.25);
}

/* Sur tactile, touch.js vide #hud dans les rails #hud-rail-left/-right
   (voir plus bas) : il ne reste plus qu'à le sortir du flux pour que le
   plateau récupère toute la hauteur qu'il occupait. */
.touch-device #hud { display: none; }

#resource-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.resource-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 2px 5px rgba(0, 0, 0, 0.3);
}

.resource-group-wealth {
  background: linear-gradient(180deg, #6e5116 0%, #4a350c 100%);
  border: 1px solid rgba(241, 196, 15, 0.45);
}

.resource-group-materials {
  background: linear-gradient(180deg, #3d5c2e 0%, #294020 100%);
  border: 1px solid rgba(123, 201, 95, 0.4);
}

.res-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: bold;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.res-icon {
  font-size: 15px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.4));
}

.resource-divider {
  width: 2px;
  height: 20px;
  border-radius: 1px;
  background: rgba(255, 255, 255, 0.16);
}

#hud-main {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
}

#abilities-bar {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}

.ability-slot {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  border-radius: 6px;
  border: 2px solid #3d5c2e;
  background: #1b2a1a;
  filter: grayscale(1);
  opacity: 0.45;
  transition: opacity 0.15s ease, filter 0.15s ease, border-color 0.15s ease;
}

.ability-slot.unlocked {
  filter: none;
  opacity: 1;
  background: #eafbe0;
  border-color: #7bc95f;
  cursor: pointer;
}

#hud-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.hud-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 16px;
}

#plateau-info {
  font-size: 14px;
  opacity: 0.9;
}

#room-code-display {
  font-weight: bold;
  letter-spacing: 2px;
}

#player-name-display {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255,255,255,.13);
  color: #fff8d5;
}
#player-name-avatar { font-size: 20px; line-height: 1; }
#player-name-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

#players-toggle-btn, #backpack-btn, #challenge-btn, #challenge-ready-btn, #leave-room-btn {
  font-size: 13px;
  padding: 6px 10px;
  border: none;
  border-radius: 8px;
  background: #7bc95f;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s ease, transform 0.1s ease;
}

#challenge-ready-btn {
  background: #2ecc71;
  font-weight: bold;
}

#challenge-ready-btn:disabled {
  background: #8a8a6a;
  color: #eee;
  cursor: default;
}

#players-toggle-btn:hover, #backpack-btn:hover, #challenge-btn:hover, #leave-room-btn:hover {
  background: #5aa845;
  transform: translateY(-1px);
}

#leave-room-btn {
  background: #d9a45f;
}

#challenge-btn {
  background: #f1c40f;
  color: #4a3520;
  font-weight: bold;
}

#challenge-btn:hover {
  background: #d4ac0d;
}

#challenge-btn:disabled {
  background: #8a8a6a;
  color: #eee;
  cursor: default;
}

#challenge-status {
  font-size: 13px;
  opacity: 0.9;
}

#forest-wrapper {
  position: relative;
  width: 900px;
  height: 600px;
}

#forest {
  position: relative;
  width: 900px;
  height: 600px;
  background: linear-gradient(#7bc95f, #5aa845);
  border: 0;
  border-radius: 0 0 12px 12px;
  overflow: hidden;
}

.entity {
  position: absolute;
  font-size: 48px;
  line-height: 1;
  user-select: none;
  transition: transform 0.05s linear;
  transform: translate(-50%, -50%);
}

.world-layer {
  position: absolute;
  width: 900px;
  height: 600px;
  transform-origin: 0 0;
  will-change: transform;
}

.world-chunk {
  position: absolute;
  width: 900px;
  height: 600px;
}

.terrain-blend-surface {
  position: absolute;
  z-index: -1;
  pointer-events: none;
  isolation: isolate;
}

.terrain-blend-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mask-size: 100% 100%;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
}

#player {
  font-size: 36px;
  z-index: 10;
}

#player.inside-house-player {
  font-size: 64px;
}

#player.inside-house-player .avatar-sprite {
  width: 60px;
  height: 76px;
}

/* Lumo : petit esprit forestier local qui accompagne le joueur. */
.adventure-companion { z-index: 9; width: 38px; height: 45px; font-size: 0; cursor: pointer; filter: drop-shadow(0 3px 3px rgba(15,54,49,.4)); }
.adventure-companion .player-label { top: -13px; font-size: 8px; color: #fff7bd; background: rgba(24,66,58,.82); }
.adventure-companion .speech-bubble {
  bottom: calc(100% + 34px);
  z-index: 35;
  width: max-content;
  max-width: 240px;
  margin-bottom: 0;
  padding: 7px 11px;
  border: 2px solid #74bfa3;
  white-space: normal;
  text-align: center;
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 9px;
}
.adventure-companion .speech-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: #74bfa3;
}
.companion-dialogue-portrait {
  position: relative;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border: 2px solid #28685f;
  border-radius: 48% 48% 44% 44%;
  background: radial-gradient(circle at 40% 30%,#eaffc6 0 3px,#91ddb0 4px 45%,#48a695 75%);
  box-shadow: inset -4px -5px 0 rgba(26,104,94,.22),0 0 7px rgba(164,255,198,.7);
}
.portrait-ear { position: absolute; top: -7px; width: 11px; height: 14px; border: 2px solid #28685f; background: #75cfa5; clip-path: polygon(50% 0,100% 100%,0 82%); }
.portrait-ear-left { left: 1px; transform: rotate(-18deg); }
.portrait-ear-right { right: 1px; transform: rotate(18deg) scaleX(-1); }
.portrait-eye { position: absolute; top: 14px; width: 4px; height: 5px; border-radius: 50%; background: #173f3d; box-shadow: 0 0 2px #fff; }
.portrait-eye-left { left: 8px; }
.portrait-eye-right { right: 8px; }
.portrait-star { position: absolute; left: 12px; bottom: 1px; color: #fff4a4; font: normal 10px/1 serif; text-shadow: 0 0 4px #fff; }
.companion-dialogue-text { display: block; min-width: 0; }

#companion-panel { position: fixed; inset: 0; z-index: 145; display: grid; place-items: center; padding: 14px; background: rgba(8,25,22,.82); backdrop-filter: blur(3px); }
#companion-dialogue-content { width: min(570px,94vw); max-height: 90vh; overflow-y: auto; padding: 22px; border: 4px solid #74bfa3; border-radius: 20px; background: radial-gradient(circle at 15% 10%,rgba(145,221,176,.2),transparent 30%),linear-gradient(145deg,#244f46,#142f2d); color: #f4ffe7; box-shadow: 0 18px 55px rgba(0,0,0,.62),inset 0 0 28px rgba(156,255,198,.1); }
.companion-dialogue-heading { display: flex; align-items: center; justify-content: center; gap: 22px; margin-bottom: 16px; }
.companion-dialogue-heading h2 { margin: 0; color: #fff2a8; font-size: 30px; }
.companion-dialogue-heading p { margin: 4px 0 0; color: #bfe9cf; font-size: 12px; }
.companion-closeup { position: relative; width: 92px; height: 92px; border: 4px solid #28685f; border-radius: 48% 48% 44% 44%; background: radial-gradient(circle at 40% 30%,#f5ffd9 0 8px,#91ddb0 9px 48%,#48a695 78%); box-shadow: inset -10px -12px rgba(26,104,94,.22),0 0 22px rgba(164,255,198,.72); animation: companion-float 2s ease-in-out infinite; }
.closeup-ear { position: absolute; top: -22px; width: 34px; height: 40px; border: 4px solid #28685f; background: #75cfa5; clip-path: polygon(50% 0,100% 100%,0 82%); }
.closeup-ear.left { left: 3px; transform: rotate(-18deg); }.closeup-ear.right { right: 3px; transform: rotate(18deg) scaleX(-1); }
.closeup-eye { position: absolute; top: 40px; width: 11px; height: 14px; border-radius: 50%; background: #173f3d; box-shadow: 0 0 5px #fff; }.closeup-eye.left { left: 23px; }.closeup-eye.right { right: 23px; }
.closeup-star { position: absolute; left: 35px; bottom: 5px; color: #fff4a4; font: normal 25px/1 serif; text-shadow: 0 0 10px #fff; }
#companion-dialogue-message { min-height: 58px; margin-bottom: 14px; padding: 13px 15px; border: 2px solid rgba(145,221,176,.55); border-radius: 13px; background: rgba(255,255,255,.1); font-size: 14px; line-height: 1.45; text-align: center; }
#companion-dialogue-actions { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
#companion-dialogue-actions button,#companion-close-btn { padding: 10px; border: 2px solid #609d87; border-radius: 10px; background: #326f60; color: #f4ffe7; font: bold 12px inherit; cursor: pointer; }
#companion-dialogue-actions button:hover { border-color: #fff2a8; background: #438875; transform: translateY(-1px); }
#companion-close-btn { display: block; margin: 15px auto 0; min-width: 120px; background: #203f3a; }
@media (max-width:520px) { #companion-dialogue-content { padding: 16px; }.companion-closeup { width: 72px; height: 72px; }.closeup-eye { top: 31px; }.closeup-star { left: 27px; }.companion-dialogue-heading h2 { font-size: 24px; }#companion-dialogue-actions { grid-template-columns: 1fr; } }
.companion-shadow { position: absolute; left: 8px; bottom: 0; width: 25px; height: 7px; border-radius: 50%; background: rgba(21,71,77,.28); }
.companion-body { position: absolute; left: 6px; top: 5px; width: 28px; height: 31px; border: 2px solid #28685f; border-radius: 48% 48% 44% 44%; background: radial-gradient(circle at 40% 30%,#eaffc6 0 3px,#91ddb0 4px 45%,#48a695 75%); box-shadow: inset -4px -5px 0 rgba(26,104,94,.22),0 0 9px rgba(164,255,198,.75); animation: companion-float 1.8s ease-in-out infinite; }
.companion-ear { position: absolute; top: -8px; width: 12px; height: 15px; border: 2px solid #28685f; background: #75cfa5; clip-path: polygon(50% 0,100% 100%,0 82%); }
.companion-ear.ear-left { left: 0; transform: rotate(-18deg); }
.companion-ear.ear-right { right: 0; transform: rotate(18deg) scaleX(-1); }
.companion-face::before,.companion-face::after { content: ""; position: absolute; top: 12px; width: 4px; height: 5px; border-radius: 50%; background: #173f3d; box-shadow: 0 0 2px #fff; }
.companion-face::before { left: 6px; }
.companion-face::after { right: 6px; }
.companion-star { position: absolute; left: 10px; bottom: 2px; color: #fff4a4; font: normal 11px/1 serif; text-shadow: 0 0 5px #fff; }
.companion-tail { position: absolute; left: 1px; top: 20px; width: 19px; height: 11px; border: 3px solid #53b79a; border-right: 0; border-bottom-color: transparent; border-radius: 70% 0 0 50%; transform-origin: right center; animation: companion-tail 1.1s ease-in-out infinite alternate; }
.adventure-companion.facing-left .companion-body { transform: scaleX(-1); }
.adventure-companion.facing-left .companion-tail { left: 20px; transform: scaleX(-1); }
.adventure-companion.following .companion-body { animation: companion-catch-up .55s ease-in-out infinite; }
@keyframes companion-float { 0%,100% { translate: 0 1px; } 50% { translate: 0 -4px; } }
@keyframes companion-tail { to { rotate: -13deg; } }
@keyframes companion-catch-up { 0%,100% { translate: 0 1px; rotate: -4deg; } 50% { translate: 0 -5px; rotate: 4deg; } }
@media (prefers-reduced-motion: reduce) { .companion-body,.companion-tail { animation: none !important; } }

.tree {
  font-size: 64px;
  z-index: 1;
  /* Purement décoratif (aucun clic n'y est jamais rattaché) : laisser passer
     le clic vers #forest en dessous, sinon le déplacement au clic (PC) ne
     déclenche rien dès qu'on vise un arbre — très fréquent vu leur nombre. */
  pointer-events: none;
}

.biome-decor .entity-emoji {
  display: block;
  background-position: center bottom;
  background-repeat: no-repeat;
  background-size: contain;
  filter: drop-shadow(0 5px 4px rgba(20, 28, 18, .22));
  transform-origin: center bottom;
}

.orchard-tree::after {
  content: "🍎  🍎";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 54px;
  transform: translateX(-50%);
  font-size: 13px;
  letter-spacing: 7px;
  filter: drop-shadow(0 1px 1px rgba(70, 30, 20, .4));
  pointer-events: none;
}

.npc {
  z-index: 5;
  cursor: pointer;
}

.animal-npc .entity-emoji {
  display: inline-block;
  transform-origin: center bottom;
  animation: animal-idle 3.8s ease-in-out var(--animal-idle-delay, 0ms) infinite;
  will-change: transform;
}

.animal-npc::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -5px;
  z-index: -1;
  width: 30px;
  height: 7px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(31, 48, 27, .2);
  animation: animal-idle-shadow 3.8s ease-in-out var(--animal-idle-delay, 0ms) infinite;
}

.animal-habitat {
  z-index: 2;
  width: 112px;
  height: 82px;
  pointer-events: none;
}

.habitat-mound {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 94px;
  height: 42px;
  transform: translateX(-50%);
  border-radius: 55% 55% 18% 18%;
  background: radial-gradient(circle at 30% 15%, #8c7045 0 5px, transparent 6px), linear-gradient(#9a7a48, #665033);
  box-shadow: inset 0 5px rgba(255,255,255,.08), 0 4px 6px rgba(0,0,0,.25);
}

.habitat-hole {
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 42px;
  height: 31px;
  transform: translateX(-50%);
  border: 5px solid #59432d;
  border-bottom: 0;
  border-radius: 50% 50% 5px 5px;
  background: radial-gradient(ellipse at center bottom, #17130f, #392c21 70%);
}

.habitat-branch { position: absolute; left: 3px; right: 3px; bottom: 16px; height: 10px; transform: rotate(-4deg); border-radius: 8px; background: #69472c; }
.habitat-nest { position: absolute; left: 50%; bottom: 12px; width: 64px; height: 27px; transform: translateX(-50%); border-radius: 8px 8px 50% 50%; background: repeating-linear-gradient(12deg, #927044 0 4px, #674b2d 5px 8px); box-shadow: 0 4px 5px rgba(0,0,0,.22); }

.habitat-fence { position: absolute; left: 0; right: 0; height: 34px; border-top: 7px solid #9b7547; border-bottom: 7px solid #795735; background: repeating-linear-gradient(90deg, transparent 0 10px, #8b663d 11px 17px, transparent 18px 29px); }
.habitat-fence-back { top: 8px; opacity: .82; }
.habitat-fence-front { bottom: 0; }

@keyframes animal-idle {
  0%, 42%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  48% { transform: translateY(-2px) rotate(-1.5deg) scale(1.015, .985); }
  54% { transform: translateY(-5px) rotate(1.5deg) scale(.99, 1.02); }
  60% { transform: translateY(0) rotate(0deg) scale(1); }
}

@keyframes animal-idle-shadow {
  0%, 42%, 60%, 100% { transform: translateX(-50%) scaleX(1); opacity: .8; }
  54% { transform: translateX(-50%) scaleX(.78); opacity: .5; }
}

@media (prefers-reduced-motion: reduce) {
  .animal-npc .entity-emoji,
  .animal-npc::after { animation: none; will-change: auto; }
}

.item {
  z-index: 3;
  cursor: pointer;
}

.item .resource-sprite {
  display: block;
  width: 46px;
  height: 46px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  filter: drop-shadow(0 4px 3px rgba(40, 52, 29, .24));
}

.resource-tree .resource-sprite {
  width: 64px;
  height: 58px;
}

.resource-stone .resource-sprite,
.resource-iron .resource-sprite {
  width: 54px;
  height: 52px;
}

.collectible-resource {
  z-index: 4;
  filter: drop-shadow(0 0 3px rgba(255, 230, 109, 0.7));
  animation: resource-pulse 1.4s ease-in-out infinite;
}

.resource-progress {
  position: absolute;
  top: -16px;
  left: 50%;
  min-width: 30px;
  transform: translateX(-50%);
  padding: 2px 6px;
  border: 2px solid #fff;
  border-radius: 9px;
  background: rgba(47, 77, 42, 0.92);
  color: #fff;
  font: bold 10px/1 "Trebuchet MS", sans-serif;
  text-align: center;
}

.collectible-resource.resource-hit .entity-emoji {
  display: inline-block;
  animation: resource-hit 0.5s ease-out;
}

@keyframes resource-hit {
  0% { transform: scale(1) rotate(0); }
  35% { transform: scale(0.82) rotate(-7deg); }
  70% { transform: scale(1.12) rotate(6deg); }
  100% { transform: scale(1) rotate(0); }
}

@keyframes resource-pulse {
  0%, 100% { filter: drop-shadow(0 0 2px rgba(255, 230, 109, 0.55)); }
  50% { filter: drop-shadow(0 0 5px rgba(255, 230, 109, 0.8)); }
}

.town-hall-building {
  z-index: 2;
}

.town-hall-building {
  width: 430px;
  height: 250px;
  cursor: pointer;
  filter: drop-shadow(0 10px 10px rgba(31, 42, 37, 0.38));
}

.town-hall-building.town-style-coast { filter: hue-rotate(145deg) saturate(.8) brightness(1.12); }
.town-hall-building.town-style-mining { filter: grayscale(.6) contrast(1.12); }
.town-hall-building.town-style-flowers { filter: hue-rotate(285deg) saturate(1.2) brightness(1.08); }
.town-hall-building.town-style-bamboo { filter: hue-rotate(55deg) saturate(.85); }
.town-hall-building.town-style-stone { filter: grayscale(.85) brightness(.94); }

.town-hall-main,
.town-hall-wing {
  position: absolute;
  bottom: 30px;
  border: 4px solid #858b86;
  background: linear-gradient(100deg, #f1f0e8, #cfd3cf 48%, #e5e5dd);
  box-shadow: inset 0 0 0 5px rgba(255,255,255,.22);
}

.town-hall-main {
  left: 50%;
  z-index: 4;
  width: 170px;
  height: 145px;
  transform: translateX(-50%);
  border-radius: 8px 8px 2px 2px;
}

.town-hall-wing {
  z-index: 2;
  width: 145px;
  height: 105px;
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.town-hall-wing.wing-left { left: 12px; border-radius: 10px 0 3px 5px; }
.town-hall-wing.wing-right { right: 12px; border-radius: 0 10px 5px 3px; }

.town-hall-roof {
  position: absolute;
  top: 63px;
  left: 50%;
  z-index: 5;
  width: 215px;
  height: 72px;
  transform: translateX(-50%);
  clip-path: polygon(50% 0, 100% 70%, 92% 100%, 8% 100%, 0 70%);
  background: repeating-linear-gradient(100deg, #31583c 0 13px, #294c34 14px 26px);
  border-bottom: 6px solid #203f2b;
}

.town-hall-tower {
  position: absolute;
  top: 2px;
  left: 50%;
  z-index: 3;
  width: 82px;
  height: 92px;
  transform: translateX(-50%);
  border: 4px solid #777f79;
  border-radius: 40px 40px 5px 5px;
  background: linear-gradient(90deg, #d5d7d2, #f3f1e8, #c4cac5);
}

.town-hall-clock {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 4px solid #8b6b3f;
  border-radius: 50%;
  background: #fff8dc;
  font-size: 27px;
}

.town-hall-crest {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 3px solid #9a783f;
  border-radius: 50% 50% 45% 45%;
  background: #f0d88c;
  font-size: 25px;
}

.town-hall-door {
  position: absolute;
  bottom: -4px;
  left: 50%;
  width: 64px;
  height: 72px;
  display: flex;
  overflow: hidden;
  transform: translateX(-50%);
  border: 5px solid #71502f;
  border-radius: 32px 32px 2px 2px;
  background: #80552e;
}

.town-hall-door span { flex: 1; border-right: 2px solid #53351f; background: repeating-linear-gradient(90deg, #9a6737 0 8px, #86562f 9px 16px); }
.town-hall-door span:last-child { border-right: 0; border-left: 2px solid #53351f; }

.town-hall-window {
  width: 34px;
  height: 43px;
  border: 5px solid #765333;
  border-radius: 16px 16px 3px 3px;
  background: linear-gradient(135deg, #fff1a6, #8ed4d8);
  box-shadow: inset 0 0 8px rgba(255,255,255,.75), 0 0 8px rgba(255,224,116,.35);
}

.town-hall-steps {
  position: absolute;
  bottom: 12px;
  left: 50%;
  z-index: 6;
  width: 112px;
  height: 23px;
  transform: translateX(-50%);
  border-radius: 4px;
  background: repeating-linear-gradient(0deg, #aeb3b0 0 6px, #858b88 7px 8px);
  clip-path: polygon(15% 0, 85% 0, 100% 100%, 0 100%);
}

.town-hall-building:hover { filter: drop-shadow(0 12px 13px rgba(31,42,37,.48)) brightness(1.03); }

@media (prefers-reduced-motion: no-preference) {
  .town-hall-clock { animation: town-hall-glow 3s ease-in-out infinite; }
  @keyframes town-hall-glow { 50% { box-shadow: 0 0 14px rgba(255,230,109,.6); } }
}

.village-house {
  font-size: 60px;
  z-index: 2;
}

.npc-house {
  width: 116px;
  height: 112px;
  z-index: 3;
  cursor: pointer;
  filter: drop-shadow(0 7px 6px rgba(26,38,24,.34));
}

.npc-house-wall {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 72px;
  border: 4px solid #705137;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(90deg, #d6bd8c, #f0d7a4, #c9aa75);
}

.npc-house-roof {
  position: absolute;
  top: 0;
  left: 3px;
  z-index: 2;
  width: 110px;
  height: 58px;
  clip-path: polygon(50% 0, 100% 72%, 92% 100%, 8% 100%, 0 72%);
  background: repeating-linear-gradient(105deg, #41633d 0 11px, #355333 12px 22px);
}

.npc-house-door { position: absolute; bottom: 0; left: 50%; width: 28px; height: 42px; transform: translateX(-50%); border: 3px solid #634329; border-radius: 13px 13px 0 0; background: #8f6037; }
.npc-house-window { position: absolute; left: 10px; top: 17px; width: 23px; height: 24px; border: 3px solid #725036; border-radius: 8px 8px 2px 2px; background: #a9e0df; }
.npc-house-sign { position: absolute; top: 42px; right: 3px; z-index: 4; width: 34px; height: 34px; display: grid; place-items: center; border: 3px solid #815f35; border-radius: 50%; background: #f2dc9d; font-size: 20px; }
.npc-house:hover { filter: drop-shadow(0 9px 8px rgba(26,38,24,.45)) brightness(1.04); }

.npc-house-biome-2 .npc-house-roof { background: repeating-linear-gradient(90deg, #4e8a91 0 11px, #3d737d 12px 22px); }
.npc-house-biome-3 .npc-house-wall { background: linear-gradient(90deg, #aaa89b, #d6d2c2, #97978d); }
.npc-house-biome-3 .npc-house-roof { background: repeating-linear-gradient(105deg, #67675e 0 11px, #55564f 12px 22px); }
.npc-house-biome-4 .npc-house-roof { background: repeating-linear-gradient(105deg, #6f8c3e 0 11px, #587532 12px 22px); }
.npc-house-biome-5 .npc-house-roof { background: repeating-linear-gradient(105deg, #9b618e 0 11px, #7e4e78 12px 22px); }
.npc-house-biome-6 .npc-house-wall { background: repeating-linear-gradient(90deg, #b8a66a 0 9px, #927f4f 10px 13px); }
.npc-house-biome-7 .npc-house-roof { background: repeating-linear-gradient(105deg, #b3913e 0 11px, #8f7332 12px 22px); }

.npc-interior-counter { width: 300px; height: 48px; z-index: 7; }
.npc-behind-counter { z-index: 6; }

.housekeeper-npc {
  width: 42px;
  height: 76px;
  transition: left 6s linear, top 6s linear;
  filter: drop-shadow(0 5px 3px rgba(34, 28, 20, .3));
}

.housekeeper-visual { display: block; width: 42px; height: 76px; font-size: 0; }
.housekeeper-person { position: relative; display: block; width: 42px; height: 76px; transform-origin: 50% 85%; }
.housekeeper-npc.facing-left .housekeeper-person { transform: scaleX(-1); }

.housekeeper-head {
  position: absolute;
  top: 3px;
  left: 11px;
  z-index: 5;
  width: 22px;
  height: 25px;
  border: 2px solid #70462e;
  border-radius: 48% 48% 45% 45%;
  background: #d99a6c;
}
.housekeeper-hair { position: absolute; inset: -3px -2px auto; height: 11px; border-radius: 55% 55% 35% 20%; background: #5b3b2a; }
.housekeeper-hair::after { content: ""; position: absolute; right: -4px; top: 5px; width: 7px; height: 13px; border-radius: 50%; background: #5b3b2a; }
.housekeeper-face::before, .housekeeper-face::after { content: ""; position: absolute; top: 11px; width: 2px; height: 3px; border-radius: 50%; background: #3d3029; }
.housekeeper-face::before { left: 5px; }
.housekeeper-face::after { right: 5px; }

.housekeeper-body {
  position: absolute;
  top: 26px;
  left: 9px;
  z-index: 3;
  width: 26px;
  height: 29px;
  border: 2px solid #344f56;
  border-radius: 8px 8px 5px 5px;
  background: linear-gradient(90deg,#527983,#6f99a0 48%,#456c75);
}
.housekeeper-apron { position: absolute; left: 5px; top: 7px; width: 14px; height: 21px; border-radius: 3px 3px 6px 6px; background: #f1ead9; box-shadow: inset 0 -5px #ddd3bd; }
.housekeeper-arm { position: absolute; top: 3px; z-index: -1; width: 8px; height: 28px; border: 2px solid #344f56; border-radius: 6px; background: #5e8992; transform-origin: 50% 3px; }
.housekeeper-arm::after { content: ""; position: absolute; left: 0; bottom: -4px; width: 6px; height: 7px; border-radius: 50%; background: #d99a6c; }
.housekeeper-arm.arm-left { left: -7px; transform: rotate(5deg); }
.housekeeper-arm.arm-right { right: -7px; transform: rotate(-5deg); }

.housekeeper-leg { position: absolute; top: 52px; z-index: 2; width: 9px; height: 20px; border-radius: 3px; background: #394c59; transform-origin: 50% 2px; }
.housekeeper-leg.leg-left { left: 12px; }
.housekeeper-leg.leg-right { right: 10px; }
.housekeeper-leg b { position: absolute; left: -1px; bottom: -3px; width: 12px; height: 6px; border-radius: 5px 6px 3px 3px; background: #4c3428; }

.housekeeper-npc.walking .housekeeper-person { animation: housekeeper-body-walk .58s ease-in-out infinite alternate; }
.housekeeper-npc.walking .leg-left { animation: housekeeper-leg-left .58s ease-in-out infinite alternate; }
.housekeeper-npc.walking .leg-right { animation: housekeeper-leg-right .58s ease-in-out infinite alternate; }
.housekeeper-npc.walking .arm-left { animation: housekeeper-arm-left .58s ease-in-out infinite alternate; }
.housekeeper-npc.walking .arm-right { animation: housekeeper-arm-right .58s ease-in-out infinite alternate; }

/* Variantes achetables : peau, coiffure, uniforme et tablier sont séparés. */
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="1"] .housekeeper-body,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="1"] .housekeeper-arm { background: #6e8d4e; border-color: #3e5831; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="1"] .housekeeper-apron { background: #d8c17b; box-shadow: inset 0 -5px #b79d54; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="2"] .housekeeper-body,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="2"] .housekeeper-arm { background: #3e4657; border-color: #202737; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="2"] .housekeeper-apron { background: #f7f4e9; box-shadow: inset 0 -5px #d8d3c5; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="2"] .housekeeper-hair { background: #b6a891; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="2"] .housekeeper-hair::after { background: #b6a891; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="3"] .housekeeper-body,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="3"] .housekeeper-arm { background: #a95f8b; border-color: #713d5c; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="3"] .housekeeper-apron { background: #f0c7db; box-shadow: inset 0 -5px #d49bb9; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="3"] .housekeeper-head { background: #825438; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="3"] .housekeeper-hair,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="3"] .housekeeper-hair::after { background: #292329; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="4"] .housekeeper-body,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="4"] .housekeeper-arm { background: #b07a3f; border-color: #704a27; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="4"] .housekeeper-apron { background: #668f78; box-shadow: inset 0 -5px #456d59; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="4"] .housekeeper-hair,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="4"] .housekeeper-hair::after { background: #b76c35; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="5"] .housekeeper-body,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="5"] .housekeeper-arm { background: #e8d5d1; border-color: #9f7772; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="5"] .housekeeper-apron { background: #fff7e8; box-shadow: inset 0 -5px #e9b4bd; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="6"] .housekeeper-body,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="6"] .housekeeper-arm { background: #397ca0; border-color: #24516c; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="6"] .housekeeper-apron { background: #d5e8ec; box-shadow: inset 0 -5px #9dc9d4; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="6"] .housekeeper-head { background: #6f472f; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="6"] .housekeeper-hair,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="6"] .housekeeper-hair::after { background: #171f29; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="7"] .housekeeper-body,
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="7"] .housekeeper-arm { background: #704f9d; border-color: #49336a; }
:is(.housekeeper-npc, .housekeeper-style)[data-appearance="7"] .housekeeper-apron { background: #f0ca55; box-shadow: inset 0 -5px #d49a38; }

#housekeeper-style-panel,
#housekeeper-naming-panel {
  position: fixed;
  inset: 0;
  z-index: 125;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(10,20,10,.88);
}

#housekeeper-style-content {
  width: min(720px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px;
  border: 4px solid #c69152;
  border-radius: 18px;
  background: linear-gradient(145deg,#3c5b32,#243d25);
  color: #fff8e7;
  text-align: center;
  box-shadow: 0 12px 35px rgba(0,0,0,.55);
}
#housekeeper-home-skin-section > p { margin: 6px 0 16px; color: #dbe9ce; }
#housekeeper-home-skin-grid { display: flex; flex-direction: column; gap: 10px; }
#housekeeper-home-skin-grid h4 { margin: 0; font-size: 13px; color: #ffe66d; }
#housekeeper-style-content > p { margin: 6px 0 16px; color: #dbe9ce; }
#housekeeper-style-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; }
.housekeeper-style-choice { display: flex; min-height: 132px; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 3px solid #718865; border-radius: 12px; background: rgba(255,255,255,.09); color: #fff8e7; font-family: inherit; cursor: pointer; }
.housekeeper-style-choice:hover { border-color: #ffe66d; transform: translateY(-2px); }
.housekeeper-style-choice.current { border-color: #7bc95f; background: rgba(123,201,95,.2); }
.housekeeper-style-choice small { color: #ffe99b; }
.housekeeper-style { position: relative; display: block; width: 42px; height: 76px; filter: drop-shadow(0 4px 2px rgba(0,0,0,.3)); }

/* ---------- Accueil du personnel de maison (nom + apparence) ---------- */

#housekeeper-naming-content {
  width: min(480px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px 24px;
  border: 4px solid #c69152;
  border-radius: 18px;
  background: linear-gradient(145deg,#3c5b32,#243d25);
  color: #fff8e7;
  text-align: center;
  box-shadow: 0 12px 35px rgba(0,0,0,.55);
  animation: housekeeper-naming-pop .35s ease-out;
}
#housekeeper-naming-content h2 { margin: 0 0 6px; color: #ffe66d; }
#housekeeper-naming-content > p { margin: 0 0 18px; color: #dbe9ce; }

#housekeeper-naming-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
  padding: 18px 0 10px;
  background: radial-gradient(ellipse at center, rgba(255,255,255,.1), transparent 70%);
  border-radius: 50%;
}
#housekeeper-naming-preview .housekeeper-style { width: 66px; height: 118px; transform: scale(1.2); }

#housekeeper-naming-appearances {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}
.housekeeper-naming-choice {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
  border: 3px solid #718865;
  border-radius: 10px;
  background: rgba(255,255,255,.09);
  cursor: pointer;
}
.housekeeper-naming-choice:hover { border-color: #ffe66d; transform: translateY(-2px); }
.housekeeper-naming-choice.selected { border-color: #7bc95f; background: rgba(123,201,95,.25); }
.housekeeper-naming-choice .housekeeper-style { transform: scale(.72); }

#housekeeper-naming-input {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 18px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 3px solid #718865;
  background: #eafbe0;
  color: #2b2b2b;
  text-align: center;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#housekeeper-naming-input:focus { border-color: #ffe66d; box-shadow: 0 0 0 4px rgba(255,230,109,.16); }

#housekeeper-naming-actions { margin-top: 16px; }
#housekeeper-naming-actions button {
  padding: 10px 22px;
  border: 0;
  border-radius: 9px;
  background: #669550;
  color: white;
  font: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: background .15s, transform .15s;
}
#housekeeper-naming-actions button:hover:not(:disabled) { background: #7caf61; transform: translateY(-1px); }
#housekeeper-naming-actions button:disabled { opacity: .5; cursor: not-allowed; }

@keyframes housekeeper-naming-pop {
  from { opacity: 0; transform: scale(.92) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (max-width: 640px) {
  #housekeeper-naming-appearances { grid-template-columns: repeat(3, 1fr); }
}

/* Habitants de la ville, construits sur le même modèle articulé. */
.city-resident {
  width: 42px;
  height: 72px;
  z-index: 6;
  filter: drop-shadow(0 4px 3px rgba(34,28,20,.28));
}
.city-resident-visual { display: block; width: 42px; height: 72px; font-size: 0; }
.city-resident .housekeeper-style { transform: scale(.88); transform-origin: 50% 100%; }
.city-resident .housekeeper-person { animation: city-resident-idle 3.2s ease-in-out infinite; }
.city-resident:nth-of-type(even) .housekeeper-person { animation-delay: -1.4s; }
.city-resident .player-label { top: -18px; min-width: max-content; font-size: 10px; }
.city-resident:hover .housekeeper-person { filter: brightness(1.08); }

.future-quest-badge {
  position: absolute;
  top: -14px;
  right: -12px;
  z-index: 8;
  display: grid;
  width: 23px;
  height: 23px;
  place-items: center;
  border: 2px solid #86652e;
  border-radius: 50%;
  background: #ffe899;
  font-size: 13px;
  box-shadow: 0 2px 5px rgba(0,0,0,.3);
  animation: future-quest-float 1.8s ease-in-out infinite alternate;
}

@keyframes city-resident-idle {
  0%, 45%, 100% { translate: 0 0; rotate: 0deg; }
  50% { translate: 0 -2px; rotate: -1deg; }
  58% { translate: 0 0; rotate: 1deg; }
}
@keyframes future-quest-float { to { transform: translateY(-3px) rotate(4deg); } }

@media (prefers-reduced-motion: reduce) {
  .city-resident .housekeeper-person, .future-quest-badge { animation: none; }
}
#housekeeper-style-actions { display: flex; justify-content: center; gap: 10px; margin-top: 16px; }
#housekeeper-style-actions button { padding: 9px 14px; border: 0; border-radius: 9px; background: #669550; color: white; font: inherit; cursor: pointer; }
#housekeeper-style-actions button:hover { background: #7caf61; }

@media (max-width: 560px) {
  #housekeeper-style-content { max-height: 94vh; overflow: auto; padding: 14px; }
  #housekeeper-style-grid { grid-template-columns: repeat(2,1fr); }
  #housekeeper-style-actions { flex-direction: column; }
}

@keyframes housekeeper-body-walk { to { translate: 0 -2px; rotate: 1deg; } }
@keyframes housekeeper-leg-left { from { rotate: 18deg; } to { rotate: -18deg; } }
@keyframes housekeeper-leg-right { from { rotate: -18deg; } to { rotate: 18deg; } }
@keyframes housekeeper-arm-left { from { rotate: -16deg; } to { rotate: 16deg; } }
@keyframes housekeeper-arm-right { from { rotate: 16deg; } to { rotate: -16deg; } }

@media (prefers-reduced-motion: reduce) {
  .housekeeper-npc { transition-duration: .01ms; }
  .housekeeper-npc.walking .housekeeper-person,
  .housekeeper-npc.walking .housekeeper-leg,
  .housekeeper-npc.walking .housekeeper-arm { animation: none; }
}

.village-counter {
  width: 74px;
  height: 36px;
  z-index: 4;
  cursor: default;
}

.village-counter .counter-shape {
  position: absolute;
  inset: 0;
  background: linear-gradient(#a9723f, #8a5a2f);
  border: 3px solid #6b4423;
  border-radius: 6px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
}

.village-counter .counter-sign {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
}

.skill-counter {
  width: 260px;
  height: 44px;
  z-index: 6;
}

.skill-counter .counter-sign {
  left: 18%;
}

.skill-counter .counter-shape {
  background: linear-gradient(#c69152, #89562f);
  border-width: 4px;
  box-shadow: 0 5px 8px rgba(0, 0, 0, 0.4);
}

.house-object {
  font-size: 64px;
  z-index: 5;
  cursor: pointer;
}

#house-door {
  font-size: 72px;
  z-index: 1;
}

.house-icon {
  font-size: 0;
}

.house-icon .icon-shape {
  position: absolute;
}

/* Chest: body + domed lid + gold band + lock, as separate parts */
.house-icon-chest {
  width: 64px;
  height: 50px;
}

.house-icon-chest .icon-part-0 {
  bottom: 0;
  left: 5px;
  width: 54px;
  height: 26px;
  background: linear-gradient(#9a6a3a, #7a4f28);
  border: 3px solid #4a2f18;
  border-top: none;
  border-radius: 0 0 8px 8px;
}

.house-icon-chest .icon-part-1 {
  top: 2px;
  left: 0;
  width: 64px;
  height: 22px;
  background: linear-gradient(#8a5a2f, #6b4423);
  border: 3px solid #4a2f18;
  border-radius: 14px 14px 4px 4px;
}

.house-icon-chest .icon-part-2 {
  top: 21px;
  left: 5px;
  width: 54px;
  height: 6px;
  background: linear-gradient(#f1c40f, #d4ac0d);
  border-top: 1px solid #a67c00;
  border-bottom: 1px solid #a67c00;
}

.house-icon-chest .icon-part-3 {
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: 13px;
  height: 15px;
  background: #f1c40f;
  border: 2px solid #a67c00;
  border-radius: 3px;
}

.house-icon-chest .icon-part-3::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 50%;
  width: 3px;
  height: 5px;
  background: #a67c00;
  transform: translateX(-50%);
}

/* Table */
.house-icon-table {
  width: 84px;
  height: 52px;
}

.house-icon-table .icon-shape {
  inset: 0;
  background: linear-gradient(#d9a15c, #c07f3a);
  border: 3px solid #7a4a1f;
  border-radius: 12px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.35);
}

.house-icon-table .icon-shape::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 10px;
  right: 10px;
  height: 2px;
  background: rgba(0, 0, 0, 0.15);
  transform: translateY(-50%);
}

/* Fridge */
.house-icon-fridge {
  width: 48px;
  height: 78px;
}

.house-icon-fridge .icon-shape {
  inset: 0;
  background: #eef3f0;
  border: 3px solid #b7c4bd;
  border-radius: 7px;
}

.house-icon-fridge .icon-shape::before {
  content: "";
  position: absolute;
  top: 25px;
  left: 4px;
  right: 4px;
  height: 3px;
  background: #b7c4bd;
}

.house-icon-fridge .icon-shape::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 7px;
  width: 5px;
  height: 12px;
  background: #7c8f86;
  border-radius: 2px;
  box-shadow: 0 33px 0 #7c8f86;
}

.trophy {
  font-size: 56px;
  z-index: 6;
  filter: drop-shadow(0 0 6px gold);
  animation: trophy-pulse 1s ease-in-out infinite alternate;
}

@keyframes trophy-pulse {
  from {
    transform: translate(-50%, -50%) scale(1);
  }
  to {
    transform: translate(-50%, -50%) scale(1.15);
  }
}

.construction-site,
.construction-complete {
  font-size: 52px;
  z-index: 5;
  cursor: pointer;
}

.construction-site {
  filter: drop-shadow(0 0 5px #ffcf5c);
  animation: construction-wobble 1.4s ease-in-out infinite alternate;
}

.construction-complete {
  filter: drop-shadow(0 0 4px #8fd18f);
}

.construction-complete .entity-emoji { display: block; }
.building-preview-world { transform: scale(1.28); transform-origin: 50% 80%; }
.building-preview-world[data-kind="medium"] { transform: scale(1.38); }
.building-preview-world[data-kind="large"] { transform: scale(1.48); }

@keyframes construction-wobble {
  from {
    transform: translate(-50%, -50%) rotate(-3deg);
  }
  to {
    transform: translate(-50%, -50%) rotate(3deg);
  }
}

/* ---------- Catalogue compact du maçon ----------
   Une seule grille, une ligne horizontale par famille et aucune galerie
   défilante : les vingt silhouettes d'une taille restent visibles ensemble. */
#mason-panel { padding: 6px; }
#mason-content {
  width: min(1180px, 98vw);
  max-height: 98vh;
  padding: 12px 16px;
  overflow-y: auto;
  overflow-x: hidden;
}

#mason-content .talent-heading { margin-bottom: 7px; }
#mason-content .talent-advisor-avatar { font-size: 38px; }
#mason-content .talent-heading h2 { font-size: 21px; }

#mason-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

#mason-grid .plan-card {
  min-height: 0;
  height: 78px;
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr) 132px;
  grid-template-rows: 37px 31px;
  gap: 2px 10px;
  padding: 4px 6px;
  border: 0;
  border-bottom: 2px solid rgba(215, 230, 190, .38);
  border-radius: 0;
  background: transparent;
  transform: none;
}

#mason-grid .plan-card:first-child { border-top: 2px solid rgba(215, 230, 190, .38); }
#mason-grid .plan-card:hover { transform: none; background: rgba(255,255,255,.035); }
#mason-grid .plan-card > strong { align-self: end; font-size: 13px; line-height: 1.05; }

#mason-grid .plan-style-gallery,
#mason-grid .plan-style-gallery[data-kind="small"],
#mason-grid .plan-style-gallery[data-kind="medium"],
#mason-grid .plan-style-gallery[data-kind="large"] {
  grid-column: 2;
  grid-row: 1 / 3;
  display: grid;
  grid-template-columns: repeat(20, minmax(30px, 1fr));
  align-items: center;
  gap: 3px;
  width: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: visible;
}

#mason-grid .plan-style-gallery[data-kind="serre"],
#mason-grid .plan-style-gallery[data-kind="terrarium"],
#mason-grid .plan-style-gallery[data-kind="voliere"],
#mason-grid .plan-style-gallery[data-kind="aquarium"] {
  grid-template-columns: repeat(3, 66px);
  justify-content: start;
}

/* Deux rangées de dix : les maisons gardent leur silhouette complète. */
#mason-grid .plan-card[data-kind="small"],
#mason-grid .plan-card[data-kind="medium"],
#mason-grid .plan-card[data-kind="large"] {
  height: 152px;
  grid-template-rows: 72px 70px;
}

#mason-grid .plan-style-gallery[data-kind="small"],
#mason-grid .plan-style-gallery[data-kind="medium"],
#mason-grid .plan-style-gallery[data-kind="large"] {
  grid-template-columns: repeat(10, minmax(62px, 1fr));
  grid-template-rows: repeat(2, 70px);
  gap: 4px 5px;
}

#mason-grid .plan-style-choice,
#mason-grid .plan-style-gallery[data-kind="small"] .plan-style-choice,
#mason-grid .plan-style-gallery[data-kind="medium"] .plan-style-choice,
#mason-grid .plan-style-gallery[data-kind="large"] .plan-style-choice {
  width: 100%;
  height: 66px;
  padding: 0;
  border-width: 2px;
  border-radius: 6px;
  overflow: visible;
}

#mason-grid .building-preview {
  margin: 0 auto;
  transform: scale(.62);
  transform-origin: 50% 58%;
}

#mason-grid .building-preview[data-kind="medium"] { transform: scale(.64); }
#mason-grid .building-preview[data-kind="large"] { transform: scale(.67); }

#mason-grid .plan-style-gallery[data-kind="small"] .building-preview { transform: scale(.88); transform-origin: 50% 50%; }
#mason-grid .plan-style-gallery[data-kind="medium"] .building-preview { transform: scale(.9); transform-origin: 50% 50%; }
#mason-grid .plan-style-gallery[data-kind="large"] .building-preview { transform: scale(.92); transform-origin: 50% 50%; }

#mason-grid .plan-style-name {
  grid-column: 1;
  grid-row: 2;
  min-height: 0;
  align-self: start;
  font-size: 9px;
  line-height: 1.05;
}

#mason-grid .plan-card-resources {
  grid-column: 3;
  grid-row: 1;
  align-self: end;
  font-size: 9px;
  line-height: 1.2;
}

#mason-grid .plan-action {
  grid-column: 3;
  grid-row: 2;
  align-self: start;
  width: 100%;
  padding: 5px 3px;
  font-size: 9px;
}

#mason-message {
  min-height: 0;
  margin: 6px 0;
  padding: 6px 10px;
  font-size: 11px;
  line-height: 1.2;
}

#mason-close-btn { padding: 5px 20px; font-size: 12px; }

.mason-empty-plans {
  padding: 28px;
  border: 2px dashed #91ad7d;
  border-radius: 12px;
  color: #fff0ad;
  text-align: center;
}

@media (max-width: 850px) {
  #mason-content { overflow: auto; }
  #mason-grid .plan-card { height: auto; min-height: 132px; grid-template-columns: 100px minmax(0, 1fr); grid-template-rows: 30px 72px 24px; }
  #mason-grid .plan-style-gallery,
  #mason-grid .plan-style-gallery[data-kind="small"],
  #mason-grid .plan-style-gallery[data-kind="medium"],
  #mason-grid .plan-style-gallery[data-kind="large"] { grid-column: 1 / 3; grid-row: 2; grid-template-columns: repeat(10, minmax(30px, 1fr)); }
  #mason-grid .plan-style-gallery[data-kind="serre"],
  #mason-grid .plan-style-gallery[data-kind="terrarium"],
  #mason-grid .plan-style-gallery[data-kind="voliere"],
  #mason-grid .plan-style-gallery[data-kind="aquarium"] { grid-template-columns: repeat(3, 66px); }
  #mason-grid .plan-style-name { grid-column: 1; grid-row: 3; }
  #mason-grid .plan-card-resources { grid-column: 2; grid-row: 1; }
  #mason-grid .plan-action { grid-column: 2; grid-row: 3; }

  #mason-grid .plan-card[data-kind="small"],
  #mason-grid .plan-card[data-kind="medium"],
  #mason-grid .plan-card[data-kind="large"] {
    min-height: 306px;
    grid-template-rows: 30px 280px 24px;
  }
  #mason-grid .plan-style-gallery[data-kind="small"],
  #mason-grid .plan-style-gallery[data-kind="medium"],
  #mason-grid .plan-style-gallery[data-kind="large"] {
    grid-template-columns: repeat(5, minmax(62px, 1fr));
    grid-template-rows: repeat(4, 68px);
  }
}

.remote-player {
  z-index: 9;
}

.player-label {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  font-family: "Trebuchet MS", sans-serif;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  padding: 1px 6px;
  border-radius: 6px;
  white-space: nowrap;
}

.speech-bubble {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px;
  background: #fff;
  color: #2b2b2b;
  font-size: 13px;
  font-family: "Trebuchet MS", sans-serif;
  padding: 4px 10px;
  border-radius: 10px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  z-index: 20;
}

/* ---------- Players panel ---------- */

#players-panel {
  position: absolute;
  top: 62px;
  left: 10px;
  z-index: 30;
  background: #fff8e7;
  border: 3px solid #7a5230;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  color: #2b2b2b;
  min-width: 160px;
  max-width: 260px;
}

#players-panel div {
  padding: 2px 0;
}

/* ---------- Direction arrows (off-screen players) ---------- */

#direction-arrows {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}

.direction-arrow {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 2px;
  pointer-events: none;
}

.direction-arrow .arrow-glyph {
  display: inline-block;
  font-size: 22px;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}

.direction-arrow .arrow-emoji {
  font-size: 15px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  padding: 1px 4px;
}

/* ---------- Minimap ---------- */

#minimap-column {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
}

#quest-menu-btn {
  padding: 5px 7px;
  border: 2px solid #8b6b3f;
  border-radius: 8px;
  background: linear-gradient(#f4e4b8, #d5b978);
  color: #4d3821;
  font: bold 11px/1.2 inherit;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0,0,0,.28);
}

#minimap-coords {
  text-align: center;
  font-size: 11px;
  font-weight: bold;
  color: #eafbe0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

#active-potions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 3px;
  min-height: 0;
}

.active-potion-badge {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 20px;
  height: 22px;
  flex-shrink: 0;
}

.active-potion-badge .potion-icon {
  transform: scale(0.55);
}

.active-potion-badge .active-potion-time {
  position: absolute;
  bottom: -3px;
  left: 50%;
  transform: translateX(-50%);
  font: bold 7px/1 inherit;
  color: #fff8e7;
  background: rgba(0, 0, 0, 0.6);
  padding: 1px 3px;
  border-radius: 5px;
  white-space: nowrap;
}

#minimap {
  position: relative;
  flex-shrink: 0;
  width: 118px;
  height: 118px;
  display: grid;
  gap: 0;
  background: #102219;
  border: 3px solid #8b6b3f;
  border-radius: 12px;
  padding: 5px;
  box-shadow: inset 0 0 15px rgba(0,0,0,.55), 0 5px 12px rgba(0,0,0,.35);
  cursor: zoom-in;
  overflow: hidden;
  touch-action: none;
  transition: width .25s ease, height .25s ease, border-radius .25s ease;
}

/* Agrandie, le clic/tap sert à glisser la vue (voir pointerdown dans
   net.js) — plus à fermer, d'où le curseur "grab" et les boutons dédiés
   ci-dessous plutôt qu'un simple clic n'importe où. */
.minimap-canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; border-radius: inherit; }

.minimap-recenter-btn, .minimap-close-btn {
  display: none;
  position: absolute;
  z-index: 12;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #fff8e7;
  border: 2px solid #7a5230;
  color: #3d2b18;
  box-shadow: 0 3px 8px rgba(0,0,0,.4);
  cursor: pointer;
  font-family: inherit;
  padding: 0;
}
#minimap.expanded .minimap-recenter-btn, #minimap.expanded .minimap-close-btn { display: flex; }

.minimap-recenter-btn { left: 12px; bottom: 12px; width: 38px; height: 38px; font-size: 18px; }
.minimap-close-btn { right: 12px; top: 12px; width: 34px; height: 34px; font-size: 16px; }

.minimap-town-marker {
  position: absolute;
  z-index: 6;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 1px 2px #000) drop-shadow(0 0 3px #ffe66d);
}
.minimap-town-marker span {
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border: 2px solid #fff0a8;
  border-radius: 50%;
  background: #6f4b25;
  font-size: 11px;
  line-height: 1;
}
.minimap-town-marker strong {
  display: none;
  position: absolute;
  top: calc(100% + 3px);
  width: max-content;
  max-width: 120px;
  padding: 2px 5px;
  border: 1px solid #f4d47b;
  border-radius: 5px;
  background: rgba(38, 31, 22, .92);
  color: #fff4c3;
  font-size: 8px;
  white-space: nowrap;
}
#minimap.expanded .minimap-town-marker span { width: 30px; height: 30px; border-width: 3px; font-size: 19px; }
#minimap.expanded .minimap-town-marker strong { display: block; }
.minimap-town-marker.town-marker-coast { filter: drop-shadow(0 1px 2px #000) drop-shadow(0 0 5px #6ee7ff); }
.minimap-town-marker.town-marker-mining,
.minimap-town-marker.town-marker-stone { filter: drop-shadow(0 1px 2px #000) drop-shadow(0 0 5px #d5d1c7); }
.minimap-town-marker.town-marker-flowers { filter: drop-shadow(0 1px 2px #000) drop-shadow(0 0 5px #ff91d2); }
.minimap-town-marker.town-marker-bamboo { filter: drop-shadow(0 1px 2px #000) drop-shadow(0 0 5px #9cf08d); }

.minimap-self-marker {
  position: absolute;
  z-index: 10;
  display: grid;
  width: 18px;
  height: 18px;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 50%;
  background: #3279a8;
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px #000) drop-shadow(0 0 5px #62d9ff);
}
#minimap.expanded .minimap-self-marker { width: 32px; height: 32px; border-width: 3px; font-size: 21px; }

#minimap.expanded {
  position: fixed;
  z-index: 300;
  top: 50%;
  left: 50%;
  width: min(82vmin, 680px);
  height: min(82vmin, 680px);
  transform: translate(-50%, -50%);
  padding: 12px;
  border-width: 6px;
  border-radius: 22px;
  /* Agrandie, le clic/tap sert à glisser la vue (voir pointerdown dans
     net.js) — plus à fermer, d'où "grab" plutôt que "zoom-out" et les
     boutons ◎/✕ dédiés plutôt qu'un simple clic n'importe où. */
  cursor: grab;
  box-shadow: 0 0 0 100vmax rgba(7,18,12,.82), inset 0 0 32px rgba(0,0,0,.45), 0 18px 60px rgba(0,0,0,.65);
}

#minimap.expanded.dragging { cursor: grabbing; }

.minimap-cell {
  position: relative;
  border-radius: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1px;
  box-shadow: inset 0 0 2px rgba(0,0,0,.12);
}

.minimap-cell[data-biome="0"] { background-image: radial-gradient(circle, rgba(19,84,37,.45), transparent 65%); }
.minimap-cell[data-biome="1"] { background-image: linear-gradient(135deg, rgba(238,222,112,.15), transparent); }
.minimap-cell[data-biome="2"] { background-image: radial-gradient(ellipse, rgba(218,250,255,.22), transparent 65%); }
.minimap-cell[data-biome="3"] { background-image: linear-gradient(145deg, rgba(65,62,48,.32), transparent 55%); }
.minimap-cell[data-biome="4"] { background-image: radial-gradient(circle, rgba(230,190,75,.18), transparent 55%); }
.minimap-cell[data-biome="5"] { background-image: radial-gradient(circle, rgba(255,211,240,.18), transparent 60%); }
.minimap-cell[data-biome="6"] { background-image: linear-gradient(90deg, rgba(19,91,70,.25), transparent); }
.minimap-cell[data-biome="7"] { background-image: radial-gradient(circle, rgba(255,246,155,.24), transparent 65%); }

.minimap-cell.current {
  outline: 2px solid #fff;
  outline-offset: -2px;
}

.minimap-cell.home::after {
  content: "🏠";
  font-size: 5px;
  position: absolute;
  z-index: 3;
}

#minimap.expanded .minimap-cell.home::after { font-size: clamp(9px, 1.5vmin, 15px); }

.minimap-cell.my-house::after {
  content: "📍";
  font-size: 5px;
  position: absolute;
  z-index: 4;
  filter: drop-shadow(0 0 1px #ffd166);
}

#minimap.expanded .minimap-cell.my-house::after { font-size: clamp(9px, 1.5vmin, 15px); }

.minimap-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.4);
}

#minimap.expanded .minimap-dot { width: 8px; height: 8px; border-width: 2px; }

/* ---------- Journal de quêtes ---------- */

#quest-panel {
  position: fixed;
  inset: 0;
  z-index: 320;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15px;
  background: rgba(8, 19, 12, .88);
}

#quest-content {
  width: min(680px, 95vw);
  max-height: 92vh;
  overflow: auto;
  padding: 22px;
  border: 5px solid #8b6b3f;
  border-radius: 18px;
  background: linear-gradient(145deg, #f6edcf, #dfca98);
  color: #493720;
  box-shadow: 0 18px 55px rgba(0,0,0,.58), inset 0 0 35px rgba(139,107,63,.18);
}

.quest-panel-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  margin-bottom: 16px;
}

.quest-panel-heading > span { font-size: 45px; }
.quest-panel-heading h2 { font-size: 24px; }
.quest-panel-heading p { font-size: 12px; opacity: .72; }
#quest-list { display: flex; flex-direction: column; gap: 10px; }

.quest-card {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border: 2px solid rgba(112,83,43,.32);
  border-radius: 12px;
  background: rgba(255,255,255,.48);
  box-shadow: 0 4px 10px rgba(83,60,30,.13);
}

.quest-card.challenge-quest { border-color: #c8941e; background: linear-gradient(110deg, rgba(255,239,166,.8), rgba(255,255,255,.52)); }
.quest-card-icon { font-size: 34px; text-align: center; }
.quest-card-body h3 { margin-bottom: 4px; font-size: 15px; }
.quest-card-body p { font-size: 12px; line-height: 1.4; }

.quest-color-hint { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 11px; }
.quest-color-hint span { width: 34px; height: 22px; border: 3px solid #fff; border-radius: 6px; box-shadow: 0 1px 5px rgba(0,0,0,.35); }

.quest-cancel-btn, #quest-close-btn {
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: #b85f55;
  color: #fff;
  font: bold 11px inherit;
  cursor: pointer;
}

.quest-fixed-label { padding: 5px 7px; border-radius: 7px; background: rgba(112,83,43,.14); font-size: 10px; font-weight: bold; }
.quest-empty { padding: 28px 15px; text-align: center; opacity: .72; }
#quest-close-btn { display: block; margin: 16px auto 0; padding: 9px 22px; background: #628a4d; }

@media (max-width: 520px) {
  #quest-content { padding: 14px; }
  .quest-card { grid-template-columns: 38px 1fr; }
  .quest-card-icon { font-size: 28px; }
  .quest-cancel-btn, .quest-fixed-label { grid-column: 2; justify-self: start; }
}

/* ---------- Announcement banner ---------- */

#announcement {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: #f1c40f;
  color: #4a3520;
  font-weight: bold;
  padding: 8px 18px;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  text-align: center;
  max-width: 80%;
}

#announcement.announcement-big {
  font-size: 22px;
  padding: 14px 26px;
}

#pickup-toast {
  position: absolute;
  bottom: 170px;
  left: 14px;
  z-index: 50;
  background: #2f4d2a;
  color: #eafbe0;
  font-weight: bold;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid #7bc95f;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  max-width: 60%;
}

/* ---------- Chat ---------- */

#chat-btn {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 25;
  font-size: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid #3d5c2e;
  background: #fff8e7;
  cursor: pointer;
}

#chat-menu {
  position: absolute;
  top: 62px;
  left: 10px;
  z-index: 25;
  display: block;
  background: #fff8e7;
  border: 3px solid #7a5230;
  border-radius: 10px;
  padding: 8px;
  /* #chat-menu vit dans #stage, mis à l'échelle par transform: scale(). Le
     min(...) ci-dessous calcule la taille RÉELLE (à l'écran) souhaitée —
     390px ou la largeur de l'écran, selon le plus petit — puis la division
     par --stage-scale (posée par applyStageScale) convertit cette taille
     réelle en taille locale équivalente, pour qu'une fois réduite par le
     transform elle redonne bien la taille réelle visée, quelle que soit
     l'échelle du plateau. Diviser un seul des deux termes du min() ne
     suffit pas : les deux représentent une taille réelle, donc les deux
     doivent être compensés ensemble. */
  width: calc(min(390px, 100vw - 20px) / var(--stage-scale, 1));
  max-height: calc(min(430px, 100vh - 82px) / var(--stage-scale, 1));
  overflow: hidden;
}

#chat-menu button {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border: none;
  border-radius: 8px;
  background: #eafbe0;
  cursor: pointer;
}

.chat-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

#chat-menu .chat-tab {
  padding: 7px 3px;
  background: #ead7b7;
  font-size: 12px;
  font-weight: bold;
}

#chat-menu .chat-tab.active {
  color: #fff;
  background: #5d8a45;
}

.chat-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  max-height: calc(min(365px, 100vh - 135px) / var(--stage-scale, 1));
  overflow-y: auto;
  overscroll-behavior: contain;
}

#chat-menu button:hover {
  background: #cfe8c4;
}

/* ---------- Dialogue box ---------- */

#dialogue-box {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 760px;
  background: #fff8e7;
  border: 4px solid #7a5230;
  border-radius: 14px;
  padding: 14px 20px;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
  z-index: 40;
}

#dialogue-speaker {
  font-weight: bold;
  font-size: 18px;
  color: #4a3520;
  margin-bottom: 6px;
}

#dialogue-text {
  font-size: 17px;
  color: #2b2b2b;
  margin-bottom: 10px;
}

#dialogue-next {
  font-size: 15px;
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  background: #7bc95f;
  cursor: pointer;
}

#dialogue-next:hover {
  background: #5aa845;
}

/* ---------- Touch controls ---------- */

#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
#touch-controls.panel-open { visibility: hidden; }
.touch-device {
  --hud-rail-width: 112px;
  --touch-dock-height: 60px;
}
.touch-device.joystick-move-mode { --touch-dock-height: 114px; }
.touch-device #chat-btn,
.touch-device #btn-backpack-touch { display: none; }
.touch-device.touch-move-mode #joystick-touch-zone,
.touch-device.touch-move-mode #btn-talk { display: none !important; }

.tap-destination-marker {
  position: absolute;
  z-index: 7;
  width: 26px;
  height: 14px;
  transform: translate(-50%,-50%);
  border: 3px solid rgba(224,250,255,.92);
  border-radius: 50%;
  background: rgba(70,184,202,.18);
  box-shadow: 0 0 0 5px rgba(92,213,224,.14);
  pointer-events: none;
  animation: tap-destination-pulse .8s ease-out infinite;
}
@keyframes tap-destination-pulse { from { scale: .7; opacity: 1; } to { scale: 1.25; opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .tap-destination-marker { animation: none; } }

/* Zone tactile invisible où poser le doigt pour faire apparaître le
   joystick : couvre la moitié gauche de l'écran, mais s'arrête avant les
   boutons d'action à droite pour ne jamais leur voler un tap. */
#joystick-touch-zone {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  right: 190px;
  pointer-events: auto;
  touch-action: none;
}

#joystick-base {
  position: fixed;
  left: 0;
  top: 0;
  width: 156px;
  height: 156px;
  margin: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.18) 0 31%, rgba(22,42,26,.58) 33% 68%, rgba(255,255,255,.28) 70% 72%, rgba(19,35,22,.48) 74%);
  border: 2px solid rgba(255,255,255,.58);
  box-shadow: 0 7px 22px rgba(0,0,0,.38), inset 0 2px 7px rgba(255,255,255,.16);
  pointer-events: none;
  touch-action: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  transition: opacity .1s ease;
}

#joystick-base.active { opacity: 1; border-color: rgba(255,230,109,.95); }

#joystick-hint {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  pointer-events: none;
  opacity: .85;
  transition: opacity .15s ease;
}

#joystick-touch-zone.active #joystick-hint { opacity: 0; }

#joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 66px;
  height: 66px;
  margin: -33px 0 0 -33px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fff, #dcebd5 62%, #a9c99e);
  border: 3px solid #31582f;
  box-shadow: 0 5px 10px rgba(0,0,0,.35);
  pointer-events: none;
}

.touch-control-label {
  display: inline-block;
  margin-top: 4px;
  padding: 3px 9px;
  border-radius: 12px;
  background: rgba(18,34,21,.72);
  color: #fff;
  font-size: 11px;
  font-weight: bold;
  text-shadow: 0 1px 2px #000;
}

#touch-actions {
  position: absolute;
  /* Les rails du HUD ne doivent pas intercepter les boutons de commande. */
  z-index: 2;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: var(--hud-rail-width);
  padding: 6px;
  border-radius: 16px;
  background: #2f4d2a;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 48px;
  align-items: end;
  justify-items: end;
  gap: 6px;
  pointer-events: none;
}

.touch-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,.72);
  background: linear-gradient(145deg, rgba(255,255,255,.96), rgba(212,232,204,.93));
  color: #234221;
  box-shadow: 0 6px 17px rgba(0,0,0,.4), inset 0 1px 2px #fff;
  pointer-events: auto;
  touch-action: none;
  font-family: inherit;
  font-weight: bold;
}

.touch-action span { font-size: 25px; line-height: 1; }
.touch-action small { margin-top: 2px; font-size: 10px; line-height: 1; }
.touch-action:active { transform: translateY(2px); filter: brightness(.9); }
.touch-action-small { width: 100%; height: 48px; }
.touch-action-main {
  grid-column: 1 / -1;
  grid-row: 2;
  align-self: end;
  width: 100%;
  height: 48px;
  flex-direction: row;
  gap: 8px;
  border: 3px solid #ffe66d;
  background: linear-gradient(145deg, #fff8d9, #cce7bd);
}
.touch-action-main span { font-size: 26px; }
#btn-backpack-touch { grid-column: 1; grid-row: 1; }
#btn-chat-touch { grid-column: 1; grid-row: 1; }
#touch-mode-toggle { grid-column: 2; grid-row: 1; }

/* ---------- Rails HUD (tactile) ---------- */
/* touch.js déplace ici, élément par élément, le contenu de #hud (masqué —
   voir la règle .touch-device #hud plus haut) pour rendre au plateau toute
   la hauteur que le bandeau occupait. Chaque rail reste compact et ancré en
   haut, sans jamais s'étendre jusqu'au joystick ou aux boutons d'action. */
.hud-rail {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  width: var(--hud-rail-width);
  max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
  padding: 6px;
  border-radius: 12px;
  background: linear-gradient(180deg, #3b5d34 0%, #2f4d2a 55%, #253f21 100%);
  box-shadow: 0 8px 20px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.08);
  color: #fff;
  pointer-events: auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #7bc95f transparent;
}
.hud-rail > * { flex-shrink: 0; min-width: 0; }

#hud-rail-left { left: max(8px, env(safe-area-inset-left)); }
#hud-rail-right {
  right: max(8px, env(safe-area-inset-right));
  max-height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)) - var(--touch-dock-height) - 8px);
}
.hud-rail:empty { display: none; }

.hud-rail .hud-row,
.hud-rail #resource-bar {
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
}

.hud-rail .resource-divider { display: none; }
.hud-rail .resource-group { justify-content: center; }
.hud-rail .resource-group-wealth { display: grid; grid-template-columns: minmax(0, 1fr); padding: 5px 7px; gap: 4px; border-radius: 10px; }
.hud-rail .res-chip { justify-content: space-between; gap: 2px; font-size: 12px; }
.touch-device #backpack-content .resource-group-materials { flex-wrap: wrap; justify-content: center; border-radius: 10px; }

.hud-rail #room-code-display,
.hud-rail #player-name-display,
.hud-rail #plateau-info,
.hud-rail #challenge-status {
  font-size: 12px;
  text-align: center;
}
.hud-rail #player-name-display { justify-content: center; flex-direction: row; gap: 5px; padding: 6px 3px; min-height: 34px; }
.hud-rail #player-name-avatar { flex-shrink: 0; }

.hud-rail #players-toggle-btn,
.hud-rail #backpack-btn,
.hud-rail #challenge-btn,
.hud-rail #challenge-ready-btn,
.hud-rail #leave-room-btn,
.hud-rail #quest-menu-btn {
  width: 100%;
  font-size: 12px;
  padding: 7px 6px;
  text-align: center;
  min-height: 44px;
  overflow-wrap: anywhere;
}

.hud-rail #abilities-bar {
  position: static;
  transform: none;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}
.hud-rail .ability-slot { width: 44px; height: 44px; font-size: 20px; }
.hud-rail .ability-slot.locked { display: none; }
.hud-rail #abilities-bar:not(:has(.unlocked)) { display: none; }
.hud-rail #challenge-status:empty, .hud-rail #active-potions:empty { display: none; }
.hud-rail #plateau-info, .hud-rail #challenge-status { overflow-wrap: anywhere; line-height: 1.35; }

.hud-rail #minimap:not(.expanded) { width: 100%; height: auto; aspect-ratio: 1; margin: 0 auto; }
.hud-rail #minimap-coords { font-size: 10px; }
.hud-rail #active-potions { justify-content: center; flex-wrap: wrap; }

@media (hover: none) and (pointer: coarse) and (max-height: 520px) {
  #joystick-base { width: 136px; height: 136px; }
  .touch-control-label { display: none; }
  .hud-rail { font-size: 12px; }
}

#mobile-party-btn, #mobile-party-close {
  min-height: 44px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 10px;
  background: #496d38;
  color: #fff8d9;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
}
#mobile-party-menu {
  margin: auto;
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 18px;
  border: 2px solid #7bc95f;
  border-radius: 18px;
  background: #2f4d2a;
  color: #fff8d9;
  overflow-y: auto;
}
#mobile-party-menu::backdrop { background: rgba(10,20,10,.8); }
.mobile-party-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.mobile-party-heading h2 { font-size: 20px; }
#mobile-party-close { width: 44px; }
#mobile-party-content { display: flex; flex-direction: column; gap: 12px; }
#mobile-party-content button { min-height: 44px; font-size: 15px; }
#mobile-party-content #players-panel { position: static; min-width: 0; max-width: none; }
#mobile-party-content #room-code-display { text-align: center; font-size: 20px; }
#mobile-party-content #minimap-coords { font-size: 13px; }

@media (max-height: 340px) and (orientation: landscape) {
  .touch-device { --hud-rail-width: 108px; }
  .hud-rail #minimap:not(.expanded) { width: 72px; }
}

/* ---------- Help text ---------- */

#help-text {
  width: 900px;
  max-width: 95vw;
  color: #cfe8c4;
  font-size: 13px;
  text-align: center;
}

/* ---------- Phone layout ---------- */

@media (hover: none) and (pointer: coarse) and (max-width: 1400px) {
  html,
  body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body {
    position: fixed;
    inset: 0;
    align-items: flex-start;
  }

  #game-container {
    width: 100vw;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    justify-content: center;
    gap: 0;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
  }

  #hud {
    padding: 5px 12px;
    gap: 3px;
  }

  .hud-row {
    font-size: 15px;
  }

  #help-text {
    display: none;
  }

  #stage-outer {
    flex: 0 0 auto;
  }

  #players-toggle-btn,
  #leave-room-btn {
    min-height: 36px;
  }

  #chat-btn {
    width: 54px;
    height: 54px;
    font-size: 26px;
  }

  #dialogue-next {
    min-width: 120px;
    min-height: 42px;
  }
}

@media (hover: none) and (pointer: coarse) and (max-width: 600px) and (orientation: portrait) {
  #game-container::before {
    content: "↻ Tourne ton téléphone pour agrandir la carte";
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    left: 50%;
    z-index: 200;
    transform: translateX(-50%);
    width: max-content;
    max-width: 90vw;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(27, 42, 26, 0.9);
    color: #fff;
    font-size: 13px;
    text-align: center;
    pointer-events: none;
  }
}
