* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; background: #9fd3e8; }
canvas { display: block; }

#hud {
  position: fixed; top: 0; left: 0; right: 0;
  padding: 12px 16px;
  color: #fff; font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  text-shadow: 0 1px 3px rgba(0,0,0,.5);
  pointer-events: none; z-index: 10;
}
#title { font-size: 20px; font-weight: 700; letter-spacing: 1px; }
#hint { font-size: 13px; opacity: .9; margin-top: 4px; }
#count {
  position: fixed; top: 12px; right: 16px;
  background: rgba(0,0,0,.35); padding: 6px 12px; border-radius: 20px;
  font-size: 14px; font-family: "PingFang SC", sans-serif;
}

#joystick {
  position: fixed; left: 22px; bottom: 22px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,.18);
  border: 2px solid rgba(255,255,255,.35);
  touch-action: none; z-index: 20;
}
#joy-thumb {
  position: absolute; left: 50%; top: 50%;
  width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(255,255,255,.55);
  border: 2px solid rgba(255,255,255,.8);
}

#loading {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: #9fd3e8; color: #2b4a2f; font-size: 18px;
  font-family: "PingFang SC", sans-serif; z-index: 30;
  transition: opacity .6s;
}
#loading.hide { opacity: 0; pointer-events: none; }

#activity-prompt {
  display: none;
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
  background: rgba(20,30,20,.7); color: #fff; padding: 10px 18px;
  border-radius: 22px; font-size: 15px; font-family: "PingFang SC", sans-serif;
  z-index: 25; white-space: nowrap; pointer-events: none;
}

/* 活动中「退出」按钮（鼠标可点，无需键盘） */
#exit-activity {
  display: none;
  position: fixed; top: 52px; right: 16px;
  background: rgba(178,42,42,.92); color: #fff;
  border: none; border-radius: 22px;
  padding: 10px 18px; font-size: 15px; font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  cursor: pointer; z-index: 27; box-shadow: 0 2px 10px rgba(0,0,0,.35);
  pointer-events: auto;
}
#exit-activity:hover { background: rgba(208,54,54,.96); }
#exit-activity:active { transform: scale(.96); }

/* 桌面端不显示摇杆（触摸设备会由 JS 打开） */
body.no-touch #joystick { display: none; }

/* 人情世故账本 HUD（M4） */
#social {
  position: fixed; top: 56px; left: 16px;
  background: rgba(0,0,0,.35); color: #fff; padding: 8px 12px; border-radius: 10px;
  font-size: 13px; font-family: "PingFang SC", "Microsoft YaHei", sans-serif; line-height: 1.55;
  z-index: 10; pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,.5);
}
#social b { color: #ffd93d; }

/* 当前枢纽 HUD（M5） */
#hub {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.35); color: #fff; padding: 6px 16px; border-radius: 20px;
  font-size: 15px; font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  z-index: 11; pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,.5);
}

/* 景点切换器（分场景：顶栏按钮直接传送） */
#scenes {
  position: fixed; top: 52px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 12; pointer-events: auto;
}
#scenes button {
  background: rgba(0,0,0,.35); color: #fff; border: 1px solid rgba(255,255,255,.25);
  border-radius: 18px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif; white-space: nowrap;
  transition: background .2s, transform .1s;
}
#scenes button:hover { background: rgba(0,0,0,.55); }
#scenes button:active { transform: scale(.95); }
#scenes button.active { background: rgba(60,140,80,.92); border-color: rgba(255,255,255,.6); }

/* 飘字提示（M4） */
#toast {
  position: fixed; left: 50%; top: 22%; transform: translateX(-50%);
  background: rgba(20,40,20,.82); color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 15px; font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  z-index: 28; opacity: 0; transition: opacity .3s; pointer-events: none; white-space: nowrap;
}

/* ============ 移动端适配（触摸设备） ============ */
/* 摇杆与功能键默认隐藏，仅在无 hover 的粗指针设备（手机/平板）显示 */
#joystick, #mobile-actions { display: none; }

@media (hover: none) and (pointer: coarse) {
  /* 左下虚拟摇杆：用 env() 避开刘海 / 底部横条安全区 */
  /* ★ m273：摇杆也贴边 —— 与右边圆盘完全对称（右盘是 right 12 / bottom 18） */
  #joystick {
    display: block; position: fixed;
    left: calc(12px + env(safe-area-inset-left));
    bottom: calc(18px + env(safe-area-inset-bottom));
    width: 132px; height: 132px; border-radius: 50%;
    background: rgba(255,255,255,.13); border: 2px solid rgba(255,255,255,.34);
    touch-action: none; z-index: 45;
    user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  }
  #joystick-knob {
    position: absolute; left: 50%; top: 50%; width: 58px; height: 58px;
    margin: -29px 0 0 -29px; border-radius: 50%;
    background: rgba(255,255,255,.45); border: 2px solid rgba(255,255,255,.62);
    pointer-events: none; transition: transform .05s linear;
  }
  /* ★ m256 右下功能圆盘：不再是"一列三个独立键"，改成手游式一个圆盘 + 盘内分键。
     外框 176px（内容区 172，绝对定位以内容区为基准）；主键「跳」在右下＝拇指自然落点，
     泳/话/聊 沿内弧排。间距已核：任意两键中心距(62.6~84.9) > 两半径和(50~62)，互不压住。
     ★ 容器 pointer-events:none，只有按钮吃触摸 —— 免得这 176px 的盘挡住"点地面走过去"。 */
  #mobile-actions {
    display: block; position: fixed; width: 132px; height: 132px; border-radius: 50%;
    right: calc(12px + env(safe-area-inset-right));
    bottom: calc(18px + env(safe-area-inset-bottom));
    background: radial-gradient(circle at 64% 64%, rgba(255,255,255,.13), rgba(255,255,255,.05) 68%, rgba(255,255,255,0) 71%);
    border: 2px solid rgba(255,255,255,.22);
    touch-action: none; pointer-events: none; z-index: 45;
  }
  .mbtn {
    position: absolute; border-radius: 50%;
    background: rgba(255,255,255,.20); border: 2px solid rgba(255,255,255,.46);
    color: #fff; font-weight: 600;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    padding: 0; line-height: 1;
    touch-action: none; pointer-events: auto;
    user-select: none; -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .mbtn:active { background: rgba(255,255,255,.50); transform: scale(.94); }
  /* ★ m270 圆盘缩到 132px（与左边摇杆等大；相对 m266 的 190px 约 2/3）。
     内容区 128 ⇒ 圆心 (64,64)；四键沿半径 45px 排，正中心留 40px 视角盘。
     实测间距：跳↔中心盘 45 > 39；跳↔相邻键 63.6 > 35；相邻副键 63.6 > 32 ⇒ 均不重叠。 */
  .mbtn-main { left: 77px; top: 77px; width: 38px; height: 38px; font-size: 14px; background: rgba(255,255,255,.28); border-color: rgba(255,255,255,.62); }
  .mbtn-sub  { width: 32px; height: 32px; font-size: 12px; }
  #btn-talk   { left: 80px; top: 16px; }   /* 右上：说话 → 开聊天窗 */
  #btn-run    { left: 16px; top: 80px; }   /* 左下：跑（开关） */
  #btn-crouch { left: 16px; top: 16px; }   /* 左上：蹲（开关） */

  /* 跑/蹲 是开关量，亮起来表示"开着"（由 main.js 5Hz 贴 class，不是每帧写 DOM） */
  .mbtn-on { background: rgba(255,214,120,.88) !important; border-color: rgba(255,238,190,.95) !important; color: #3a2a00 !important; }

  /* ★ m266 中心视角盘：拖动它转视角（左右＝水平环绕，上下＝俯仰） */
  #viewpad {
    position: absolute; left: 44px; top: 44px; width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,.10); border: 2px dashed rgba(255,255,255,.46);
    pointer-events: auto; touch-action: none;
  }
  #viewpad-knob {
    position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px;
    border-radius: 50%; background: rgba(255,255,255,.34); border: 2px solid rgba(255,255,255,.58);
    pointer-events: none; transition: transform .05s linear;
  }

  /* ★ m257 ② 桌面那两个固定小按钮在手机上会压住摇杆/圆盘：
     「💬 聊」并进圆盘的「话」键 → 触摸设备上藏掉；
     「退出」改成右上角一个小圆（用户令）：34px、只留 🚪 图标，文字标签 .exit-label 隐藏。
     ★ 必须 !important，否则盖不住 index.html 里的行内样式。 */
  #btn-chat { display: none !important; }
  /* ★★★ m379（用户令）：「小地图放到最右上角去」——
     原来最右上是【退出小圆】(top:8px)，小地图被挤到 top:50px 让位。
     现在反过来：小地图占最右上，退出小圆挪到它正下方。
     小地图高度 = 宽度 × 0.75（canvas 内部分辨率 240×180 ⇒ 4:3），手机端宽 min(24vw,128px) ⇒ 高约 96px。 */
  #btn-exit {
    left: auto !important; bottom: auto !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
    top: calc(8px + min(24vw, 128px) * 0.75 + 10px + env(safe-area-inset-top)) !important;
    width: 34px !important; height: 34px !important;
    padding: 0 !important; border-radius: 50% !important;
    font-size: 16px !important; line-height: 1 !important;
    display: flex !important; align-items: center !important; justify-content: center !important;
  }
  #btn-exit .exit-label { display: none; }
  /* ★ 小地图【隐藏】时，最右上的东西换成了那个「🗺」恢复按钮（34px 圆）——
     退出小圆要跟着它往下让，别跟它叠在一起。
     ⚠ 第一版写成回到 top:8px，结果两个圆完全重叠（实测截图才发现，逻辑数字看着都对）。 */
  body.mm-hidden #btn-exit {
    top: calc(8px + 34px + 10px + env(safe-area-inset-top)) !important;
  }
  /* 小地图：手机上缩小，占【最右上角】 */
  #minimap-canvas {
    width: min(24vw, 128px) !important;
    top: calc(8px + env(safe-area-inset-top)) !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
  }
  /* 隐藏/显示小地图的按钮：叠在小地图【内部】右上角 */
  #mm-toggle {
    top: calc(14px + env(safe-area-inset-top)) !important;
    right: calc(18px + env(safe-area-inset-right)) !important;
    width: 24px !important; height: 24px !important;
    font-size: 14px !important;
  }
  /* 小地图已隐藏 ⇒ 按钮自己顶到最右上，撑大一点当恢复入口 */
  #mm-toggle.mm-off {
    top: calc(8px + env(safe-area-inset-top)) !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
    width: 34px !important; height: 34px !important;
    font-size: 17px !important;
    border-radius: 50% !important;
    background: rgba(30, 60, 90, 0.7) !important;
  }
  /* ★ m382：「⛶ 全屏」按钮（只在非全屏时由 JS 显示）—— 排在退出小圆正下方。
     右上角这一列的排布（自上而下）：小地图(97) → 退出小圆(34) → 全屏小圆(34)，每格间隔 10px。 */
  #btn-fullscreen {
    left: auto !important; bottom: auto !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
    top: calc(8px + min(24vw, 128px) * 0.75 + 10px + 34px + 10px + env(safe-area-inset-top)) !important;
    width: 34px !important; height: 34px !important;
    padding: 0 !important; border-radius: 50% !important;
    font-size: 16px !important; line-height: 1 !important;
    align-items: center !important; justify-content: center !important;
  }
  #btn-fullscreen .fs-label { display: none; }
  /* 小地图隐藏时，上面那两格都上移了 ⇒ 全屏小圆跟着上移一格（省掉小地图那 97px） */
  body.mm-hidden #btn-fullscreen {
    top: calc(8px + 34px + 10px + 34px + 10px + env(safe-area-inset-top)) !important;
  }
  /* ★ m566a：「🏠 回城」小圆（防卡住）—— 排在全屏小圆正下方，常显。
     右上角这一列（自上而下）：小地图(97) → 退出(34) → 全屏(34) → 回城(34)，间隔 10px。 */
  #btn-home {
    left: auto !important; bottom: auto !important;
    right: calc(10px + env(safe-area-inset-right)) !important;
    top: calc(8px + min(24vw, 128px) * 0.75 + 10px + 34px + 10px + 34px + 10px + env(safe-area-inset-top)) !important;
    width: 34px !important; height: 34px !important;
    padding: 0 !important; border-radius: 50% !important;
    font-size: 16px !important; line-height: 1 !important;
    align-items: center !important; justify-content: center !important;
  }
  #btn-home .home-label { display: none; }
  body.mm-hidden #btn-home {
    top: calc(8px + 34px + 10px + 34px + 10px + 34px + 10px + env(safe-area-inset-top)) !important;
  }
  /* 顶部 HUD 手机上收紧，避免长提示占满屏 */
  #hud { max-width: 62vw; }
  #hint { font-size: 11px; line-height: 1.45; }
}

/* ============ 全景地图浮层（双击小地图打开） ============ */
#mm-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;   /* 最上层 */
  background: rgba(0,0,0,.62);
  align-items: center; justify-content: center;
}
#mm-overlay.show { display: flex; }
#mm-full-canvas {
  width: min(92vw, 640px); height: auto;
  border: 2px solid rgba(255,255,255,.5); border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.55); background: #000;
}
#mm-overlay-close {
  position: fixed; top: calc(20px + env(safe-area-inset-top));
  right: calc(20px + env(safe-area-inset-right));
  width: 46px; height: 46px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.92); color: #222;
  font-size: 26px; line-height: 1; cursor: pointer; z-index: 101;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ============ 聊天（★ m271 拆两块：常驻的透明记录 + 按需出现的实心打字窗） ============
   用户令：① 打字窗【不透明】 ② 屏幕上的聊天内容【透明】 ③ 聊天窗关掉仍能看到内容
           ④ 每条注明是公聊还是私聊（跟谁聊）
   以前消息和输入框挤在同一个面板里 —— 关掉面板，聊天记录也一起没了。 */
#chat-wrap {
  position: fixed; left: 14px; width: min(92vw, 520px);
  bottom: calc(158px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px;
  z-index: 60; pointer-events: none;      /* 默认不吃触摸，免得挡住"点地面走过去" */
  max-height: 52vh;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
}
/* ── 聊天记录：常驻可见、透明。没有底板，只靠文字描边保证可读 ⇒ 不挡画面 ──
   ★ m272：pointer-events:auto 让记录【随时可以滑动翻回去看】（用户令）。
   高度是 flex:0 1 auto ⇒ 消息少时只有几行高，不会白占屏幕；多了才长到 max-height。 */
#chat-feed {
  flex: 0 1 auto; min-height: 0; max-height: 38vh; overflow-y: auto;
  padding: 1px 2px 0;
  font-size: 13px; line-height: 1.45; color: #eaf2ff;
  text-shadow: 0 1px 3px rgba(0,0,0,.95), 0 0 9px rgba(0,0,0,.8);
  scrollbar-width: thin;
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── 会话筛选条（★ m272）：全部 / 公屏 / 私聊·某人，点一下只看那一路 ── */
#chat-filter {
  flex: 0 0 auto; display: none; align-items: center; gap: 5px;
  pointer-events: auto;
}
#chat-chips {
  flex: 1 1 auto; min-width: 0; display: flex; gap: 4px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
#chat-chips::-webkit-scrollbar { height: 0; }
.chip {
  flex: 0 0 auto; padding: 2px 9px; border-radius: 11px;
  font-size: 11px; line-height: 17px; font-family: inherit; white-space: nowrap;
  color: #cfe3f5; background: rgba(0,0,0,.5);
  border: 1px solid rgba(255,255,255,.24); cursor: pointer;
}
.chip-on { background: rgba(95,168,255,.9); color: #04263f; border-color: rgba(150,205,255,.95); font-weight: 700; }
.chip-muted { opacity: .45; }
#chat-mute {
  flex: 0 0 auto; width: 28px; height: 23px; padding: 0; border-radius: 11px;
  font-size: 12px; line-height: 1; font-family: inherit; cursor: pointer;
  background: rgba(0,0,0,.5); color: #cfe3f5; border: 1px solid rgba(255,255,255,.24);
}
#chat-mute:disabled { opacity: .3; cursor: default; }
/* ── m576 公屏收短：默认折叠几行；筛选条上 ▼展开/▲收起、✕关闭；关闭后留 💬 小钮重开 ── */
#chat-fold, #chat-close {
  flex: 0 0 auto; width: 28px; height: 23px; padding: 0; border-radius: 11px;
  font-size: 12px; line-height: 1; font-family: inherit; cursor: pointer;
  background: rgba(0,0,0,.5); color: #cfe3f5; border: 1px solid rgba(255,255,255,.24);
}
#chat-wrap.chat-fold #chat-feed { max-height: 92px; }   /* ≈5 行 */
#chat-wrap.chat-hide #chat-feed,
#chat-wrap.chat-hide #chat-filter { display: none !important; }  /* ★ 必须 !important：筛选条是内联 display */
#chat-reopen {
  display: none; align-self: flex-start;
  width: 36px; height: 32px; padding: 0; border-radius: 16px;
  font-size: 15px; line-height: 1; font-family: inherit; cursor: pointer;
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.28);
  pointer-events: auto;
}
#chat-wrap.chat-hide #chat-reopen { display: block; }
.chat-line { margin-bottom: 2px; word-break: break-word; opacity: .96; }
.chat-name { color: #9ad8ff; font-weight: 600; cursor: pointer; }
.chat-name:hover { text-decoration: underline; }   /* m577：一眼看出名字可点 */
.chat-line.chat-sys { color: #b9c9d8; font-style: italic; }
/* 每条前面的标签：一眼看出公屏 / 私聊给谁 / 私聊来自谁 */
.chat-tag {
  display: inline-block; margin-right: 5px; padding: 0 4px; border-radius: 4px;
  font-size: 10px; line-height: 15px; vertical-align: 1px;
  background: rgba(0,0,0,.45); border: 1px solid rgba(255,255,255,.22); color: #cfe3f5;
}
.tag-pub   { color: #a8c8e0; border-color: rgba(168,200,224,.40); }
.tag-to    { color: #ffd479; border-color: rgba(255,212,121,.55); }
.tag-from  { color: #ffd479; border-color: rgba(255,212,121,.60); background: rgba(255,212,121,.16); }
.tag-sys   { color: #b9c9d8; border-color: rgba(185,201,216,.35); }

/* ── 打字窗：★ 不透明，只在 .chat-open（点了「话/聊」）时出现 ── */
#chat-bar {
  flex: 0 0 auto; display: none; gap: 6px; padding: 7px;
  background: #0e1522;                     /* ← 实心，不透明 */
  border: 1px solid rgba(255,255,255,.22); border-radius: 10px;
  box-shadow: 0 8px 26px rgba(0,0,0,.55);
  pointer-events: auto;
}
#chat-wrap.chat-open #chat-bar { display: flex; }
#chat-wrap.chat-open { pointer-events: auto; }   /* 打开时才让记录可滚动 */
#chat-target {
  flex: 0 0 auto; max-width: 40%; padding: 7px 6px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.22); background: #182234;
  color: #eaf2ff; font-size: 13px; outline: none;
}
#chat-input {
  flex: 1 1 auto; min-width: 0; padding: 7px 10px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.22); background: #182234;
  color: #eaf2ff; font-size: 14px; outline: none;
}
#chat-input::placeholder { color: rgba(234,242,255,.42); }
#chat-send {
  flex: 0 0 auto; padding: 7px 15px; border-radius: 8px;
  border: 1px solid rgba(120,190,255,.55); background: rgba(95,168,255,.92);
  color: #04263f; font-weight: 700; font-size: 13px; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
#chat-send:active { background: rgba(120,195,255,1); }

/* ── 手机档 ── */
@media (hover: none) and (pointer: coarse) {
  #chat-wrap { left: 8px; right: 8px; width: auto; gap: 5px;
               bottom: calc(158px + env(safe-area-inset-bottom)); }
  #chat-feed { font-size: 11px; line-height: 1.4; max-height: 30vh; }
  .chip { font-size: 10px; line-height: 15px; padding: 1px 7px; }
  #chat-mute, #chat-fold, #chat-close { width: 25px; height: 20px; font-size: 11px; }
  .chat-tag { font-size: 9px; line-height: 13px; padding: 0 3px; margin-right: 4px; }
  #chat-bar { padding: 6px; }
  #chat-target { font-size: 12px; padding: 6px 5px; max-width: 34%; }
  #chat-input { font-size: 13px; padding: 6px 9px; }
  #chat-send { font-size: 12px; padding: 6px 13px; }
}

/* iOS Safari 在输入框 font-size < 16px 时会自动放大整页 —— 只对 iOS 放行 16px */
@supports (-webkit-touch-callout: none) {
  @media (hover: none) and (pointer: coarse) {
    #chat-input { font-size: 16px; }
  }
}
