* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0b0f19;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  color: #f8fafc;
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
}

/* ==========================================================================
   LOBBY SCREEN
   ========================================================================== */
.overlay-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.88), rgba(2, 6, 23, 0.98));
  backdrop-filter: blur(8px);
  z-index: 100;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lobby-card {
  background: rgba(30, 41, 59, 0.85);
  border: 2px solid #3b82f6;
  border-radius: 16px;
  padding: 32px 40px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 25px rgba(59, 130, 246, 0.3);
}

.game-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(135deg, #60a5fa, #38bdf8, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

.game-subtitle {
  font-size: 13px;
  color: #94a3b8;
  margin-bottom: 24px;
}

.avatar-preview-box {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

#avatarPreviewCanvas {
  background: #0f172a;
  border: 2px solid #475569;
  border-radius: 12px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
}

.form-group {
  margin-bottom: 18px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.game-input {
  width: 100%;
  padding: 12px 16px;
  background: #0f172a;
  border: 1.5px solid #475569;
  border-radius: 8px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.game-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

.color-picker-grid {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.color-option {
  cursor: pointer;
}

.color-option input {
  display: none;
}

.color-swatch {
  display: inline-block;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.color-option input:checked + .color-swatch {
  transform: scale(1.15);
  border-color: #ffffff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
}

.hat-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.hat-option {
  cursor: pointer;
}

.hat-option input {
  display: none;
}

.hat-card {
  display: block;
  text-align: center;
  padding: 8px;
  background: #0f172a;
  border: 1.5px solid #334155;
  border-radius: 8px;
  font-size: 13px;
  color: #94a3b8;
  transition: all 0.2s;
}

.hat-option input:checked + .hat-card {
  background: #1e3a8a;
  border-color: #60a5fa;
  color: #ffffff;
  font-weight: 700;
}

.btn-play {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  border: none;
  border-radius: 10px;
  color: #ffffff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  margin-top: 8px;
}

.btn-play:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(37, 99, 235, 0.6);
}

.btn-play:active {
  transform: translateY(1px);
}

/* ==========================================================================
   GAME HUD
   ========================================================================== */
#gameHud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

#gameHud.hidden {
  display: none;
}

/* Top Left: Player Status */
.hud-top-left {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  padding: 10px 16px;
  border-radius: 12px;
  border: 1.5px solid #334155;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.player-info-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-player-name {
  font-size: 14px;
  font-weight: 700;
  color: #f8fafc;
}

.hud-level-badge {
  background: #f59e0b;
  color: #0f172a;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 6px;
}

.bar-wrapper {
  width: 140px;
  height: 10px;
  background: #334155;
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  transition: width 0.2s ease;
}

.bar-hp {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.bar-xp {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  height: 6px;
}

.bar-text {
  font-size: 9px;
  color: #cbd5e1;
  font-family: monospace;
}

/* Top Center: Resource counters */
.hud-top-center {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  padding: 8px 18px;
  border-radius: 20px;
  border: 1.5px solid #334155;
  pointer-events: auto;
}

.resource-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

/* Top Right: Minimap & Status */
.hud-top-right {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: auto;
}

.minimap-wrapper {
  background: rgba(15, 23, 42, 0.9);
  border: 2px solid #475569;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}

#minimapCanvas {
  display: block;
}

.hud-widgets-row {
  display: flex;
  gap: 6px;
}

.hud-btn {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid #475569;
  border-radius: 8px;
  color: #cbd5e1;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.hud-btn:hover {
  background: #334155;
  color: #ffffff;
}

.online-badge {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 700;
  color: #4ade80;
}

/* Bottom Center: Hotbar */
.hud-bottom-center {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  padding: 8px 12px;
  border-radius: 14px;
  border: 2px solid #334155;
  pointer-events: auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.hotbar-slot {
  width: 52px;
  height: 52px;
  background: #1e293b;
  border: 2px solid #475569;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.hotbar-slot:hover {
  transform: translateY(-4px);
  border-color: #94a3b8;
}

.hotbar-slot.active {
  border-color: #38bdf8;
  background: #0f2744;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.5);
  transform: translateY(-4px);
}

.slot-key {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 9px;
  color: #94a3b8;
  font-weight: 800;
}

.slot-icon {
  font-size: 20px;
}

.slot-count {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 10px;
  font-weight: 800;
  color: #fef08a;
}

/* Bottom Left: Chat Box */
.hud-bottom-left {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 320px;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  border: 1.5px solid #334155;
  border-radius: 12px;
  overflow: hidden;
  pointer-events: auto;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.chat-messages {
  height: 140px;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  scrollbar-width: thin;
}

.chat-row {
  line-height: 1.4;
  word-break: break-word;
}

.chat-author {
  font-weight: 700;
}

.chat-text {
  color: #f1f5f9;
}

.chat-system {
  color: #facc15;
  font-style: italic;
}

.chat-input-row {
  display: flex;
  border-top: 1px solid #334155;
  background: #0f172a;
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 12px;
  color: #ffffff;
  font-size: 12px;
  outline: none;
}

.btn-chat-send {
  background: #2563eb;
  border: none;
  color: #ffffff;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

/* Bottom Right: Quick Emotes */
.hud-bottom-right {
  position: absolute;
  bottom: 20px;
  right: 20px;
  display: flex;
  gap: 6px;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(6px);
  padding: 6px;
  border-radius: 10px;
  border: 1px solid #334155;
  pointer-events: auto;
}

.emote-btn {
  background: #1e293b;
  border: 1px solid #475569;
  border-radius: 6px;
  font-size: 18px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.emote-btn:hover {
  transform: scale(1.15);
  background: #334155;
}

/* ==========================================================================
   DEATH SCREEN
   ========================================================================== */
.death-card {
  background: rgba(69, 10, 10, 0.9);
  border: 2px solid #ef4444;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 0 35px rgba(239, 68, 68, 0.5);
}

.death-title {
  font-size: 26px;
  color: #fca5a5;
  margin-bottom: 8px;
}

.death-msg {
  font-size: 14px;
  color: #cbd5e1;
  margin-bottom: 24px;
}

.btn-respawn {
  padding: 12px 32px;
  background: #ef4444;
  border: none;
  border-radius: 8px;
  color: #ffffff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.5);
  transition: transform 0.15s;
}

.btn-respawn:hover {
  transform: scale(1.05);
}

/* ==========================================================================
   HELP MODAL
   ========================================================================== */
.help-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
}

.help-modal.hidden {
  display: none;
}

.help-card {
  background: #1e293b;
  border: 1.5px solid #475569;
  border-radius: 14px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
}

.help-card h3 {
  margin-bottom: 14px;
  color: #38bdf8;
}

.help-list {
  list-style: none;
  font-size: 13px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-list kbd {
  background: #0f172a;
  border: 1px solid #475569;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
  font-weight: bold;
  color: #fbbf24;
}

.btn-close-help {
  margin-top: 18px;
  width: 100%;
  padding: 10px;
  background: #334155;
  border: none;
  border-radius: 8px;
  color: #ffffff;
  cursor: pointer;
}
