* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #0a0e1a; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #f3ead6;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
}
#scene { position: fixed; inset: 0; display: block; width: 100%; height: 100%; }

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

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; gap: 18px; align-items: center;
  padding: 10px 16px;
  font-size: 14px; letter-spacing: .04em;
  background: linear-gradient(to bottom, rgba(10,14,26,.72), rgba(10,14,26,0));
  text-shadow: 0 1px 2px #000;
  flex-wrap: wrap;
}
#topbar #clock { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 16px; }
#topbar #sun, #topbar #weather { color: #d9c9a3; }
#topbar #coords { margin-left: auto; color: #9fb0c9; font-size: 12px; }
#topbar #build {
  margin-left: 10px; padding: 1px 7px; border-radius: 3px;
  color: #8a9ab0; font-size: 11px; cursor: default;
  border: 1px solid rgba(159, 176, 201, .3); background: rgba(10, 14, 26, .35);
}
/* 顶栏唯一一处「世界之外」的状态：在线人数。
   时间/天气/坐标都是「你在这个世界里看到的」，这个不是 ——
   所以它用另一种颜色（冷灰 → 在线时转草绿），一眼分得清。 */
#topbar #netbtn {
  margin-left: 8px; padding: 2px 9px; border-radius: 4px;
  font-size: 11.5px; letter-spacing: .04em; cursor: pointer;
  color: #8a9ab0; border: 1px solid rgba(159, 176, 201, .3); background: rgba(10, 14, 26, .35);
  pointer-events: auto;
}
#topbar #netbtn:hover { color: #f3ead6; border-color: #d8a657; }
#topbar #netbtn.on { color: #cfe3b8; border-color: #7fb069; background: rgba(24, 40, 22, .6); }

#crosshair {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px;
  transform: translate(-50%, -50%);
  border: 1.5px solid rgba(255,255,255,.85); border-radius: 50%;
  box-shadow: 0 0 4px #000; pointer-events: none;
}

#status {
  position: absolute; left: 14px; bottom: 14px;
  display: flex; flex-direction: column; gap: 8px; width: 190px;
}
.meter { display: grid; grid-template-columns: 34px 1fr 44px; gap: 8px; align-items: center; font-size: 12px; }
.meter label { color: #d9c9a3; }
.meter .track { height: 9px; border-radius: 5px; background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.15); overflow: hidden; }
.meter .fill { height: 100%; width: 100%; background: #7fb069; transition: width .3s linear; }
.meter[data-k="temp"] .fill { background: #e08a5a; }
.meter[data-k="thirst"] .fill { background: #5aa6e0; }
.meter .val { text-align: right; font-variant-numeric: tabular-nums; color: #e6dcc2; }

#hint {
  position: absolute; left: 50%; bottom: 96px; transform: translateX(-50%);
  font-size: 13px; color: #f3ead6; background: rgba(10,14,26,.6);
  padding: 6px 14px; border-radius: 14px; opacity: 0; transition: opacity .25s;
  max-width: 80vw; text-align: center;
}
#hint.show { opacity: 1; }

#prompt {
  position: absolute; left: 50%; top: calc(50% + 18px); transform: translateX(-50%);
  font-size: 13px; color: #f6efdd; background: rgba(10,14,26,.62);
  padding: 5px 12px; border-radius: 12px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.12); opacity: 0; transition: opacity .15s;
}
#prompt.show { opacity: 1; }

#inv {
  position: absolute; right: 14px; bottom: 14px; max-width: 46vw;
  display: flex; flex-wrap: wrap; gap: 6px 8px; justify-content: flex-end; align-items: center;
  font-size: 12px;
}
#inv .slot { background: rgba(10,14,26,.55); border: 1px solid rgba(255,255,255,.14); border-radius: 8px; padding: 3px 8px; color: #eadfc4; pointer-events: auto; cursor: pointer; }
#inv .slot:hover { background: rgba(58,45,32,.85); }
#inv .slot i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
#inv .slot b { color: #fff; }
#inv .empty { color: #8d97a8; font-style: italic; }
#inv .w { background: rgba(10,14,26,.7); border: 1px solid rgba(255,255,255,.16); border-radius: 8px; padding: 3px 8px; color: #cbb98f; font-variant-numeric: tabular-nums; }

#actions { position: absolute; right: 16px; bottom: 64px; display: none; flex-direction: column; gap: 10px; pointer-events: auto; }
body.touch #actions { display: flex; }
/* AI 按钮在 #actions 里，跟着一起显示即可。
   之前这里给 #btn-ai 写了 position:absolute + body.touch 下 display:none，
   结果真机（body.touch）上按钮被主动藏起来 —— 修掉。 */
#btn-ai { font-size: 12px; color: #d8a657; border-color: #a8865c; }
#btn-ai.on { color: #f3ead6; border-color: #d8a657; background: rgba(58,45,32,.95); }
#actions button, #craft button {
  font: inherit; color: #f3ead6; background: rgba(58,45,32,.9); border: 1px solid #7a6543;
  border-radius: 10px; padding: 10px 16px; cursor: pointer; letter-spacing: .1em;
}
#actions button:active { background: #4a3a29; }

/* ============ 图鉴（dex.js） ============ */
#kb-dex { display: flex; flex-direction: column; gap: 10px; }

.dx-bar { display: flex; gap: 6px; flex-wrap: wrap; }
.dx-tab {
  font: inherit; font-size: 12px; color: #b39b74;
  background: rgba(30,24,16,.7); border: 1px solid #5a4a33;
  border-radius: 8px; padding: 5px 11px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.dx-tab i { font-style: normal; font-size: 10px; color: #7a705c; }
.dx-tab.on { color: #f3ead6; border-color: #a8865c; background: rgba(58,45,32,.9); }
.dx-tab.on i { color: #cbb98f; }

.dx-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 6px; max-height: 32vh; overflow-y: auto; padding-right: 4px;
}
.dx-cell {
  text-align: left; font: inherit; cursor: pointer;
  background: rgba(24,22,18,.8); border: 1px solid #3a3229;
  border-left: 3px solid #5a4a33;
  border-radius: 8px; padding: 7px 9px; color: #d8ccae;
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.dx-cell b { font-size: 13px; font-weight: 500; }
.dx-cell i { font-style: normal; font-size: 10px; color: #8a7d64; }
.dx-cell.got { border-left-color: #a8865c; }
.dx-cell.sel { background: rgba(58,45,32,.95); border-color: #d8a657; }
.dx-c-ore   { border-left-color: #7a9ab8; }
.dx-c-item  { border-left-color: #8a7d64; }
.dx-c-recipe{ border-left-color: #6f9a7a; }
.dx-c-element { border-left-color: #a87ab8; }

.dx-detail {
  background: rgba(24,22,18,.9); border: 1px solid #5a4a33;
  border-radius: 10px; padding: 12px; overflow-y: auto; max-height: 40vh;
}
.dx-title {
  font-size: 15px; font-weight: 500; color: #f3ead6;
  margin-bottom: 9px; display: flex; align-items: center; gap: 7px;
}
.dx-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dx-own, .dx-lock {
  font-style: normal; font-size: 10px; padding: 2px 6px; border-radius: 5px;
}
.dx-own { color: #cfe0b8; background: rgba(90,120,60,.3); }
.dx-lock { color: #8a7d64; background: rgba(60,50,40,.4); }

.dx-sec {
  font-size: 11px; color: #a8865c; letter-spacing: .08em;
  margin: 12px 0 5px; padding-bottom: 3px; border-bottom: 1px solid #3a3229;
}
.dx-sec:first-of-type { margin-top: 4px; }

.dx-kv { width: 100%; border-collapse: collapse; font-size: 12px; }
.dx-kv th {
  text-align: left; vertical-align: top; white-space: nowrap;
  color: #8a7d64; font-weight: 400; padding: 3px 10px 3px 0; width: 1%;
}
.dx-kv td { color: #d8ccae; padding: 3px 0; line-height: 1.55; }
.dx-kv b { color: #d8a657; font-weight: 500; }

.dx-note { font-size: 12px; color: #8a7d64; line-height: 1.6; }

.dx-chain { font-size: 12px; line-height: 2; }
.dx-chain em { font-style: normal; color: #6a5f4a; margin: 0 4px; }
.dx-node {
  display: inline-block; padding: 2px 7px; border-radius: 6px;
  border: 1px solid #4a4034; background: rgba(40,34,26,.7); color: #b3a48a;
}
.dx-node i { font-style: normal; font-size: 10px; color: #7a705c; margin-left: 5px; }
.dx-lit   { border-color: #6f8a4a; background: rgba(70,90,45,.28); color: #cfe0b8; }
.dx-open  { border-color: #a8865c; color: #e0cfa8; }
.dx-locked{ border-color: #3a3229; color: #7a705c; }
.dx-target{ border-color: #d8a657; background: rgba(90,70,35,.35); color: #f3ead6; }

/* AI 代玩面板：右上角浮层，羊皮纸/石板基调，跟知识面板一致 */
#ai {
  position: absolute; right: 16px; top: 56px; z-index: 45; width: 320px;
  pointer-events: auto; animation: fadeIn .18s ease;
}
#ai.hidden { display: none; }
.ai-box {
  background: rgba(24,22,18,.94); border: 1px solid #7a6543; border-radius: 8px;
  box-shadow: 0 8px 26px rgba(0,0,0,.5); overflow: hidden;
}
.ai-head {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  background: rgba(58,45,32,.7); border-bottom: 1px solid #4a3a29; color: #f3ead6;
}
.ai-head strong { font-size: 13px; font-weight: 600; }
.ai-model { font-size: 11px; color: #b39b74; }
.ai-head #ai-close {
  margin-left: auto; background: none; border: none; color: #b39b74;
  font-size: 18px; line-height: 1; cursor: pointer;
}
.ai-head #ai-close:hover { color: #f3ead6; }
.ai-body { padding: 11px 12px; min-height: 88px; }
.ai-thinking { font-size: 12px; color: #8a9ab0; margin-bottom: 6px; }
.ai-last { font-size: 13px; color: #f3ead6; margin-bottom: 8px; }
.ai-act { display: block; font-weight: 600; }
.ai-conf { font-size: 11px; color: #6fa8d8; margin-left: 6px; }
.ai-urg { font-size: 11px; color: #d8a657; margin-left: 6px; }
.ai-p { display: flex; align-items: center; gap: 7px; font-size: 11px; color: #8a9ab0; margin: 3px 0; }
.ai-p span { flex: 0 0 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-p i { flex: 1; height: 3px; background: linear-gradient(90deg,#7a6543,#a8865c); border-radius: 2px; }
.ai-p b { flex: 0 0 30px; text-align: right; font-weight: 500; }
/* 行走条：结构固定，只改 textContent/width —— 不重建 DOM，所以不闪 */
.ai-walking {
  display: flex; align-items: center; gap: 8px; padding: 6px 9px; margin-bottom: 7px;
  background: rgba(58,45,32,.5); border: 1px solid #5a4a33; border-radius: 6px;
  font-size: 12px; color: #cbb98f;
}
.ai-walking[hidden] { display: none; }
.ai-walk-ico {
  flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%;
  background: #d8a657; animation: aiPulse 1.1s ease-in-out infinite;
}
@keyframes aiPulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
.ai-walk-bar {
  flex: 1; height: 3px; border-radius: 2px; background: rgba(0,0,0,.35);
  overflow: hidden; display: block;
}
.ai-walk-bar b {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #7a6543, #d8a657);
  border-radius: 2px; transition: width .22s linear;
}
@media (prefers-reduced-motion: reduce) {
  .ai-walk-ico { animation: none; }
  .ai-walk-bar b { transition: none; }
}
.ai-hint { font-size: 11px; color: #b39b74; margin-top: 8px; line-height: 1.55; }
.ai-hint code { background: #1a1a18; padding: 1px 4px; border-radius: 3px; font-size: 10px; }
.ai-foot {
  display: flex; align-items: center; gap: 9px; padding: 8px 12px;
  border-top: 1px solid #3a3229; font-size: 11px; color: #8a9ab0;
}
.ai-foot #ai-toggle {
  font: inherit; font-size: 12px; color: #f3ead6; background: rgba(58,45,32,.9);
  border: 1px solid #7a6543; border-radius: 6px; padding: 5px 12px; cursor: pointer;
}
.ai-foot label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.ai-stat { margin-left: auto; font-size: 11px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; } }

/* ══ 弹层公共版式：制作 / 定居 / 储物箱 ══
   ⚠️ 三处必须**共用同一条规则**，不许各抄一份。踩过的坑：版式抄了三份，
     给后两份补了 `max-height + overflow` 却漏掉制作面板 —— 116 条配方把
     .craft-box 撑到 20478px（视口 702px），flex 居中把顶部推到 -9888px，
     标题和关闭按钮全在屏幕外，且滚不动。浏览器实测复现。
   三个维度缺一不可，少一个都会重演：
     · max-height    —— 不设它，内容多高盒子就多高
     · overflow-y    —— 不设它，超出的部分既看不见也够不着
     · touch-action  —— body 上禁用了手势（见文件顶部），这里不放行，
                        桌面能用滚轮滚、真机上手指划不动 */
#craft, #settle, #box, #login {
  position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(6,8,14,.55); pointer-events: auto;
}
#craft .craft-box, #settle .craft-box, #box .craft-box, #login .craft-box {
  width: min(460px, 92vw);
  max-height: 84vh; overflow-y: auto; touch-action: pan-y;
  overscroll-behavior: contain;      /* 划到底别把身后的场景带着弹 */
  scrollbar-width: thin; scrollbar-color: #4a3f2e transparent;
  background: rgba(24,20,14,.96); border: 1px solid #7a6543; border-radius: 12px;
  padding: 18px; box-shadow: 0 10px 40px #000;
}
.craft-box::-webkit-scrollbar { width: 8px; }
.craft-box::-webkit-scrollbar-thumb { background: #4a3f2e; border-radius: 4px; }
.craft-box h3 { font-size: 15px; letter-spacing: .14em; color: #e6d3a8; margin-bottom: 12px; }
/* 三级导航的表头：返回键只在第二、三级出现，标题跟着层级换 */
.craft-box .craft-head {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
  position: sticky; top: -18px; z-index: 2;      /* 滚长列表时标题不跟着走 */
  background: rgba(24,20,14,.96); padding: 6px 0 2px; margin-top: -6px;
}
.craft-box .craft-head h3 { margin-bottom: 0; flex: 1; }
#craft-back {
  font: inherit; font-size: 12px; color: #c8b790; background: rgba(48,38,26,.9);
  border: 1px solid #6a583b; border-radius: 8px; padding: 5px 11px; cursor: pointer;
  letter-spacing: .06em; flex: 0 0 auto;
}
#craft-back:active { background: #4a3a29; }

/* ============ 多人登录（P6.8.1 · js/net.js） ============
   复用 .craft-box 的版式（弹层 + 滚动三件套），只补表单那几行。
   ⚠️ 面板 id 是 #login，但盒子用 .craft-box —— 这是故意的：
      check-docs 的「弹层必须能滚动」那节是按 .craft-box 找盒子的，
      新弹层套用同一个类，就自动被那道守卫罩住，不用再教它认第二个类名。 */
#login .net-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
#login .net-head h3 { margin-bottom: 0; flex: 1; }
#login .net-note { font-size: 11.5px; color: #8d8570; line-height: 1.7; margin-bottom: 14px; }
#login .net-note b { color: #c8b790; font-weight: 500; }
#login .net-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
#login .net-row span { width: 42px; flex: 0 0 auto; font-size: 12.5px; color: #d9c9a3; }
#login .net-row input {
  flex: 1; min-width: 0; font: inherit; font-size: 13px; color: #f3ead6;
  background: rgba(10,14,26,.6); border: 1px solid #5a4a33; border-radius: 8px;
  padding: 9px 11px; letter-spacing: .04em;
}
#login .net-row input::placeholder { color: #6d6656; }
#login .net-row input:focus { outline: none; border-color: #a8865c; }
#login .net-row input:disabled { opacity: .5; }
#login .net-captcha-line {
  display: flex; align-items: center; gap: 10px; margin: -2px 0 4px 52px;
  font-size: 13px; color: #d9c9a3; letter-spacing: .04em;
}
#login .net-captcha-line #net-captcha-q { flex: 1; font-variant-numeric: tabular-nums; }
#login .net-captcha-line button {
  font: inherit; font-size: 11.5px; color: #c8b790; background: transparent;
  border: 1px solid #5b4d36; border-radius: 7px; padding: 3px 9px; cursor: pointer;
}
#login .net-captcha-line button:hover { color: #f3ead6; border-color: #a8865c; }
#login .net-acts { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
#login .net-acts button {
  font: inherit; flex: 1; min-width: 96px; color: #f3ead6; background: rgba(58,45,32,.9);
  border: 1px solid #7a6543; border-radius: 10px; padding: 10px 16px; cursor: pointer;
  letter-spacing: .1em;
}
#login .net-acts button:active { background: #4a3a29; }
#login .net-msg { min-height: 16px; margin-top: 10px; font-size: 12px; color: #c8b790; }
#login .net-msg.bad { color: #e0705a; }
#login .net-state { margin-top: 2px; font-size: 11.5px; color: #8d8570; line-height: 1.6; }
#login .net-skip {
  font: inherit; font-size: 12px; margin-top: 14px; width: 100%; letter-spacing: .06em;
  color: #9aa8bd; background: rgba(10,14,26,.5); border: 1px solid rgba(159,176,201,.28);
  border-radius: 8px; padding: 8px 14px; cursor: pointer;
}
#login .net-skip:active { background: rgba(30,40,56,.8); }
#login #net-close {
  font: inherit; font-size: 17px; line-height: 1; padding: 0 4px; cursor: pointer;
  color: #9a8a6c; background: none; border: none;
}
#login #net-close:hover { color: #f3ead6; }

/* ── 第一级：分类网格 ── */
#craft .cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
@media (max-width: 420px) { #craft .cat-grid { grid-template-columns: 1fr; } }
#craft .cat-card {
  text-align: left; font: inherit; cursor: pointer;
  background: rgba(38,31,21,.85); border: 1px solid rgba(255,255,255,.13);
  border-radius: 10px; padding: 11px 13px; color: #f3ead6;
}
#craft .cat-card:active { background: rgba(58,45,32,.95); }
#craft .cat-card .cc-top { display: flex; align-items: baseline; gap: 6px; }
#craft .cat-card .cc-name { font-size: 13.5px; letter-spacing: .04em; flex: 1; }
/* 能做的 / 全部 —— 一眼看出这分类里现在有几件活得干得动 */
#craft .cat-card .cc-n { font-size: 11.5px; color: #8d8570; font-variant-numeric: tabular-nums; }
#craft .cat-card .cc-n.has { color: #a9cf8f; }
#craft .cat-card .cc-desc { font-size: 11px; color: #8d8570; margin-top: 4px; line-height: 1.5; }

/* ── 第二级：物品列表 ── */
#craft .rrow {
  display: flex; align-items: center; gap: 9px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.12); border-radius: 9px;
  padding: 9px 12px; margin-bottom: 7px;
}
#craft .rrow:active { background: rgba(58,45,32,.7); }
#craft .rrow.ok { border-color: rgba(127,176,105,.55); }
#craft .rrow i { flex: 0 0 11px; height: 11px; border-radius: 3px; }
#craft .rrow .rn { flex: 1; font-size: 13px; color: #f3ead6; }
#craft .rrow .rs { flex: 0 0 auto; font-size: 11px; }
#craft .rrow .rs.ok { color: #a9cf8f; }
#craft .rrow .rs.no { color: #8d8570; }
#craft .rrow .rc { flex: 0 0 auto; font-size: 11px; color: #6a6252; }

/* ── 第三级：详情 ── */
#craft .rdetail .rname { font-size: 15px; }
#craft .rdetail .rback-line { margin-bottom: 4px; }
/* 原料不够的那一样标红 —— 「缺哪样」比「缺几样」更有用 */
.craft-box .rneed .lack { color: #d98a6a; }
.craft-box .recipe { border: 1px solid rgba(255,255,255,.12); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.craft-box .recipe.ok { border-color: #7fb069; }
.craft-box .rname { font-size: 14px; color: #f3ead6; }
.craft-box .rneed { font-size: 12px; color: #c8b790; margin-top: 4px; }
.craft-box .rnote { font-size: 11px; color: #8d8570; margin-top: 3px; line-height: 1.6; }
.craft-box .rwhy { font-size: 11px; color: #d98a6a; margin-top: 3px; }
.craft-box .recipe button { margin-top: 8px; padding: 7px 16px; }
.craft-box .recipe button[disabled] { opacity: .4; cursor: not-allowed; }
#craft #craft-close, #settle #settle-close, #box #box-close { display: block; margin: 4px auto 0; }

/* 三段进度条：「分阶段」这件事得让人一眼看见走到哪了 */
#settle .stgbar { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
#settle .stg {
  font-size: 10.5px; letter-spacing: .04em; color: #8d8570;
  border: 1px solid rgba(255,255,255,.14); border-radius: 999px; padding: 2px 8px;
}
#settle .stg.ok { color: #a9cf8f; border-color: #5c7f46; }
#settle .stg.now { color: #f3ead6; border-color: #d8a657; background: rgba(216,166,87,.12); }

#box .bxsect {
  font-size: 11.5px; color: #b39b74; letter-spacing: .08em;
  margin: 12px 0 6px; padding-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.10);
}
#box .bxsect:first-child { margin-top: 0; }
#box .bxempty { font-size: 12px; color: #6f6857; padding: 4px 2px; }
#box .bxrow { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #e6dcc4; padding: 3px 0; }
#box .bxrow i { flex: 0 0 12px; height: 12px; border-radius: 3px; display: inline-block; }
#box .bxrow .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#box .bxrow .n { flex: 0 0 46px; text-align: right; color: #c8b790; }
#box .bxrow button { margin: 0; padding: 4px 9px; font-size: 11px; }
#box .bxfoot { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
#box .bxfoot button { padding: 7px 14px; }
#box .bxfoot button[disabled] { opacity: .4; cursor: not-allowed; }
#box .bxfoot .rnote { font-size: 11px; color: #8d8570; margin: 0; }

#joystick {
  position: absolute; left: 26px; bottom: 92px; width: 130px; height: 130px;
  border-radius: 50%; background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.18); display: none;
  pointer-events: auto;
}
#joystick #knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(243,234,214,.35); border: 1.5px solid rgba(243,234,214,.7);
}
body.touch #joystick { display: block; }

#loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  font-size: 15px; color: #cbb98f; letter-spacing: .08em;
}

#fatal {
  position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 60;
  padding: 12px 16px; border-radius: 8px;
  background: rgba(80,12,12,.94); color: #ffe3d6;
  font: 13px/1.5 ui-monospace, Consolas, monospace;
  white-space: pre-wrap; word-break: break-all;
  border: 1px solid #b04141; box-shadow: 0 4px 18px #000;
  pointer-events: auto; max-height: 45vh; overflow: auto;
}

#deadscreen {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: radial-gradient(circle at 50% 40%, rgba(60,10,10,.85), rgba(6,4,4,.97));
  pointer-events: auto; text-align: center; padding: 24px;
}
#deadscreen h1 { font-size: 46px; letter-spacing: .3em; color: #d64545; text-shadow: 0 2px 12px #000; }
#deadscreen p { color: #e6c9a8; font-size: 15px; }
#deadscreen p.sub { color: #8d7f6b; font-size: 13px; }
#deadscreen button {
  margin-top: 10px; padding: 12px 30px; font-size: 15px; letter-spacing: .15em;
  color: #f3ead6; background: #3a2d20; border: 1px solid #7a6543; border-radius: 8px; cursor: pointer;
}
#deadscreen button:hover { background: #4a3a29; }
.hidden { display: none !important; }

/* ══════════════════════════════════════════════════════
   知识面板：元素周期表 + 知识树
   延续羊皮纸/石板基调，与既有 HUD 一致
   ══════════════════════════════════════════════════════ */
#knowledge {
  position: absolute; inset: 0; z-index: 25;
  display: flex; flex-direction: column;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(58,46,32,.96), rgba(12,14,20,.985) 70%),
    rgba(10,12,18,.97);
  pointer-events: auto;
  padding: 12px 16px 16px;
  overflow: hidden;
}

.kb-head { display: flex; gap: 10px; align-items: center; flex: 0 0 auto; padding-bottom: 10px; }
.kb-tab {
  font: inherit; font-size: 14px; letter-spacing: .08em; cursor: pointer;
  padding: 7px 18px; border-radius: 6px;
  color: #b9a982; background: rgba(30,26,20,.7); border: 1px solid #5a4c36;
  transition: all .16s ease;
}
.kb-tab:hover { color: #e8d9b4; background: rgba(48,40,29,.85); }
.kb-tab.active { color: #f3ead6; background: #3d3325; border-color: #8a7350; box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.kb-close {
  margin-left: auto; font: inherit; font-size: 20px; line-height: 1; cursor: pointer;
  width: 32px; height: 32px; border-radius: 6px;
  color: #b9a982; background: rgba(30,26,20,.7); border: 1px solid #5a4c36;
}
.kb-close:hover { color: #e8d9b4; background: rgba(60,40,32,.85); }

.kb-body { flex: 1 1 auto; overflow: auto; padding-right: 4px; }
.kb-body::-webkit-scrollbar { width: 8px; }
.kb-body::-webkit-scrollbar-thumb { background: #4a3f2e; border-radius: 4px; }

.dim { color: #7d7461; font-size: 12px; }

/* ── 元素周期表 ── */
.pt-head { display: flex; align-items: baseline; gap: 14px; margin-bottom: 12px; }
.pt-head h3 { font-size: 17px; font-weight: 600; letter-spacing: .12em; color: #e8d9b4; }
.pt-count { font-size: 13px; color: #9c8f75; }
.pt-count b { color: #e8c46a; font-size: 17px; }

.ptable { display: inline-block; min-width: 100%; }
.prow { display: grid; grid-template-columns: repeat(18, 1fr); gap: 3px; }
.ecell {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 4px; border: 1px solid rgba(0,0,0,.45); cursor: pointer;
  font-size: 10px; line-height: 1.1; user-select: none;
  transition: transform .1s ease, filter .12s ease;
  position: relative;
}
.ecell:hover { transform: scale(1.12); filter: brightness(1.3); z-index: 2; }
.ecell .ez { font-size: 8px; opacity: .65; }
.ecell .es { font-size: 13px; font-weight: 600; }
.ecell.empty { background: transparent; border: none; cursor: default; }
.ecell.empty:hover { transform: none; filter: none; }

/* 未获得：只有序号，暗淡 —— 保留探索感，不剧透名字 */
.ecell.dark {
  background: rgba(28,26,22,.6); border: 1px solid #37332a;
  color: #5c5648;
}
.ecell.dark .es { font-size: 12px; font-weight: 500; }
.ecell.lit { color: #16130e; border: 1px solid rgba(0,0,0,.6); box-shadow: inset 0 1px 0 rgba(255,255,255,.25); }
.ecell.lit .ez { color: rgba(0,0,0,.55); }
.ecell.lit .es { color: #14110c; }

/* 分类配色（低饱和土色系，贴合羊皮纸） */
.e-alkali     { background: #d98b6a; }
.e-alkaline   { background: #d9a86a; }
.e-transition { background: #c9a86a; }
.e-post       { background: #a8b884; }
.e-metalloid  { background: #8fb8a8; }
.e-nonmetal   { background: #8fa8c9; }
.e-halogen    { background: #b89ad9; }
.e-noble      { background: #d9c46a; }
.e-lanth      { background: #c98ab8; }
.e-actin      { background: #b87a8a; }

.frow { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.flabel {
  width: 44px; flex: 0 0 auto; font-size: 10px; color: #9c8f75;
  text-align: right; letter-spacing: .04em;
}
.fcells { display: grid; grid-template-columns: repeat(15, 1fr); gap: 3px; flex: 1 1 auto; max-width: 780px; }

.pt-legend { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; font-size: 10px; }
.pt-legend span { padding: 3px 8px; border-radius: 3px; color: #16130e; }

.pt-detail { margin-top: 8px; min-height: 120px; }
.pd { display: flex; gap: 16px; align-items: flex-start; padding: 12px; background: rgba(22,20,16,.7); border: 1px solid #3a352a; border-radius: 8px; }
.pd .bohr { flex: 0 0 auto; }
.pd-main { flex: 1 1 auto; min-width: 0; }
.pd-head { display: flex; align-items: baseline; gap: 10px; }
.pd-z { font-size: 13px; color: #8b8067; }
.pd-sym { font-size: 24px; font-weight: 700; color: #e8c46a; }
.pd-name { font-size: 18px; color: #f3ead6; }
.pd-line { font-size: 12px; color: #9c8f75; margin-top: 3px; }
.pd-src { font-size: 13px; color: #cfc3a4; margin-top: 8px; line-height: 1.6; }
.pd-src b { color: #d9c9a3; font-size: 11px; letter-spacing: .06em; }
.pd-tier { font-size: 11px; color: #7d7461; margin-top: 6px; }
.pd-unknown { padding: 16px; background: rgba(22,20,16,.7); border: 1px solid #3a352a; border-radius: 8px; }
.pd-unknown .pd-sym { font-size: 24px; color: #5c5648; }
.pd-lock { font-size: 13px; color: #a8935f; margin-top: 6px; }
.pd-hint { font-size: 11px; color: #7d7461; margin-top: 6px; }

/* ── 知识树 ── */
.kt-stat { font-size: 12px; color: #9c8f75; margin-bottom: 8px; }
.kt-stat b { color: #e8c46a; font-size: 15px; }

.kt-wrap { overflow-x: auto; padding-bottom: 6px; }
.kt-cols { min-width: 1180px; }
.kt-headrow, .kt-row { display: grid; grid-template-columns: 80px repeat(9, 1fr); gap: 6px; }
.kt-headrow { margin-bottom: 6px; }
.kt-era {
  text-align: center; font-size: 11px; letter-spacing: .06em; color: #9c8f75;
  padding: 5px 2px; border-bottom: 1px solid #3a352a;
}
.kt-era-name { white-space: nowrap; }
.kt-blabel {
  font-size: 11px; color: #8b8067; display: flex; align-items: center; justify-content: flex-end;
  padding-right: 4px; text-align: right;
}
.kt-cell { display: flex; flex-direction: column; gap: 5px; min-height: 34px; }

.tnode {
  padding: 6px 7px; border-radius: 5px; cursor: pointer;
  border: 1px solid #3a352a; background: rgba(30,28,22,.75);
  transition: all .14s ease; user-select: none;
}
.tnode .tn-name { font-size: 11.5px; color: #8b8067; line-height: 1.25; }
.tnode .tn-el { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 3px; }
.tnode .tn-el i { font-style: normal; font-size: 8.5px; padding: 1px 3px; border-radius: 2px; background: rgba(200,180,130,.16); color: #9c8f75; }

.tnode.locked { opacity: .55; }
.tnode.locked .tn-name { color: #6a6355; }
.tnode.open { border-color: #8a7350; background: rgba(62,50,32,.7); }
.tnode.open .tn-name { color: #cfc3a4; }
.tnode.lit { border-color: #c9743a; background: rgba(96,62,34,.75); box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.tnode.lit .tn-name { color: #f3ead6; font-weight: 600; }
.tnode.planned { opacity: .34; border-style: dashed; border-color: #44403a; }
.tnode.planned .tn-name { color: #5c5648; }
.tnode:hover { filter: brightness(1.35); transform: translateX(1px); }
.tnode.sel { outline: 1.5px solid #e8c46a; outline-offset: 1px; }

.kt-detail { margin-top: 14px; }
.kd { padding: 12px 14px; background: rgba(22,20,16,.75); border: 1px solid #3a352a; border-radius: 8px; }
.kd-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.kd-name { font-size: 17px; font-weight: 600; color: #f3ead6; }
.kd-status { font-size: 10.5px; padding: 2px 7px; border-radius: 3px; letter-spacing: .05em; }
.kd-lit { background: rgba(201,116,58,.28); color: #e8a877; }
.kd-open { background: rgba(138,115,80,.28); color: #d9c9a3; }
.kd-locked { background: rgba(70,66,56,.4); color: #8b8067; }
.kd-planned { background: rgba(60,56,48,.4); color: #7d7461; }
.kd-note { font-size: 13px; color: #cfc3a4; line-height: 1.65; }
.kd-meta { font-size: 11.5px; color: #9c8f75; margin-top: 8px; line-height: 1.7; }
.kd-meta b { color: #7d7461; font-weight: 500; }
.kd-in { font-size: 11.5px; color: #8b8067; margin-top: 5px; }

/* ── 地图（v0.3.47）──
   这一块刻意**不跟着暗色主题走成深色**：它画的就是一块熟革，
   所以纸面是米黄色、字是褐色 —— 与元素周期表/知识树用暗底不同。
   这不是配色不一致，是「地图是一件东西」的直接体现：
   它得长得像一块被带在身上的皮子，而不是像一块界面面板。 */
.map-wrap { max-width: 720px; }
.map-canvas-box {
  border-radius: 8px; overflow: hidden;
  box-shadow: 0 3px 14px rgba(0,0,0,.5), inset 0 0 0 1px rgba(255,255,255,.06);
  /* 皮子摆在深色桌面上：外面一圈暗，里面才是纸 —— 这层对比就是「手工感」的来源 */
  padding: 3px; background: rgba(20,17,13,.7);
}
.map-canvas-box canvas { display: block; width: 100%; height: auto; border-radius: 6px; }
.map-legend {
  display: flex; flex-wrap: wrap; gap: 12px;
  font-size: 11.5px; color: #9c8f75; margin-top: 9px;
}
.map-legend span { letter-spacing: .02em; }
.map-legend .map-me { color: #c9743a; }
.map-note { margin-top: 7px; line-height: 1.7; }
.map-lock {
  padding: 20px 22px; border-radius: 8px;
  background: rgba(22,20,16,.6); border: 1px dashed #4a4234;
  color: #cfc3a4; line-height: 1.85; font-size: 13px;
}
.map-lock p { margin: 0 0 6px; }
.map-lock p:last-child { margin-bottom: 0; }
.map-lock b { color: #e8d9b4; }
.map-lock .dim { margin-top: 10px; line-height: 1.75; }

/* ── 触屏适配：面板按钮加大、知识面板可滚动 ── */
body.touch #knowledge { padding: 16px 12px; }
body.touch .kb-tab { padding: 10px 20px; font-size: 15px; }
body.touch .ecell .es { font-size: 12px; }
body.touch .tnode { padding: 8px; }
body.touch .tnode .tn-name { font-size: 12px; }
