/* ============ 全局 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0d1117;
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  color: #e8e8e8;
}

#app { position: fixed; inset: 0; }

#game-canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }

.hidden { display: none !important; }

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

#crosshair {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255,255,255,0.9);
  font-size: 26px; line-height: 1;
  text-shadow: 0 0 2px rgba(0,0,0,0.8), 0 1px 2px rgba(0,0,0,0.7);
  mix-blend-mode: difference;
}
#crosshair span { display: block; transform: translateY(-2px); }

#health, #hunger, #oxygen {
  position: absolute; display: flex; gap: 1px;
  left: 50%; transform: translateX(-50%);
}
#health  { bottom: 84px; }
#hunger  { bottom: 64px; }
#oxygen  { bottom: 44px; }
#health img, #hunger img, #oxygen img {
  width: 18px; height: 18px; image-rendering: pixelated;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6));
}

#hotbar {
  position: absolute; bottom: 8px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 2px;
  background: rgba(12,12,14,0.55);
  border: 2px solid rgba(255,255,255,0.25);
  border-radius: 4px; padding: 2px;
}

.hslot {
  width: 44px; height: 44px; position: relative;
  background: rgba(30,30,34,0.75);
  border: 2px solid rgba(0,0,0,0.6);
  border-radius: 3px;
  transition: transform 0.1s ease;
}
.hslot.selected {
  border-color: #fff;
  box-shadow: 0 0 6px rgba(255,255,255,0.55), inset 0 0 8px rgba(255,255,255,0.18);
  animation: slot-pop 0.22s ease-out;
}
@keyframes slot-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.14); }
  100% { transform: scale(1.06); }
}
.hslot .num {
  position: absolute; left: 2px; top: 0;
  font-size: 11px; color: rgba(255,255,255,0.85);
  text-shadow: 0 1px 2px #000;
}
.hslot img, .hslot canvas { width: 40px; height: 40px; }
.hslot img { image-rendering: pixelated; }
.hslot .count {
  position: absolute; right: 2px; bottom: 0;
  font-size: 13px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000;
}

#fps {
  position: absolute; left: 8px; top: 8px;
  font-size: 12px; color: rgba(255,255,255,0.75);
  text-shadow: 0 1px 2px #000;
  font-family: Consolas, monospace;
}

/* ============ 通用界面（背包/工作台/熔炉/暂停）============ */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,8,12,0.45);
  backdrop-filter: blur(3px);
}

.panel {
  position: relative;
  background: rgba(22,24,30,0.94);
  border: 2px solid rgba(255,255,255,0.18);
  border-radius: 10px;
  padding: 18px 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.65);
  max-width: 96vw; max-height: 94vh; overflow: auto;
  pointer-events: auto;
}
.small-panel { width: 340px; }

/* 面板右上角关闭按钮（移动端点背包后也能退出；触屏高亮反馈） */
.btn-close {
  position: absolute; top: 10px; right: 10px;
  width: 30px; height: 30px;
  border: 2px solid rgba(255,255,255,0.35);
  border-radius: 50%;
  background: rgba(30,32,40,0.85);
  color: #ffd54a; font-size: 15px; line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.btn-close:active { background: #ffd54a; color: #16181e; }
.btn-close .close-x { display: block; transform: translateY(-1px); }

.panel-title {
  text-align: center; font-size: 20px; font-weight: bold;
  color: #ffd54a; margin-bottom: 14px;
  text-shadow: 0 1px 2px #000;
  padding-right: 32px;
}

.inv-layout { display: flex; gap: 26px; align-items: flex-start; }
.inv-left { min-width: 200px; }
.inv-right { min-width: 350px; }

.label {
  font-size: 13px; color: #9aa4b2; margin: 10px 0 6px;
  letter-spacing: 1px;
}

.craft-area { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.arrow { font-size: 26px; color: #ffd54a; text-shadow: 0 1px 2px #000; transition: transform 0.08s; user-select: none; }
.arrow { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.arrow:active { transform: scale(1.2); color: #fff6a0; }
.big-arrow { font-size: 34px; }

.grid { display: grid; gap: 2px; }
.grid2 { grid-template-columns: repeat(2, 46px); }
.grid3 { grid-template-columns: repeat(3, 46px); }
.grid10 { grid-template-columns: repeat(10, 46px); }

/* 槽位 */
.slot {
  width: 46px; height: 46px; position: relative;
  background: rgba(10,10,14,0.9);
  border: 2px solid rgba(120,120,130,0.55);
  border-radius: 3px;
  cursor: default;
}
.slot.big { width: 52px; height: 52px; }
.slot:hover { border-color: rgba(255,255,255,0.9); background: rgba(40,40,48,0.9); }
.slot.hover-source { border-color: #ffd54a; }
.slot img, .slot canvas { width: 100%; height: 100%; display: block; }
.slot img { image-rendering: pixelated; }
.slot .count {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 14px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000;
  pointer-events: none;
}
.slot .dur {
  position: absolute; left: 3px; right: 3px; bottom: 2px; height: 3px;
  background: rgba(0,0,0,0.55); border-radius: 1px; overflow: hidden;
  pointer-events: none;
}
.slot .dur i { display: block; height: 100%; background: #6ce86c; }
.slot .dur i.mid { background: #ffd54a; }
.slot .dur i.low { background: #ff5a5a; }

.out-slot {
  width: 56px; height: 56px; position: relative;
  background: rgba(10,10,14,0.9);
  border: 2px dashed rgba(255,213,74,0.7);
  border-radius: 4px;
}
.out-slot img { width: 100%; height: 100%; image-rendering: pixelated; }
.out-slot .count {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 14px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000;
}

/* 创造模式物品栏 */
.creative-panel { width: 620px; max-width: 94vw; }
.creative-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.ctab {
  padding: 7px 26px; font-size: 15px; font-weight: bold; color: #c9d1dc;
  background: rgba(40,44,54,0.9); border: 2px solid rgba(120,120,130,0.55);
  border-radius: 6px 6px 0 0; cursor: pointer;
}
.ctab:hover { border-color: rgba(255,255,255,0.8); }
.ctab.active { color: #1d1d1d; background: #ffd54a; border-color: #ffd54a; }
.creative-grid {
  display: grid; grid-template-columns: repeat(6, 46px);
  gap: 2px; justify-content: center;
  height: 170px; overflow-y: auto;
  padding: 6px;
  border: 1px solid rgba(255,255,255,0.12); border-radius: 6px;
  background: rgba(10,10,14,0.35);
}
.creative-grid::-webkit-scrollbar { width: 10px; }
.creative-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.28); border-radius: 5px; }
.creative-grid::-webkit-scrollbar-track { background: rgba(255,255,255,0.06); }
.creative-hotbar-area { display: flex; flex-direction: column; align-items: center; margin-top: 14px; }
.creative-hotbar-area .label { margin-top: 0; }
#creative-hotbar .slot.selected { border-color: #ffd54a; box-shadow: 0 0 6px rgba(255,213,74,0.55); }

.inv-tips { margin-top: 14px; font-size: 12px; color: #8b93a0; line-height: 1.8; }

.panel-close-hint {
  text-align: center; margin-top: 14px;
  font-size: 12px; color: #6b7280;
}

/* 熔炉 */
.furnace-layout { display: flex; gap: 26px; align-items: center; flex-wrap: wrap; }
.fn-left, .fn-mid { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.fn-right { display: flex; align-items: center; }
.fn-help { font-size: 12px; color: #8b93a0; line-height: 1.8; max-width: 260px; }
.fn-gauge { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #9aa4b2; }
.gauge {
  width: 52px; height: 14px; background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.25); border-radius: 2px;
  overflow: hidden;
}
.gauge.wide { width: 120px; height: 18px; }
.gauge .gauge-fill { height: 100%; width: 0%; transition: width 0.15s linear; }

/* 按钮 */
.btn {
  display: block; width: 100%;
  padding: 11px 18px; margin: 8px 0;
  font-size: 16px; font-family: inherit;
  color: #fff; background: #2f3542;
  border: 2px solid rgba(255,255,255,0.22);
  border-radius: 6px; cursor: pointer;
  transition: all 0.12s;
}
.btn:hover { background: #3d4453; border-color: rgba(255,255,255,0.5); transform: translateY(-1px); }
.btn.primary { background: #1e6f3f; border-color: #2ea35a; }
.btn.primary:hover { background: #268a50; }
.btn.danger { background: #6e1f1f; border-color: #a33a2e; }
.btn.danger:hover { background: #8a2828; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn.small { padding: 6px 12px; font-size: 13px; width: auto; display: inline-block; margin: 4px; }

/* ============ 帮助面板合成配方表 ============ */
.help-panel { max-height: 86vh; overflow-y: auto; }
.help-recipes {
  margin: 14px 0 4px; padding: 12px; text-align: left;
  background: rgba(0,0,0,0.35); border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 14px; line-height: 1.9;
}
.recipes-title { color: #ffd54a; font-weight: bold; margin-bottom: 6px; letter-spacing: 1px; }
.recipe-row { color: #dfe6f0; }
.recipe-row b { color: #fff; }
.recipe-row + .recipe-row { border-top: 1px dashed rgba(255,255,255,0.08); }

.menu-buttons { max-width: 300px; margin: 6px auto 0; }

/* ============ 死亡界面 ============ */
.death-title {
  text-align: center; font-size: 34px; font-weight: bold;
  color: #ff4444; text-shadow: 0 2px 6px rgba(255,0,0,0.5);
  margin: 6px 0;
}
.death-sub { text-align: center; color: #9aa4b2; margin-bottom: 10px; font-size: 14px; }
.death-panel { border-color: rgba(255,60,60,0.5); }

/* ============ 主菜单 ============ */
#menu { position: fixed; inset: 0; z-index: 30; }
.menu-bg {
  position: absolute; inset: 0;
  background: linear-gradient(160deg, rgba(10,20,40,0.82) 0%, rgba(16,40,75,0.78) 45%, rgba(10,25,16,0.82) 100%);
  overflow: hidden;
}
.menu-bg::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(90,160,255,0.18), transparent 55%),
    radial-gradient(ellipse at 80% 70%, rgba(70,220,140,0.14), transparent 55%);
  animation: pulse 6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 0.7; } 50% { opacity: 1; } }

.menu-box {
  position: relative; z-index: 2;
  max-width: 460px; margin: 0 auto;
  padding: 8vh 32px 0; text-align: center;
}
.menu-title {
  font-size: 52px; letter-spacing: 2px; color: #fff;
  text-shadow: 0 3px 14px rgba(60,140,255,0.55);
  margin-bottom: 4px;
}
.menu-title .accent { color: #ffd54a; }
.menu-sub { color: #9fb4d8; margin-bottom: 30px; font-size: 15px; letter-spacing: 3px; }

.menu-seed-row { max-width: 340px; margin: 0 auto 6px; text-align: left; }
.menu-seed-row .label { display: block; margin: 0 0 4px; }
.menu-mode-row { max-width: 340px; margin: 0 auto 12px; text-align: left; display: flex; align-items: center; gap: 8px; }
.menu-mode-row .label { display: inline; margin: 0; }
.mode-btn {
  padding: 5px 16px; font-size: 13px; font-family: inherit; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.35); border-radius: 5px;
  background: rgba(0,0,0,0.35); color: rgba(255,255,255,0.7);
  transition: all 0.1s;
}
.mode-btn.active { background: #ffd54a; color: #16181e; border-color: #ffd54a; font-weight: bold; }
.mode-btn:not(.active):active, .mode-btn:not(.active):hover { background: rgba(255,255,255,0.15); color: #fff; }
#seed-input {
  width: 100%; padding: 9px 12px; font-size: 15px; font-family: inherit;
  color: #fff; background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; outline: none;
}
#seed-input:focus { border-color: #ffd54a; }
.save-info { margin-top: 12px; font-size: 13px; color: #8b93a0; min-height: 20px; }

.menu-footer {
  position: absolute; bottom: 14px; width: 100%; text-align: center;
  font-size: 12px; color: rgba(255,255,255,0.4); z-index: 2;
}

/* 主菜单漂浮方块装饰 */
.menu-bg .float-cube {
  position: absolute; border-radius: 6px;
  animation: floaty 7s ease-in-out infinite;
  opacity: 0.5;
  box-shadow: inset -8px -8px 12px rgba(0,0,0,0.4), inset 6px 6px 10px rgba(255,255,255,0.12);
}
@keyframes floaty {
  0%,100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-36px) rotate(10deg); }
}

/* ============ 操作说明 ============ */
#help-overlay { z-index: 40; }
.help-panel { width: 460px; }
.help-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px;
  font-size: 14px; line-height: 1.7;
}
.help-grid kbd {
  display: inline-block; padding: 1px 7px; margin-right: 2px;
  background: #2b313d; border: 1px solid rgba(255,255,255,0.3);
  border-bottom-width: 3px; border-radius: 4px;
  font-size: 12px; font-family: Consolas, monospace; color: #ffd54a;
}

/* ============ 命令控制台 ============ */
#console {
  position: fixed; left: 0; right: 0; top: 0;
  height: 40%; max-height: 320px;
  z-index: 45;
  display: flex; flex-direction: column;
  background: rgba(8, 10, 16, 0.88);
  border-bottom: 2px solid rgba(255, 213, 74, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-family: Consolas, "Courier New", monospace;
  padding: 10px 16px;
}

#console-log {
  flex: 1; overflow-y: auto;
  font-size: 13px; line-height: 1.7;
  color: #d8d8d8;
  white-space: pre-wrap; word-break: break-all;
}
#console-log .cmd { color: #9fb4d8; }
#console-log .err { color: #ff6b6b; }
#console-log .ok  { color: #7ee87e; }
#console-log .info { color: #8b93a0; }

.console-input-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.console-prompt { color: #ffd54a; font-size: 15px; font-weight: bold; }
#console-input {
  flex: 1;
  background: transparent; border: none; outline: none;
  color: #fff; font-family: inherit; font-size: 14px;
  caret-color: #ffd54a;
}

/* ============ 鼠标手持物品 / 提示 ============ */
#cursor-item {
  position: fixed; z-index: 50; width: 46px; height: 46px;
  pointer-events: none; transform: translate(-50%, -50%);
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.7));
}
#cursor-item img { width: 100%; height: 100%; image-rendering: pixelated; }
#cursor-item .count {
  position: absolute; right: 3px; bottom: 1px;
  font-size: 14px; font-weight: bold; color: #fff;
  text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000;
}

#tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: rgba(12,8,24,0.95); border: 1px solid rgba(120,60,220,0.6);
  color: #fff; font-size: 13px; padding: 4px 10px; border-radius: 4px;
  white-space: nowrap;
}

#toast {
  position: fixed; left: 50%; top: 18%; z-index: 70;
  transform: translateX(-50%);
  background: rgba(20,24,32,0.9); border: 1px solid rgba(255,213,74,0.6);
  color: #ffd54a; font-size: 15px; padding: 10px 22px; border-radius: 6px;
  transition: opacity 0.4s; pointer-events: none;
}

/* ============ 触屏虚拟按键（移动端）============ */
#touch-ui { display: none; }
#touch-ui.visible { display: block; }
.touch-ui {
  position: fixed; inset: 0; z-index: 15;
  pointer-events: none; /* 容器不拦，子元素自接管 */
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
.touch-ui .joy-wrap {
  position: absolute; left: 24px; bottom: 26px;
  width: 130px; height: 130px; pointer-events: auto;
  background: radial-gradient(circle, rgba(255,255,255,0.08) 0%, rgba(255,255,255,0.03) 60%, transparent 70%);
  border: 2px solid rgba(255,255,255,0.18); border-radius: 50%;
  z-index: 2; opacity: 0.80;
}
.touch-ui .joy-base {
  position: absolute; left: 50%; top: 50%;
  width: 100px; height: 100px;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(255,255,255,0.22);
  border-radius: 50%;
}
.touch-ui .joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, rgba(255,255,255,0.85), rgba(160,180,220,0.85));
  border-radius: 50%;
  box-shadow: 0 3px 10px rgba(0,0,0,0.5);
  transition: transform 0.04s linear;
}
.touch-ui .joy-wrap.active .joy-base { border-color: rgba(255,213,74,0.5); }
.touch-ui .joy-wrap.active { opacity: 1; background: radial-gradient(circle, rgba(255,255,255,0.13) 0%, rgba(255,255,255,0.05) 60%, transparent 70%); }

/* 视角触摸区：铺满全屏（摇杆与按钮 zone 在其上层，优先响应） */
.touch-ui .look-zone {
  position: absolute; inset: 0;
  pointer-events: auto;
  touch-action: none;
  z-index: 1;
}

/* 按钮面板（屏幕右下，左侧留出摇杆区） */
.touch-ui .touch-pad {
  position: absolute; right: 76px; bottom: 14px;
  display: grid;
  grid-template-columns: 52px 52px 52px;
  grid-template-rows: 52px 52px;
  gap: 8px;
  pointer-events: auto;
  z-index: 3;
}
.touch-ui .tbtn {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: 12px;
  background: rgba(36,42,56,0.45);
  border: 2px solid rgba(255,255,255,0.25);
  color: #fff; text-shadow: 0 1px 3px #000;
  touch-action: none;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s, background 0.1s;
}
.touch-ui .tbtn:active, .touch-ui .tbtn.pressed {
  background: rgba(100,160,230,0.5);
  border-color: #ffd54a;
  transform: scale(0.92);
}
.touch-ui .tbtn-glyph { font-size: 22px; line-height: 1; pointer-events: none; }
.touch-ui .tbtn-label { font-size: 9px; color: rgba(255,255,255,0.65); margin-top: 1px; pointer-events: none; }
.touch-ui .btn-jump { background: rgba(60,120,200,0.45); border-color: rgba(100,180,255,0.5); }
.touch-ui .btn-jump:active, .touch-ui .btn-jump.pressed { background: rgba(80,160,240,0.55); }
.touch-ui .btn-attack { background: rgba(180,50,50,0.4); border-color: rgba(255,100,80,0.5); }
.touch-ui .btn-attack:active, .touch-ui .btn-attack.pressed { background: rgba(220,70,50,0.55); }
.touch-ui .btn-interact { background: rgba(40,140,80,0.4); border-color: rgba(80,220,130,0.5); }
.touch-ui .btn-interact:active, .touch-ui .btn-interact.pressed { background: rgba(60,180,100,0.55); }

/* 右侧边栏一排按钮 */
.touch-ui .touch-side {
  position: absolute; right: 6px; top: 50%;
  transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: auto;
  z-index: 3;
}
.touch-ui .touch-side .tbtn {
  width: 48px; height: 48px;
  border-radius: 10px;
  background: rgba(28,34,46,0.55);
  border-color: rgba(255,255,255,0.2);
}
.touch-ui .touch-side .tbtn-glyph { font-size: 18px; }
.touch-ui .touch-side .tbtn-label { display: none; }
.touch-ui .touch-side .side-fly .tbtn-label { display: block; font-size: 11px; margin-top: 1px; }
.touch-ui .touch-side .side-fly { background: rgba(30, 111, 63, 0.85); border-color: #2ea35a; }
.touch-ui .touch-side .side-fly.pressed { background: #4bd07a; color: #0c2013; }
.touch-ui .touch-side .side-fly.flying { background: #ffd54a; color: #16181e; border-color: #fff6a0; animation: flyPulse 1.2s ease-in-out infinite; }
@keyframes flyPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,213,74,0.6); } 50% { box-shadow: 0 0 10px 3px rgba(255,213,74,0.5); } }

/* 横屏时按钮紧凑 */
@media (orientation: landscape) {
  .touch-ui .touch-pad { right: 62px; gap: 6px; grid-template-columns: 48px 48px 48px; }
  .touch-ui .touch-pad .tbtn { width: 48px; height: 48px; }
  .touch-ui .touch-side { right: 4px; gap: 6px; }
  .touch-ui .touch-side .tbtn { width: 42px; height: 42px; }
  .touch-ui .joy-wrap { left: 16px; bottom: 16px; width: 110px; height: 110px; }
  .touch-ui .joy-knob { width: 46px; height: 46px; }
  .touch-ui .joy-base { width: 84px; height: 84px; }
}
