* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0%, #2b2d42 0%, #1a1b2a 70%);
  color: #f4f1de;
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 12px 40px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.wrap {
  width: 100%;
  max-width: 920px;
  text-align: center;
}

h1 {
  margin: 0 0 14px;
  font-size: 28px;
  letter-spacing: 4px;
  color: #ffd166;
  text-shadow: 0 2px 0 #00000040;
}

.hud {
  display: flex;
  justify-content: center;
  gap: 22px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 16px;
}

.hud-item b {
  color: #ffd166;
  font-size: 18px;
}

.stage {
  position: relative;
  display: inline-block;
  border: 4px solid #3d405b;
  border-radius: 8px;
  box-shadow: 0 10px 30px #00000060;
  background: #11131f;
  line-height: 0;
}

canvas {
  display: block;
  border-radius: 4px;
}

.tip {
  margin: 16px auto 0;
  max-width: 640px;
  font-size: 14px;
  color: #c9c9d4;
  line-height: 1.7;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0c0d18cc;
  border-radius: 4px;
  backdrop-filter: blur(2px);
  transition: opacity 0.2s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  background: #232539;
  border: 1px solid #3d405b;
  border-radius: 12px;
  padding: 28px 34px;
  max-width: 80%;
  box-shadow: 0 12px 40px #00000080;
}

.overlay-card h2 {
  margin: 0 0 14px;
  font-size: 24px;
  color: #ffd166;
}

.overlay-card p {
  margin: 0 0 20px;
  font-size: 15px;
  line-height: 1.8;
  color: #e7e7ef;
}

#overlay-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  background: linear-gradient(180deg, #ef8354, #d9534f);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 12px 28px;
  border-radius: 999px;
  box-shadow: 0 4px 0 #a23b39;
  transition: transform 0.08s ease;
}

#overlay-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #a23b39;
}

/* ============================================================
 * 移动端 / 触摸设备（浮窗控制 + 自适应布局）
 * 仅在 (pointer: coarse) 触摸设备上显示浮窗、启用全屏布局
 * ============================================================ */

.touch-controls {
  display: none; /* 桌面端默认隐藏 */
}

.touch-controls.hidden {
  display: none !important;
}

/* 浮窗按钮基础样式 */
.tbtn {
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  border: none;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.06s ease, background 0.06s ease;
  cursor: pointer;
}

.tbtn:active {
  transform: scale(0.93);
  background: rgba(255, 255, 255, 0.32);
}

.tbtn.bomb {
  position: fixed;
  right: calc(env(safe-area-inset-right, 0px) + 16px);
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  width: 86px;
  height: 86px;
  border-radius: 50%;
  flex-direction: column;
  font-size: 30px;
  background: linear-gradient(180deg, rgba(239, 131, 84, 0.88), rgba(217, 83, 79, 0.88));
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}

.tbtn.bomb span {
  font-size: 12px;
  margin-top: 3px;
  letter-spacing: 1px;
}

@media (pointer: coarse) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  body {
    flex-direction: column;
    padding: 0;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  .wrap {
    max-width: none;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding:
      calc(env(safe-area-inset-top, 0px) + 8px)
      calc(env(safe-area-inset-right, 0px) + 10px)
      0
      calc(env(safe-area-inset-left, 0px) + 10px);
  }

  h1 {
    font-size: 18px;
    letter-spacing: 2px;
    margin: 4px 0 8px;
  }

  .hud {
    font-size: 13px;
    gap: 14px;
    margin-bottom: 8px;
  }

  .hud-item b {
    font-size: 15px;
  }

  .stage {
    flex: 1 1 auto;
    width: 100%;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-width: 2px;
  }

  canvas {
    border-radius: 4px;
  }

  .tip {
    display: none; /* 移动端隐藏说明，节省空间 */
  }

  .overlay {
    border-radius: 4px;
  }

  .overlay-card {
    padding: 22px 26px;
  }

  .overlay-card h2 {
    font-size: 20px;
  }

  /* 浮窗控制：覆盖全屏但仅按钮可点 */
  .touch-controls {
    display: block;
    position: fixed;
    inset: 0;
    pointer-events: none; /* 容器不拦截，仅按钮接收触摸 */
    z-index: 20;
  }
}
