/* =====================================================================
   CoreCraftia in-game HUD - fluid layout system (Phase 1)

   One grid layer (#hud-layer) covers the viewport. Every HUD element is
   assigned a named grid area, so nothing is positioned with coordinates:
   the browser can be resized continuously and the areas re-flow.

   Sizing comes from a handful of fluid tokens (clamp on vmin/vw), never
   from zoom/scale or per-resolution overrides.

   Structural breakpoints (available WIDTH only - a portrait tablet is
   "compact", not "phone"):
     desktop  >= 1024px   profile | docked chat | actions+minimap ; hotbar row
     compact   640-1023   chat collapsed to a bubble, icon-only action strip
     phone     <  640     right-edge button column, full-width hotbar
   ===================================================================== */

:root{
  /* --- fluid tokens --------------------------------------------------- */
  --hud-pad-t: max(8px, env(safe-area-inset-top));
  --hud-pad-r: max(10px, env(safe-area-inset-right));
  --hud-pad-b: max(6px, env(safe-area-inset-bottom));
  --hud-pad-l: max(10px, env(safe-area-inset-left));
  --hud-gap: clamp(6px, 0.8vw, 14px);
  --hud-unit: clamp(44px, 5vmin + 14px, 72px);         /* square action buttons */
  --hud-icon: calc(var(--hud-unit) * 0.5);              /* sprite inside a button */
  --hud-slot: clamp(40px, 4.5vmin + 14px, 62px);        /* hotbar slot */
  --hud-touch-visual: clamp(64px, 9vmin, 76px);         /* visible control disc */
  --hud-touch-hit: clamp(76px, 11vmin, 90px);           /* finger-friendly hit target */
  --hud-font: clamp(11px, 0.5vmin + 8px, 14px);
  --hud-font-sm: clamp(9.5px, 0.4vmin + 7px, 11.5px);
  --hud-radius: clamp(10px, 1.2vmin, 18px);
  --hud-profile-w: clamp(230px, 20vw, 340px);
  --hud-chat-w: clamp(300px, 34vw, 560px);
  --hud-map-w: clamp(168px, 14vw, 240px);
  /* whatever is left of the top row after the profile and the docked chat
     - the action strip wraps into two rows instead of pushing the chat */
  --hud-right-max: calc(100vw - var(--hud-pad-l) - var(--hud-pad-r) - var(--hud-profile-w) - var(--hud-chat-w) - 2 * var(--hud-gap));
  --hud-avatar: clamp(52px, 9vmin, 96px);
  --hud-bar-h: clamp(20px, 3.6vmin, 32px);
  --hud-bar-font: clamp(11px, 1.7vmin, 15px);

  /* --- glass surface shared by every HUD panel ------------------------ */
  --hud-glass: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 40%), rgba(10, 26, 54, 0.52);
  --hud-glass-strong: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0) 30%), rgba(10, 26, 54, 0.66);
  --hud-border: 1px solid rgba(130, 190, 255, 0.34);
  --hud-shadow: 0 8px 20px rgba(0,0,0,0.26), inset 0 1px 0 rgba(255,255,255,0.10);
  --hud-ink: #f4fbff;
  --hud-ink-dim: rgba(214, 236, 255, 0.78);
}

/* ===================================================================== */
/* 1. The layer: three stacked rows                                        */
/*    top    = profile | docked chat | right column (actions over minimap) */
/*    mid    = flexible spacer; ping/fps bottom-left, zoom bottom-right    */
/*    bottom = touch-left | hotbar | touch-right                           */
/* ===================================================================== */
#hud-layer{
  position: fixed;
  inset: 0;
  z-index: 3200;
  display: none;
  box-sizing: border-box;
  padding: var(--hud-pad-t) var(--hud-pad-r) var(--hud-pad-b) var(--hud-pad-l);
  gap: var(--hud-gap);
  flex-direction: column;
  pointer-events: none;             /* the game canvas stays clickable between panels */
}
body.is-game-world #hud-layer{ display: flex; }
#hud-layer .hud-row{ display: grid; gap: var(--hud-gap); min-width: 0; pointer-events: none; }
#hud-layer .hud-row-top{
  grid-template-columns: var(--hud-profile-w) minmax(0, 1fr) auto;
  /* row 1 is exactly the profile's height; anything taller in the right
     column (minimap + kill feed) grows row 2, so the chat never stretches */
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "profile chat right"
    "quick   .    right";
  align-items: start;
}
/* bottom row: ping/fps and zoom sit above the touch clusters, the hotbar
   spans both rows between them (it gets its own row on narrow screens) */
#hud-layer .hud-row-bottom{
  margin-top: auto;                 /* pushed to the bottom; the gap between rows is free space */
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  grid-template-areas:
    "net    hotbar zoom"
    "touchL hotbar touchR";
  align-items: end;
}
/* whatever a legacy rule or inline style says, HUD children are laid out by the rows */
#hud-layer .hud-row > *,
#hud-layer #hud-right > *,
#hud-layer #mini-profile,
#hud-layer .mini-profile-actions,
#hud-layer #touch-left,
#hud-layer #touch-right,
#hud-layer #touch-zoom{
  position: static !important;
  inset: auto !important;
  transform: none !important;
  zoom: 1 !important;
  margin: 0 !important;
  min-width: 0 !important;
  max-width: none !important;
  pointer-events: auto;
}
#hud-layer #mobile-controls,
#hud-layer #touch-left,
#hud-layer #touch-right,
#hud-layer #touch-left button,
#hud-layer #touch-right button{
  touch-action: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-tap-highlight-color: transparent;
}
/* wrappers whose children are the real grid items */
#hud-layer #mini-profile-stack,
#hud-layer .mini-profile-bottom-row,
#hud-layer #mobile-controls{ display: contents !important; }

#hud-layer #mini-profile{ grid-area: profile; }
#hud-layer .mini-profile-actions{ grid-area: quick; justify-self: start; }
#hud-layer #chat-container{ grid-area: chat; align-self: stretch; justify-self: start; }
#hud-layer #hud-right{ grid-area: right; justify-self: end; display: flex; flex-direction: column; align-items: flex-end; gap: var(--hud-gap); pointer-events: none; max-width: var(--hud-right-max) !important; min-width: 0; }
#hud-layer #hud-right > *{ pointer-events: auto; }
#hud-layer #monster-kill-feed:empty{ display: none !important; }
#hud-layer #hud-net{ grid-area: net; justify-self: start; align-self: end; }
#hud-layer #touch-zoom{ grid-area: zoom; justify-self: end; align-self: end; }
#hud-layer #touch-left{ grid-area: touchL; }
#hud-layer #touch-right{ grid-area: touchR; }
#hud-layer #gameplay-quick-panel{ grid-area: hotbar; justify-self: center; }

/* ===================================================================== */
/* 2. Mini profile                                                         */
/* ===================================================================== */
#hud-layer #mini-profile{
  width: 100%;
  box-sizing: border-box;
  padding: clamp(6px, 1vmin, 12px) clamp(8px, 1.2vmin, 14px);
  border-radius: var(--hud-radius);
  background: var(--hud-glass);
  border: var(--hud-border);
  box-shadow: var(--hud-shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: clamp(6px, 1vmin, 12px);
}
#hud-layer #mini-profile .mini-profile-top{ display: flex; align-items: center; gap: clamp(6px, 1vmin, 10px); width: 100%; min-width: 0; }
#hud-layer #mini-profile .mini-avatar-shell,
#hud-layer #mini-profile .mini-avatar-stage{
  flex: 0 0 var(--hud-avatar) !important;
  width: var(--hud-avatar) !important;
  height: var(--hud-avatar) !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
  overflow: visible !important;
}
#hud-layer #mini-profile .mini-avatar-stage{ transform-origin: 0 0; }
#hud-layer #mini-profile .mini-profile-meta{ flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: clamp(3px, 0.6vmin, 6px); }
#hud-layer #mini-profile .mini-profile-name-row{ display: flex; align-items: center; padding-left: 4px; min-width: 0; }
#hud-layer #mini-profile .mini-profile-name{
  font-size: clamp(13px, 1.9vmin, 20px);
  font-weight: 900;
  line-height: 1.1;
  color: var(--mini-name-color, #fff);
  text-shadow: 0 2px 4px rgba(0,0,0,0.75);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#hud-layer #mini-badges:empty{ display: none; }
#hud-layer #mini-profile .mini-profile-stats{ display: flex; flex-direction: column; gap: clamp(3px, 0.6vmin, 7px); }
#hud-layer #mini-profile .mini-stat-row{ display: flex; align-items: center; position: relative; min-width: 0; }
#hud-layer #mini-profile .mini-stat-label{ display: none; }
/* round icon, overlapping the bar's left edge */
#hud-layer #mini-profile{
  --mini-ico: calc(var(--hud-bar-h) + 6px);           /* round stat icon (used by the bars too) */
  --mini-ico-tile: calc(var(--mini-ico) * 0.55);
}
#hud-layer #mini-profile .mini-stat-icon{
  position: relative;
  z-index: 2;
  flex: 0 0 var(--mini-ico) !important;
  width: var(--mini-ico) !important;
  height: var(--mini-ico) !important;
  min-width: 0 !important;
  min-height: 0 !important;
  margin: 0 calc(var(--mini-ico) * -0.85) 0 0 !important;
  border-radius: 50% !important;
  box-sizing: border-box;
  border: 2px solid rgba(255,255,255,0.28);
  box-shadow: 0 3px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.15);
  display: grid !important;
  place-items: center;
  padding: calc((var(--mini-ico) - var(--mini-ico-tile)) / 2 - 2px) !important;
  font-size: 0;
  image-rendering: auto;              /* 125px source tiles, downscaled - keep them smooth */
}
/* sprite layer clipped to the content box (exactly one 11x8 tile, no bleed),
   colour layer on the whole circle */
#hud-layer #mini-profile .mini-stat-icon-hp{
  background:
    url("/photos/icons_tilemap.png") 0% 57.1428% / 1100% 800% no-repeat content-box content-box,
    rgba(120, 12, 24, 0.9) border-box;
  border-color: rgba(255, 120, 120, 0.55);
}
#hud-layer #mini-profile .mini-stat-icon-mana{
  background:
    url("/photos/icons_tilemap.png") 10% 28.5714% / 1100% 800% no-repeat content-box content-box,
    rgba(12, 60, 130, 0.9) border-box;
  border-color: rgba(120, 190, 255, 0.6);
}
#hud-layer #mini-profile .mini-stat-icon.mini-profile-level{
  padding: 0;
  clip-path: none !important;
  background:
    url("/photos/icons_tilemap.png") 0% 71.4286% / 1100% 800% no-repeat border-box border-box,
    rgba(3, 12, 30, 0.7) border-box !important;
  border-color: rgba(255, 210, 90, 0.6) !important;
}
#hud-layer #mini-profile .mini-stat-icon.mini-profile-level::before{ display: none !important; }
#hud-layer #mini-profile .mini-stat-icon.mini-profile-level .mini-profile-level-num{
  position: relative;
  z-index: 1;
  font-size: calc(var(--mini-ico) * 0.4);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 1px 0 #000, 0 0 4px #000;
  transform: translateY(6%);
}
#hud-layer #mini-profile .mini-profile-hp-track,
#hud-layer #mini-profile .mini-profile-mana-track,
#hud-layer #mini-profile .mini-profile-xp-track{
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  height: var(--hud-bar-h);
  border-radius: calc(var(--hud-bar-h) / 2);
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.35);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.3);
}
#hud-layer #mini-profile .mini-profile-hp-track{ background: rgba(120, 12, 24, 0.55); }
#hud-layer #mini-profile .mini-profile-mana-track{ background: rgba(12, 50, 120, 0.55); }
#hud-layer #mini-profile .mini-profile-xp-track{ background: rgba(120, 78, 0, 0.55); }
#hud-layer #mini-profile .mini-profile-hp-fill,
#hud-layer #mini-profile .mini-profile-mana-fill,
#hud-layer #mini-profile .mini-profile-xp-fill{
  position: absolute;
  inset: 0 auto 0 0;
  /* the first icon-width sits under the round icon; progress on the rest */
  width: calc(var(--mini-ico) * 0.9 + (100% - var(--mini-ico) * 0.9) * var(--fill, 100) / 100);
  border-radius: inherit;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), inset 0 -2px 0 rgba(0,0,0,0.18);
}
#hud-layer #mini-profile .mini-profile-hp-fill{ background: linear-gradient(180deg, #ff2f45, #d80f2c); }
#hud-layer #mini-profile .mini-profile-mana-fill{ background: linear-gradient(180deg, #2f95ff, #1e6ff0); }
#hud-layer #mini-profile .mini-profile-xp-fill{ background: linear-gradient(180deg, #ffbf1f, #f5a300); }
#hud-layer #mini-profile .mini-profile-hp-label{
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding-left: calc(var(--mini-ico) * 1.05);
  font-size: var(--hud-bar-font);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0,0,0,0.82), 0 0 6px rgba(0,0,0,0.5);
  white-space: nowrap;
  overflow: hidden;
}
#hud-layer #mini-profile .mini-profile-hp-label::before{ content: "HP: "; white-space: pre; }
#hud-layer #mini-profile .mini-stat-row-mana .mini-profile-hp-label::before{ content: "Mana: "; }
#hud-layer #mini-profile .mini-stat-row-xp .mini-profile-hp-label::before{ content: "XP: "; }
#hud-layer #mini-profile .mini-profile-hp{ font-size: inherit; font-weight: 800; }

/* CLAIM / Quests column */
#hud-layer .mini-profile-actions{
  display: flex !important;
  flex-direction: column;
  gap: var(--hud-gap);
  pointer-events: auto;
}
#hud-layer .mini-profile-action{
  width: var(--hud-unit);
  height: var(--hud-unit);
  box-sizing: border-box;
  border-radius: var(--hud-radius);
  border: var(--hud-border);
  background: var(--hud-glass);
  box-shadow: var(--hud-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 3px;
  cursor: pointer;
  color: var(--hud-ink);
}
#hud-layer .mini-profile-action[hidden]{ display: none !important; }
#hud-layer .mini-profile-action-icon{
  width: var(--hud-icon);
  height: var(--hud-icon);
  background-image: url("/photos/icons_tilemap.png");
  background-repeat: no-repeat;
  background-size: 1100% 800%;
  image-rendering: auto;
  margin: 0 !important;
}
#hud-layer .mini-profile-action-timer .mini-profile-action-icon{ background-position: 40% 71.4286%; }   /* gift (5,6) */
#hud-layer .mini-profile-action-daily .mini-profile-action-icon{ background-position: 90% 0%; }        /* (10,1) */
#hud-layer .mini-profile-action-events .mini-profile-action-icon{ background-position: 10% 0%; }       /* scroll (2,1) */
#hud-layer .mini-profile-action-label{ font-size: var(--hud-font-sm); font-weight: 900; line-height: 1; text-shadow: 0 1px 0 rgba(0,0,0,0.7); }
#hud-layer .mini-profile-action.is-claim-ready .mini-profile-action-icon{ animation: hudClaimDance 7.5s ease-in-out infinite; transform-origin: 50% 70%; }
@keyframes hudClaimDance{ 0%,78%,100%{ transform: none; } 82%{ transform: rotate(-8deg) scale(1.08); } 86%{ transform: rotate(8deg) scale(1.08); } 90%{ transform: rotate(-5deg); } 94%{ transform: rotate(4deg); } }

/* ===================================================================== */
/* 3. Chat (docked on desktop, overlay on compact/phone)                  */
/* ===================================================================== */
#hud-layer #chat-container{
  width: min(100%, var(--hud-chat-w)) !important;
  min-width: 0 !important;
  max-width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  box-sizing: border-box;
  padding: clamp(6px, 1vmin, 10px) !important;
  gap: clamp(5px, 0.8vmin, 8px) !important;
  border-radius: var(--hud-radius) !important;
  background: var(--hud-glass-strong) !important;
  border: var(--hud-border) !important;
  box-shadow: var(--hud-shadow) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: visible !important;
  /* the chat contributes no intrinsic height to the row: the mini profile
     sets the row height and the chat stretches to exactly that */
  contain: size;
}
#hud-layer #chat-container.chat-collapsed{ display: none !important; }
#hud-layer .cc-chat-head{ display: flex; align-items: center; gap: 6px; padding: 0 2px; }
#hud-layer .cc-chat-tabs{ display: flex; gap: 5px; flex-wrap: nowrap; min-width: 0; }
#hud-layer .cc-chat-tab{
  padding: 0 clamp(8px, 1vmin, 13px) !important;
  height: clamp(22px, 3vmin, 30px);
  border-radius: 999px !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  background: rgba(3, 12, 30, 0.55) !important;
  color: #dbeeff !important;
  font-size: var(--hud-font-sm) !important;
  font-weight: 800 !important;
  white-space: nowrap;
  box-shadow: none !important;
  cursor: pointer;
}
#hud-layer .cc-chat-tab.is-active{
  background: linear-gradient(180deg, #3ea2ff, #1f6fe0) !important;
  border-color: rgba(140, 200, 255, 0.9) !important;
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(31, 111, 224, 0.4) !important;
}
#hud-layer .cc-chat-actions{ margin-left: auto; display: flex; align-items: center; gap: 6px; }
#hud-layer #chat-toggle-button{
  width: clamp(24px, 3.2vmin, 32px) !important;
  min-width: 0 !important;
  height: clamp(24px, 3.2vmin, 32px) !important;
  border-radius: 999px !important;
  padding: 0 !important;
  font-size: 0 !important;
  background: linear-gradient(180deg, #3ea2ff, #1f6fe0) !important;
  border: 1px solid rgba(140, 200, 255, 0.9) !important;
  box-shadow: 0 4px 10px rgba(31, 111, 224, 0.35) !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  color: #fff;
  cursor: pointer;
}
#hud-layer #chat-toggle-button::before{ content: "\2699"; font-size: clamp(13px, 1.9vmin, 17px); line-height: 1; color: #fff; }
#hud-layer #chat-box{
  flex: 1 1 0 !important;
  min-height: 0 !important;
  max-height: none !important;
  border-radius: calc(var(--hud-radius) * 0.7) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  background: rgba(3, 12, 30, 0.62) !important;
  padding: clamp(5px, 0.8vmin, 9px) clamp(7px, 1vmin, 10px) !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 3px !important;
  overflow: auto !important;
  scrollbar-width: thin;
}
/* newest lines sit right above the input; free space (when the box is
   taller than its content) stays at the top instead of under the messages */
#hud-layer #chat-box > :first-child{ margin-top: auto !important; }
#hud-layer #chat-box > div{ font-size: var(--hud-font) !important; line-height: 1.32 !important; color: #f2f8ff !important; overflow-wrap: anywhere !important; }
#hud-layer #chat-box .chat-time{ color: rgba(199, 226, 255, 0.55) !important; font-weight: 700 !important; }
#hud-layer #chat-box .chat-tag{ font-weight: 900 !important; }
#hud-layer #chat-box .chat-tag-system{ color: #2ee66b !important; }
#hud-layer #chat-box .chat-tag-user{ color: #7cd8ff !important; }
#hud-layer #chat-input-bar{ display: flex !important; align-items: center !important; gap: 6px !important; margin: 0 !important; }
#hud-layer #chat-input{
  flex: 1 1 auto !important;
  min-width: 0 !important;
  height: clamp(30px, 4.2vmin, 38px) !important;
  border-radius: 999px !important;
  padding: 0 clamp(9px, 1.4vmin, 14px) !important;
  border: 1px solid rgba(255,255,255,0.10) !important;
  background: rgba(3, 12, 30, 0.62) !important;
  color: #edf7ff !important;
  font: inherit !important;
  font-size: var(--hud-font) !important;
  outline: none !important;
}
#hud-layer #chat-input:focus{ border-color: rgba(120, 190, 255, 0.8) !important; }
#hud-layer .cc-chat-emoji{
  flex: 0 0 auto;
  width: clamp(28px, 4vmin, 36px) !important;
  min-width: 0 !important;
  height: clamp(28px, 4vmin, 36px) !important;
  border-radius: 999px !important;
  padding: 0 !important;
  border: 1px solid rgba(255,255,255,0.10) !important;
  background: rgba(3, 12, 30, 0.62) !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#hud-layer .cc-chat-emoji::before{
  content: "";
  width: 56%; aspect-ratio: 1; border-radius: 50%;
  background:
    radial-gradient(circle at 35% 40%, #0b1c3a 10%, transparent 12%),
    radial-gradient(circle at 65% 40%, #0b1c3a 10%, transparent 12%),
    radial-gradient(circle at 50% 78%, transparent 22%, #0b1c3a 25%, #0b1c3a 32%, transparent 35%),
    #f4f8ff;
}
#hud-layer .cc-chat-emoji:hover,
#hud-layer .cc-chat-emoji.is-open{ border-color: rgba(120, 190, 255, 0.8) !important; background: rgba(18, 44, 88, 0.7) !important; }
#hud-layer #clear-chat-button{
  flex: 0 0 auto;
  width: clamp(36px, 5vmin, 44px) !important;
  min-width: 0 !important;
  height: clamp(30px, 4.2vmin, 38px) !important;
  padding: 0 !important;
  font-size: 0 !important;
  border: 0 !important;
  border-radius: calc(var(--hud-radius) * 0.7) !important;
  background: linear-gradient(180deg, #3a9bff, #1f6fe0) !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#hud-layer #clear-chat-button::before{ content: "\27A4"; font-size: clamp(14px, 2vmin, 18px); line-height: 1; color: #fff; transform: translateX(1px); }
#hud-layer .cc-chat-emoji-picker{
  position: absolute !important;
  left: 8px !important;
  bottom: calc(100% - 56px) !important;
  z-index: 5 !important;
  display: grid !important;
  grid-template-columns: repeat(auto-fill, 30px) !important;
  width: min(280px, 80vw);
  gap: 4px !important;
  padding: 8px !important;
  border-radius: 12px !important;
  background: rgba(6, 18, 40, 0.96) !important;
  border: 1px solid rgba(130, 190, 255, 0.35) !important;
  box-shadow: 0 12px 28px rgba(0,0,0,0.45) !important;
}
#hud-layer .cc-chat-emoji-picker[hidden]{ display: none !important; }
#hud-layer .cc-chat-emoji-item{ width: 30px; height: 30px; border: 0; border-radius: 8px; background: rgba(255,255,255,0.05); font-size: 18px; line-height: 1; cursor: pointer; padding: 0; }
#hud-layer .cc-chat-emoji-item:hover{ background: rgba(62, 162, 255, 0.35); }
/* chat bubble (only used by the compact / phone layouts) */
#hud-layer #chat-fab{
  display: none;
  width: var(--hud-unit);
  height: var(--hud-unit);
  border-radius: 50%;
  border: var(--hud-border);
  background: var(--hud-glass-strong);
  box-shadow: var(--hud-shadow);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  position: relative;
  flex: 0 0 auto;
}
#hud-layer #chat-fab::before{ content: ""; width: 44%; height: 32%; border-radius: 999px; background: #eaf6ff; }
#hud-layer #chat-fab::after{ content: ""; position: absolute; left: 36%; bottom: 24%; border: 5px solid transparent; border-top-color: #eaf6ff; border-left-color: #eaf6ff; }
#hud-layer #chat-fab.has-unread::before{ box-shadow: 0 0 0 2px #ff5d6e; }
body.chat-mobile-open #hud-layer #chat-fab{ background: linear-gradient(180deg, #3ea2ff, #1f6fe0); }

/* ===================================================================== */
/* 4. Top-right actions (buttons + coins)                                  */
/* ===================================================================== */
#hud-layer #hud-actions{
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;       /* two rows when the top row is tight */
  align-items: center !important;
  justify-content: flex-end !important;
  gap: var(--hud-gap) !important;
  width: auto !important;
  padding: 0 !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}
#hud-layer #hud-actions .hud-actions-group{ display: contents !important; }
#hud-layer #coin-display{ order: 0 !important; }
#hud-layer #inventory-button-hud{ order: 1 !important; }
#hud-layer #shop-button-hud{ order: 2 !important; }
#hud-layer #quests-button-hud{ order: 3 !important; }
#hud-layer #friends-button{ order: 4 !important; }
#hud-layer #backToLobbyButton{ order: 5 !important; }
#hud-layer #chat-fab{ order: 6 !important; }

#hud-layer #hud-actions .cc-button:not(#coin-display),
#hud-layer #backToLobbyButton{
  width: var(--hud-unit) !important;
  min-width: 0 !important;
  max-width: none !important;
  height: var(--hud-unit) !important;
  min-height: 0 !important;
  box-sizing: border-box;
  padding: 3px !important;
  border-radius: var(--hud-radius) !important;
  border: var(--hud-border) !important;
  background: var(--hud-glass) !important;
  box-shadow: var(--hud-shadow) !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 2px !important;
  color: var(--hud-ink) !important;
  font: inherit !important;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
#hud-layer #hud-actions .cc-button:not(#coin-display):hover,
#hud-layer #backToLobbyButton:hover{
  border-color: rgba(120, 200, 255, 0.95) !important;
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0) 40%), rgba(18, 44, 88, 0.62) !important;
}
/* sprite: static block sized by the button token, exact 11x8 tile (no px maths) */
#hud-layer .hud-tilemap-icon{
  position: static !important;
  display: block !important;
  width: var(--hud-icon) !important;
  height: var(--hud-icon) !important;
  margin: 0 !important;
  transform: none !important;
  background-size: 1100% 800% !important;
  image-rendering: auto !important;   /* hi-res sheet (125px tiles) shown at ~1/4 - smooth, not nearest */
  flex: 0 0 auto;
}
#hud-layer #backToLobbyButton::after,
#hud-layer #quests-button-hud::after,
#hud-layer #inventory-button-hud::after,
#hud-layer #shop-button-hud::after,
#hud-layer #friends-button .friends-label{
  content: attr(data-label);
  display: block;
  width: 100%;
  text-align: center;
  font-size: var(--hud-font-sm);
  font-weight: 900;
  line-height: 1;
  color: var(--hud-ink);
  text-shadow: 0 1px 0 rgba(0,0,0,0.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#hud-layer #friends-button .friends-count{ display: none !important; }
#hud-layer #hud-actions #coin-display.cc-button{
  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;
  height: var(--hud-unit) !important;
  min-height: 0 !important;
  box-sizing: border-box;
  padding: 0 calc(var(--hud-unit) * 0.12) 0 calc(var(--hud-unit) * 0.18) !important;
  border-radius: var(--hud-radius) !important;
  border: var(--hud-border) !important;
  background: var(--hud-glass) !important;
  box-shadow: var(--hud-shadow) !important;
  display: flex !important;
  align-items: center !important;
  gap: calc(var(--hud-unit) * 0.12) !important;
  cursor: default;
}
#hud-layer #coin-display .coin-atlas-icon{
  width: var(--hud-icon) !important;
  height: var(--hud-icon) !important;
  flex: 0 0 var(--hud-icon) !important;
  background-size: 1100% 800% !important;
  background-position: 30% 0% !important;      /* gold coin (4,1) */
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.45));
}
#hud-layer #coin-display #coin-icon{ display: none !important; }
#hud-layer #coin-display .coin-copy{ display: flex !important; align-items: center; min-width: 0; }
#hud-layer #coin-display #coin-count{
  font-size: clamp(12px, 1.8vmin, 20px) !important;
  font-weight: 900 !important;
  color: #fff !important;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}
#hud-layer #coin-display .coin-plus{
  width: calc(var(--hud-unit) * 0.5) !important;
  height: calc(var(--hud-unit) * 0.5) !important;
  border: 0 !important;
  border-radius: calc(var(--hud-radius) * 0.6) !important;
  background: linear-gradient(180deg, #34d07f, #1fa85f) !important;
  color: #062b16 !important;
  font-size: calc(var(--hud-unit) * 0.34) !important;
  font-weight: 900 !important;
  line-height: 1 !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.35) !important;
}
#hud-layer #coin-display .coin-plus:hover{ filter: brightness(1.08); }

/* ===================================================================== */
/* 5. Minimap                                                              */
/* ===================================================================== */
#hud-layer #mini-map-stack{
  width: var(--hud-map-w) !important;
  display: flex !important;
  flex-direction: column;
  gap: var(--hud-gap);
}
#hud-layer #mini-map-panel{
  width: 100% !important;
  box-sizing: border-box;
  padding: clamp(6px, 1vmin, 12px) !important;
  border-radius: var(--hud-radius) !important;
  border: var(--hud-border) !important;
  background: var(--hud-glass) !important;
  box-shadow: var(--hud-shadow) !important;
  position: static !important;
}
#hud-layer .mini-map-head{ display: flex; align-items: baseline; justify-content: space-between; gap: 6px; min-width: 0; }
#hud-layer .mini-map-title{ font-size: var(--hud-font); font-weight: 800; color: var(--hud-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#hud-layer .mini-map-floor{ font-size: var(--hud-font-sm); font-weight: 800; color: var(--hud-ink-dim); white-space: nowrap; }
#hud-layer .mini-map-view{
  position: relative;
  width: 100% !important;
  aspect-ratio: 5 / 4;
  height: auto !important;
  max-height: none !important;
  margin-top: clamp(4px, 0.8vmin, 8px);
  border-radius: calc(var(--hud-radius) * 0.6);
  overflow: hidden;
  background: rgba(3, 12, 30, 0.45);
  border: 1px solid rgba(255,255,255,0.08);
}
/* map content (cells / markers) - drawn by items.js into .mini-map-view */
#hud-layer .mini-map-grid{ position: absolute; inset: 0; display: grid; gap: 0; pointer-events: none; }
#hud-layer .mini-map-cell{ display: block; position: relative; border-radius: 0; box-shadow: inset 0 1px 0 rgba(255,255,255,0.05), inset 0 -1px 0 rgba(0,0,0,0.14); background-clip: padding-box; image-rendering: pixelated; overflow: hidden; }
#hud-layer .mini-map-cell.is-mini-plant{ box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), inset 0 -1px 0 rgba(0,0,0,0.18), 0 0 0 1px rgba(255,255,255,0.03); filter: saturate(1.08) brightness(1.02); clip-path: polygon(50% 0%, 66% 6%, 82% 18%, 100% 36%, 88% 50%, 100% 64%, 82% 82%, 66% 94%, 50% 100%, 34% 94%, 18% 82%, 0% 64%, 12% 50%, 0% 36%, 18% 18%, 34% 6%); }
#hud-layer .mini-map-cell.is-mini-tree{ filter: saturate(1.1) brightness(1.03); }
#hud-layer .mini-map-cell.is-mini-trunk-crown::before{ content: ""; position: absolute; inset: 28%; border-radius: 50%; background: linear-gradient(180deg, rgba(102, 61, 30, 0.96), rgba(58, 31, 15, 0.98)); box-shadow: inset 0 1px 0 rgba(255,255,255,0.08); pointer-events: none; }
#hud-layer .mini-map-cell.is-mini-block123{ box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), inset 0 -1px 0 rgba(0,0,0,0.18), 0 0 0 1px rgba(255,255,255,0.03); }
#hud-layer .mini-map-cell.is-mini-block123::before{ content: ""; position: absolute; inset: 12%; background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(0,0,0,0.08)), linear-gradient(135deg, transparent 0 36%, rgba(255,255,255,0.16) 36% 44%, transparent 44% 100%), linear-gradient(225deg, transparent 0 36%, rgba(255,255,255,0.16) 36% 44%, transparent 44% 100%); pointer-events: none; }
#hud-layer .mini-map-cell.is-mini-water{ box-shadow: inset 0 1px 0 rgba(255,255,255,0.14), inset 0 -1px 0 rgba(0,0,0,0.12), 0 0 0 1px rgba(255,255,255,0.04); }
#hud-layer .mini-map-cell.is-mini-soil{ box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), inset 0 -1px 0 rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04); }
#hud-layer .mini-map-cell.is-mini-soil-top{ box-shadow: inset 0 1px 0 rgba(255,255,255,0.16), inset 0 -1px 0 rgba(0,0,0,0.18), 0 0 0 1px rgba(255,255,255,0.03); }
#hud-layer .mini-map-cell.is-mini-stone{ border-radius: 6%; box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), inset 0 -1px 0 rgba(0,0,0,0.2), 0 0 0 1px rgba(255,255,255,0.04); }
#hud-layer .mini-map-marker{ position: absolute; width: 6px; height: 6px; border-radius: 50%; left: 50%; top: 50%; transform: translate(-50%, -50%); background: #fff; border: 1px solid rgba(34, 199, 255, 0.95); box-shadow: 0 0 0 2px rgba(34, 199, 255, 0.18), 0 0 8px rgba(34, 199, 255, 0.4); pointer-events: none; }
#hud-layer .mini-map-monsters,
#hud-layer .mini-map-npcs{ position: absolute; inset: 0; pointer-events: none; }
#hud-layer .mini-map-monster-dot{ position: absolute; width: 5px; height: 5px; border-radius: 50%; transform: translate(-50%, -50%); background: #ff3b30; border: 1px solid rgba(255, 255, 255, 0.85); box-shadow: 0 0 4px rgba(255, 59, 48, 0.85); pointer-events: none; }
#hud-layer .mini-map-npc-dot{ position: absolute; width: 7px; height: 7px; border-radius: 2px; transform: translate(-50%, -50%) rotate(45deg); background: #ffd60a; border: 1px solid rgba(255, 255, 255, 0.9); box-shadow: 0 0 5px rgba(255, 214, 10, 0.9); pointer-events: none; }
#hud-layer .mini-map-meta{ display: flex; justify-content: space-between; gap: 6px; margin-top: clamp(4px, 0.8vmin, 8px); font-size: var(--hud-font-sm); font-weight: 800; color: var(--hud-ink-dim); white-space: nowrap; }
#hud-layer #monster-kill-feed{ font-size: var(--hud-font-sm); }

/* ===================================================================== */
/* 6. Bottom hotbar                                                        */
/* ===================================================================== */
#hud-layer #gameplay-quick-panel{
  width: 100% !important;
  max-width: 100% !important;
  container-type: inline-size;       /* hotbar slots size against this box */
  box-sizing: border-box;
  padding: clamp(4px, 0.7vmin, 8px) clamp(6px, 0.9vmin, 10px) !important;
  border-radius: var(--hud-radius) !important;
  border: var(--hud-border) !important;
  background: var(--hud-glass) !important;
  box-shadow: var(--hud-shadow) !important;
  display: block !important;
  overflow: hidden !important;
  flex: none !important;
}
#hud-layer #gameplay-quick-panel::before{ display: none !important; }
#hud-layer #gameplay-history{ display: block !important; }
#hud-layer .pi-hotbar-wrap{
  /* 13 slots + section gaps must fit the panel: the slot shrinks with the
     panel width (container units) and never below the usable minimum */
  --hud-slot-fit: clamp(34px, calc((100cqw - 118px) / 13), var(--hud-slot));
  --pi-hotbar-slot-size: var(--hud-slot-fit);
  --pi-hotbar-slot-gap: clamp(3px, 0.5vmin, 7px);
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: safe center;        /* centred, but never clipped on the left */
  gap: clamp(6px, 0.9vmin, 12px) !important;
  width: auto !important;
  max-width: 100%;
  overflow-x: auto !important;         /* fallback when the row is wider than its cell */
  overflow-y: hidden !important;
  scrollbar-width: none;
}
#hud-layer .pi-hotbar-wrap::-webkit-scrollbar{ display: none; }
#hud-layer .pi-hotbar-section{ width: auto !important; flex: 0 0 auto !important; overflow: visible !important; padding: 0 !important; border: 0 !important; }
#hud-layer .pi-hotbar-section-smart,
#hud-layer .pi-hotbar-section-skills{ border-left: 1px solid rgba(255,255,255,0.12) !important; padding-left: clamp(6px, 0.9vmin, 12px) !important; }
#hud-layer .pi-hotbar-section-title{ display: none !important; }
#hud-layer .pi-hotbar-grid{ display: flex !important; flex-wrap: nowrap !important; gap: var(--pi-hotbar-slot-gap) !important; width: auto !important; }
#hud-layer .pi-hotbar-slot{
  position: relative;
  flex: 0 0 var(--hud-slot-fit);
  width: var(--hud-slot-fit) !important;
  height: var(--hud-slot-fit) !important;
  box-sizing: border-box;
  border-radius: calc(var(--hud-radius) * 0.75) !important;
  border: 1px solid var(--inv-rarity-color, rgba(130, 190, 255, 0.34)) !important;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0) 50%), rgba(6, 16, 36, 0.55) !important;
  box-shadow: 0 6px 14px rgba(0,0,0,0.26), inset 0 1px 0 rgba(255,255,255,0.06) !important;
  padding: 0 !important;
  overflow: hidden;
  cursor: pointer;
  color: #f4fbff;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
}
#hud-layer .pi-hotbar-slot.is-empty{ background: rgba(6, 16, 36, 0.35) !important; opacity: 0.9; }
#hud-layer .pi-hotbar-slot.is-skill{ border-color: rgba(120, 200, 255, 0.28) !important; }
#hud-layer .pi-hotbar-slot:hover{ transform: translateY(-1px); }
#hud-layer .pi-hotbar-slot.is-active{
  border-color: #4fb3ff !important;
  box-shadow: 0 0 0 2px rgba(79, 179, 255, 0.55) inset, 0 0 18px rgba(79, 179, 255, 0.45), 0 6px 14px rgba(0,0,0,0.32) !important;
}
#hud-layer .pi-hotbar-slot-icon-wrap{ position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#hud-layer .pi-hotbar-slot.is-skill .pi-hotbar-slot-icon-wrap{ padding: 12%; }
#hud-layer .pi-hotbar-slot-icon{ width: 100% !important; height: 100% !important; object-fit: fill; image-rendering: pixelated; display: block; }
#hud-layer .pi-hotbar-slot.is-skill .pi-hotbar-slot-icon{ border-radius: 20%; }
#hud-layer .pi-hotbar-slot-empty{ width: 100%; height: 100%; border-radius: inherit; border: 1px dashed rgba(173, 237, 255, 0.22); opacity: 0.45; box-sizing: border-box; }
#hud-layer .pi-hotbar-slot-num,
#hud-layer .pi-hotbar-slot-qty{
  position: absolute;
  z-index: 2;
  padding: 0 2px;
  font-size: clamp(9px, calc(var(--hud-slot-fit) * 0.2), 12px);
  font-weight: 900;
  line-height: 1;
  color: #f6fbff;
  text-shadow: 0 1px 0 rgba(0,0,0,0.9), 0 0 4px rgba(0,0,0,0.85), 0 0 8px rgba(0,0,0,0.6);
  background: none;
  border: 0;
}
#hud-layer .pi-hotbar-slot-num{ top: 8%; left: 10%; }
#hud-layer .pi-hotbar-slot-num:empty{ display: none; }
#hud-layer .pi-hotbar-slot-qty{ right: 10%; bottom: 8%; }
#hud-layer .pi-hotbar-slot-qty.is-blank{ display: none; }
#hud-layer .pi-hotbar-slot-label{ display: none; }

/* ===================================================================== */
/* 7. Touch controls + zoom                                                */
/* ===================================================================== */
#hud-layer #touch-left,
#hud-layer #touch-right,
#hud-layer #touch-zoom{
  display: flex !important;        /* items.js toggles an inline display:block/none */
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center;
  gap: var(--hud-gap);
  pointer-events: auto;
}
#hud-layer #touch-left[style*="display: none"],
#hud-layer #touch-right[style*="display: none"]{ display: none !important; }
#hud-layer #touch-zoom{ flex-direction: row; }
#hud-layer #touch-left button,
#hud-layer #touch-right button{
  width: var(--hud-touch-hit) !important;
  height: var(--hud-touch-hit) !important;
  min-width: var(--hud-touch-hit) !important;
  min-height: var(--hud-touch-hit) !important;
  box-sizing: border-box;
  border-radius: 50% !important;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  color: #f4fbff !important;
  padding: 0 !important;
  display: grid !important;
  place-items: center !important;
  position: relative;
  overflow: visible;
  transform: none !important;
  font-size: 0 !important;
  cursor: pointer;
}
#hud-layer #touch-left button::before,
#hud-layer #touch-right button::before{
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--hud-touch-visual);
  height: var(--hud-touch-visual);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: var(--hud-border);
  background: var(--hud-glass);
  box-shadow: var(--hud-shadow);
  box-sizing: border-box;
  pointer-events: none;
}
#hud-layer #touch-left button .hud-tilemap-icon,
#hud-layer #touch-right button .hud-tilemap-icon{
  position: relative;
  z-index: 1;
  width: calc(var(--hud-touch-visual) * 0.6) !important;
  height: calc(var(--hud-touch-visual) * 0.6) !important;
}
#hud-layer #touch-left button:active,
#hud-layer #touch-right button:active,
#hud-layer #touch-left button.is-pressed,
#hud-layer #touch-right button.is-pressed{ background: transparent !important; }
#hud-layer #touch-left button:active::before,
#hud-layer #touch-right button:active::before,
#hud-layer #touch-left button.is-pressed::before,
#hud-layer #touch-right button.is-pressed::before{
  background: linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0) 40%), rgba(18, 44, 88, 0.82);
}
#hud-layer #touch-zoom button{
  width: calc(var(--hud-unit) * 0.7) !important;
  height: calc(var(--hud-unit) * 0.7) !important;
  min-width: 0 !important;
  min-height: 0 !important;
  border-radius: 50% !important;
  border: var(--hud-border) !important;
  background: var(--hud-glass) !important;
  box-shadow: var(--hud-shadow) !important;
  color: #f4fbff !important;
  font-size: calc(var(--hud-unit) * 0.3) !important;
  font-weight: 900;
  line-height: 1;
  padding: 0 !important;
  transform: none !important;
}

/* ===================================================================== */
/* 8. Ping / FPS                                                           */
/* ===================================================================== */
#hud-layer #hud-net{ display: flex !important; gap: 6px; pointer-events: none; }
#hud-layer .hud-net-chip{
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: clamp(18px, 2.6vmin, 24px);
  padding: 0 clamp(6px, 1vmin, 9px);
  border-radius: 8px;
  background: var(--hud-glass);
  border: var(--hud-border);
  color: #dff3ff;
  font: 700 var(--hud-font-sm)/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#hud-layer .hud-net-ping::before{ content: ""; width: 8px; height: 8px; border-radius: 50%; background: #f5b400; box-shadow: 0 0 6px currentColor; }
#hud-layer .hud-net-ping[data-level="good"]::before{ background: #2ee66b; }
#hud-layer .hud-net-ping[data-level="bad"]::before{ background: #ff4d4d; }
#hud-layer .hud-net-fps{ color: #7fe3a1; }

/* ===================================================================== */
/* 9. Quest toast - anchored above the hotbar, centred, no JS coordinates  */
/* ===================================================================== */
#quest-complete-toast{
  position: fixed !important;
  left: 50% !important;
  right: auto !important;
  bottom: calc(var(--hud-pad-b) + var(--hud-slot) + clamp(24px, 4vmin, 44px)) !important;
  transform: translateX(-50%) !important;
  width: min(88vw, 320px) !important;
}

/* ===================================================================== */
/* 10. Breakpoints - structural only                                       */
/* ===================================================================== */

/* ---- compact: 640-1023px. Chat becomes a bubble + overlay; actions strip
        is icon-only; profile narrower. Applies to portrait tablets and
        landscape phones alike (width decides, not orientation). ---- */
@media (max-width: 1023px){
  :root{
    --hud-profile-w: clamp(200px, 30vw, 300px);
    --hud-map-w: clamp(150px, 20vw, 200px);
    --hud-right-max: calc(100vw - var(--hud-pad-l) - var(--hud-pad-r) - var(--hud-profile-w) - var(--hud-gap));
  }
  #hud-layer .hud-row-top{
    grid-template-areas:
      "profile . right"
      "quick   . right";
  }
  #hud-layer #chat-fab{ display: inline-flex; }
  #hud-layer #hud-actions .cc-button,
  #hud-layer #backToLobbyButton{ width: var(--hud-unit) !important; height: var(--hud-unit) !important; }
  #hud-layer #backToLobbyButton::after,
  #hud-layer #quests-button-hud::after,
  #hud-layer #inventory-button-hud::after,
  #hud-layer #shop-button-hud::after,
  #hud-layer #friends-button .friends-label{ display: none; }
  #hud-layer .hud-tilemap-icon{ width: calc(var(--hud-unit) * 0.58) !important; height: calc(var(--hud-unit) * 0.58) !important; }
  /* chat overlay (intentional overlay - excluded from the collision sweep) */
  #hud-layer #chat-container{
    display: none !important;
    position: fixed !important;
    left: var(--hud-pad-l) !important;
    right: calc(var(--hud-pad-r) + var(--hud-unit) + var(--hud-gap)) !important;
    top: calc(var(--hud-pad-t) + var(--hud-unit) + var(--hud-gap)) !important;
    width: auto !important;
    height: min(50vh, 380px) !important;
    z-index: 3300;
  }
  body.chat-mobile-open #hud-layer #chat-container{ display: flex !important; }
  /* the hotbar takes a full-width row of its own; with on-screen controls
     enabled they sit above it instead of squeezing it */
  #hud-layer .hud-row-bottom{
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "net    .      zoom"
      "touchL .      touchR"
      "hotbar hotbar hotbar";
  }
  #hud-layer #gameplay-quick-panel{ justify-self: stretch; }
}

/* ---- phone: < 640px. Right-edge column of buttons under the minimap,
        full-width single-row hotbar. ---- */
@media (max-width: 639px){
  :root{
    --hud-profile-w: minmax(0, 1fr);
    --hud-right-max: none;
    --hud-map-w: clamp(124px, 34vw, 160px);
    --hud-unit: clamp(42px, 11vw, 52px);
    --hud-touch-visual: clamp(64px, 16vw, 76px);
    --hud-touch-hit: clamp(78px, 20vw, 90px);
    --hud-avatar: clamp(44px, 12vw, 60px);
    --hud-bar-h: clamp(16px, 4.4vw, 20px);
    --hud-bar-font: clamp(10px, 2.8vw, 12px);
  }
  #hud-layer .hud-row-top{
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto 1fr;        /* quick actions sit right under the profile */
    grid-template-areas:
      "profile right"
      "quick   right";
  }
  #hud-layer #hud-right{ flex-direction: column; }
  #hud-layer #mini-map-stack{ order: 0; }
  #hud-layer #hud-actions{ order: 1; }
  #hud-layer #mini-profile{ width: 100%; }
  /* two-column button block under the minimap (a single column is taller
     than short phones) - the coin pill takes the full block width */
  #hud-layer #hud-actions{
    display: grid !important;
    width: var(--hud-map-w);                 /* same width as the minimap above it */
    grid-template-columns: repeat(2, minmax(var(--hud-unit), 1fr));
    justify-items: end;
    gap: var(--hud-gap) !important;
  }
  #hud-layer #backToLobbyButton{ order: 0 !important; }
  #hud-layer #inventory-button-hud{ order: 1 !important; }
  #hud-layer #shop-button-hud{ order: 2 !important; }
  #hud-layer #quests-button-hud{ order: 3 !important; }
  #hud-layer #friends-button{ order: 4 !important; }
  #hud-layer #chat-fab{ order: 5 !important; }
  #hud-layer #coin-display{ order: 6 !important; grid-column: 1 / -1; justify-self: stretch; width: 100% !important; height: calc(var(--hud-unit) * 0.72) !important; max-width: none !important; }
  #hud-layer #coin-display #coin-count{ font-size: clamp(11px, 2.8vw, 12.5px) !important; }
  #hud-layer #gameplay-quick-panel{ border-radius: var(--hud-radius) var(--hud-radius) 0 0 !important; }
  /* two rows: favourites + smart slots, then the skill slots */
  #hud-layer .pi-hotbar-wrap{
    --hud-slot-fit: clamp(34px, calc((100cqw - 64px) / 8), var(--hud-slot));
    flex-wrap: wrap !important;
    justify-content: center;
    row-gap: clamp(4px, 1vw, 8px) !important;
  }
  #hud-layer .pi-hotbar-section-skills{ border-left: 0 !important; padding-left: 0 !important; }
  #hud-layer #chat-container{
    right: calc(var(--hud-pad-r) + var(--hud-unit) + var(--hud-gap)) !important;
    top: calc(var(--hud-pad-t) + var(--hud-avatar) + 3 * var(--hud-bar-h) + 40px) !important;
    height: min(46vh, 340px) !important;
  }
}

/* ---- short: landscape phones (height < 480px, width >= 640px). Not a
        layout of its own - a height modifier on top of compact/desktop:
        smaller vitals, quick actions beside the profile, the hotbar back
        between the touch clusters so everything fits vertically. ---- */
@media (max-height: 479px) and (min-width: 640px){
  :root{
    --hud-avatar: 40px;
    --hud-bar-h: 14px;
    --hud-bar-font: 10px;
    --hud-map-w: 112px;
    --hud-touch-visual: clamp(64px, 18vh, 72px);
    --hud-touch-hit: clamp(78px, 22vh, 88px);
    --hud-unit: 44px;
    --hud-slot: 40px;
  }
  #hud-layer .hud-row-top{
    grid-template-columns: var(--hud-profile-w) auto minmax(0, 1fr) auto;
    grid-template-rows: auto;
    grid-template-areas: "profile quick chat right";
  }
  #hud-layer .mini-profile-actions{ flex-direction: row; align-self: start; }
  #hud-layer .hud-row-bottom{
    grid-template-rows: auto auto;
    grid-template-areas:
      "net    hotbar zoom"
      "touchL hotbar touchR";
  }
  #hud-layer #gameplay-quick-panel{ justify-self: center; border-radius: var(--hud-radius) !important; }
  /* one row when it fits, otherwise favourites+smart / skills on two rows
     (never a horizontal scroll on a phone) */
  #hud-layer .pi-hotbar-wrap{
    --hud-slot-fit: clamp(34px, calc((100cqw - 118px) / 13), var(--hud-slot));
    flex-wrap: wrap !important;
    justify-content: center;
    row-gap: 4px !important;
  }
  #hud-layer .pi-hotbar-section-skills{ border-left: 1px solid rgba(255,255,255,0.12) !important; padding-left: clamp(6px, 0.9vmin, 12px) !important; }
  #hud-layer #chat-container{ height: min(60vh, 300px) !important; }
}

@media (prefers-reduced-motion: reduce){
  #hud-layer .mini-profile-action.is-claim-ready .mini-profile-action-icon{ animation: none; }
}
