:root {
  --ink: #2d2a4a;
  --ink-soft: #5a5680;
  --ink-faint: #8b86ad;
  --pink: #ff65b2;
  --pink-light: #ffd4eb;
  --cyan: #00bbf9;
  --cyan-light: #cbf3f0;
  --purple: #9b5de5;
  --yellow: #fee440;
  --mint: #38b000;
  --mint-light: #ccff33;
  --orange: #f15bb5;
  --card-bg: #ffffff;
  --line: rgba(45, 42, 74, 0.16);
  --px: 'Press Start 2P', monospace, system-ui;
  --sans: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --sky-day-top: #70c8ff;
  --sky-day-mid: #fca5e3;
  --sky-day-low: #ffe169;
  --sky-day-bot: #9cf5cb;
  --sky-night-top: #100b2b;
  --sky-night-mid: #2e1452;
  --sky-night-low: #701c7c;
  --sky-night-bot: #ff6ba8;
}

* { box-sizing: border-box; margin: 0; padding: 0; user-select: none; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: var(--sans); color: var(--ink); font-size: 13.5px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background: linear-gradient(180deg, var(--sky-day-top) 0%, var(--sky-day-mid) 40%, var(--sky-day-low) 75%, var(--sky-day-bot) 100%);
  background-attachment: fixed;
  transition: background 1.5s ease;
  position: relative;
}

body.night-mode {
  background: linear-gradient(180deg, var(--sky-night-top) 0%, var(--sky-night-mid) 45%, var(--sky-night-low) 75%, var(--sky-night-bot) 100%);
}

/* 扫描线质感叠加 */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 3px);
  mix-blend-mode: overlay;
}

#fx {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
}

/* 3D 渲染主画布容器 */
#scene-container {
  position: fixed; inset: 0; z-index: 3; width: 100%; height: 100%; overflow: hidden;
}
#three-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
}

.px { font-family: var(--px); line-height: 1.4; }

/* 实体边框新野兽派按钮 */
button {
  font-family: inherit; cursor: pointer; outline: none; border: none;
  transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--pink); color: #fff; border: 2.5px solid var(--ink);
  padding: 6px 14px; border-radius: 12px; font-size: 12px; font-weight: 800;
  letter-spacing: 0.5px; box-shadow: 3px 3px 0 var(--ink);
}
.btn:hover {
  transform: translate(-1.5px, -1.5px); box-shadow: 4.5px 4.5px 0 var(--ink);
}
.btn:active {
  transform: translate(1.5px, 1.5px); box-shadow: 1px 1px 0 var(--ink);
}
.btn.ghost { background: #fff; color: var(--ink); }
.btn.cy { background: var(--cyan); color: #fff; }
.btn.mint { background: #70e000; color: var(--ink); }
.btn.gold { background: var(--yellow); color: var(--ink); }
.btn.sm { padding: 4px 10px; font-size: 11px; border-radius: 8px; }

/* ========================================================
   1. 顶部全局 HUD (城镇指标 + 资源看板 + 快捷工具)
======================================================== */
#hud-top {
  position: fixed; top: 12px; left: 16px; right: 16px; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  pointer-events: none;
}

.hud-panel {
  pointer-events: auto; background: #ffffff; border: 2.5px solid var(--ink);
  border-radius: 99px; padding: 6px 14px; box-shadow: 3.5px 3.5px 0 var(--ink);
  display: flex; align-items: center; gap: 10px;
}

/* 左侧：城镇名与等级 */
.town-badge {
  background: var(--yellow); border: 2px solid var(--ink); border-radius: 99px;
  padding: 3px 10px; font-family: var(--px); font-size: 8.5px; font-weight: 900;
}
.town-info {
  display: flex; flex-direction: column; min-width: 130px;
}
.town-name { font-weight: 900; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.town-meta { font-size: 10px; color: var(--ink-soft); }

/* 中间：经营四大核心资源 */
.res-pill {
  display: flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 99px;
  background: #fbfaff; border: 2px solid var(--ink); font-family: var(--px); font-size: 8.5px;
  box-shadow: 1.5px 1.5px 0 var(--ink);
}
.res-pill .dot { width: 7px; height: 7px; border-radius: 50%; border: 1px solid var(--ink); }
.res-pill.coins .dot { background: var(--yellow); }
.res-pill.pop .dot { background: var(--cyan); }
.res-pill.eco .dot { background: #70e000; }
.res-pill.power .dot { background: var(--pink); }

/* 右侧：快捷工具按钮 */
.icon-btn {
  width: 32px; height: 32px; border-radius: 10px; background: #fff; border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  box-shadow: 2px 2px 0 var(--ink); color: var(--ink); pointer-events: auto;
}
.icon-btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); background: var(--yellow); }
.icon-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.icon-btn.active { background: var(--pink); color: #fff; }

/* 3D 浮动操作指引 */
.scene-hint {
  position: fixed; left: 16px; top: 74px; z-index: 40; pointer-events: none;
  font-family: var(--px); font-size: 8px; color: var(--ink);
  background: #ffffff; border: 2px solid var(--ink); padding: 5px 12px;
  border-radius: 99px; box-shadow: 2.5px 2.5px 0 var(--ink);
}

/* ========================================================
   2. 左下角：镇长助理动森对白窗口
======================================================== */
#companion-bubble {
  position: fixed; left: 16px; bottom: 16px; z-index: 45;
  background: #ffffff; border: 2.5px solid var(--ink); border-radius: 18px;
  padding: 8px 14px; box-shadow: 3.5px 3.5px 0 var(--ink); max-width: 310px;
  display: flex; align-items: center; gap: 9px; pointer-events: auto;
}
.bubble-avatar {
  font-size: 22px; width: 34px; height: 34px; border-radius: 10px; background: var(--yellow);
  border: 2px solid var(--ink); display: flex; align-items: center; justify-content: center;
  box-shadow: 1.5px 1.5px 0 var(--ink); flex-shrink: 0;
}
.bubble-body { display: flex; flex-direction: column; overflow: hidden; }
.bubble-speaker { font-family: var(--px); font-size: 7.5px; color: var(--purple); font-weight: 700; }
.bubble-text { font-size: 11.5px; color: var(--ink); line-height: 1.45; margin-top: 1px; }

/* ========================================================
   3. 底部建造与沙盒创意码头 (#arsenal-dock)
======================================================== */
#arsenal-dock {
  position: fixed; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  pointer-events: auto; width: min(880px, 96vw);
}

.dock-tabs {
  display: flex; gap: 6px; background: #ffffff; border: 2px solid var(--ink);
  border-radius: 99px; padding: 3px 8px; box-shadow: 2.5px 2.5px 0 var(--ink);
}
.dock-tab {
  font-family: var(--px); font-size: 7.5px; padding: 3px 9px; border-radius: 99px;
  background: transparent; color: var(--ink-soft); border: 2px solid transparent;
}
.dock-tab.active {
  background: var(--yellow); color: var(--ink); border-color: var(--ink); font-weight: 700;
  box-shadow: 1px 1px 0 var(--ink);
}

.dock-container {
  display: flex; gap: 9px; background: #ffffff; border: 3px solid var(--ink);
  border-radius: 18px; padding: 8px 12px; box-shadow: 5px 5px 0 var(--ink);
  overflow-x: auto; max-width: 100%;
}
.dock-card {
  flex: 0 0 auto; width: 106px; background: #ffffff; border: 2.5px solid var(--ink);
  border-radius: 14px; padding: 6px 4px; text-align: center; cursor: pointer;
  box-shadow: 2.5px 2.5px 0 var(--ink); transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  position: relative;
}
.dock-card:hover {
  transform: translateY(-3px); box-shadow: 4px 4px 0 var(--ink);
}
.dock-card.selected {
  border-color: var(--pink); background: #fffcfd; transform: translateY(-5px);
  box-shadow: 5px 5px 0 var(--pink);
}
.dock-card.disabled {
  opacity: 0.55; cursor: not-allowed; filter: grayscale(0.6);
}
.card-hotkey {
  position: absolute; top: 3px; left: 5px; font-family: var(--px); font-size: 7px;
  background: var(--ink); color: #fff; border-radius: 4px; padding: 1px 3.5px;
}
.card-icon {
  font-size: 24px; height: 30px; display: flex; align-items: center; justify-content: center;
  margin: 1px 0;
}
.card-name { font-size: 11px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tag { font-family: var(--px); font-size: 6.5px; color: var(--ink-soft); margin-top: 1px; }
.card-cost {
  margin-top: 4px; font-family: var(--px); font-size: 7.5px; color: var(--pink);
  background: rgba(255, 101, 178, 0.12); border-radius: 5px; padding: 1px 3px;
  display: flex; align-items: center; justify-content: center; gap: 3px;
}

/* ========================================================
   4. 右下角建筑检视与升级抽屉 (#node-drawer)
======================================================== */
#node-drawer {
  position: fixed; right: 16px; bottom: 16px; width: 270px; z-index: 60;
  background: #ffffff; border: 3px solid var(--ink); border-radius: 18px;
  padding: 14px; box-shadow: 5px 5px 0 var(--ink);
  transform: translateX(130%); transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
  pointer-events: auto;
}
#node-drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.drawer-badge {
  font-family: var(--px); font-size: 7px; padding: 2.5px 7px; border-radius: 99px;
  border: 1.5px solid var(--ink); background: var(--yellow);
}
.drawer-close {
  width: 22px; height: 22px; border-radius: 50%; background: var(--pink); color: #fff;
  border: 2px solid var(--ink); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 900;
}
.drawer-title { font-size: 15px; font-weight: 900; }
.drawer-desc { font-size: 11px; color: var(--ink-soft); margin: 5px 0 10px; line-height: 1.5; }
.drawer-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px;
  background: #faf8ff; border: 1.5px dashed var(--line); border-radius: 10px; padding: 6px;
}
.stat-item b { font-family: var(--px); font-size: 10px; color: var(--purple); display: block; }
.stat-item span { font-size: 9px; color: var(--ink-soft); }
.drawer-actions { display: flex; gap: 6px; }

/* ========================================================
   5. 通用弹窗覆盖层 (成就图鉴、拍立得相纸)
======================================================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(26, 20, 64, 0.72);
  backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal-window {
  background: #fff; border: 3.5px solid var(--ink); border-radius: 22px;
  padding: 22px; box-shadow: 6px 6px 0 var(--ink); max-width: 660px; width: 92vw;
  max-height: 85vh; overflow-y: auto; position: relative;
}
.modal-close {
  position: absolute; right: 14px; top: 14px; width: 28px; height: 28px;
  border-radius: 50%; background: var(--pink); color: #fff; border: 2px solid var(--ink);
  font-size: 14px; font-weight: 900;
}

/* 图鉴徽章卡片网格 */
.ach-grid-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.ach-card-mini {
  background: #fff; border: 2px solid var(--ink); border-radius: 12px;
  padding: 8px; text-align: center; box-shadow: 2px 2px 0 var(--ink);
  opacity: 0.45; transition: opacity 0.2s, transform 0.2s;
}
.ach-card-mini.unlocked { opacity: 1; border-color: var(--pink); background: #fffcfd; }
.ach-icon-mini { font-size: 20px; margin-bottom: 3px; }
.ach-name-mini { font-size: 10.5px; font-weight: 800; }
.ach-desc-mini { font-size: 8.5px; color: var(--ink-soft); margin-top: 2px; }

/* 悬浮数字飘字 */
.float-text {
  position: fixed; pointer-events: none; z-index: 100; font-family: var(--px);
  font-size: 11px; font-weight: 900; text-shadow: 2px 2px 0 var(--ink);
  animation: floatUp 0.85s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(0.85); opacity: 0; }
  25% { transform: translate(-50%, -8px) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -36px) scale(1); opacity: 0; }
}

/* 响应式适配 */
@media (max-width: 900px) {
  #hud-top { flex-wrap: wrap; }
  #companion-bubble { display: none; }
  .ach-grid-mini { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 580px) {
  .dock-card { width: 88px; padding: 4px 2px; }
  .card-icon { font-size: 20px; height: 26px; }
  .card-name { font-size: 9.5px; }
}
