* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 0;
}

/* ===== Crosshair ===== */
#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  z-index: 10;
  pointer-events: none;
  text-shadow: 0 0 2px rgba(0,0,0,0.8);
}

#crosshair::before {
  content: '+';
}

/* ===== HUD ===== */
#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 10;
  pointer-events: none;
}

.hud-item {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
  margin-bottom: 4px;
}

/* ===== Coordinates ===== */
#coords {
  position: fixed;
  bottom: 70px;
  left: 12px;
  color: rgba(255,255,255,0.5);
  font-size: 12px;
  font-family: monospace;
  z-index: 10;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* ===== Mode Switch Button ===== */
#mode-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.25);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  z-index: 10;
  letter-spacing: 0.03em;
  transition: border-color 0.2s, background 0.2s;
}

#mode-btn:hover {
  border-color: rgba(255,255,255,0.6);
  background: rgba(0,0,0,0.7);
}

/* ===== Mining Progress Bar ===== */
#mining-bar-container {
  position: fixed;
  bottom: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: none;
}

#mining-bar {
  width: 200px;
  height: 6px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.2);
  overflow: hidden;
}

#mining-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ff6644, #ff2200);
  transition: width 0.05s linear;
}

/* ===== Hotbar ===== */
#hotbar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 3px;
  z-index: 20;
}

.hotbar-slot {
  width: 48px;
  height: 48px;
  background: rgba(0,0,0,0.6);
  border: 2px solid rgba(255,255,255,0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}

.hotbar-slot:hover {
  border-color: rgba(255,255,255,0.5);
}

.hotbar-slot.selected {
  border-color: #fff;
  background: rgba(255,255,255,0.15);
}

.hotbar-slot.empty {
  opacity: 0.4;
}

/* Palette button "…" */
.hotbar-slot.palette-btn {
  background: rgba(80,80,80,0.7);
  color: rgba(255,255,255,0.7);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
}

.hotbar-slot.palette-btn:hover {
  background: rgba(100,100,100,0.8);
  color: #fff;
}

/* Block color preview in hotbar */
.hotbar-block-color {
  width: 24px;
  height: 24px;
  border: 1px solid rgba(255,255,255,0.15);
}

.hotbar-block-name {
  font-size: 8px;
  color: rgba(255,255,255,0.7);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 44px;
  text-align: center;
}

/* Slot key label */
.hotbar-key {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 10px;
  color: rgba(255,255,255,0.4);
  pointer-events: none;
}

/* ===== Block Palette Overlay ===== */
#block-palette {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.65);
  z-index: 100;
  justify-content: center;
  align-items: center;
}

.palette-panel {
  background: rgba(20,20,20,0.92);
  border: 2px solid rgba(255,255,255,0.2);
  padding: 0;
  min-width: 320px;
  max-width: 90vw;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.palette-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

#palette-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.5);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
}

#palette-close:hover {
  color: #fff;
}

#palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
  padding: 16px;
  overflow-y: auto;
}

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.palette-item:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.25);
}

.palette-item.selected {
  border-color: #fff;
  background: rgba(255,255,255,0.12);
}

.palette-item-color {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255,255,255,0.15);
}

.palette-item-name {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  margin-top: 4px;
  white-space: nowrap;
}

.palette-footer {
  padding: 10px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.4);
  font-size: 12px;
  text-align: center;
}

/* ===== Death Screen ===== */
#death-screen {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(180,30,30,0.55);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 200;
}

#death-screen h2 {
  color: #fff;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 12px rgba(0,0,0,0.5);
  margin-bottom: 24px;
}

#death-screen button {
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.4);
  padding: 12px 32px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: border-color 0.2s, background 0.2s;
}

#death-screen button:hover {
  border-color: #fff;
  background: rgba(0,0,0,0.8);
}

/* ===== Main Menu ===== */
#main-menu {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.75);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 300;
}

.menu-content {
  text-align: center;
  max-width: 600px;
  padding: 20px;
}

#main-menu h1 {
  color: #fff;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-shadow: 0 2px 16px rgba(0,0,0,0.5);
  margin-bottom: 24px;
}

/* Create New World Button */
.create-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, #4a90d9, #357abd);
  color: #fff;
  border: none;
  padding: 14px 32px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.25s ease;
  box-shadow: 0 4px 12px rgba(74, 144, 217, 0.35);
  margin-bottom: 32px;
}

.create-btn:hover {
  background: linear-gradient(135deg, #5a9fe9, #458ace);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(74, 144, 217, 0.45);
}

.plus-icon {
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
}

/* Saved Worlds Section */
.saved-worlds-section {
  margin-bottom: 24px;
}

.saved-worlds-section h2 {
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  text-align: left;
}

.worlds-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.action-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border: 2px solid rgba(255,255,255,0.2);
}

.action-btn:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.4);
}

.action-btn.danger {
  background: rgba(220, 53, 69, 0.2);
  color: #ff6b7a;
  border-color: rgba(220, 53, 69, 0.4);
}

.action-btn.danger:hover {
  background: rgba(220, 53, 69, 0.3);
  border-color: rgba(220, 53, 69, 0.6);
}

.worlds-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  max-height: 300px;
  overflow-y: auto;
}

.world-card {
  background: rgba(30, 30, 30, 0.85);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  cursor: pointer;
  overflow: hidden;
  transition: all 0.2s ease;
  position: relative;
}

.world-card:hover {
  border-color: rgba(74, 144, 217, 0.6);
  transform: translateY(-2px);
}

.world-card-checkbox {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 18px;
  height: 18px;
  cursor: pointer;
  z-index: 10;
  accent-color: #4a90d9;
}

.world-card-delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: rgba(220, 53, 69, 0.8);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s, background 0.2s;
}

.world-card:hover .world-card-delete-btn {
  opacity: 1;
}

.world-card-delete-btn:hover {
  background: rgba(220, 53, 69, 1);
}

.world-thumbnail {
  width: 100%;
  height: 100px;
  background: linear-gradient(180deg, #4a7c59, #2d5a3d);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.world-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.world-thumbnail .placeholder-icon {
  font-size: 32px;
  color: rgba(255,255,255,0.3);
}

.world-info {
  padding: 10px 12px;
}

.world-name {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.world-date {
  color: rgba(255,255,255,0.5);
  font-size: 11px;
}

.empty-state {
  color: rgba(255,255,255,0.4);
  font-size: 14px;
  padding: 20px;
  text-align: center;
  grid-column: 1 / -1;
}

/* Dialog Overlay */
.dialog-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.7);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 400;
}

.dialog-content {
  background: rgba(30,30,30,0.95);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  text-align: center;
}

.dialog-content h3 {
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

#world-name-input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0,0,0,0.4);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

#world-name-input:focus {
  border-color: #4a90d9;
}

#world-name-input::placeholder {
  color: rgba(255,255,255,0.4);
}

.dialog-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.dialog-buttons button {
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.dialog-buttons button.danger {
  background: linear-gradient(135deg, #dc3545, #c82333);
  color: #fff;
  border: none;
}

.dialog-buttons button.danger:hover {
  background: linear-gradient(135deg, #e85c6b, #d6334c);
}

#save-world-btn {
  background: linear-gradient(135deg, #4a90d9, #357abd);
  color: #fff;
  border: none;
}

#save-world-btn:hover {
  background: linear-gradient(135deg, #5a9fe9, #458ace);
}

#cancel-save-btn,
#cancel-delete-btn {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.8);
  border: 2px solid rgba(255,255,255,0.2);
}

#cancel-save-btn:hover,
#cancel-delete-btn:hover {
  background: rgba(255,255,255,0.15);
}

/* ===== Pause Overlay ===== */
#pause-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.4);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 50;
  cursor: pointer;
}

#pause-overlay p {
  color: #fff;
  font-size: 18px;
  text-shadow: 0 1px 6px rgba(0,0,0,0.6);
}

/* ===== Break Particles ===== */
#particles-container {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 8;
}

.break-particle {
  position: absolute;
  width: 6px;
  height: 6px;
  pointer-events: none;
  animation: particleFly 0.6s ease-out forwards;
}

@keyframes particleFly {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0.3);
  }
}

/* ===== Controls Hint ===== */
#controls-hint {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255,255,255,0.6);
  font-size: 14px;
  text-align: center;
  z-index: 5;
  pointer-events: none;
  display: none;
  line-height: 2;
  text-shadow: 0 1px 3px rgba(0,0,0,0.7);
}
