* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; font-family: system-ui, Arial, sans-serif; overscroll-behavior: none; }

#game { position: fixed; inset: 0; z-index: 0; }
#game canvas { display: block; }

#login {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4a90d9, #6aa84f);
}
.login-card {
  background: #fff; padding: 36px 40px; border-radius: 16px;
  text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.25); width: 320px;
}
.login-card h1 { margin-bottom: 8px; font-size: 26px; }
.login-card p { margin-bottom: 20px; color: #555; font-size: 14px; }
#nameInput {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 2px solid #ddd; border-radius: 10px; margin-bottom: 14px; outline: none;
}
#nameInput:focus { border-color: #4a90d9; }
#startBtn {
  width: 100%; padding: 12px; font-size: 16px; font-weight: bold;
  border: none; border-radius: 10px; background: #4a90d9; color: #fff; cursor: pointer;
}
#startBtn:hover { background: #3a7bc0; }
#startBtn:disabled { opacity: .6; cursor: default; }

#crosshair {
  position: fixed; left: 50%; top: 50%; width: 22px; height: 22px;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 20;
}
#crosshair::before, #crosshair::after { content: ''; position: absolute; background: rgba(255,255,255,.9); }
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; transform: translateX(-50%); }
#crosshair::after  { top: 50%; left: 0; height: 2px; width: 100%; transform: translateY(-50%); }
body.is-mobile #crosshair { display: none; }

#coords, #online {
  position: fixed; top: 12px; z-index: 20; pointer-events: none;
  background: rgba(0,0,0,.45); color: #fff; padding: 6px 10px;
  border-radius: 8px; font-size: 13px;
}
#coords { left: 12px; }
#online { right: 12px; }

#playerList {
  position: fixed; top: 46px; right: 12px; z-index: 20;
  background: rgba(0,0,0,.45); color: #fff; padding: 8px 10px;
  border-radius: 8px; font-size: 13px; min-width: 130px;
}
.player-list-title { font-weight: bold; margin-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.3); padding-bottom: 3px; }
.player-row { padding: 1px 0; }

#hotbar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 6px; z-index: 20;
  background: rgba(0,0,0,.35); padding: 6px; border-radius: 12px;
}
.hotbar-item {
  width: 48px; height: 48px; border-radius: 8px;
  border: 2px solid rgba(255,255,255,.4); cursor: pointer;
  position: relative; transition: transform .1s;
}
.hotbar-item.active {
  border-color: #fff; transform: translateY(-6px);
  box-shadow: 0 0 0 2px rgba(255,255,255,.5);
}
.hotbar-item .key {
  position: absolute; top: 2px; left: 5px; font-size: 11px;
  color: #fff; text-shadow: 0 1px 2px #000;
}

#chatLog {
  position: fixed; left: 12px; bottom: 80px; z-index: 35;
  width: 320px; max-width: 70vw; max-height: 180px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  pointer-events: none; opacity: 0; transition: opacity .3s;
  font-size: 14px;
}
#chatLog.visible { opacity: 1; }
.chat-msg {
  background: rgba(0,0,0,.5); color: #fff; padding: 3px 8px;
  border-radius: 6px; word-wrap: break-word; width: fit-content; max-width: 100%;
}
.chat-msg.system { color: #ffe082; background: rgba(0,0,0,.35); font-style: italic; }
.chat-msg b { color: #8fd0ff; }

#chatInput {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  width: 320px; max-width: 80vw; padding: 10px 12px; font-size: 15px;
  border: 2px solid #4a90d9; border-radius: 10px; outline: none;
  z-index: 40; display: none; background: #fff;
}
body.is-mobile #chatInput { bottom: 200px; }
body.is-mobile #chatLog { bottom: 200px; }

#mobileControls { display: none; }
body.is-mobile #mobileControls { display: block; }

#lookArea { position: fixed; inset: 0; z-index: 10; touch-action: none; }

#joystickZone {
  position: fixed; left: 22px; bottom: 22px; width: 120px; height: 120px;
  border-radius: 50%; background: rgba(255,255,255,.15);
  border: 2px solid rgba(255,255,255,.35); z-index: 30; touch-action: none;
}
#joystickKnob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px;
  margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255,255,255,.45); pointer-events: none;
}

#actionButtons {
  position: fixed; right: 16px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px; z-index: 30;
}
.action-btn {
  width: 50px; height: 50px; border-radius: 50%; font-size: 22px;
  border: 2px solid rgba(255,255,255,.5); background: rgba(0,0,0,.35);
  color: #fff; display: flex; align-items: center; justify-content: center;
  cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
}
.action-btn:active { background: rgba(255,255,255,.3); }

#inventory {
  position: fixed; top: 46px; left: 12px; z-index: 20;
  background: rgba(0,0,0,.5); color: #fff; padding: 8px 10px;
  border-radius: 8px; font-size: 13px; min-width: 130px;
  pointer-events: none;
}
.inv-title { font-weight: bold; margin-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.3); padding-bottom: 3px; }
.inv-empty { opacity: .6; }
.inv-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.inv-swatch { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(255,255,255,.4); flex-shrink: 0; }
.inv-name { flex: 1; }
.inv-count { color: #ffe082; }

#passInput {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border: 2px solid #ddd; border-radius: 10px; margin-bottom: 14px; outline: none;
}
#passInput:focus { border-color: #4a90d9; }
#regBtn {
  width: 100%; padding: 12px; font-size: 16px; font-weight: bold;
  border: none; border-radius: 10px; background: #6aa84f; color: #fff; cursor: pointer; margin-top: 8px;
}
#regBtn:hover { background: #5a9142; }
#regBtn:disabled { opacity: .6; cursor: default; }
#authMsg { margin-top: 10px; font-size: 14px; color: #c62828; min-height: 18px; text-align: center; }
