:root {
  --bg: #10131a;
  --panel: #171b24;
  --panel-2: #1e232e;
  --line: #2a3040;
  --text: #e6e9f0;
  --dim: #8b93a7;
  --accent: #6ee06e;
  --accent-dim: #2f5c33;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  /* iOS Safari 的 100vh 含地址栏，比真正的可视区高，底部信息条会被挤出屏幕 */
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
header h1 { font-size: 15px; margin: 0; letter-spacing: .5px; }
header nav { display: flex; gap: 6px; }
.version { margin-left: auto; color: var(--dim); font-size: 12px; }

button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
}
button { cursor: pointer; }
/* 触摸设备没有 hover，点下去要有反馈，否则像是没点中 */
@media (hover: hover) { button:hover { border-color: #3c465c; } }
button:active { background: #262c3a; }

.tab { background: transparent; border-color: transparent; color: var(--dim); }
.tab.active { background: var(--accent-dim); color: #d8ffd8; border-color: #3d7a42; }

#loading { padding: 40px; color: var(--dim); }

.panel { display: none; flex: 1; min-height: 0; }
.panel.active { display: flex; }

/* ---------- 生物 ---------- */
.sidebar {
  width: 280px;
  flex: none;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 10px;
  min-height: 0;
}
.sidebar input[type=search] { width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 99px; color: var(--dim); }
.chip.on { background: var(--accent-dim); color: #d8ffd8; border-color: #3d7a42; }
.count { font-size: 12px; color: var(--dim); }

.mob-list { flex: 1 1 0; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.mob-row {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border-color: transparent; text-align: left; padding: 5px 8px;
}
@media (hover: hover) { .mob-row:hover { background: var(--panel-2); } }
.mob-row:active { background: var(--panel-2); }
.mob-row.on { background: var(--accent-dim); border-color: #3d7a42; }
.mob-thumb {
  width: 32px; height: 32px; flex: none;
  image-rendering: pixelated;
  object-fit: cover;
  border-radius: 4px;
  background: #0c0e13;
}
.mob-name { display: flex; flex-direction: column; line-height: 1.25; overflow: hidden; }
.mob-name small { color: var(--dim); font-size: 11px; }

.stage { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
}
.stage-head h2 { margin: 0; font-size: 18px; }
.stage-head code { color: var(--dim); font-size: 12px; }
.stage-controls { margin-left: auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--dim); }
.stage-controls label { display: flex; align-items: center; gap: 5px; }
.stage-controls label, .stage-controls button { white-space: nowrap; }
.check input { width: auto; }
#speed { width: 90px; padding: 0; }

.canvas-wrap {
  flex: 1;
  min-height: 0;
  background: radial-gradient(circle at 50% 38%, #2b3550 0%, #141822 62%, #0d1016 100%);
}
#mob-canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
/* 长按 3D 视图不要弹出系统的选择 / 分享菜单 */
#mob-canvas, .art.viewer {
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#mob-canvas:active { cursor: grabbing; }

.stage-foot {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 18px; border-top: 1px solid var(--line); background: var(--panel);
}
.metas { display: flex; flex-wrap: wrap; gap: 8px; }
.meta {
  display: flex; gap: 6px; align-items: baseline;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 3px 9px; font-size: 12px;
}
.meta span { color: var(--dim); }
.meta.warn { border-color: #6b5a24; background: #2a2412; }
.meta.warn span, .meta.warn b { color: #e8c96a; }
.meta.bad { border-color: #7a3b34; background: #2d1a17; cursor: help; }
.meta.bad span, .meta.bad b { color: #f0907f; }
.row-warn { margin-left: auto; color: #f0907f; font-size: 12px; flex: none; }
.meta.warn { border-color: #7a5a2d; background: #2a2216; color: #e8c98a; }
.meta.warn span { color: #b99a5e; }
.hint { margin-left: auto; color: var(--dim); font-size: 12px; }
.only-coarse { display: none; }
@media (pointer: coarse) {
  .only-fine { display: none; }
  .only-coarse { display: inline; }
}

/* ---------- 物品 ---------- */
#panel-items { flex-direction: column; position: relative; }
.items-head {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--line); flex: none;
}
.items-head input[type=search] { width: 280px; }

.item-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px; padding: 16px; align-content: start;
}
.item-cell {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 4px; background: var(--panel); border-color: var(--line);
}
@media (hover: hover) { .item-cell:hover { background: var(--panel-2); border-color: var(--accent-dim); } }
.item-cell:active { background: var(--panel-2); border-color: var(--accent-dim); }
.item-cell img, .item-cell canvas { width: 40px; height: 40px; image-rendering: pixelated; }
.item-cell span {
  font-size: 11px; color: var(--dim); text-align: center; line-height: 1.25;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#item-backdrop { position: absolute; inset: 0; background: rgba(8, 10, 14, .55); display: none; }

#item-detail {
  position: absolute; right: 18px; bottom: 18px; width: 280px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 18px; box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
}
#item-detail h3 { margin: 14px 0 2px; font-size: 16px; }
#item-detail code { color: var(--dim); font-size: 12px; }
#item-detail .metas { margin-top: 12px; }
#item-detail-close {
  position: absolute; top: 8px; right: 8px; border-color: transparent;
  background: transparent; color: var(--dim); font-size: 18px; line-height: 1; padding: 2px 7px;
}

.art { height: 120px; display: flex; align-items: center; justify-content: center; }
.art.flat img { width: 96px; height: 96px; image-rendering: pixelated; }
.art.model canvas { image-rendering: pixelated; }
/* 详情里的可拖动 3D 预览 */
.art.viewer { height: 200px; display: block; cursor: grab; touch-action: none; }
.art.viewer:active { cursor: grabbing; }
.art.viewer canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

@media (max-width: 980px) {
  .sidebar { width: 210px; }
  .stage-controls { gap: 8px; }
}

/* 窄面板（比如嵌在 IDE 里）时把侧栏改成上下布局 */
@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 10px 14px; padding: 8px 12px; }
  header h1 { font-size: 14px; }
  .version { margin-left: 0; }

  /* iOS 上小于 16px 的输入框一聚焦就会把整页放大，而且不会退回去。
     只有会聚焦的文本框和下拉需要，按钮不触发，放大了反而占地方 */
  input[type=search], input[type=text], select { font-size: 16px; }

  #panel-mobs { flex-direction: column; }
  /* 上下按比例分，不要写死高度 —— 写死时 canvas 的 min-height 会把底部信息条顶出屏幕 */
  .sidebar {
    width: 100%;
    height: auto;
    flex: 1 1 38%;
    min-height: 150px;
    padding: 8px 12px;
    gap: 8px;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .stage { flex: 1 1 62%; }
  /* 面板太窄时分类标签改成单行横向滚动，省出列表空间 */
  .sidebar .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .sidebar .chip { white-space: nowrap; }
  .stage-head { padding: 8px 12px; gap: 8px 12px; }
  .stage-controls { margin-left: 0; }
  .canvas-wrap { min-height: 150px; }
  /* 信息条挤成一行横向滚动 —— 在 375 宽上它会折成三行，把自己顶出屏幕 */
  .stage-foot { flex-wrap: nowrap; overflow-x: auto; padding: 6px 12px; gap: 8px; }
  .stage-foot .metas { flex-wrap: nowrap; }
  .stage-foot .meta { white-space: nowrap; }
  .hint { margin-left: 0; white-space: nowrap; }

  .items-head { flex-wrap: wrap; padding: 10px 12px; }
  .items-head input[type=search] { width: 100%; }
  .item-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); padding: 12px; }
  /* 详情改成底部抽屉：加遮罩、点外面能关、内容自己滚 */
  #item-backdrop:not([hidden]) { display: block; }
  #item-detail {
    left: 0; right: 0; bottom: 0; top: auto; width: auto;
    border-radius: 14px 14px 0 0;
    max-height: 76%;
    overflow-y: auto;
    padding: 16px 14px 20px;
  }
  #item-detail-close { top: 4px; right: 4px; font-size: 22px; padding: 10px 16px; }
  .art.viewer { height: 34vh; max-height: 260px; }
  .art.flat img { width: 72px; height: 72px; }
}

/* 横屏手机：宽度够、高度不够。头尾压扁成单行，把纵向空间全留给 3D 视图 */
@media (max-height: 500px) {
  header { padding: 4px 12px; gap: 12px; }
  header h1 { font-size: 13px; }

  /* 即使宽度落进上面那个断点，横屏也保持左右分栏 */
  #panel-mobs { flex-direction: row; }
  .sidebar {
    width: 200px; height: auto; flex: none;
    padding: 8px; gap: 6px;
    border-right: 1px solid var(--line); border-bottom: none;
  }
  .sidebar .chips { flex-wrap: nowrap; overflow-x: auto; }
  .sidebar .chip { white-space: nowrap; }

  .stage-head { padding: 5px 12px; gap: 10px; flex-wrap: nowrap; overflow-x: auto; }
  .stage-head h2 { font-size: 14px; }
  .stage-head code { display: none; }
  .stage-controls { flex-wrap: nowrap; margin-left: auto; }
  .canvas-wrap { min-height: 0; }
  .stage-foot { padding: 4px 12px; gap: 8px; flex-wrap: nowrap; overflow-x: auto; }
  .stage-foot .hint { display: none; }
  .stage-foot .metas { flex-wrap: nowrap; }
  .stage-foot .meta { white-space: nowrap; }

  .items-head { padding: 6px 12px; }
  .art.viewer { height: 30vh; }
}
