* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  height: 100%;
  background: #0a0710;
  color: #c9c2d6;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#frame {
  position: relative;
  width: min(90vw, 800px);
  aspect-ratio: 4 / 3;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 60px rgba(120, 40, 120, 0.35), 0 0 0 1px rgba(255,255,255,0.06);
}
#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  cursor: pointer;
  background: #06040a;
  touch-action: none;
}
#hint {
  position: absolute;
  left: 0;
  right: 0;
  top: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  letter-spacing: 2px;
  color: #b9a6e0;
  text-shadow: 0 0 8px rgba(0,0,0,0.8);
  pointer-events: none;
  transition: opacity .4s;
  padding: 0 10px;
  text-align: center;
}
#hint.hidden { opacity: 0; }
#ctrls {
  font-size: 12px;
  color: #6b6280;
  letter-spacing: 1px;
  text-align: center;
  padding: 0 8px;
}

/* ---------- 触屏控制 ---------- */
#touch { display: none; }
body.touch #touch,
#touch.force { display: flex; }

#touch {
  width: min(96vw, 820px);
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 0 6px;
  touch-action: none;
}
.dpad { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.dpad-mid { display: flex; gap: 6px; }
.actions { display: flex; align-items: flex-end; gap: 10px; }
.act-small { display: flex; flex-direction: column; gap: 8px; }

.tb {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid rgba(180, 150, 220, 0.35);
  background: rgba(40, 26, 58, 0.72);
  color: #e7dcff;
  border-radius: 14px;
  font-size: 22px;
  width: 62px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
  touch-action: none;
  user-select: none;
  transition: transform .05s, background .1s;
}
.tb:active, .tb.on {
  background: rgba(120, 70, 150, 0.9);
  transform: scale(0.94);
}
.tb.act { width: 74px; height: 74px; font-size: 15px; }
.tb.act-eye {
  background: linear-gradient(135deg, rgba(255,180,90,0.28), rgba(255,70,60,0.28));
  border-color: rgba(255, 180, 120, 0.5);
  color: #ffe9c9;
}
.tb.act-j {
  background: rgba(60, 90, 70, 0.7);
  border-color: rgba(140, 220, 170, 0.4);
}
.tb.mini { width: 56px; height: 34px; font-size: 13px; border-radius: 10px; }

@media (pointer: coarse) {
  #touch { display: flex; }
  #ctrls { display: none; }
}

/* 窄屏：画面尽量占满宽度，给控制留空间；按钮缩小以塞进一行 */
@media (max-width: 760px) {
  html, body { justify-content: flex-start; padding-top: 8px; gap: 10px; }
  #frame { width: 96vw; box-shadow: 0 0 30px rgba(120, 40, 120, 0.3); }
  #ctrls { display: none; }
  #touch { display: flex; gap: 8px; padding: 0 4px; }
  .dpad { gap: 5px; }
  .dpad-mid { gap: 5px; }
  .actions { gap: 7px; }
  .act-small { gap: 6px; }
  .tb { width: 50px; height: 50px; font-size: 18px; border-radius: 11px; }
  .tb.act { width: 60px; height: 60px; font-size: 13px; }
  .tb.mini { width: 48px; height: 30px; font-size: 12px; border-radius: 9px; }
}
@media (max-width: 360px) {
  .tb { width: 44px; height: 44px; font-size: 16px; }
  .tb.act { width: 54px; height: 54px; font-size: 12px; }
  .tb.mini { width: 44px; height: 28px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  html, body { flex-direction: row; flex-wrap: wrap; }
}
