/* ═══ 囤囤鼠的自动化工厂 · 深色工业科幻风 ═══ */
:root {
  --bg: #0b0f14; --panel: #121824; --panel2: #171f2e; --line: #26344a;
  --txt: #cfd9e6; --dim: #7a8aa0; --accent: #4ade80; --gold: #f4c95d;
  --danger: #e05a5a; --info: #5ac8e0;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--txt);
  font: 14px/1.5 "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  user-select: none;
}
#app {
  display: grid; height: 100vh;
  grid-template-columns: 200px 1fr 250px;
  grid-template-rows: 48px 1fr 44px;
  grid-template-areas: "top top top" "build map insp" "tool tool tool";
}
/* ── 顶栏 ── */
#topbar {
  grid-area: top; display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: linear-gradient(180deg, #141c2b, #101623); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 700; letter-spacing: .5px; color: #e8eef7; white-space: nowrap; }
.hud { display: flex; gap: 16px; flex: 1; overflow: hidden; }
.hud-item { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.hud-item i { font-style: normal; color: var(--dim); font-size: 12px; }
.hud-item b { font-variant-numeric: tabular-nums; }
.hud-item.gold b { color: var(--gold); }
#hudPower.warn { color: var(--info); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .4; } }
#speedBar { display: flex; gap: 4px; }
.spd {
  background: var(--panel2); color: var(--txt); border: 1px solid var(--line);
  padding: 4px 9px; border-radius: 5px; cursor: pointer; font-size: 12px;
}
.spd.active { background: #1f4a33; border-color: var(--accent); color: var(--accent); }
.menu-toggle { display: none; }

/* ── 建造菜单 ── */
#buildMenu {
  grid-area: build; background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 8px; scrollbar-width: thin;
}
.menu-cat {
  font-size: 11px; color: var(--dim); letter-spacing: 2px; margin: 10px 4px 4px;
  border-bottom: 1px dashed #223047; padding-bottom: 3px;
}
.menu-items { display: flex; flex-direction: column; gap: 4px; }
.build-btn {
  display: flex; align-items: center; gap: 8px; text-align: left;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 7px;
  color: var(--txt); padding: 6px 8px; cursor: pointer; transition: border-color .12s;
}
.build-btn:hover { border-color: #3d5578; }
.build-btn.active { border-color: var(--accent); background: #17281f; }
.build-btn.poor { opacity: .45; }
.bb-icon { width: 30px; height: 30px; flex: none; display: grid; place-items: center; background: #0d1420; border-radius: 5px; }
.bb-name { flex: 1; font-size: 13px; }
.bb-cost { font-size: 11px; color: var(--gold); white-space: nowrap; }

/* ── 地图 ── */
#mapWrap { grid-area: map; position: relative; overflow: hidden; }
#game { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
#hamster { position: absolute; left: 10px; bottom: 10px; pointer-events: none; opacity: .92; }
.hamster-talk {
  position: absolute; left: 84px; bottom: 6px; max-width: 250px;
  background: #1c2739ee; border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 11px; font-size: 12px; color: #e8eef7;
  opacity: 0; transform: translateY(6px); transition: .25s;
}
.hamster-talk.show { opacity: 1; transform: none; }
#mobileBtns { display: none; }

/* ── 检查器 ── */
#inspector {
  grid-area: insp; background: var(--panel); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 12px; font-size: 13px;
}
.insp-empty { color: var(--dim); text-align: center; margin-top: 30px; line-height: 2.2; }
.insp-empty span { font-size: 12px; opacity: .8; }
#inspector h3 { font-size: 15px; color: #e8eef7; display: flex; justify-content: space-between; align-items: center; }
.insp-pos { color: var(--dim); font-size: 11px; margin-bottom: 8px; }
.insp-sec { margin: 10px 0 4px; font-size: 12px; color: var(--dim); letter-spacing: 1px; }
.st { font-size: 11px; padding: 2px 8px; border-radius: 9px; background: #26344a; font-weight: 400; }
.st-run { background: #1f4a33; color: var(--accent); }
.st-starve { background: #4a3a14; color: #e8b04a; }
.st-blocked { background: #4a1f1f; color: #f08a8a; }
.st-nopower { background: #143a4a; color: var(--info); }
.st-idle, .st-nores { background: #26344a; color: var(--dim); }
.progbar { height: 8px; background: #0d1420; border-radius: 4px; overflow: hidden; }
.progbar div { height: 100%; background: linear-gradient(90deg, #2ea86a, var(--accent)); transition: width .12s linear; }
.bufrow { display: flex; flex-wrap: wrap; gap: 8px; }
.bufitem { display: flex; align-items: center; gap: 3px; background: #0d1420; padding: 3px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.belt-items { display: flex; flex-wrap: wrap; gap: 4px; }
.insp-stat { margin-top: 8px; color: var(--dim); font-size: 12px; line-height: 1.7; }
.insp-btns { display: flex; gap: 8px; margin-top: 14px; }
.insp-btns button, .big, .slot button, .wh-actions button, .tool-btn {
  background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
  border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px;
}
.insp-btns button:hover, .tool-btn:hover { border-color: #3d5578; }
button.danger, .page-close:hover { border-color: var(--danger) !important; color: #f0a0a0 !important; }
.itemicon { width: 26px; height: 26px; vertical-align: middle; }
select, input[type=number] {
  background: #0d1420; color: var(--txt); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 7px; font-size: 12px; width: 100%;
}
input[type=number] { width: 74px; }
.dim { color: var(--dim); }

/* ── 底部工具栏 ── */
#toolbar {
  grid-area: tool; display: flex; align-items: center; gap: 6px; padding: 0 10px;
  background: var(--panel); border-top: 1px solid var(--line);
}
.tool-btn.active { border-color: var(--accent); background: #17281f; color: var(--accent); }
.page-btn {
  background: none; border: none; color: #9ab5d8; cursor: pointer;
  font-size: 13px; padding: 6px 10px; border-radius: 6px;
}
.page-btn:hover { background: var(--panel2); color: var(--txt); }
.tb-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.tb-spacer { flex: 1; }
.recover-chip {
  background: #4a3a14; color: #ffd97a; border: 1px solid #8a6d2a; border-radius: 14px;
  padding: 4px 12px; font-size: 12px; cursor: pointer;
}
.hidden { display: none !important; }

/* ── 页面弹窗 ── */
#pageModal {
  position: fixed; inset: 0; background: rgba(4,8,14,.72); display: none;
  place-items: center; z-index: 40; backdrop-filter: blur(2px);
}
#pageModal.show { display: grid; }
.page-shell {
  width: min(1080px, 94vw); height: min(84vh, 860px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  display: flex; flex-direction: column; overflow: hidden;
}
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel2);
}
.page-head h2 { font-size: 17px; letter-spacing: 1px; }
.page-close { background: none; border: 1px solid var(--line); color: var(--dim); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
#pageBody { flex: 1; overflow-y: auto; padding: 16px 20px; }

/* 仓库 */
.wh-controls { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; color: var(--dim); font-size: 12px; }
.wh-controls label { display: flex; align-items: center; gap: 6px; }
.wh-controls select { width: auto; }
.wh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.wh-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.wh-card.full { border-color: var(--accent); box-shadow: 0 0 14px #4ade8022; }
.wh-head { display: flex; align-items: center; gap: 10px; }
.wh-head .itemicon { width: 40px; height: 40px; }
.wh-name { font-weight: 600; flex: 1; }
.wh-name small { color: var(--gold); font-weight: 400; }
.wh-badges { display: flex; flex-direction: column; gap: 3px; }
.badge { font-size: 10px; padding: 2px 7px; border-radius: 8px; }
.badge.full { background: #1f4a33; color: var(--accent); }
.badge.ever { background: #3a3148; color: #c8a8e8; }
.badge.lock { background: #26344a; color: var(--dim); }
.wh-count { font-variant-numeric: tabular-nums; margin: 7px 0 3px; }
.wh-bar { height: 9px; background: #0d1420; border-radius: 5px; overflow: hidden; margin-bottom: 5px; }
.wh-bar div { height: 100%; background: linear-gradient(90deg, #2a6a9a, #5ac8e0); min-width: 2px; }
.wh-bar div.fullbar { background: linear-gradient(90deg, #2ea86a, var(--accent)); }
.wh-rate { font-size: 11px; color: var(--dim); margin-bottom: 7px; }
.wh-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; font-size: 11px; }
.wh-actions .ov, .wh-actions .mk { display: flex; align-items: center; gap: 3px; color: var(--dim); }
.wh-desc { font-size: 11px; color: #5b6c84; margin-top: 6px; }

/* 统计 */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; text-align: center; }
.stat-card b { display: block; font-size: 20px; color: #e8eef7; }
.stat-card span { font-size: 11px; color: var(--dim); }
.stat-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.stat-table th, .stat-table td { padding: 6px 9px; border-bottom: 1px solid #1c2839; text-align: left; }
.stat-table th { color: var(--dim); font-weight: 400; }
.pos { color: var(--accent); } .neg { color: var(--danger); }
.logbox { background: #0d1420; border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px; color: var(--dim); max-height: 180px; overflow-y: auto; }
#pageBody h4 { margin: 14px 0 8px; color: #9ab5d8; font-size: 13px; letter-spacing: 1px; }

/* 成就 */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.ach { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; opacity: .65; }
.ach.got { border-color: var(--gold); opacity: 1; background: linear-gradient(160deg, #2a2410, var(--panel2)); }
.ach-name { font-weight: 700; }
.ach.got .ach-name::after { content: ' ✓'; color: var(--gold); }
.ach-desc { font-size: 12px; color: var(--dim); margin: 4px 0; }
.ach-time { font-size: 11px; color: var(--accent); }

/* 存档 */
.save-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.save-row label.big { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 12px; }
.slot-list { display: flex; flex-direction: column; gap: 6px; }
.slot { display: flex; gap: 10px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-size: 12px; }
.slot-name { font-weight: 600; min-width: 140px; }
.slot-ts { color: var(--dim); flex: 1; }

/* 帮助 */
.help-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; }
.help-cols h4 { color: var(--accent); margin-bottom: 6px; }
.help-cols ul { padding-left: 18px; color: var(--dim); font-size: 13px; }
.help-cols li { margin: 5px 0; }

/* 致命错误横幅 (循环存活, 仅提示) */
#fatalBar {
  display: none; position: fixed; top: 52px; left: 50%; transform: translateX(-50%);
  z-index: 99; background: #4a1f1fee; color: #ffd7d7; border: 1px solid var(--danger);
  padding: 10px 18px; border-radius: 10px; font-size: 13px; max-width: 90vw;
}
/* 性能浮层 */
#perfOverlay {
  position: fixed; left: 212px; top: 54px; z-index: 50; pointer-events: none;
  background: rgba(13,20,32,.82); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; font: 11px/1.6 monospace; color: #9fd8b8; white-space: nowrap;
}
#perfOverlay b { color: #cfe3ff; font-weight: 600; }
.perf-hist { display: flex; gap: 6px; color: #6b7f99; }
.perf-bg { color: var(--info); }

/* 科技页 */
.tech-cur, .tech-bonus { background: var(--panel2); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; font-size: 13px; }
.tech-bonus { border-color: var(--line); color: var(--dim); }
.tech-bonus span { color: #9fd8b8; margin-left: 8px; }
.tech-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.tech-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }
.tech-card.done { border-color: var(--accent); background: linear-gradient(160deg, #14241c, var(--panel2)); }
.tech-card.cur { border-color: var(--info); }
.tech-card.lock { opacity: .55; }
.tech-name { font-weight: 700; font-size: 13.5px; }
.tech-eff { color: #9fd8b8; margin: 3px 0; }
.tech-desc { color: var(--dim); margin-bottom: 4px; }
.tech-pre { font-size: 11.5px; margin-bottom: 4px; }
.tech-cost { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 6px 0; }
.tech-card button { width: 100%; background: #1f4a33; color: var(--accent); border: 1px solid #2c6848; border-radius: 6px; padding: 6px; cursor: pointer; }
.tech-card button:disabled { background: var(--panel); color: var(--dim); border-color: var(--line); cursor: not-allowed; }
.mk-next { background: #0d1420; border: 1px dashed #2c3d58; border-radius: 8px; padding: 8px; font-size: 12px; margin: 6px 0; }
#inspUp { width: 100%; background: #1f4a33; color: var(--accent); border: 1px solid #2c6848; border-radius: 6px; padding: 7px; cursor: pointer; margin-bottom: 8px; }
#inspUp:disabled { background: var(--panel2); color: var(--dim); border-color: var(--line); cursor: not-allowed; }

/* 配方大全 */
.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin-bottom: 8px; }
.recipe-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.recipe-card summary { cursor: pointer; color: #9ab5d8; font-size: 12px; margin-top: 6px; }
.chain { list-style: none; padding-left: 0; font-size: 12.5px; margin: 6px 0; }
.chain ul { list-style: none; padding-left: 22px; border-left: 1px dashed #2c3d58; margin-left: 10px; }
.chain li { margin: 4px 0; }
.chain .bufitem { padding: 1px 6px; }

/* 设置页 */
.set-list { max-width: 560px; }
.set-row { display: flex; gap: 10px; align-items: flex-start; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer; font-size: 14px; }
.set-row input { margin-top: 3px; width: auto; }
.set-row small { display: block; margin-top: 2px; }
.set-row i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin: 0 2px; vertical-align: -1px; }

/* 提示条 */
#toasts { position: fixed; top: 58px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast {
  background: #1c2739ee; border: 1px solid var(--line); color: #e8eef7;
  padding: 8px 16px; border-radius: 8px; font-size: 13px;
  animation: toastin .18s ease-out;
}
.toast.fade { opacity: 0; transition: opacity .5s; }
@keyframes toastin { from { transform: translateY(-8px); opacity: 0; } }

/* ── 响应式: 手机 ── */
@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 46px 1fr 44px;
    grid-template-areas: "top" "map" "tool";
  }
  #buildMenu {
    position: fixed; left: 0; top: 46px; bottom: 44px; width: 210px; z-index: 30;
    transform: translateX(-105%); transition: transform .2s; box-shadow: 8px 0 24px rgba(0,0,0,.5);
  }
  #buildMenu.open { transform: none; }
  .menu-toggle { display: block; background: var(--panel2); color: var(--txt); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; }
  #inspector {
    position: fixed; right: 8px; top: 52px; width: min(320px, 86vw); max-height: 60vh; z-index: 30;
    border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.6);
    display: none;
  }
  #inspector:has(h3) { display: block; }
  .hud { gap: 9px; font-size: 12px; }
  #perfOverlay { left: auto; right: 8px; top: 50px; }
  .hud-item i { display: none; }
  #speedBar .spd { padding: 4px 7px; }
  #mobileBtns { display: flex; gap: 6px; position: absolute; right: 10px; bottom: 12px; }
  .mbtn {
    background: #1c2739dd; color: var(--txt); border: 1px solid var(--line);
    border-radius: 8px; padding: 9px 12px; font-size: 13px; min-width: 52px;
  }
  .mbtn.active { border-color: var(--danger); color: #f0a0a0; }
  #hamster svg { width: 56px; }
  .hamster-talk { left: 60px; max-width: 55vw; }
  #toolbar { overflow-x: auto; }
  .page-shell { height: 92vh; width: 97vw; }
}
