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

html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  background: #000;
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
}

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

#hurt {
  position: fixed;
  inset: 0;
  background: rgba(255, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 15;
}

.hidden { display: none !important; }

/* 覆盖层 */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 28, 0.82);
  backdrop-filter: blur(3px);
  z-index: 20;
}

.panel {
  background: rgba(20, 26, 44, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 32px 40px;
  min-width: 340px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.panel.wide { min-width: 560px; max-width: 90vw; max-height: 88vh; overflow: auto; }

.panel h1 { font-size: 34px; margin-bottom: 4px; }
.panel h1 span { font-size: 16px; color: #7fdc6f; vertical-align: middle; }
.panel h2 { font-size: 24px; margin-bottom: 18px; }
.subtitle { color: #b8c4d8; margin-bottom: 22px; }

.panel label { display: block; margin-bottom: 16px; color: #cdd7e8; font-size: 14px; }
.panel input {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: #12182a;
  color: #fff;
  outline: none;
}
.panel input:focus { border-color: #7fdc6f; }

.panel button {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 11px;
  font-size: 15px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: #232c44;
  color: #fff;
  cursor: pointer;
  transition: background 0.12s;
}
.panel button:hover { background: #2d3856; }
.panel button.primary { background: #3fae4a; border-color: #3fae4a; }
.panel button.primary:hover { background: #4cc458; }

.tips { margin-top: 18px; color: #93a1b8; font-size: 12.5px; line-height: 1.9; }

#loading-text { margin-top: 14px; font-size: 15px; color: #7fdc6f; }

/* 方块库 */
#library-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.lib-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  background: #1a2236;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  color: #cdd7e8;
  font-size: 11px;
  cursor: pointer;
}
.lib-item:hover { border-color: #7fdc6f; background: #232c44; }
.lib-item img { width: 32px; height: 32px; image-rendering: pixelated; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
}
#crosshair::before, #crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.9);
  mix-blend-mode: difference;
}
#crosshair::before { left: 50%; top: 0; width: 2px; height: 100%; margin-left: -1px; }
#crosshair::after { top: 50%; left: 0; height: 2px; width: 100%; margin-top: -1px; }

#info {
  position: absolute;
  top: 12px;
  left: 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  background: rgba(0, 0, 0, 0.25);
  padding: 8px 10px;
  border-radius: 6px;
}

#vitals {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 180px;
  align-items: flex-end;
}
.vital-row { display: flex; align-items: center; gap: 6px; width: 100%; }
.vital-icon { width: 16px; font-size: 14px; text-align: center; }
.bar-track {
  flex: 1;
  height: 10px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  overflow: hidden;
}
.bar { height: 100%; width: 100%; transition: width 0.15s; }
.bar.health { background: linear-gradient(180deg, #ff5b5b, #c62828); }
.bar.hunger { background: linear-gradient(180deg, #ffc66d, #b9771e); }

#death-screen .panel { border-color: rgba(255, 90, 90, 0.5); }
#death-screen h2 { color: #ff6b6b; }

#hotbar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.35);
  padding: 6px;
  border-radius: 8px;
}
.slot {
  position: relative;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  cursor: pointer;
}
.slot.selected { border-color: #fff; background: rgba(255, 255, 255, 0.22); }
.slot img { width: 40px; height: 40px; image-rendering: pixelated; }
.slot span {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.7);
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.12s;
  pointer-events: none;
}
.slot.selected span { opacity: 1; }

#toast {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  pointer-events: none;
}

/* 存档列表 / 种子分享 */
#save-list { margin-top: 16px; text-align: left; max-height: 40vh; overflow: auto; }
.save-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  margin-bottom: 8px;
  background: rgba(255, 255, 255, 0.04);
}
.save-info { flex: 1; font-size: 13px; color: #cdd7e8; line-height: 1.5; word-break: break-all; }
.save-row button { display: inline-block; width: auto; margin: 0; padding: 6px 12px; font-size: 13px; flex-shrink: 0; }
.save-row button.primary { background: #3fae4a; border-color: #3fae4a; }
.no-save { color: #93a1b8; text-align: center; padding: 10px; font-size: 13px; }

#pause-seed { color: #cdd7e8; font-size: 14px; margin: 4px 0 6px; }
#copy-seed-btn { display: inline-block; width: auto; margin: 0 0 10px; padding: 6px 14px; font-size: 13px; }

/* 模式选择 / 生存界面 */
.panel select {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 9px 12px;
  font-size: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: #12182a;
  color: #fff;
  outline: none;
}

#inventory-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
  margin: 12px 0;
}
.inv-slot {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  cursor: pointer;
}
.inv-slot.hot { border-color: #7fdc6f; }
.inv-slot img { width: 80%; height: 80%; image-rendering: pixelated; }
.inv-slot .cnt {
  position: absolute;
  right: 2px;
  bottom: 1px;
  font-size: 10px;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}

#recipe-list { text-align: left; }
.recipe-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04);
}
.recipe-info { flex: 1; font-size: 13px; color: #cdd7e8; }
.recipe-row button { display: inline-block; width: auto; margin: 0; padding: 6px 12px; font-size: 13px; flex-shrink: 0; }

/* 设置界面 */
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0;
  text-align: left;
}
.setting-row label { flex: 0 0 150px; color: #cdd7e8; font-size: 14px; }
.setting-row input[type="range"] { flex: 1; }
.setting-row select {
  flex: 1;
  padding: 8px 10px;
  font-size: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: #12182a;
  color: #fff;
}
#settings-screen h3 { margin: 18px 0 8px; text-align: left; }
#bind-list { text-align: left; }
.bind-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.04);
}
.bind-row .bind-name { flex: 1; color: #cdd7e8; font-size: 14px; }
.bind-row .bind-key {
  min-width: 90px;
  padding: 5px 10px;
  text-align: center;
  background: #12182a;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  color: #fff;
  font-size: 14px;
}
.bind-row button { display: inline-block; width: auto; margin: 0; padding: 5px 12px; font-size: 13px; }

/* 小地图 */
#minimap {
  position: absolute;
  right: 14px;
  bottom: 90px;
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-radius: 6px;
  background: rgba(10, 20, 40, 0.6);
  pointer-events: none;
}
