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

body {
  background: #1a1a2e;
  color: #eee;
  font-family: 'Segoe UI', sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.hidden { display: none !important; }
.error-msg { color: #e94560; font-size: 13px; min-height: 18px; }

/* ---- WELCOME ---- */
#welcome {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  z-index: 100;
  gap: 20px;
  overflow-y: auto;
  padding: 24px 0;
}
#siteLogo {
  max-width: min(260px, 60vw);
  max-height: 100px;
  object-fit: contain;
  image-rendering: auto;
  border-radius: 8px;
}
.welcome-box {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 16px;
  padding: 40px;
  width: min(520px, 94vw);
  display: flex; flex-direction: column; gap: 16px;
  backdrop-filter: blur(10px);
}
.welcome-box h1 { font-size: 2.2rem; text-align: center; }
.welcome-box h1 span { color: #e94560; }
.welcome-sub { text-align: center; color: #aaa; font-size: 14px; }

#playerName {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  width: 100%;
}
#playerName:focus { border-color: #e94560; }

#charGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
  max-height: 280px;
  overflow-y: auto;
}
.char-card {
  background: rgba(255,255,255,0.06);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 10px 6px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.char-card:hover { border-color: rgba(233,69,96,0.5); background: rgba(255,255,255,0.1); }
.char-card.selected { border-color: #e94560; background: rgba(233,69,96,0.15); }
.char-preview {
  width: 64px; height: 64px;
  image-rendering: pixelated;
  object-fit: none;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  position: relative;
}
.char-preview canvas { image-rendering: pixelated; }
.char-name { font-size: 12px; text-align: center; color: #ccc; }

/* ---- AGE GATE ---- */
.age-gate-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: #ccc; cursor: pointer;
  user-select: none;
}
.age-gate-row input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: #e94560; cursor: pointer; flex-shrink: 0;
}
.terms-link-row {
  font-size: 13px; text-align: center;
}
.terms-link-row a {
  color: #e94560; text-decoration: none;
}
.terms-link-row a:hover { text-decoration: underline; }

#btnJoin {
  background: #e94560;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.15s;
}
#btnJoin:disabled { opacity: 0.4; cursor: not-allowed; }
#btnJoin:not(:disabled):hover { opacity: 0.85; }

/* ---- GAME ---- */
#gameWrap {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  /* needed for gif overlay positioning */
  overflow: hidden;
}
#gameCanvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  z-index: 2;
  background: transparent;
}

/* ---- CHAT BAR ---- */
#chatBar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  width: min(500px, 90vw);
  z-index: 20;
}
#chatInput {
  flex: 1;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  padding: 8px 12px;
  outline: none;
  backdrop-filter: blur(4px);
}
#chatInput:focus { border-color: #e94560; }
#chatBar button {
  background: #e94560;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14px;
}

/* ---- PRIVATE DOCK (slides down from top-right) ---- */
#privateDock {
  position: fixed;
  top: 0; right: 12px;
  width: 300px;
  background: rgba(15,20,40,0.97);
  border: 1px solid rgba(255,255,255,0.15);
  border-top: none;
  border-radius: 0 0 12px 12px;
  z-index: 30;
  backdrop-filter: blur(10px);
}
#privateDockHeader {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
#pmTabs { flex: 1; display: flex; gap: 4px; overflow-x: auto; }
.pm-tab {
  background: rgba(255,255,255,0.1);
  border: none; border-radius: 4px;
  color: #ccc; font-size: 11px;
  padding: 2px 7px;
  cursor: pointer;
  white-space: nowrap;
}
.pm-tab.active { background: #e94560; color: #fff; }
#btnPrivateDock {
  background: none; border: none; color: #ccc;
  cursor: pointer; font-size: 14px; padding: 0 4px;
}
/* Body: hidden by default, slides open via dock-open class */
#privateDockBody {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  padding: 0 8px;
  display: flex; flex-direction: column; gap: 6px;
}
#privateDock.dock-open #privateDockBody {
  max-height: 320px;
  padding: 8px;
}
#pmLog {
  height: 150px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px;
  color: #ccc;
}
.pm-msg { padding: 3px 6px; border-radius: 4px; }
.pm-msg.from-me { background: rgba(233,69,96,0.2); align-self: flex-end; }
.pm-msg.from-other { background: rgba(255,255,255,0.07); align-self: flex-start; }
#pmInputRow { display: flex; gap: 4px; align-items: center; }
#pmTo {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px; color: #fff;
  font-size: 12px; padding: 4px 6px;
  width: 80px;
}
#pmInput {
  flex: 1;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px; color: #fff;
  font-size: 12px; padding: 4px 8px;
  outline: none;
}
#pmInput:focus { border-color: #e94560; }
#pmInputRow button {
  background: #e94560; color: #fff;
  border: none; border-radius: 6px;
  padding: 4px 8px; font-size: 12px; cursor: pointer;
}

/* notification dot */
#privateDockHeader .notif {
  width: 8px; height: 8px;
  background: #e94560;
  border-radius: 50%;
  display: inline-block;
  margin-left: 2px;
}

/* ---- MOBILE CONTROLS ---- */
#mobileControls {
  display: none;
  position: fixed;
  bottom: 10px; left: 0; right: 0;
  padding: 0 16px;
  pointer-events: none;
  z-index: 25;
  justify-content: space-between;
  align-items: flex-end;
}
@media (pointer: coarse) {
  #mobileControls { display: flex; }
  #chatBar { bottom: 100px; }
  /* On touch devices the chatbar buttons move into mobileControls */
  #emoteBtn, #statusBtn { display: none; }
}
#dpad { display: flex; gap: 8px; pointer-events: all; }
#actionBtns { display: flex; gap: 8px; pointer-events: all; }
.dpad-btn, .action-btn {
  width: 56px; height: 56px;
  background: rgba(0,0,0,0.5);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  color: #fff; font-size: 18px;
  cursor: pointer;
  user-select: none;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-tap-highlight-color: transparent;
}
.dpad-btn:active, .action-btn:active {
  background: rgba(233,69,96,0.5);
  border-color: #e94560;
}
#btnJump { background: rgba(233,69,96,0.4); border-color: #e94560; }

/* ---- PORTRAIT MOBILE: full layout overhaul ---- */
@media (pointer: coarse) and (orientation: portrait) {

  /* Game area: top 88vh */
  #gameWrap { bottom: 12vh; }

  /* ── Control bar: dpad + action buttons ONLY ── */
  #mobileControls {
    bottom: 0;
    height: 12vh;
    min-height: 54px;
    background: rgba(10, 14, 28, 0.97);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 0 14px;
    align-items: center;
    pointer-events: all;
    justify-content: space-between;
  }
  .dpad-btn, .action-btn {
    width: 50px; height: 50px;
    font-size: 17px;
  }
  /* emote/status now have dedicated spots — hide them from controls */
  #mobileEmoteBtn, #mobileStatusBtn { display: none; }

  /* ── Chat bar: hidden by default on portrait mobile, shown via chat-active ── */
  #chatBar {
    display: none;
    position: fixed;
    bottom: calc(12vh + 8px);
    left: 10px;
    right: 62px;       /* gap for emote button */
    top: auto;
    height: auto;
    min-height: 0;
    width: auto;
    transform: none;
    background: transparent;
    gap: 6px;
    align-items: center;
    z-index: 26;
  }
  #chatBar.chat-active {
    display: flex;
  }
  #chatInput {
    font-size: 14px;
    padding: 10px 12px;
    min-width: 0;
    flex: 1;
  }
  #btnSend {
    display: flex;
    padding: 10px 12px;
    font-size: 15px;
  }

  /* ── Emote button: bottom-right of game area, same row as chat ── */
  #emoteBtn {
    display: flex !important;  /* override coarse-pointer hide */
    position: fixed;
    bottom: calc(12vh + 8px);
    right: 10px;
    left: auto;
    top: auto;
    width: 44px;
    height: 44px;
    font-size: 22px;
    border-radius: 50%;
  }

  /* ── Status button: top-right, just below private chat dock ── */
  #statusBtn {
    display: flex !important;
    position: fixed;
    top: 40px;
    right: 10px;
    bottom: auto;
    left: auto;
    width: 34px;
    height: 34px;
    font-size: 15px;
    border-radius: 50%;
  }

  /* ── Emote bar: flies UP from emote button (bottom-right) ── */
  #emoteBar {
    bottom: calc(12vh + 62px);
    left: auto;
    right: 10px;
    transform: translateY(14px);   /* no X-centering needed */
    max-width: min(280px, 80vw);
  }
  #emoteBar.open { transform: translateY(0); }

  /* ── Status menu: flies DOWN from status button (top-right) ── */
  #statusMenu {
    top: 80px;
    bottom: auto;
    left: auto;
    right: 10px;
    transform: translateX(0) translateY(-10px);  /* opens downward */
    min-width: 170px;
  }
  #statusMenu.open { transform: translateX(0) translateY(0); }

  /* ── Chat log: just above chat input ── */
  #chatLog {
    bottom: calc(12vh + 62px) !important;
    left: 10px !important;
    right: 62px !important;
    width: auto !important;
    transform: none !important;
  }
  #chatLogToggle {
    bottom: calc(12vh + 62px) !important;
    left: 10px !important;
    right: auto !important;
    transform: none !important;
  }

  /* ── Private dock: full width at top ── */
  #privateDock {
    right: 0; left: 0;
    width: 100%;
    border-radius: 0 0 12px 12px;
  }
  #pmLog { height: 120px; }
}

/* ---- WORLD SELECT ---- */
#worldSelect {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  z-index: 90;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.world-select-wrap { width: min(860px, 100%); }
.world-select-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 24px;
}
.world-select-header h2 { font-size: 1.6rem; }
#btnBackToWelcome {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; color: #ccc;
  padding: 8px 14px; cursor: pointer; font-size: 14px;
}
#btnBackToWelcome:hover { background: rgba(255,255,255,0.14); }
#worldGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.world-card {
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.world-card:hover { border-color: #e94560; transform: translateY(-2px); }
.world-thumb {
  width: 100%; aspect-ratio: 16/7;
  object-fit: cover; object-position: left center;
  display: block;
  background: #0f3460;
}
.world-thumb-placeholder {
  width: 100%; aspect-ratio: 16/7;
  background: linear-gradient(135deg, #0f3460, #1a1a2e);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: rgba(255,255,255,0.2);
}
.world-info { padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; }
.world-name { font-size: 15px; font-weight: 600; }
.world-count { font-size: 12px; color: #aaa; background: rgba(255,255,255,0.08); border-radius: 10px; padding: 2px 8px; }
.world-count.has-players { color: #4caf50; background: rgba(76,175,80,0.15); }
.world-empty { color: #666; text-align: center; padding: 40px; grid-column: 1/-1; }

/* ---- EMOTE + STATUS BUTTONS (in chatBar) ---- */
#emoteBtn, #statusBtn {
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 18px;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: border-color 0.15s, background 0.15s;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
#emoteBtn:hover, #statusBtn:hover { background: rgba(233,69,96,0.3); border-color: #e94560; }
#emoteBtn.active { background: rgba(233,69,96,0.4); border-color: #e94560; }
#statusBtn.has-status { border-color: rgba(255,255,255,0.55); background: rgba(255,255,255,0.08); }

/* ---- EMOTE BAR (slides up) ---- */
#emoteBar {
  position: fixed;
  bottom: 68px;
  left: 50%;
  transform: translateX(-50%) translateY(14px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.18s ease;
  background: rgba(15,20,40,0.97);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  padding: 10px 10px 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: min(360px, 88vw);
  justify-content: center;
  z-index: 40;
  backdrop-filter: blur(14px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
}
#emoteBar.open {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}
.emote-pick-btn {
  width: 46px;
  height: 46px;
  background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, border-color 0.1s, transform 0.12s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}
.emote-pick-btn:hover { background: rgba(233,69,96,0.3); border-color: #e94560; transform: scale(1.18); }
.emote-pick-btn:active { transform: scale(0.96); }
.emote-pick-btn img { width: 28px; height: 28px; image-rendering: pixelated; object-fit: contain; }

/* ---- STATUS MENU (slides up) ---- */
#statusMenu {
  position: fixed;
  bottom: 68px;
  left: 50%;
  transform: translateX(calc(-50% + min(115px, 20vw))) translateY(14px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), opacity 0.18s ease;
  background: rgba(15,20,40,0.97);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 190px;
  z-index: 40;
  backdrop-filter: blur(14px);
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
}
#statusMenu.open {
  transform: translateX(calc(-50% + min(115px, 20vw))) translateY(0);
  opacity: 1;
  pointer-events: all;
}
.status-pick-btn {
  background: rgba(255,255,255,0.06);
  border: 1.5px solid transparent;
  border-radius: 8px;
  color: #ddd;
  font-size: 13px;
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s, border-color 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.status-pick-btn:hover { background: rgba(255,255,255,0.13); }
.status-pick-btn.active { font-weight: 600; color: #fff; background: rgba(255,255,255,0.1); }
.status-pick-btn .s-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.status-pick-btn.clear-btn {
  color: #777;
  border-top: 1px solid rgba(255,255,255,0.08);
  margin-top: 3px;
  border-radius: 0 0 8px 8px;
}
.status-pick-btn.clear-btn:hover { color: #e94560; background: rgba(233,69,96,0.1); }

/* ---- LANDSCAPE MOBILE: raise panels above control bar ---- */
@media (pointer: coarse) and (orientation: landscape) {
  #emoteBar   { bottom: calc(66px + 80px); }
  #statusMenu { bottom: calc(66px + 80px); }
}

/* ---- On mobile (touch) align top-left icons with status button (top: 40px) ---- */
@media (pointer: coarse) {
  #peopleBtn, #muteBtn, #btnChangeWorld, #backpackBtn {
    top: 40px;
  }
}

/* ---- MUTE BUTTON ---- */
#muteBtn {
  position: fixed;
  top: 10px; left: 52px;
  width: 36px; height: 36px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  z-index: 22;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  padding: 0;
  transition: border-color 0.15s, background 0.15s;
}
#muteBtn.muted { background: rgba(233,69,96,0.35); border-color: #e94560; }
#muteBtn:hover { border-color: #e94560; }

/* ---- PEOPLE BUTTON ---- */
#peopleBtn {
  position: fixed;
  top: 10px; left: 10px;
  width: 36px; height: 36px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  z-index: 22;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  padding: 0;
  transition: border-color 0.15s, background 0.15s;
}
#peopleBtn:hover { border-color: #e94560; background: rgba(233,69,96,0.3); }
#peopleBadge {
  position: absolute;
  top: -4px; right: -4px;
  background: #e94560;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 8px;
  padding: 1px 4px;
  line-height: 1.4;
  min-width: 14px;
  text-align: center;
  display: none;
  pointer-events: none;
}

/* ---- CHANGE WORLD BUTTON ---- */
#btnChangeWorld {
  position: fixed;
  top: 10px; left: 94px;
  width: 36px; height: 36px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  z-index: 22;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
  padding: 0;
  transition: border-color 0.15s, background 0.15s;
}
#btnChangeWorld:hover { border-color: #e94560; background: rgba(233,69,96,0.3); }

/* ---- PEOPLE PANEL ---- */
#peoplePanel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 60;
  display: flex; align-items: flex-start; justify-content: flex-start;
}
#peoplePanelInner {
  background: rgba(12,16,32,0.98);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 0 0 12px 0;
  width: min(300px, 90vw);
  max-height: 90vh;
  display: flex; flex-direction: column;
  backdrop-filter: blur(12px);
  overflow: hidden;
}
#peoplePanelHeader {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-weight: 600;
  font-size: 14px;
}
#peoplePanelClose {
  background: none; border: none; color: #aaa; cursor: pointer; font-size: 16px; padding: 0;
}
#peoplePanelClose:hover { color: #e94560; }
#peoplePanelList {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.people-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: 7px;
  background: rgba(255,255,255,0.04);
  font-size: 13px;
}
.people-item .people-name { flex: 1; color: #e0e0e0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people-item .people-world { font-size: 11px; color: #888; }
.people-item .people-invite-btn {
  background: #e94560; border: none; border-radius: 5px;
  color: #fff; font-size: 11px; padding: 3px 8px; cursor: pointer;
  white-space: nowrap; flex-shrink: 0;
}
.people-item .people-invite-btn:hover { opacity: 0.85; }
.people-item .people-invite-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.people-section-header {
  font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px;
  padding: 6px 8px 3px;
}

/* ---- PRIVATE ROOM BAR ---- */
#privateRoomBar {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: rgba(10,14,28,0.95);
  border-bottom: 1px solid rgba(233,69,96,0.4);
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  z-index: 22;
  backdrop-filter: blur(8px);
  font-size: 13px;
}
#privateRoomName { flex: 1; color: #f9c74f; font-weight: 600; }
#privateRoomBar button {
  background: #e94560; border: none; border-radius: 6px;
  color: #fff; font-size: 12px; padding: 4px 10px; cursor: pointer;
}
#btnLeaveRoom { background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); }
#btnLeaveRoom:hover { background: rgba(233,69,96,0.4); border-color: #e94560; }

/* ---- INVITE SEND MODAL ---- */
#inviteModal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 70;
  display: flex; align-items: center; justify-content: center;
}
#inviteModalInner {
  background: rgba(12,16,32,0.98);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 14px;
  padding: 22px 24px;
  width: min(360px, 92vw);
  display: flex; flex-direction: column; gap: 14px;
  backdrop-filter: blur(12px);
}
#inviteModalInner h3 { font-size: 16px; }
.invite-row { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #bbb; }
.invite-row strong { color: #fff; }
.invite-row select,
.invite-row input[type=text] {
  margin-top: 4px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 7px; color: #fff;
  font-size: 13px; padding: 7px 10px;
  outline: none; width: 100%;
}
.invite-row select:focus, .invite-row input[type=text]:focus { border-color: #e94560; }
.invite-actions { display: flex; gap: 8px; justify-content: flex-end; }
.invite-actions button {
  border: none; border-radius: 7px;
  font-size: 13px; padding: 8px 16px; cursor: pointer;
}
#btnSendInvite { background: #e94560; color: #fff; }
#btnSendInvite:hover { opacity: 0.88; }
#btnCancelInvite { background: rgba(255,255,255,0.1); color: #ccc; border: 1px solid rgba(255,255,255,0.15); }
#btnCancelInvite:hover { background: rgba(255,255,255,0.17); }

/* ---- INCOMING INVITE NOTIFICATION ---- */
#inviteNotif {
  position: fixed;
  top: 60px; left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  pointer-events: all;
}
#inviteNotifInner {
  background: rgba(12,16,32,0.97);
  border: 1px solid #e94560;
  border-radius: 12px;
  padding: 14px 18px;
  display: flex; flex-direction: column; gap: 10px;
  min-width: 260px; max-width: min(360px, 90vw);
  backdrop-filter: blur(12px);
  box-shadow: 0 4px 24px rgba(233,69,96,0.25);
  animation: notifSlideIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes notifSlideIn {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}
#inviteNotifText { font-size: 13px; color: #e0e0e0; line-height: 1.5; }
#inviteNotifActions { display: flex; gap: 8px; justify-content: flex-end; }
#inviteNotifActions button {
  border: none; border-radius: 7px;
  font-size: 13px; padding: 7px 16px; cursor: pointer;
}
#btnAcceptInvite { background: #4caf50; color: #fff; }
#btnAcceptInvite:hover { opacity: 0.88; }
#btnDeclineInvite { background: rgba(255,255,255,0.1); color: #ccc; border: 1px solid rgba(255,255,255,0.15); }
#btnDeclineInvite:hover { background: rgba(233,69,96,0.3); border-color: #e94560; color: #e94560; }

/* ---- PRIVATE DOCK (legacy, hidden) ---- */
#privateDock { display: none !important; }

/* ---- INVITE WORLD VISUAL GRID ---- */
.invite-world-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  max-height: 180px;
  overflow-y: auto;
  margin-top: 6px;
}
.invite-world-mini {
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}
.invite-world-mini:hover { border-color: rgba(233,69,96,0.5); }
.invite-world-mini.selected { border-color: #e94560; background: rgba(233,69,96,0.12); }
.invite-world-mini-thumb {
  width: 100%; aspect-ratio: 16/7;
  object-fit: cover; display: block;
  background: #0f3460;
}
.invite-world-mini-ph {
  width: 100%; aspect-ratio: 16/7;
  background: linear-gradient(135deg, #0f3460, #1a1a2e);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: rgba(255,255,255,0.3);
}
.invite-world-mini-name {
  font-size: 11px; padding: 3px 5px;
  text-align: center; color: #ccc;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- BACKPACK BUTTON ---- */
#backpackBtn {
  position: fixed;
  top: 10px;
  left: 136px;
  width: 36px;
  height: 36px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-tap-highlight-color: transparent;
}
#backpackBtn:hover { background: rgba(233,69,96,0.3); border-color: #e94560; }

/* ---- BACKPACK PANEL ---- */
#backpackPanel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
#backpackPanelInner {
  background: rgba(15,20,40,0.98);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 16px;
  padding: 20px;
  width: min(480px, 92vw);
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  backdrop-filter: blur(16px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
}
#backpackPanelHeader {
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
}
#backpackPanelHeader span { flex: 1; }
#backpackClose {
  background: none;
  border: none;
  color: #aaa;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
#backpackClose:hover { color: #fff; }
.backpack-hint {
  font-size: 12px;
  color: #777;
  line-height: 1.4;
}
#backpackItemGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}
.backpack-item-card {
  background: rgba(255,255,255,0.05);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.backpack-item-card:hover { border-color: #e94560; background: rgba(233,69,96,0.1); }
.backpack-item-card:active { transform: scale(0.96); }
.backpack-item-card img {
  max-width: 56px;
  max-height: 44px;
  object-fit: contain;
  image-rendering: auto;
}
.backpack-item-card span {
  font-size: 11px;
  color: #ccc;
  text-align: center;
  word-break: break-word;
  line-height: 1.3;
}

/* ---- PLACEMENT BAR ---- */
#placementBar {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(10,14,28,0.97);
  border: 1px solid rgba(233,69,96,0.5);
  border-top: none;
  border-radius: 0 0 16px 16px;
  padding: 10px 18px 12px;
  z-index: 50;
  backdrop-filter: blur(14px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.6);
  max-width: min(600px, 98vw);
  pointer-events: all;
  user-select: none;
}
.pb-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
#placementPreview {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#placementItemName {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
}
/* Layer toggle button */
.pb-layer-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.pb-layer-btn.layer-infront {
  background: rgba(33,150,243,0.18);
  border-color: rgba(33,150,243,0.6);
  color: #64b5f6;
}
.pb-layer-btn.layer-behind {
  background: rgba(156,39,176,0.18);
  border-color: rgba(156,39,176,0.6);
  color: #ce93d8;
}
.pb-layer-btn:hover { opacity: 0.8; }
.pb-layer-icon { font-size: 14px; }

.pb-drag-hint {
  font-size: 11px;
  color: #555;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}
#btnCancelPlace {
  background: rgba(233,69,96,0.18);
  color: #e94560;
  border: 1px solid rgba(233,69,96,0.4);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
#btnCancelPlace:hover { background: rgba(233,69,96,0.35); }

/* Mobile */
@media (pointer: coarse) and (orientation: portrait) {
  #placementBar { padding: 8px 12px 10px; gap: 8px; }
  .pb-drag-hint { display: none; }
  #placementItemName { max-width: 70px; }
}

/* ---- TOAST ---- */
.game-toast {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-16px);
  background: rgba(20,24,40,0.95);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  white-space: nowrap;
}
.game-toast.toast-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
