*, *::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; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  z-index: 100;
}
.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; }

#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;
}
#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
}

/* ---- CHAT BAR ---- */
#chatBar {
  position: fixed;
  bottom: 60px;
  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 ---- */
#privateDock {
  position: fixed;
  bottom: 0; right: 12px;
  width: 280px;
  background: rgba(15,20,40,0.95);
  border: 1px solid rgba(255,255,255,0.15);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  z-index: 30;
  backdrop-filter: blur(8px);
}
#privateDockHeader {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 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;
}
#privateDockBody {
  padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
}
#pmLog {
  height: 160px;
  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; }
#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; }
}
#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; }

/* ---- 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; }
