* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  touch-action: none;
  overscroll-behavior: none;
}
body {
  font-family: "Courier New", Consolas, "Microsoft YaHei", monospace;
  color: #fff;
}
#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  left: 0; right: 0; top: 0;
  display: flex;
  justify-content: space-around;
  padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 8px) 0 calc(env(safe-area-inset-left) + 8px);
  pointer-events: none;
  font-weight: bold;
  font-size: clamp(12px, 2.3vw, 24px);
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 #000;
  z-index: 5;
}
#hud div { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
#hud b, #hud em { font-style: normal; }
.coin {
  display: inline-block;
  width: .55em; height: .8em;
  background: #fcd000;
  border: 2px solid #c84c0c;
  border-radius: 50%;
  vertical-align: -0.08em;
  margin-right: 3px;
}

#topbtns {
  position: fixed;
  top: calc(env(safe-area-inset-top) + clamp(44px, 7vw, 66px));
  right: calc(env(safe-area-inset-right) + 10px);
  display: flex;
  gap: 8px;
  z-index: 6;
}
#topbtns button {
  width: 40px; height: 40px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,.85);
  background: rgba(0,0,0,.3);
  color: #fff;
  font: bold 16px monospace;
  cursor: pointer;
}
#topbtns button.off { opacity: .45; text-decoration: line-through; }

/* ---------- Overlay ---------- */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.4);
  z-index: 10;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#overlay.hidden { display: none; }
#overlay.black { background: #000; }
.panel { text-align: center; padding: 20px; max-width: 94vw; }
.logo {
  display: inline-block;
  background: #c84c0c;
  border: 4px solid #fcbcb0;
  box-shadow: 0 0 0 4px #000, 8px 8px 0 4px rgba(0,0,0,.35);
  padding: clamp(10px, 2.5vw, 22px) clamp(16px, 5vw, 48px);
  color: #fcbcb0;
  text-shadow: 3px 3px 0 #000;
  font-weight: 900;
  line-height: 1.05;
}
.logo .l1 { display: block; font-size: clamp(18px, 4vw, 40px); text-align: left; }
.logo .l2 { display: block; font-size: clamp(30px, 8vw, 78px); }
.logo .l3 { display: block; font-size: clamp(18px, 4vw, 40px); text-align: right; color: #fcd000; }
.sub { margin: 16px 0 6px; font-size: clamp(14px, 2.6vw, 22px); font-weight: bold; text-shadow: 2px 2px 0 #000; }
.big { font-size: clamp(26px, 6vw, 56px); font-weight: 900; text-shadow: 3px 3px 0 #000; margin-bottom: 14px; }
.mid { font-size: clamp(16px, 3.2vw, 28px); font-weight: bold; margin: 8px 0; }
.bigbtn {
  margin-top: 18px;
  padding: 12px 36px;
  font: bold clamp(16px, 3vw, 24px) "Microsoft YaHei", sans-serif;
  color: #fff;
  background: #e52521;
  border: 3px solid #fff;
  border-radius: 10px;
  box-shadow: 0 5px 0 #8a1010;
  cursor: pointer;
}
.bigbtn:active { transform: translateY(3px); box-shadow: 0 2px 0 #8a1010; }
.help { margin-top: 18px; font-size: clamp(12px, 1.9vw, 15px); line-height: 1.8; opacity: .95; text-shadow: 1px 1px 0 #000; }
.help kbd {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid #fff;
  border-radius: 4px;
  background: rgba(0,0,0,.35);
  font-family: monospace;
}
body.touch .help.pc { display: none; }
body:not(.touch) .help.mobile { display: none; }

/* ---------- Touch controls ---------- */
#touch { display: none; position: fixed; inset: 0; pointer-events: none; z-index: 7; }
body.touch #touch { display: block; }
/* 经典十字方向键（红白机风格）：半透明圆形底座 + 实心十字。
   整个圆形区域都可触摸，四角算斜向（例如右下 = 右 + 蹲） */
#dpad {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 12px);
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  width: clamp(130px, 40vmin, 200px);
  height: clamp(130px, 40vmin, 200px);
  border-radius: 50%;
  -webkit-user-select: none;
  background: radial-gradient(circle, rgba(0,0,0,.16) 55%, rgba(0,0,0,.24));
  border: 2px solid rgba(255,255,255,.35);
  pointer-events: auto;
  touch-action: none;
}
/* 热区：整个圆形底座都能按，还向外多扩出一圈透明区域，手指按偏一点也能识别 */
#dpad::before {
  content: "";
  position: absolute;
  left: -18%; top: -18%; right: -18%; bottom: -18%;
  border-radius: 50%;
}
/* 每一臂都按底座的百分比绝对定位：十字占底座的 82%，每格 27.34%。
   十字本身不接收触摸，触摸统一交给底座按位置判断方向 */
#dpad .arm, #dpad .hub {
  position: absolute;
  pointer-events: none;
  width: 27.34%;
  height: 27.34%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(25,25,30,.58);
  color: rgba(255,255,255,.82);
  font-size: min(4.6vmin, 22px);
  line-height: 1;
  transition: background .06s;
}
#dpad .up    { left: 36.33%; top: 9%;      border-radius: 9px 9px 0 0; box-shadow: inset 0 3px 0 rgba(255,255,255,.18); }
#dpad .left  { left: 9%;      top: 36.33%; border-radius: 9px 0 0 9px; box-shadow: inset 3px 0 0 rgba(255,255,255,.18); }
#dpad .hub   { left: 36.33%; top: 36.33%; }
#dpad .right { left: 63.67%; top: 36.33%; border-radius: 0 9px 9px 0; box-shadow: inset -3px 0 0 rgba(0,0,0,.25); }
#dpad .down  { left: 36.33%; top: 63.67%; border-radius: 0 0 9px 9px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
/* 中心的圆形凹点 */
#dpad .hub::after {
  content: "";
  position: absolute;
  left: 27%; top: 27%;
  width: 46%; height: 46%;
  border-radius: 50%;
  background: rgba(0,0,0,.28);
  box-shadow: inset 0 2px 3px rgba(0,0,0,.35);
}
#dpad .arm.on { background: rgba(255,255,255,.42); color: #fff; }
.tbtn {
  position: absolute;
  width: min(19vmin, 96px);
  height: min(19vmin, 96px);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font: bold min(7vmin, 34px) sans-serif;
  color: #fff;
  background: rgba(229,37,33,.55);
  border: 3px solid rgba(255,255,255,.7);
  pointer-events: auto;
  touch-action: none;
}
.tbtn.on { background: rgba(229,37,33,.9); transform: scale(.94); }
#btnA { right: calc(env(safe-area-inset-right) + 16px); bottom: calc(env(safe-area-inset-bottom) + min(14vmin, 70px)); }
#btnB { right: calc(env(safe-area-inset-right) + min(24vmin, 122px)); bottom: calc(env(safe-area-inset-bottom) + 14px); background: rgba(40,80,220,.55); }
#btnB.on { background: rgba(40,80,220,.9); }

#rotateHint {
  display: none;
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 70px);
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(0,0,0,.5);
  font: 13px "Microsoft YaHei", sans-serif;
  z-index: 6;
  pointer-events: none;
}
@media (orientation: portrait) {
  body.touch #rotateHint { display: block; }
}

/* 弹出菜单时隐藏触控按钮，避免和文字叠在一起 */
body.menu #touch { display: none; }
#overlay { overflow-y: auto; }

/* 手机横屏：屏幕矮，标题和文字按高度缩小，排版收紧 */
@media (orientation: landscape) and (max-height: 520px) {
  .panel { padding: 10px 16px; }
  .logo {
    border-width: 3px;
    box-shadow: 0 0 0 3px #000, 5px 5px 0 3px rgba(0,0,0,.35);
    padding: 1.6vh 4.5vh;
    text-shadow: 2px 2px 0 #000;
  }
  .logo .l1 { font-size: max(14px, 5.5vh); }
  .logo .l2 { font-size: max(26px, 11vh); }
  .logo .l3 { font-size: max(14px, 5.5vh); }
  .sub { margin: 2.2vh 0 0; font-size: max(13px, 4vh); }
  .bigbtn { margin-top: 2.6vh; padding: 1.6vh 5.5vh; font-size: max(15px, 4.4vh); border-width: 2px; box-shadow: 0 4px 0 #8a1010; }
  .help { margin-top: 2.4vh; font-size: max(12px, 3.2vh); line-height: 1.6; max-width: 80vw; margin-left: auto; margin-right: auto; }
  .big { font-size: max(24px, 9vh); margin-bottom: 1.5vh; }
  .mid { font-size: max(13px, 4.6vh); margin: 1vh 0; }
  #hud { font-size: max(12px, 3.6vh); }
}
