* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color: transparent; user-select:none; }
html, body { width:100%; height:100%; overflow:hidden; background:#5c94fc; font-family: "Press Start 2P", monospace; touch-action: none; }
#game-wrap {
  position:fixed; inset:0;
  display:flex; align-items:center; justify-content:center;
  background:#5c94fc; /* 与天空同色，避免极端比例下出现黑边 */
  overflow:hidden;
}
canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background:#5c94fc;
  display:block;
  /* 由 fitCanvas() 在 JS 中按 9:16 比例计算实际像素尺寸 */
}
/* HUD：定位由 fitCanvas() 在 JS 中按画布尺寸同步 */
#hud {
  position:fixed; top:0; left:0; width:0;
  color:#fff;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", monospace;
  font-weight:bold;
  display:flex; justify-content:space-between; pointer-events:none;
  text-shadow: 2px 2px 0 #000;
  font-size: 12px;
  letter-spacing: 0.5px;
  z-index: 5;
  padding: 6px 8px 0;
  box-sizing: border-box;
}
#hud .item { background: rgba(0,0,0,0.0); padding:2px 4px; white-space: nowrap; }

/* Touch controls */
#controls {
  position: fixed; left:0; right:0;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  display:none;
  justify-content: space-between;
  align-items: center;
  padding: 0 14px;
  pointer-events:none;
  z-index:50;
  --btn-size: 84px;
  --btn-jump-size: 104px;
}
#controls .group { display:flex; gap:18px; pointer-events:auto; align-items:center; }
.btn {
  width: var(--btn-size); height: var(--btn-size); border-radius:50%;
  background: rgba(255,255,255,0.22);
  border: 2px solid rgba(255,255,255,0.6);
  color:#fff; font-weight:bold; font-size:30px;
  display:flex; align-items:center; justify-content:center;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  user-select:none; touch-action: none;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
  text-shadow: 1px 1px 0 rgba(0,0,0,0.45);
}
.btn:active, .btn.active { background: rgba(255,255,255,0.5); transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.25); }
.btn.jump { width: var(--btn-jump-size); height: var(--btn-jump-size); background: rgba(255,80,80,0.55); border-color:rgba(255,255,255,0.75); font-size:18px; }
.btn.down { background: rgba(80,160,255,0.55); font-size:34px; }

/* Show on touch devices OR small screens (covers in-app WebViews that
   report (hover: hover) incorrectly). JS also force-enables via
   body.has-touch when touch events are supported. */
@media (hover: none), (pointer: coarse), (max-width: 900px) {
  #controls { display:flex; }
}
body.has-touch #controls { display:flex; }
body.no-touch #controls { display:none; }

/* Smaller phones: shrink buttons so they always fit */
@media (max-width: 420px) {
  #controls { --btn-size: 72px; --btn-jump-size: 88px; padding: 0 10px; }
  #controls .group { gap: 14px; }
}
@media (max-width: 360px) {
  #controls { --btn-size: 62px; --btn-jump-size: 76px; padding: 0 8px; }
  #controls .group { gap: 12px; }
}

/* Overlay menu */
#overlay {
  position:fixed; inset:0; background:rgba(0,0,0,0.65);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  color:#fff; z-index:20; gap:18px; text-align:center; padding:20px;
}
#overlay h1 { font-size: clamp(20px, 6vw, 48px); color:#fcd000; text-shadow: 4px 4px 0 #000, 6px 6px 0 #b00; letter-spacing:2px; }
#overlay p { font-size: clamp(12px, 3vw, 18px); line-height:1.6; max-width:600px; }
#overlay button {
  margin-top:10px;
  padding: 14px 30px; font-size: 18px; font-weight:bold;
  background:#e52521; color:#fff; border: 4px solid #fff;
  border-radius: 10px; cursor:pointer; letter-spacing:2px;
  box-shadow: 0 6px 0 #7a0000;
}
#overlay button:active { transform: translateY(3px); box-shadow: 0 3px 0 #7a0000; }
#overlay.hide { display:none; }
.small { font-size: 12px; opacity:0.75; }
.copyright {
  margin-top: 2px;
  color: rgba(255,255,255,0.45);
  font-size: clamp(11px, 2.4vw, 15px);
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", monospace;
  font-weight: bold;
  letter-spacing: 0.5px;
}

/* Motion (体感) button on start overlay */
#overlay button.motion-btn {
  margin-top: 4px;
  padding: 10px 18px;
  font-size: clamp(12px, 3vw, 16px);
  background: rgba(60,140,255,0.85);
  border: 3px solid #fff;
  box-shadow: 0 4px 0 #143a78;
  letter-spacing: 1px;
}
#overlay button.motion-btn:active { box-shadow: 0 2px 0 #143a78; transform: translateY(2px); }
.motion-status {
  color: rgba(255,255,255,0.7);
  font-size: clamp(10px, 2.2vw, 13px);
  min-height: 14px;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", monospace;
}

/* In-game motion mini panel */
.motion-mini {
  position: absolute;
  top: -56px; right: 14px;
  display: flex; gap: 8px;
  pointer-events: auto;
}
.motion-tiny {
  background: rgba(0,0,0,0.45);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.6);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", monospace;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.motion-tiny:active { background: rgba(255,255,255,0.25); }

/* Hide direction buttons when motion mode is on (keep JUMP as fallback) */
body.motion-on #btn-left,
body.motion-on #btn-right,
body.motion-on #btn-down,
.btn.hide { display: none !important; }
body.motion-on #controls { justify-content: flex-end; }

/* Game Over overlay */
#gameover {
  position:fixed; inset:0; background:rgba(0,0,0,0.78);
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  color:#fff; z-index:30; gap:18px; text-align:center; padding:20px;
  font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", monospace;
}
#gameover.hide { display:none; }
#gameover .cry-emoji {
  font-size: clamp(80px, 22vw, 160px);
  line-height: 1;
  animation: cryShake 0.6s ease-in-out infinite alternate;
  text-shadow: 0 6px 0 rgba(0,0,0,0.4);
}
@keyframes cryShake {
  0%   { transform: translate(-3px, 0)   rotate(-4deg); }
  100% { transform: translate( 3px, -6px) rotate( 4deg); }
}
#gameover h2 {
  font-size: clamp(22px, 6vw, 40px);
  color:#fcd000;
  text-shadow: 3px 3px 0 #000, 5px 5px 0 #b00;
  letter-spacing: 2px;
}
#gameover p { font-size: clamp(13px, 3.4vw, 18px); opacity: 0.9; }
#gameover button {
  margin-top: 8px;
  padding: 14px 32px; font-size: 18px; font-weight: bold;
  background:#e52521; color:#fff; border:4px solid #fff;
  border-radius:10px; cursor:pointer; letter-spacing:2px;
  box-shadow: 0 6px 0 #7a0000;
}
#gameover button:active { transform: translateY(3px); box-shadow: 0 3px 0 #7a0000; }
