/* ============================================================
   PUEI CRAFT · 游戏 UI
   容器使用 assets/ui 原始 PNG；透明槽位只负责交互和物品图片。
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #292d2a;
  --paper: #c6c6c6;
  --paper-hi: #f4f4f4;
  --paper-lo: #555b55;
  --green: #527e3f;
  --green-hi: #6a9b52;
  --gold: #f0cf75;
  --u: 2px;
  --hud-slot: 36px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0c1110;
  color: var(--ink);
  font-family: Consolas, "Courier New", "Microsoft YaHei", monospace;
  user-select: none;
  -webkit-user-select: none;
}

button, input, a { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}
.hidden, [hidden] { display: none !important; }
#game { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(7, 12, 11, .58);
}
.overlay.solid { background: #101714; }

/* ---------- 菜单 ---------- */
.panel {
  position: relative;
  width: min(340px, 92vw);
  padding: 20px;
  background: var(--paper);
  border: 2px solid #151815;
  box-shadow:
    inset 2px 2px 0 var(--paper-hi),
    inset -2px -2px 0 var(--paper-lo),
    8px 8px 0 rgba(0, 0, 0, .28);
}
.panel-title {
  margin: -20px -20px 18px;
  padding: 12px 16px;
  background: #303b33;
  color: #f5f5ed;
  font-size: 15px;
  letter-spacing: .08em;
  text-shadow: 2px 2px 0 #182019;
  box-shadow: inset 0 -2px 0 #1e2821;
}
.panel-sub, .panel-foot {
  text-align: center;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
.panel-sub { margin: -6px 0 16px; font-size: 11px; color: #525b54; }
.panel-foot { margin-top: 16px; font-size: 10px; color: #626b63; }
.menu { display: grid; gap: 10px; }

.btn {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 9px 14px;
  border: 2px solid #171a17;
  background: #858b85;
  color: #20251f;
  box-shadow: inset 2px 2px 0 #c9cec9, inset -2px -2px 0 #4d534d;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: #9ca39c; }
.btn:active { box-shadow: inset 2px 2px 0 #4d534d, inset -2px -2px 0 #c9cec9; }
.btn.primary { background: var(--green); color: #fff; text-shadow: 1px 2px 0 #2c4721; }
.btn.primary:hover { background: var(--green-hi); }

/* ---------- 加载与标题 ---------- */
.load-box { width: min(460px, 88vw); text-align: center; }
.logo {
  color: #dcf4cf;
  font-weight: 900;
  line-height: 1;
  letter-spacing: .05em;
  text-shadow: 0 3px 0 #334c2a, 0 6px 0 #1d2c19, 0 10px 24px #000;
}
.logo span { color: var(--gold); }
.load-box .logo { font-size: clamp(30px, 6vw, 52px); }
.load-status { min-height: 20px; margin: 24px 0 10px; color: #d7e1d8; font-size: 12px; }
.load-bar { height: 16px; padding: 3px; border: 2px solid #748075; background: #1d2720; }
.load-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--green-hi);
  box-shadow: inset 0 -3px 0 #3d692d;
  transition: width .18s linear;
}
.load-tip { margin-top: 14px; color: #78867b; font-size: 10px; letter-spacing: .12em; }

#titleScreen { background: transparent; }
.title-shade {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, rgba(15, 31, 24, .12), rgba(4, 9, 7, .82));
}
.title-wrap { position: relative; width: min(380px, 92vw); text-align: center; }
.logo.big { font-size: clamp(38px, 7vw, 68px); }
.title-sub {
  margin: 16px 0 30px;
  color: #d5dfd5;
  font-size: 11px;
  letter-spacing: .34em;
  text-shadow: 0 2px 3px #000;
}
.title-foot {
  margin-top: 22px;
  color: #a9b5aa;
  font-size: 10px;
  line-height: 1.8;
  text-shadow: 0 1px 2px #000;
}

/* ---------- 设置 ---------- */
.setting { margin: 16px 0; }
.setting label { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 12px; }
.setting label b { color: #3e6332; }
input[type="range"] {
  width: 100%;
  height: 8px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid #242a24;
  background: #555e56;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 22px;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid #1d231d;
  background: var(--green-hi);
  box-shadow: inset 2px 2px 0 #a4c791;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 20px;
  border: 2px solid #1d231d;
  border-radius: 0;
  background: var(--green-hi);
}
.settings-tip { margin: 16px 0; color: #5b645c; font-size: 10px; line-height: 1.6; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#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, .94);
  box-shadow: 0 0 1px 1px rgba(0, 0, 0, .85);
}
#crosshair::before { left: 8px; top: 0; width: 2px; height: 18px; }
#crosshair::after { left: 0; top: 8px; width: 18px; height: 2px; }

#hotbar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  display: grid;
  grid-template-columns: repeat(9, var(--hud-slot));
  gap: 0;
  padding: 3px;
  transform: translateX(-50%);
  border: 2px solid rgba(10, 13, 11, .9);
  background: rgba(42, 48, 43, .82);
  box-shadow: inset 0 0 0 2px rgba(211, 220, 211, .22), 0 3px 12px rgba(0, 0, 0, .35);
}
#hotbar .slot {
  position: relative;
  width: var(--hud-slot);
  height: var(--hud-slot);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(15, 18, 15, .85);
  background: rgba(139, 139, 139, .68);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, .32);
}
#hotbar .slot.active {
  z-index: 1;
  outline: 3px solid #f7f7ed;
  outline-offset: 1px;
  background: rgba(184, 190, 181, .85);
}
#hotbar img { width: 30px; height: 30px; object-fit: contain; image-rendering: pixelated; }
#hotbar .num {
  position: absolute;
  left: 2px;
  top: 1px;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #000;
}
#itemToast {
  position: absolute;
  left: 50%;
  bottom: 66px;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  text-shadow: 2px 2px 0 #111;
  opacity: 0;
  transition: opacity .2s;
}
#itemToast.show { opacity: 1; }
#hintChip {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(16, 24, 19, .76);
  color: #e0e7df;
  font-size: 10px;
  white-space: nowrap;
  transition: opacity .5s;
}
#hintChip.fade { opacity: 0; }
#toast {
  position: fixed;
  left: 50%;
  top: 64px;
  z-index: 90;
  transform: translateX(-50%);
  max-width: min(520px, 86vw);
  padding: 9px 14px;
  border: 1px solid #748074;
  background: rgba(25, 34, 28, .94);
  color: #f2f4ec;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}
#waterTint { position: absolute; inset: 0; background: rgba(38, 92, 168, .28); mix-blend-mode: multiply; }

/* ---------- 创造物品栏（tab_items / tab_item_search / tab_inventory） ---------- */
.inv-shell {
  /* 自动适配：4px/单位 ≈ 780×544；窗口不够时整体等比缩小 */
  --u: max(1px, min(4px, calc((100vh - 96px) / 152), calc((100vw - 40px) / 195)));
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--u) * 195);
  image-rendering: pixelated;
}

/* 标签栏：选中页向下压入面板 3u，与面板连成一体 */
.inv-topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 calc(var(--u) * 6);
}
.inv-tabbar { display: flex; align-items: flex-end; gap: calc(var(--u) * 1); }
.inv-tip {
  margin-bottom: calc(var(--u) * 5);
  color: #46504a;
  font-size: calc(var(--u) * 4.5);
  letter-spacing: .06em;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .5);
}
.inv-tab {
  display: flex;
  align-items: center;
  gap: calc(var(--u) * 2);
  height: calc(var(--u) * 16);
  padding: 0 calc(var(--u) * 3.5);
  border: var(--u) solid #000000;
  border-bottom: 0;
  background: #9b9b9b;
  box-shadow: inset var(--u) var(--u) 0 #ffffff,
              inset calc(var(--u) * -1) 0 0 #555555;
  color: #313131;
  font-size: calc(var(--u) * 5.5);
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
}
.inv-tab:hover { background: #b3b3b3; }
.inv-tab.active {
  height: calc(var(--u) * 19);
  margin-bottom: calc(var(--u) * -3);
  background: #c6c6c6;
  box-shadow: none;
  color: #111111;
}
.inv-tab svg { display: block; width: calc(var(--u) * 9); height: calc(var(--u) * 9); }

/* 面板本体：三张素材按标签切换，槽位全部由图片绘制 */
.inv-main {
  position: relative;
  z-index: 1;
  width: calc(var(--u) * 195);
  height: calc(var(--u) * 136);
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 100% 100%;
  image-rendering: pixelated;
  box-shadow: calc(var(--u) * 3) calc(var(--u) * 3) 0 rgba(0, 0, 0, .28);
}
.inv-main[data-tab="items"] { background-image: url("./assets/ui/tab_items.png"); }
.inv-main[data-tab="search"] { background-image: url("./assets/ui/tab_item_search.png"); }
.inv-main[data-tab="inventory"] { background-image: url("./assets/ui/tab_inventory.png"); }

/* 透明槽位层：与素材中的 9×5 网格逐格对齐（起点 8u/17u，步长 18u）
 * 槽位瓦片从 tab_items.png 裁出（assets/ui/slot_cell.png），由每个格子自己绘制，
 * 因此网格会跟物品图标一起滚动，不会出现背景与图标错位。 */
.ci-viewport {
  position: absolute;
  left: calc(var(--u) * 8);
  top: calc(var(--u) * 17);
  width: calc(var(--u) * 162);
  height: calc(var(--u) * 90);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  scroll-snap-type: y mandatory;
  background: #c6c6c6;
}
.ci-viewport.dragging { scroll-snap-type: none; }
.ci-viewport::-webkit-scrollbar { width: 0; height: 0; }
.ci-track, .ci-hotbar {
  display: grid;
  grid-template-columns: repeat(9, calc(var(--u) * 18));
  grid-auto-rows: calc(var(--u) * 18);
}
.ci-track { width: calc(var(--u) * 162); }
.ci-hotbar { position: absolute; left: calc(var(--u) * 8); top: calc(var(--u) * 111); }
.ci-cell {
  width: calc(var(--u) * 18);
  height: calc(var(--u) * 18);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background-color: transparent;
  background-image: url("./assets/ui/slot_cell.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  cursor: pointer;
  image-rendering: pixelated;
  scroll-snap-align: start;
}
.ci-cell.empty { cursor: default; }
.ci-cell:not(.empty):hover { box-shadow: inset 0 0 0 var(--u) rgba(255, 255, 255, .85); }
.ci-cell.active { box-shadow: inset 0 0 0 calc(var(--u) * 2) #f7f7ed; }
.ci-cell img {
  width: calc(var(--u) * 16);
  height: calc(var(--u) * 16);
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}
.ci-empty {
  position: absolute;
  left: calc(var(--u) * 8);
  top: calc(var(--u) * 17);
  width: calc(var(--u) * 162);
  height: calc(var(--u) * 90);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4a4a4a;
  font-size: calc(var(--u) * 6);
  pointer-events: none;
}

/* 搜索框：贴在素材预留的凹槽内（81u/5u，88×10u） */
.ci-search {
  position: absolute;
  left: calc(var(--u) * 81);
  top: calc(var(--u) * 5);
  width: calc(var(--u) * 88);
  height: calc(var(--u) * 10);
}
.ci-search input {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0 calc(var(--u) * 2);
  border: 0;
  background: transparent;
  color: #f4f4f4;
  font-size: calc(var(--u) * 5.5);
  letter-spacing: .02em;
  outline: none;
  caret-color: #ffffff;
  user-select: text;
  -webkit-user-select: text;
}
.ci-search input::placeholder { color: rgba(198, 198, 198, .7); }

/* 滚动条：轨道由素材绘制，滑块用 Scroller.png / Scroller_Disabled.png */
.ci-scroll {
  position: absolute;
  left: calc(var(--u) * 175);
  top: calc(var(--u) * 18);
  width: calc(var(--u) * 12);
  height: calc(var(--u) * 110);
}
.ci-thumb {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(var(--u) * 12);
  height: calc(var(--u) * 15);
  background-image: url("./assets/ui/Scroller.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  image-rendering: pixelated;
  cursor: grab;
  touch-action: none;
}
.ci-thumb.disabled {
  background-image: url("./assets/ui/Scroller_Disabled.png");
  cursor: default;
}
.ci-thumb.dragging { cursor: grabbing; }

/* 关闭按钮：与 tab_inventory.png 右下角红叉同位置同尺寸 */
.ci-close {
  position: absolute;
  left: calc(var(--u) * 172);
  top: calc(var(--u) * 111);
  width: calc(var(--u) * 18);
  height: calc(var(--u) * 18);
  padding: 0;
  border: 0;
  background: #ab7f7f;
  box-shadow: inset var(--u) var(--u) 0 #373737,
              inset calc(var(--u) * -1) calc(var(--u) * -1) 0 #ffffff;
  cursor: pointer;
}
.ci-close:hover { background: #c48f8f; }
.ci-close::before, .ci-close::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--u) * 13);
  height: calc(var(--u) * 2);
  margin: calc(var(--u) * -1) 0 0 calc(var(--u) * -6.5);
  background: #1f1f1f;
  transform: rotate(45deg);
}
.ci-close::after { transform: rotate(-45deg); }

.missing::after {
  content: attr(data-name);
  display: block;
  width: 90%;
  overflow: hidden;
  color: #fff;
  font-size: 7px;
  line-height: 1.1;
  text-align: center;
  text-shadow: 1px 1px 0 #222;
  pointer-events: none;
}

/* ---------- F3 ---------- */
#debug {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, max-content));
  justify-content: space-between;
  gap: 12px;
  color: #fff;
  font: 11px/1.55 Consolas, "Courier New", "Microsoft YaHei", monospace;
  white-space: pre;
  pointer-events: none;
}
.debug-column {
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(7, 12, 10, .72);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, .25);
}
.debug-column h2 { margin-bottom: 4px; color: var(--gold); font-size: 11px; letter-spacing: .08em; }
.debug-line { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.debug-line span { color: #aebbb0; }
.debug-line b { color: #fff; font-weight: 400; text-align: right; }

/* ---------- 触屏 ---------- */
#touchPad { position: fixed; inset: 0; z-index: 30; pointer-events: none; }
#touchPad .pad { position: absolute; bottom: 66px; display: grid; gap: 6px; pointer-events: auto; }
#touchPad .pad.left { left: 14px; grid-template-columns: repeat(3, 42px); }
#touchPad .pad.right { right: 14px; grid-template-columns: repeat(2, 48px); }
#touchPad button {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(20, 29, 23, .7);
  color: #fff;
  font-size: 11px;
  touch-action: none;
}

@media (max-width: 640px) {
  :root { --hud-slot: 32px; }
  #hotbar { bottom: 8px; }
  #hotbar img { width: 27px; height: 27px; }
  #itemToast { bottom: 57px; }
  .title-foot { display: none; }
  #debug { grid-template-columns: minmax(0, max-content); justify-content: start; font-size: 10px; }
}
/* 小屏时缩小创造物品栏，避免溢出 */
@media (max-width: 560px), (max-height: 480px) {
  .inv-shell { --u: max(1px, min(2.2px, calc((100vh - 80px) / 152), calc((100vw - 24px) / 195))); }
}
@media (max-width: 380px) {
  :root { --u: 1.65px; --hud-slot: 29px; }
  .overlay { padding: 10px; }
  #hotbar img { width: 24px; height: 24px; }
}
@media (max-height: 520px) {
  :root { --u: 1.45px; }
  .title-sub { margin-bottom: 16px; }
  .title-foot { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}

.logo-img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}
.logo.logo img { max-height: 64px; }
.logo.big img { max-height: 96px; }