* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  background: #0a0a14;
  font-family: "Courier New", monospace;
  overflow: hidden;
  color: #e8e8f0;
  -webkit-font-smoothing: none;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
body {
  position: fixed;
  inset: 0;
}

#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 30%, #1a1430 0%, #0a0a14 70%);
}

/* Frame wraps canvas + HUD + overlay, sized to the 16:9 game area */
#frame {
  position: relative;
  width: min(100vw, 177.78vh);
  height: min(56.25vw, 100vh);
}

/* The canvas is low-res and scaled up; keep pixels crisp */
#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100%;
  height: 100%;
  background: #000;
  box-shadow: 0 0 0 4px #2a2a44, 0 0 40px #000a, 0 0 80px #5050ff22;
  display: block;
}

/* HUD overlays the top of the canvas */
#hud {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 14px;
  pointer-events: none;
  font-size: 13px;
  letter-spacing: 1px;
  z-index: 3;
}

.player-hud { flex: 1; }
.player-hud.right { text-align: right; }

.name {
  font-weight: bold;
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 4px;
}
.player-hud.left .name { color: #5aa8ff; }
.player-hud.right .name { color: #ff5a6a; }

.bar {
  height: 14px;
  width: 100%;
  background: #1a1a2a;
  border: 2px solid #000;
  box-shadow: 0 0 0 2px #444466;
  position: relative;
  overflow: hidden;
}
.player-hud.right .bar { transform: scaleX(-1); }

.bar .fill {
  height: 100%;
  width: 100%;
  transition: width 0.12s linear;
}
.fill.blue {
  background: linear-gradient(to bottom, #8fd0ff 0%, #3a8fe0 55%, #1a5fb0 100%);
}
.fill.red {
  background: linear-gradient(to bottom, #ffb0b0 0%, #ff5050 55%, #b01a2a 100%);
}

#center-info {
  text-align: center;
  padding: 0 12px;
  min-width: 90px;
}
#round-text {
  font-size: 11px;
  color: #aaa;
  text-shadow: 1px 1px 0 #000;
}
#timer {
  font-size: 26px;
  font-weight: bold;
  color: #ffe070;
  text-shadow: 2px 2px 0 #000;
}

/* Overlay (title / game over) */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 20, 0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 5;
  transition: opacity 0.25s;
}
.overlay.hidden { opacity: 0; pointer-events: none; }

.overlay h1 {
  font-size: clamp(30px, 6vw, 64px);
  letter-spacing: 4px;
  color: #e8e8f0;
  text-shadow: 4px 4px 0 #2a2a44, 8px 8px 0 #000;
}
.overlay h1 span {
  color: #ffe070;
  margin: 0 6px;
}
.subtitle {
  margin-top: 6px;
  color: #8888aa;
  letter-spacing: 6px;
  font-size: 14px;
}

.controls {
  display: flex;
  gap: 28px;
  margin: 28px 0 18px;
  flex-wrap: wrap;
  justify-content: center;
}
.ctrl-block {
  border: 2px solid #33334d;
  padding: 12px 18px;
  background: #11111d;
  min-width: 210px;
}
.ctrl-block h3 {
  font-size: 13px;
  margin-bottom: 8px;
  letter-spacing: 2px;
}
.ctrl-block:nth-child(1) h3 { color: #5aa8ff; }
.ctrl-block:nth-child(2) h3 { color: #ff5a6a; }
.ctrl-block p { font-size: 12px; color: #ccc; line-height: 1.9; }
.ctrl-block b { color: #ffe070; }

/* ===== 多层级开始菜单 ===== */
.menu-step {
  width: 100%;
  max-width: 820px;
  margin: 16px 0 4px;
}
.menu-step.hidden { display: none; }

.step-title {
  font-size: 14px;
  letter-spacing: 2px;
  color: #ffe070;
  margin: 8px 0 12px;
  text-shadow: 2px 2px 0 #000;
}

.menu-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
  align-items: stretch;
}
.card-btn {
  width: 220px;
  min-height: 140px;
  border: 3px solid #000;
  background: #1a1a2e;
  color: #e8e8f0;
  font-family: inherit;
  cursor: pointer;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 0 #000, inset 0 0 0 2px #3a3a5e;
  transition: all 0.1s;
}
.card-btn:hover { filter: brightness(1.15); transform: translateY(-2px); box-shadow: 0 8px 0 #000, inset 0 0 0 2px #ffe070; }
.card-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #000, inset 0 0 0 2px #ffe070; }
.card-btn.selected { background: #2c2c4a; box-shadow: 0 6px 0 #000, inset 0 0 0 2px #ffe070; }
.card-icon { font-size: 46px; line-height: 1; }
.card-title { font-size: 17px; font-weight: bold; letter-spacing: 2px; color: #ffe070; text-shadow: 2px 2px 0 #000; }
.card-desc { font-size: 12px; color: #bcbce0; }
.card-tag {
  margin-top: 4px;
  padding: 3px 10px;
  background: #3a2a6a;
  color: #fff6c8;
  font-size: 11px;
  letter-spacing: 1px;
  border: 2px solid #000;
}
.card-tag.boss { background: #7a1a26; }
.card-tag.easy { background: #1a5a2a; }
.card-tag.new  { background: #5a1a7a; }

.back-row { margin-top: 14px; }
.ghost-btn {
  border: 2px solid #444466;
  background: transparent;
  color: #aaa;
  font-family: inherit;
  padding: 6px 16px;
  cursor: pointer;
  letter-spacing: 1px;
}
.ghost-btn:hover { color: #ffe070; border-color: #ffe070; }

.start-row { margin: 18px 0 8px; }
.start-btn {
  border: 3px solid #000;
  background: #2a7a2a;
  color: #fff;
  font-family: inherit;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 4px;
  padding: 14px 40px;
  cursor: pointer;
  box-shadow: 0 6px 0 #000, inset 0 0 0 2px #7fe07f;
  text-shadow: 2px 2px 0 #000;
}
.start-btn:hover { filter: brightness(1.15); }
.start-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #000, inset 0 0 0 2px #7fe07f; }

.mode-hint { color: #ffe070; font-size: 13px; letter-spacing: 2px; margin: 8px 0 0; }
.help-panel { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-bottom: 6px; }
.help-panel.hidden { display: none; }
.help-panel .ctrl-block { min-width: 180px; padding: 8px 14px; }
.help-panel .ctrl-block h3 { font-size: 12px; letter-spacing: 1px; margin-bottom: 6px; }
.help-panel .ctrl-block p { font-size: 11px; line-height: 1.8; }

/* ===== 积分模式 HUD ===== */
.score-hud, .enemy-hud {
  margin-top: 6px;
  font-size: 11px;
  letter-spacing: 1px;
  color: #ffe070;
  text-shadow: 1px 1px 0 #000;
  display: inline-block;
  background: rgba(0,0,0,0.5);
  padding: 2px 8px;
  border: 1px solid #444466;
}
.enemy-hud { color: #ff8f9a; }
.score-hud b, .enemy-hud b { color: #fff; }
.score-hud.hidden, .enemy-hud.hidden { display: none; }

.buff-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  background: #ff6a2a;
  color: #fff;
  font-size: 10px;
  border: 1px solid #000;
}
.buff-badge.hidden { display: none; }

/* 旋转提示按钮样式统一 */
.rotate-tip .ghost-btn { font-size: 14px; padding: 8px 22px; }

.hint {
  color: #ffe070;
  font-size: 13px;
  letter-spacing: 2px;
  animation: blink 1.1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.25; } }

/* 模式切换按钮 */
.mode-select {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.mode-btn {
  border: 3px solid #000;
  background: #2a2a44;
  color: #e8e8f0;
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 1px;
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 #000, inset 0 0 0 2px #444466;
  font-weight: bold;
  transition: all 0.1s;
}
.mode-btn:hover { filter: brightness(1.15); }
.mode-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #000; }
.mode-btn.selected {
  background: #ffe070;
  color: #1a1a2a;
  box-shadow: 0 4px 0 #7a5a1a, inset 0 0 0 2px #fff6c8;
}

/* 单人模式 / 手机：隐藏 P2 的触摸按键面板 */
#frame.mode-1p .p2-pad { display: none; }
#frame.mode-1p .p1-pad { width: 60%; }   /* 给 P1 更多空间 */
/* 1P 模式下 D-pad 和动作键集中在屏幕左下和右下 */
#frame.mode-1p .p1-pad { left: 0; right: auto; }

@media (pointer: coarse) and (max-height: 420px) {
  /* 小屏手机模式：1P 模式下再缩控件 */
  #frame.mode-1p .p1-pad .dpad { width: 150px; height: 108px; }
  #frame.mode-1p .p1-pad .abtn { width: 150px; height: 100px; }
  #frame.mode-1p .p1-pad .abtn .atk { width: 64px; height: 64px; }
  #frame.mode-1p .p1-pad .abtn .blk { width: 52px; height: 52px; }
  #frame.mode-1p .p1-pad .abtn .atk { left: 86px; top: 0; }
  #frame.mode-1p .p1-pad .abtn .blk { left: 0; bottom: 0; }
}

/* 桌面强制 2P 时也不显示 P2 触摸板（让用户用键盘） */
@media (pointer: fine) {
  .touch-group { display: none; }
  .global-tk   { display: none; }
}

/* ================= 手机适配：横屏锁定 + 触摸控件 ================= */

/* 竖屏时显示旋转提示（按最长边判断移动端，<900px 且 高>宽） */
@media (pointer: coarse) and (orientation: portrait) and (max-width: 900px) {
  #rotate-tip { display: flex; }
  #touch-layer { display: none; }
}
#rotate-tip {
  display: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, #1a1430 0%, #0a0a14 75%);
  z-index: 999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #ffe070;
  font-family: "Courier New", monospace;
  letter-spacing: 2px;
  text-align: center;
  padding: 24px;
}
.rotate-icon {
  font-size: 64px;
  margin-bottom: 20px;
  animation: rotatePhone 2.4s ease-in-out infinite;
}
@keyframes rotatePhone {
  0%, 30% { transform: rotate(0deg); }
  70%, 100% { transform: rotate(-90deg); }
}
.rotate-sub { color: #a8a8c0; margin-top: 8px; font-size: 14px; letter-spacing: 1px; }

/* 触摸层：默认不显示（桌面端），仅在 coarse 指针（触屏）下显示 */
.touch-layer {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
@media (pointer: coarse) {
  .touch-layer { display: block; }
}
.touch-group {
  position: absolute;
  bottom: 0;
  width: 46%;
  height: 100%;
  pointer-events: none;
}
.p1-pad { left: 0; }
.p2-pad { right: 0; }

.dpad {
  position: absolute;
  bottom: 2vh;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  /* Dpad 布局: 上在顶部，左右在底部一排 */
  width: 180px;
  height: 130px;
}
.p1-pad .dpad { left: 2vh; }
.p2-pad .dpad { right: 2vh; }

.dpad .tk {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.dpad .up    { left: 62px; top: 0; }
.dpad .left  { left: 0; bottom: 0; }
.dpad .right { left: 124px; bottom: 0; }

.abtn {
  position: absolute;
  bottom: 2vh;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  width: 170px;
  height: 110px;
}
.p1-pad .abtn { right: 2vh; }
.p2-pad .abtn { left: 2vh; }

.abtn .tk {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
}
.abtn .blk { width: 58px; height: 58px; }
.abtn .atk { width: 72px; height: 72px; font-size: 17px; }

/* P1 蓝系按钮布局：BLK 左下，ATK 右上 */
.p1-pad .abtn .blk { left: 0;   bottom: 0; }
.p1-pad .abtn .atk { left: 80px; top: 0; }
/* P2 红系按钮布局：BLK 右下，ATK 左上（对调，让 ATK 更容易按到） */
.p2-pad .abtn .blk { right: 0;   bottom: 0; }
.p2-pad .abtn .atk { right: 80px; top: 0; }

/* 全局 START / RESET */
.global-tk {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}
.global-tk .tk {
  padding: 6px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 1px;
  width: auto;
  height: 36px;
}

/* 按钮通用样式 */
.tk {
  border: 3px solid #000;
  background: #2a2a44;
  color: #e8e8f0;
  box-shadow: 0 4px 0 #000, inset 0 0 0 2px #444466;
  opacity: 0.86;
  transition: transform 0.06s, background 0.06s, box-shadow 0.06s, opacity 0.06s;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  font-family: inherit;
}
.tk:active, .tk.is-down {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #000, inset 0 0 0 2px #5a5a88;
  opacity: 1;
}

/* 各按钮色调 */
.p1-pad .dpad .tk, .p1-pad .abtn .blk {
  background: #1a3f7a;
  box-shadow: 0 4px 0 #000, inset 0 0 0 2px #3a8fe0;
}
.p1-pad .abtn .atk {
  background: #1a5fb0;
  box-shadow: 0 4px 0 #000, inset 0 0 0 2px #8fd0ff;
  color: #fff;
}
.p2-pad .dpad .tk, .p2-pad .abtn .blk {
  background: #7a1a26;
  box-shadow: 0 4px 0 #000, inset 0 0 0 2px #e03a4a;
}
.p2-pad .abtn .atk {
  background: #b01a2a;
  box-shadow: 0 4px 0 #000, inset 0 0 0 2px #ff8f9a;
  color: #fff;
}
.global-tk .start   { background: #3a6a2a; box-shadow: 0 4px 0 #000, inset 0 0 0 2px #7fe07f; }
.global-tk .restart { background: #7a5a1a; box-shadow: 0 4px 0 #000, inset 0 0 0 2px #ffe070; }

.tk.is-down { filter: brightness(1.25); }

/* 小屏手机进一步压缩控件大小 */
@media (pointer: coarse) and (max-height: 420px) {
  .dpad { width: 140px; height: 104px; }
  .dpad .tk { width: 44px; height: 44px; font-size: 18px; }
  .dpad .up    { left: 48px; }
  .dpad .right { left: 96px; }
  .abtn { width: 136px; height: 90px; }
  .abtn .blk { width: 48px; height: 48px; font-size: 12px; }
  .abtn .atk { width: 58px; height: 58px; font-size: 14px; }
  .p1-pad .abtn .atk { left: 66px; }
  .p2-pad .abtn .atk { right: 66px; }
}

/* 手机 HUD 字号微调 */
@media (pointer: coarse) {
  #hud { font-size: 11px; top: 4px; padding: 0 8px; }
  #center-info { min-width: 62px; padding: 0 6px; }
  #round-text { font-size: 10px; }
  #timer { font-size: 18px; }
  .name { font-size: 11px; margin-bottom: 2px; }
  .bar { height: 11px; border-width: 2px; }
  .overlay h1 { font-size: clamp(20px, 6vw, 40px); letter-spacing: 3px; }
  .subtitle { letter-spacing: 3px; font-size: 12px; }
  .controls { margin: 14px 0 8px; gap: 10px; }
  .ctrl-block { min-width: 150px; padding: 8px 10px; }
  .ctrl-block h3 { font-size: 11px; margin-bottom: 4px; letter-spacing: 1px; }
  .ctrl-block p { font-size: 10px; line-height: 1.7; }
  .hint { font-size: 11px; letter-spacing: 1px; }
}

/* =====================================================================
   手机平台强制显示（body.platform-mobile：用户在菜单里选择了「手机」）
   —— 软件横屏 + 虚拟按键常驻显示
   ===================================================================== */

/* 新的根层：移动端旋转舞台用 */
#viewport {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  z-index: 0;
}
#mobile-shell {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  transition: transform 0.25s ease, width 0s, height 0s, top 0s, left 0s;
}

/* 在 .platform-mobile 下：不管屏幕真实方向，强制横屏坐标 */
body.platform-mobile {
  background: #000;
}
body.platform-mobile #stage {
  width: 100%;
  height: 100%;
}
body.platform-mobile #frame {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
}

/* 强制虚拟按键层显示（覆盖 pointer:fine / 竖屏 的隐藏规则） */
body.platform-mobile .touch-layer {
  display: block !important;
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
/* 只强制显示 P1 触摸板；P2 在 1P/积分模式下保持隐藏 */
body.platform-mobile .p1-pad {
  display: block !important;
}
body.platform-mobile .global-tk {
  display: flex !important;
}
/* 双人模式下才显示 P2 触摸板（移动端目前没有双人，保留兼容） */
body.platform-mobile #frame.mode-2p .p2-pad {
  display: block !important;
}

/* 手机端按键更大，降低误触 */
body.platform-mobile .dpad {
  width: 42vw;
  height: 32vw;
  max-width: 220px;
  max-height: 170px;
  bottom: 4vw;
}
body.platform-mobile .dpad .tk {
  width: 32%;
  height: 48%;
  font-size: clamp(18px, 4.6vw, 28px);
  border-radius: 18px;
}
/* 四向 D-pad 布局：上中 / 左中 / 中下 / 右中 */
body.platform-mobile .dpad .up    { left: 34%; top: 0; }
body.platform-mobile .dpad .down  { left: 34%; bottom: 0; }
body.platform-mobile .dpad .left  { left: 0;   top: 26%; }
body.platform-mobile .dpad .right { left: auto; right: 0; top: 26%; bottom: auto; }

body.platform-mobile .p1-pad .dpad { left: 3vw; }
body.platform-mobile .p1-pad .abtn { right: 3vw; bottom: 4vw; }

body.platform-mobile .abtn {
  width: 38vw;
  height: 28vw;
  max-width: 200px;
  max-height: 150px;
}
body.platform-mobile .abtn .atk {
  width: 56%;
  height: 62%;
  font-size: clamp(13px, 3.8vw, 20px);
}
body.platform-mobile .abtn .blk {
  width: 40%;
  height: 46%;
  font-size: clamp(11px, 3vw, 16px);
}
body.platform-mobile .p1-pad .abtn .atk { left: 44%; top: 0; }
body.platform-mobile .p1-pad .abtn .blk { left: 0;   bottom: 0; }
body.platform-mobile .p2-pad .abtn .atk { right: 44%; top: 0; }
body.platform-mobile .p2-pad .abtn .blk { right: 0;   bottom: 0; }

body.platform-mobile .global-tk {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  gap: 10px;
}
body.platform-mobile .global-tk .tk {
  padding: 8px 18px;
  height: 40px;
  font-size: 14px;
}

/* 手机端 overlay 的 start-btn 更大、更容易点 */
body.platform-mobile .overlay .start-btn {
  padding: 18px 60px;
  font-size: 22px;
}
body.platform-mobile .card-btn {
  min-height: 120px;
  width: 44%;
  padding: 14px 10px;
}
body.platform-mobile .step-title {
  font-size: 15px;
  letter-spacing: 1px;
}

/* 软件横屏旋转：当屏幕真实为竖屏时，把 #mobile-shell 旋转 90°
   并根据 vw/vh 交换，保证能填满整个屏
   —— 由 JS 切换 .landscape-forced 来触发
*/
body.platform-mobile.landscape-forced #mobile-shell {
  /* 旋转：把横屏坐标系映射到竖屏物理屏 */
  transform: rotate(90deg);
  width: 100vh;
  height: 100vw;
  top:  50%;
  left: 50%;
  margin-left: calc(-100vh / 2);
  margin-top:  calc(-100vw / 2);
}

/* 平台=手机 时，不再依赖竖屏媒体查询强制显示 rotate-tip。
   用户选了手机后，我们主动用 JS 判断是否真的需要显示提示。
   默认隐藏（避免之前一直出现的问题） */
body.platform-mobile #rotate-tip {
  display: none !important;
}
body.platform-mobile.need-rotate-tip #rotate-tip {
  display: flex !important;
  z-index: 2000;
}

/* 平台=手机 时，.mode-1p 下 P1 触摸板占满整宽，
   让 D-pad 在左、动作键在右（而不是挤在左半屏） */
body.platform-mobile #frame.mode-1p .p1-pad {
  width: 100%;
  left: 0;
  right: 0;
}
body.platform-mobile #frame.mode-2p .p1-pad {
  left: 0;
  right: auto;
}

