* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  /* 移动端：禁止双击缩放 / 长按菜单 / 高亮，避免误触 */
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* Phaser 画布挂载点：铺满视口，交给 Phaser 的 FIT 缩放居中 */
#game-container {
  position: fixed;
  inset: 0;
  /* 沉浸式：内容避开刘海/灵动岛和底部 Home 指示条 */
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background: #0d0a06;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===================== 开始菜单 ===================== */
#start-menu {
  position: absolute;
  inset: 0;
  /* 复用游戏内木质地板素材做背景，叠一层深色渐变保证文字可读 */
  background-color: #2b1d0e;
  background-image:
    linear-gradient(rgba(20, 12, 4, 0.62), rgba(20, 12, 4, 0.62)),
    url(./public/floors/wooden.png);
  background-repeat: repeat;
  background-size: auto, 56px 56px; /* 放大像素地板，更有质感 */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  color: #fff;
  /* 沉浸式：避开刘海和 Home 指示条 */
  padding:
    calc(24px + env(safe-area-inset-top))
    24px
    calc(24px + env(safe-area-inset-bottom))
    24px;
}

/* 漂浮装饰硬币：复用游戏内硬币精灵图（切第 0 帧） */
.menu-coins {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.menu-coin {
  position: absolute;
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-size: 600% 100%; /* 6 帧横向精灵图：整体宽度=6×容器，单帧=容器宽 */
  background-position: 0% 0%; /* 取第 0 帧（硬币正面） */
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.5));
  animation: coin-bob 3.2s ease-in-out infinite;
  opacity: 0.92;
}
.menu-coin.copper {
  background-image: url(./public/CopperCoinSpin.png);
  top: 12%;
  left: 14%;
  animation-delay: 0s;
}
.menu-coin.silver {
  background-image: url(./public/SilverCoinSpin.png);
  top: 18%;
  right: 12%;
  animation-delay: 0.6s;
}
.menu-coin.gold {
  background-image: url(./public/GoldCoinSpin.png);
  bottom: 14%;
  left: 16%;
  animation-delay: 1.1s;
}
.menu-coin.small {
  width: 38px;
  height: 38px;
  background-size: 600% 100%;
  top: 72%;
  right: 18%;
  animation-delay: 1.7s;
}

@keyframes coin-bob {
  0%,
  100% {
    transform: translateY(0) rotate(-4deg);
  }
  50% {
    transform: translateY(-12px) rotate(4deg);
  }
}

.menu-title {
  position: relative;
  z-index: 1;
  font-size: clamp(32px, 9vw, 52px);
  margin: 0 0 12px;
  color: #ffd700;
  text-shadow: 0 2px 0 #8a6d00, 2px 4px 8px rgba(0, 0, 0, 0.6);
  letter-spacing: 2px;
}

.menu-subtitle {
  position: relative;
  z-index: 1;
  margin: 0 0 36px;
  font-size: clamp(13px, 3.6vw, 17px);
  color: #f3e6c4;
  opacity: 0.85;
  text-align: center;
}

#menu-buttons {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  align-items: center;
  gap: 14px;
}

.menu-button {
  background: #4a90e2;
  color: #fff;
  border: none;
  padding: 14px 10px;
  border-radius: 12px;
  cursor: pointer;
  width: 30%;
  min-height: 48px;
  font-size: clamp(15px, 4.2vw, 18px);
  font-weight: bold;
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 6px 10px rgba(0, 0, 0, 0.3);
}
.menu-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25), 0 2px 4px rgba(0, 0, 0, 0.3);
}
.menu-button:hover {
  background: #357abd;
}
.menu-button.warning {
  background: #e74c3c;
}
.menu-button.warning:hover {
  background: #c0392b;
}
.menu-button.success {
  background: #2ecc71;
}
.menu-button.success:hover {
  background: #27ae60;
}

/* ===================== 加载界面 ===================== */
#loading-container {
  position: absolute;
  inset: 0;
  background: rgba(20, 12, 4, 0.92);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1001;
  color: #fff;
  /* 沉浸式：避开刘海和 Home 指示条 */
  padding:
    calc(24px + env(safe-area-inset-top))
    24px
    calc(24px + env(safe-area-inset-bottom))
    24px;
}
.loading-title {
  font-size: clamp(24px, 7vw, 32px);
  margin-bottom: 20px;
  color: #ffd700;
}
.loading-bar-container {
  width: 80%;
  max-width: 360px;
  height: 20px;
  background: #333;
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 10px;
}
.loading-bar {
  height: 100%;
  background: #4a90e2;
  width: 0%;
  transition: width 0.3s ease;
}
.loading-text {
  font-size: 16px;
}

/* ===================== 手机端适配 ===================== */
@media (max-width: 480px) {
  #menu-buttons {
    flex-direction: column;
    gap: 16px;
  }
  .menu-button {
    width: 78%;
    min-height: 54px;
    font-size: 18px;
    padding: 16px 10px;
  }
  .menu-coin {
    width: 44px;
    height: 44px;
  }
  .menu-coin.small {
    width: 30px;
    height: 30px;
  }
}

/* 横屏手机：菜单内容收窄，避免被压扁 */
@media (max-height: 430px) and (orientation: landscape) {
  .menu-title {
    margin-bottom: 8px;
  }
  .menu-subtitle {
    margin-bottom: 18px;
  }
  .menu-coin {
    opacity: 0.7;
  }
}

/* ===================== PWA 沉浸式 ===================== */
/* 添加到主屏幕（standalone）时，隐藏滚动回弹，禁止 iOS 下拉橡皮筋 */
@media (display-mode: standalone) {
  html,
  body {
    overscroll-behavior: none;
    position: fixed;
    width: 100%;
  }
  /* 全屏模式下禁止 iOS 双击缩放和长按 */
  * {
    -webkit-touch-callout: none;
  }
}
