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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Courier New', 'Consolas', monospace;
  background: #1a1a2e;
}

#gameCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#mainMenu {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #87CEEB 0%, #B0E0E6 50%, #8BC34A 70%, #558B2F 100%);
  z-index: 100;
}

.menu-title {
  font-size: 48px;
  font-weight: bold;
  color: #fff;
  text-shadow: 4px 4px 0 #333, -2px -2px 0 #333;
  margin-bottom: 10px;
  letter-spacing: 4px;
}

.menu-subtitle {
  font-size: 18px;
  color: #fff;
  text-shadow: 2px 2px 0 #333;
  margin-bottom: 10px;
  opacity: 0.9;
}

.menu-version {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 1px 1px 0 #333;
  margin-bottom: 40px;
  font-weight: bold;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 280px;
}

.menu-btn {
  padding: 14px 24px;
  font-size: 18px;
  font-family: inherit;
  font-weight: bold;
  color: #fff;
  background: linear-gradient(180deg, #7CB342 0%, #558B2F 100%);
  border: 3px solid #33691E;
  border-radius: 4px;
  cursor: pointer;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
  box-shadow: 0 4px 0 #33691E, 0 6px 10px rgba(0,0,0,0.3);
  transition: all 0.1s ease;
}

.menu-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #8BC34A 0%, #689F38 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 0 #33691E, 0 8px 12px rgba(0,0,0,0.3);
}

.menu-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #33691E, 0 4px 6px rgba(0,0,0,0.3);
}

.menu-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#gameContainer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  pointer-events: none;
  z-index: 50;
  display: none;
}

.hud-top {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#healthBar, #hungerBar {
  display: flex;
  gap: 2px;
  font-size: 20px;
  text-shadow: 2px 2px 0 #000;
}

.heart {
  color: #F44336;
}

.heart.empty {
  color: #424242;
}

.heart.half {
  background: linear-gradient(90deg, #F44336 50%, #424242 50%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.drumstick {
  font-size: 18px;
}

.drumstick.empty {
  opacity: 0.3;
  filter: grayscale(1);
}

.drumstick.half {
  opacity: 0.7;
}

.hud-top-right {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
  z-index: 100;
}

.hud-btn {
  width: 36px;
  height: 36px;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  pointer-events: auto;
}

.hud-btn:hover {
  background: rgba(0, 0, 0, 0.7);
  border-color: rgba(255, 255, 255, 0.5);
}

#coords {
  position: absolute;
  top: 10px;
  right: 10px;
  color: #fff;
  font-size: 14px;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 8px;
  border-radius: 4px;
}

#timeDisplay {
  position: absolute;
  top: 50px;
  right: 10px;
  color: #fff;
  font-size: 14px;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px 8px;
  border-radius: 4px;
}

#hotbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #2d2d2d;
  border: 3px solid #1a1a1a;
  border-radius: 4px 4px 0 0;
  pointer-events: auto;
  z-index: 100;
}

.hotbar-slot {
  width: 48px;
  height: 48px;
  background: #424242;
  border: 2px solid #1a1a1a;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hotbar-slot.selected {
  border-color: #fff;
  background: #616161;
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
}

.item-icon {
  width: 32px;
  height: 32px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,0.3);
  position: relative;
}

.item-count {
  position: absolute;
  bottom: 2px;
  right: 2px;
  font-size: 12px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
  font-weight: bold;
}

#pausePanel, #inventoryPanel, #saveListPanel, #settingsPanel {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 80;
}

.panel {
  background: #3e2723;
  border: 4px solid #1a0f0d;
  padding: 30px;
  border-radius: 8px;
  min-width: 300px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.panel-title {
  color: #fff;
  font-size: 24px;
  text-align: center;
  margin-bottom: 20px;
  text-shadow: 2px 2px 0 #000;
}

.panel-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-btn {
  padding: 10px 20px;
  font-size: 16px;
  font-family: inherit;
  font-weight: bold;
  color: #fff;
  background: #5D4037;
  border: 2px solid #3E2723;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s ease;
}

.panel-btn:hover {
  background: #6D4C41;
}

#inventoryPanel {
  z-index: 60;
}

.inventory-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: center;
}

.inventory-panel {
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
}

.crafting-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.crafting-label {
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #000;
}

.crafting-grid-wrapper {
  display: flex;
  align-items: center;
  gap: 15px;
}

#craftingGrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 2px;
  padding: 4px;
  background: #2d2d2d;
  border: 2px solid #1a1a1a;
  width: 104px;
  height: 104px;
}

.craft-arrow {
  color: #fff;
  font-size: 24px;
}

.craft-slot {
  width: 48px;
  height: 48px;
  background: #424242;
  border: 2px solid #1a1a1a;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.craft-slot .item-icon {
  width: 32px;
  height: 32px;
}

.craft-slot .item-count {
  font-size: 12px;
}

#craftingResult {
  width: 56px;
  height: 56px;
  background: #424242;
  border: 2px solid #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

#inventorySlots {
  display: grid;
  grid-template-columns: repeat(9, 40px);
  grid-template-rows: repeat(3, 40px);
  gap: 2px;
  padding: 4px;
  background: #2d2d2d;
  border: 2px solid #1a1a1a;
}

.inventory-hotbar-label {
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #000;
  text-align: center;
  margin-bottom: 5px;
}

.inventory-hotbar {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #2d2d2d;
  border: 2px solid #1a1a1a;
  border-radius: 4px;
}

.inv-slot {
  width: 40px;
  height: 40px;
  background: #424242;
  border: 1px solid #1a1a1a;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.inv-slot .item-icon {
  width: 26px;
  height: 26px;
}

.inv-slot .item-count {
  font-size: 10px;
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  background: #c62828;
  border: 2px solid #b71c1c;
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#saveListPanel .panel {
  min-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
}

#savesList {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.save-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: #5D4037;
  border: 2px solid #3E2723;
  border-radius: 4px;
}

.save-info {
  color: #fff;
}

.save-name {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 4px;
}

.save-date {
  font-size: 12px;
  opacity: 0.7;
}

.save-actions {
  display: flex;
  gap: 6px;
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
  font-family: inherit;
  font-weight: bold;
  color: #fff;
  background: #795548;
  border: 2px solid #4E342E;
  border-radius: 3px;
  cursor: pointer;
}

.btn-small:hover {
  background: #8D6E63;
}

.settings-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background: #5D4037;
  border: 2px solid #3E2723;
  border-radius: 4px;
}

.setting-item label {
  color: #fff;
  font-size: 16px;
}

.toggle-btn {
  padding: 6px 16px;
  font-size: 14px;
  font-family: inherit;
  font-weight: bold;
  color: #fff;
  background: #7CB342;
  border: 2px solid #558B2F;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.toggle-btn.off {
  background: #757575;
  border-color: #424242;
}

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

.setting-item-slider {
  flex-direction: column;
  gap: 8px;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  background: #424242;
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: #7CB342;
  border: 2px solid #558B2F;
  border-radius: 50%;
  cursor: pointer;
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: #7CB342;
  border: 2px solid #558B2F;
  border-radius: 50%;
  cursor: pointer;
}

.slider-value {
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  min-width: 20px;
  text-align: center;
  text-shadow: 1px 1px 0 #000;
}

.btn-danger {
  background: #c62828;
  border-color: #b71c1c;
}

.btn-danger:hover {
  background: #d32f2f;
}

#touchControls {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 55;
  display: none;
}

.joystick-area {
  position: absolute;
  bottom: 80px;
  left: 15px;
  width: 140px;
  height: 140px;
  pointer-events: auto;
}

.joystick-base {
  position: absolute;
  width: 100px;
  height: 100px;
  background: rgba(255, 255, 255, 0.2);
  border: 3px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
}

.joystick-stick {
  position: absolute;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.5);
  border: 3px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
}

.action-buttons {
  position: absolute;
  bottom: 70px;
  right: 100px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
  align-items: center;
}

.action-row {
  display: flex;
  gap: 10px;
}

.action-btn {
  width: 55px;
  height: 55px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.5);
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

.jump-btn {
  background: rgba(76, 175, 80, 0.7);
  width: 70px;
  height: 70px;
}

.break-btn {
  background: rgba(244, 67, 54, 0.7);
}

.place-btn {
  background: rgba(33, 150, 243, 0.7);
}

.inv-btn {
  background: rgba(156, 39, 176, 0.7);
  font-size: 14px;
  width: 70px;
}

.action-btn:active {
  transform: scale(0.9);
}

.aux-buttons {
  position: absolute;
  bottom: 170px;
  right: 100px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
  align-items: center;
}

.cursor-joystick-area {
  position: absolute;
  bottom: 85px;
  right: 15px;
  width: 100px;
  height: 100px;
  pointer-events: auto;
}

.cursor-joystick-base {
  position: absolute;
  width: 90px;
  height: 90px;
  background: rgba(255, 193, 7, 0.2);
  border: 3px solid rgba(255, 193, 7, 0.4);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
}

.cursor-joystick-stick {
  position: absolute;
  width: 40px;
  height: 40px;
  background: rgba(255, 193, 7, 0.5);
  border: 3px solid rgba(255, 193, 7, 0.7);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
}

.cursor-crosshair {
  position: absolute;
  width: 24px;
  height: 24px;
  pointer-events: none;
  z-index: 50;
  border: 2px solid rgba(255, 193, 7, 0.8);
  border-radius: 4px;
  transform: translate(-50%, -50%);
}

.cursor-crosshair::before,
.cursor-crosshair::after {
  content: '';
  position: absolute;
  background: rgba(255, 193, 7, 0.8);
}

.cursor-crosshair::before {
  width: 2px;
  height: 100%;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
}

.cursor-crosshair::after {
  width: 100%;
  height: 2px;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

@media (max-width: 768px) {
  .menu-title {
    font-size: 32px;
  }

  .menu-subtitle {
    font-size: 14px;
  }

  .menu-buttons {
    width: 240px;
  }

  .menu-btn {
    font-size: 16px;
    padding: 12px 20px;
  }

  #hotbar {
    bottom: 0;
    padding: 2px;
  }

  .hotbar-slot {
    width: 40px;
    height: 40px;
  }

  .hotbar-slot .item-icon {
    width: 26px;
    height: 26px;
  }

  .hud-top-right {
    right: 50px;
  }

  .hud-btn {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
}
