body {
  margin: 0;
  padding: 0;
  background: #333;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

.hidden {
  display: none !important;
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: skyblue;
  touch-action: none;
}

#inventory {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 5px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 5px;
}

.inventory-item {
  width: 50px;
  height: 50px;
  border: 2px solid #555;
  cursor: pointer;
}

.inventory-item.selected {
  border-color: #fff;
}

#selected-block {
  position: fixed;
  top: 20px;
  left: 20px;
  color: white;
  background: rgba(0, 0, 0, 0.7);
  padding: 5px;
  font-size: 12px;
  border-radius: 5px;
}

#coordinates {
  position: fixed;
  top: 50px;
  right: 20px;
  color: white;
  background: rgba(0, 0, 0, 0.7);
  padding: 5px;
  font-size: 12px;
  border-radius: 5px;
}

.menu {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.9);
  padding: 20px;
  border-radius: 10px;
  text-align: center;
  color: white;
  min-width: 300px;
  max-width: 500px;
}

.menu h1 {
  font-size: 3em;
  margin-bottom: 40px;
  color: #567D46;
}

.menu button {
  display: block;
  width: 200px;
  margin: 10px auto;
  padding: 15px;
  font-size: 1.2em;
  background: #567D46;
  border: none;
  border-radius: 5px;
  color: white;
  cursor: pointer;
  transition: background 0.3s;
}

.menu button:hover {
  background: #3A5F0B;
}

#inventory-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  z-index: 1000;
}

.inventory-grid {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 95vw;
  max-width: 500px;
  padding: 10px;
  background: #c6c6c6;
  border: 4px solid #373737;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 20px;
}

.crafting-area {
  display: grid;
  grid-template-columns: auto auto;
  gap: 10px;
  align-items: center;
}

.crafting-grid {
  display: grid;
  grid-template-columns: repeat(3, 45px);
  grid-template-rows: repeat(3, 45px);
  gap: 2px;
  background: #8b8b8b;
  padding: 5px;
  border: 2px solid #373737;
}

.inventory-slots {
  display: grid;
  grid-template-columns: repeat(9, 45px);
  grid-template-rows: repeat(4, 45px);
  gap: 2px;
  background: #8b8b8b;
  padding: 5px;
  border: 2px solid #373737;
}

.inventory-slot {
  width: 45px;
  height: 45px;
  background: #6b6b6b;
  border: 2px solid #373737;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 10px;
}

.inventory-slot.selected {
  border-color: white;
}

.crafting-result {
  width: 60px;
  height: 60px;
  background: #6b6b6b;
  border: 2px solid #373737;
}

.hotbar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(9, 45px);
  gap: 2px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 5px;
}

.mobile-controls {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  z-index: 100;
  pointer-events: none;
}

.mobile-controls * {
  pointer-events: all;
}

.mobile-controls.active {
  display: block;
}

.d-pad {
  position: fixed;
  bottom: 120px;
  left: 20px;
  display: grid;
  grid-template-columns: repeat(3, 70px);
  grid-template-rows: repeat(3, 70px);
  gap: 5px;
}

.d-pad button {
  width: 70px;
  height: 70px;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 15px;
  color: white;
  font-size: 28px;
  font-weight: bold;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.d-pad button:active {
  background: rgba(255, 255, 255, 0.6);
  transform: scale(0.95);
}

.action-buttons {
  position: fixed;
  bottom: 120px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-button {
  width: 80px;
  height: 80px;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  color: white;
  font-size: 14px;
  font-weight: bold;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-button:active {
  background: rgba(255, 255, 255, 0.6);
  transform: scale(0.95);
}

/* Mobile inventory button */
.mobile-inventory-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  background: rgba(0, 0, 0, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  color: white;
  font-size: 14px;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: none;
}

.mobile-inventory-btn.active {
  display: block;
}

.mobile-inventory-btn:active {
  background: rgba(0, 0, 0, 0.9);
  transform: scale(0.95);
}

/* Auto-detect mobile devices */
@media (hover: none) and (pointer: coarse) {
  .mobile-controls {
    display: block !important;
  }
  
  .mobile-inventory-btn {
    display: block !important;
  }
}

.toggle-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 10px 0;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 34px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: #567D46;
}

input:checked + .toggle-slider:before {
  transform: translateX(26px);
}

.options-container, .help-content {
  max-height: 60vh;
  overflow-y: auto;
  margin: 20px 0;
  padding: 0 10px;
}

.option-group {
  background: rgba(0, 0, 0, 0.3);
  padding: 15px;
  margin: 10px 0;
  border-radius: 5px;
}

.option-group h3 {
  margin-top: 0;
  color: #567D46;
  font-size: 1.2em;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.slider-container input[type="range"] {
  flex: 1;
  height: 10px;
  -webkit-appearance: none;
  background: #567D46;
  border-radius: 5px;
  outline: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
}

.help-section {
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  margin: 10px 0;
  border-radius: 5px;
}

.help-section h3 {
  margin-top: 0;
  color: #567D46;
  font-size: 1.2em;
}

.help-section ul {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

.help-section li {
  padding: 5px 0;
  color: #fff;
}

.world-options {
  display: grid;
  gap: 15px;
  padding: 20px;
}

.world-options label {
  color: white;
  display: block;
  margin-bottom: 5px;
}

.world-options input, .world-options select {
  width: 100%;
  padding: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  border-radius: 4px;
}

.world-options select option {
  background: #333;
}

.world-list {
  max-height: 300px;
  overflow-y: auto;
  margin: 20px 0;
}

.world-item {
  background: rgba(255, 255, 255, 0.1);
  padding: 15px;
  margin: 10px 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.3s;
}

.world-item:hover {
  background: rgba(255, 255, 255, 0.2);
}

.world-item.selected {
  border: 2px solid #567D46;
}

.multiplayer-join {
  position: relative;
  margin: 20px 0;
}

.multiplayer-join input {
  width: 100%;
  padding: 10px;
  padding-right: 80px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  border-radius: 4px;
}

.multiplayer-join button {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  padding: 5px 15px;
  background: #567D46;
  border: none;
  color: white;
  border-radius: 3px;
  cursor: pointer;
}

.multiplayer-join button:hover {
  background: #3A5F0B;
}

.world-mode {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 20px 0;
}

.mode-option {
  background: rgba(255, 255, 255, 0.1);
  padding: 10px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.3s;
}

.mode-option:hover {
  background: rgba(255, 255, 255, 0.2);
}

.mode-option.selected {
  border-color: #567D46;
  background: rgba(86, 125, 70, 0.2);
}

.mode-option h3 {
  margin: 0 0 10px 0;
  color: #fff;
}

.mode-description {
  font-size: 0.8em;
  color: rgba(255, 255, 255, 0.7);
}

.mode-option.hardcore {
  border-color: #8B0000;
}

.mode-option.horror {
  border-color: #301934;
}

.server-info {
  background: rgba(0, 0, 0, 0.5);
  padding: 15px;
  margin: 15px 0;
  border-radius: 5px;
}

.server-info ul {
  list-style-type: none;
  padding: 0;
  margin: 10px 0;
}

.server-info li {
  color: #fff;
  margin: 5px 0;
  padding-left: 20px;
  position: relative;
}

.server-info li:before {
  content: "•";
  position: absolute;
  left: 0;
  color: #567D46;
}

.info-text {
  color: #fff;
  margin: 5px 0;
}

#chat-container {
  position: fixed;
  left: 20px;
  bottom: 200px;
  width: 300px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 5px;
  padding: 10px;
  display: none; /* Hidden by default */
}

#chat-messages {
  height: 150px;
  overflow-y: auto;
  margin-bottom: 10px;
  color: white;
  font-size: 14px;
}

#chat-input-container {
  display: flex;
  gap: 5px;
}

#chat-input {
  flex: 1;
  padding: 5px;
  border: none;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.9);
}

#chat-send {
  padding: 5px 10px;
  border: none;
  border-radius: 3px;
  background: #567D46;
  color: white;
  cursor: pointer;
}

#chat-send:hover {
  background: #3A5F0B;
}

.chat-message {
  margin: 5px 0;
  word-break: break-word;
}

.chat-username {
  color: #567D46;
  font-weight: bold;
}

/* Mobile-specific styles */
@media (max-width: 768px) {
  .menu {
    padding: 20px;
    min-width: 90vw;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
  }

  .menu h1 {
    font-size: 2em;
    margin-bottom: 20px;
  }

  .menu button {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
    margin: 8px 0;
  }

  .world-mode {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .mode-option {
    padding: 10px;
  }

  .options-container, .help-content {
    max-height: 60vh;
    padding: 0 10px;
  }

  .help-section {
    padding: 10px;
  }

  .inventory-grid {
    width: 95vw;
    max-width: 500px;
    padding: 10px;
  }

  .crafting-grid {
    grid-template-columns: repeat(3, 45px);
    grid-template-rows: repeat(3, 45px);
    gap: 2px;
    padding: 5px;
  }

  .inventory-slots {
    grid-template-columns: repeat(9, 45px);
    grid-template-rows: repeat(4, 45px);
    gap: 2px;
    padding: 5px;
  }

  .inventory-slot {
    width: 45px;
    height: 45px;
    font-size: 10px;
  }

  .hotbar {
    grid-template-columns: repeat(9, 45px);
    gap: 2px;
    padding: 5px;
  }

  #selected-block, #coordinates {
    padding: 5px;
    font-size: 12px;
  }

  #coordinates {
    top: 50px;
  }
}