* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --panel: rgba(18, 20, 24, 0.92);
  --border: #5a5f66;
  --accent: #6cc24a;
  --accent-dark: #4a8a33;
  --text: #e8eaed;
  --muted: #a7adb5;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #10131a;
  color: var(--text);
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: default;
}
#game.locked { cursor: none; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; }

#crosshair {
  position: absolute; left: 50%; top: 50%;
  width: 20px; height: 20px;
  margin: -10px 0 0 -10px;
  mix-blend-mode: difference;
}
#crosshair::before, #crosshair::after {
  content: ''; position: absolute; background: #fff;
}
#crosshair::before { left: 9px; top: 0; width: 2px; height: 20px; }
#crosshair::after { top: 9px; left: 0; height: 2px; width: 20px; }

/* 顶部指南针 */
#compass {
  position: absolute; left: 50%; top: 14px;
  transform: translateX(-50%);
  width: 300px; height: 30px;
  overflow: hidden;
  background: rgba(0, 0, 0, .32);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 4px;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}
#compass-strip { position: absolute; inset: 0; will-change: transform; }
#compass .tick {
  position: absolute; top: 12px;
  width: 1px; height: 6px;
  background: rgba(255, 255, 255, .45);
}
#compass .tick.major { top: 8px; height: 10px; background: #fff; }
#compass .tick.major::after {
  content: attr(data-label);
  position: absolute; left: 50%; top: -9px;
  transform: translateX(-50%);
  font-size: 11px; color: #fff;
  text-shadow: 1px 1px 2px #000;
  white-space: nowrap;
}
#compass .needle {
  position: absolute; left: 50%; top: 0;
  width: 2px; height: 100%;
  margin-left: -1px;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(108, 194, 74, .8);
}

/* 挖掘进度环（准星外圈） */
#mine-ring {
  position: absolute; left: 50%; top: 50%;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  --p: 0%;
  background: conic-gradient(rgba(255, 255, 255, .9) var(--p), rgba(0, 0, 0, .35) var(--p));
  -webkit-mask: radial-gradient(closest-side, transparent 74%, #000 76%);
  mask: radial-gradient(closest-side, transparent 74%, #000 76%);
}

/* 拾取提示 */
#pickup {
  position: absolute; left: 50%; bottom: 84px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  pointer-events: none;
}
#pickup .pk {
  display: flex; align-items: center; gap: 6px;
  padding: 2px 10px 2px 4px;
  background: rgba(0, 0, 0, .45);
  border-radius: 12px;
  font-size: 13px; color: #fff;
  text-shadow: 1px 1px 2px #000;
  animation: pkin .18s ease;
}
#pickup .pk i {
  width: 20px; height: 20px; display: block;
  background-size: cover; image-rendering: pixelated;
}
@keyframes pkin { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#hotbar {
  position: absolute; left: 50%; bottom: 18px;
  transform: translateX(-50%);
  display: flex; gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
}

.slot {
  position: relative;
  width: 52px; height: 52px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  image-rendering: pixelated;
  background-size: cover;
  transition: transform .08s ease, border-color .08s ease;
}
.slot.active {
  border-color: #fff;
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, .5), 0 6px 14px rgba(0, 0, 0, .5);
}
.slot .num {
  position: absolute; left: 3px; top: 1px;
  font-size: 10px; color: rgba(255, 255, 255, .65);
  text-shadow: 1px 1px 2px #000;
}
.slot { background-size: 80%; background-position: center; background-repeat: no-repeat; }
.slot .cnt {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 13px; font-weight: 700; color: #fff;
  text-shadow: 1px 1px 2px #000;
}
.slot .dur {
  position: absolute; left: 4px; right: 4px; bottom: 4px;
  height: 3px; border-radius: 2px; display: block;
}

#debug {
  position: absolute; left: 10px; top: 10px;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  font-family: Consolas, monospace;
  font-size: 13px; line-height: 1.6;
  white-space: pre;
}

#hint {
  position: absolute; right: 12px; bottom: 12px;
  font-size: 12px; color: rgba(255, 255, 255, 0.55);
  text-shadow: 1px 1px 2px #000;
}

#underwater-tint {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(30, 90, 170, .25), rgba(12, 45, 110, .55));
}

/* ---------- 全屏面板 ---------- */

.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 20px;
  background: linear-gradient(160deg, #1b2735 0%, #0d1117 60%, #090b10 100%);
  z-index: 10;
  overflow: auto;
  padding: 24px;
}
#pause, #inventory { background: rgba(6, 8, 12, 0.78); backdrop-filter: blur(3px); }
#loading { background: rgba(6, 8, 12, 0.9); }

.title { text-align: center; }
.title h1 {
  font-size: 54px; letter-spacing: 8px;
  background: linear-gradient(#dff5c8, #6cc24a);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 6px 24px rgba(108, 194, 74, .25);
}
.subtitle { color: var(--muted); margin-top: 6px; letter-spacing: 2px; }

.panel {
  width: min(620px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 26px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
.panel.narrow { width: min(380px, 100%); text-align: center; }
.panel h2 { margin-bottom: 16px; font-weight: 600; }

.row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.row label { width: 180px; color: var(--muted); font-size: 14px; }
.row input[type=text], .row select {
  flex: 1; padding: 8px 10px;
  background: #0e1116; color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
  font-size: 14px; outline: none;
}
.row input[type=text]:focus, .row select:focus { border-color: var(--accent); }
.row input[type=range] { flex: 1; accent-color: var(--accent); }

.buttons { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.buttons.vertical { flex-direction: column; }

button {
  flex: 1; min-width: 120px;
  padding: 11px 16px;
  background: #2a2f38; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 15px; cursor: pointer;
  transition: background .12s, transform .08s;
}
button:hover { background: #38404c; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent-dark); border-color: var(--accent); }
button.primary:hover { background: var(--accent); color: #10131a; }
button.danger:hover { background: #8a3333; }

.help { margin-top: 20px; border-top: 1px solid #2a2f38; padding-top: 14px; }
.help h3 { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.help ul { list-style: none; font-size: 13px; line-height: 2; color: #c6ccd4; }
.help b { color: var(--accent); }

.tip { font-size: 12px; color: var(--muted); font-weight: 400; }
#pause .tip { margin-top: 14px; }

/* ---------- 背包 / 合成 ---------- */

.inv-panel { width: auto; }
.craft-row { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 6px; }
.craft-arrow { font-size: 24px; color: var(--muted); }
.slot-grid { display: grid; gap: 4px; justify-content: center; }
.slot-grid.nine { grid-template-columns: repeat(9, 46px); }
.slot-grid.hot { margin-top: 10px; padding-top: 10px; border-top: 1px solid #333a45; }
.divider { height: 1px; background: #2a2f38; margin: 14px 0; }

.islot {
  position: relative;
  width: 46px; height: 46px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 4px;
  background-size: 82%; background-position: center; background-repeat: no-repeat;
  image-rendering: pixelated;
  cursor: pointer;
}
.islot:hover { background-color: rgba(255, 255, 255, .16); }
.islot.big { width: 58px; height: 58px; border-color: var(--accent); }
.islot .cnt {
  position: absolute; right: 2px; bottom: 0;
  font-size: 12px; font-weight: 700; color: #fff;
  text-shadow: 1px 1px 2px #000;
}
.islot .dur {
  position: absolute; left: 3px; right: 3px; bottom: 3px;
  height: 3px; border-radius: 2px; display: block;
}

/* 配方书 */
.book { margin-top: 14px; border-top: 1px solid #2a2f38; padding-top: 10px; }
.book-title { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
#recipe-list {
  display: flex; flex-wrap: wrap; gap: 5px;
  max-height: 132px; overflow-y: auto;
  padding: 2px;
}
.recipe {
  position: relative;
  width: 42px; height: 42px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(108, 194, 74, .45);
  border-radius: 4px;
  background-size: 80%; background-position: center; background-repeat: no-repeat;
  image-rendering: pixelated;
  cursor: pointer;
}
.recipe:hover { border-color: var(--accent); background-color: rgba(108, 194, 74, .18); }
.recipe.dim { opacity: .32; border-color: rgba(255, 255, 255, .12); }
.recipe .cnt {
  position: absolute; right: 2px; bottom: 0;
  font-size: 11px; font-weight: 700; color: #fff; text-shadow: 1px 1px 2px #000;
}

#cursor-stack {
  position: fixed; z-index: 40;
  width: 42px; height: 42px;
  margin: -21px 0 0 -21px;
  pointer-events: none;
  border: none; background-color: transparent;
}

#creative-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 8px;
  max-height: 52vh; overflow-y: auto;
  padding: 4px;
}
.inv-item {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 2px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid transparent; border-radius: 6px;
  cursor: pointer; font-size: 11px; color: var(--muted);
}
.inv-item:hover { border-color: var(--accent); background: rgba(108, 194, 74, .12); color: var(--text); }
.inv-item i {
  width: 40px; height: 40px; display: block;
  background-size: cover; image-rendering: pixelated;
  border-radius: 3px;
}

/* ---------- 其他 ---------- */

.loader { text-align: center; font-size: 18px; color: var(--muted); }
#loading-bar {
  width: 280px; height: 8px; margin-top: 14px;
  background: #232833; border-radius: 4px; overflow: hidden;
}
#loading-bar i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width .15s; }

#toast {
  position: fixed; left: 50%; bottom: 96px;
  transform: translateX(-50%);
  padding: 8px 18px;
  background: rgba(0, 0, 0, .7);
  border-radius: 20px;
  font-size: 14px;
  opacity: 0; transition: opacity .25s;
  pointer-events: none; z-index: 20;
}
#toast.show { opacity: 1; }
