* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 30%, #1c2a1c, #0d120d 70%);
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#stage {
  position: relative;
}

#gameCanvas {
  display: block;
  border-radius: 10px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.7);
  touch-action: none;
  background: #14181c;
}

/* ===== 弹层 ===== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: rgba(10, 14, 10, 0.78);
  border-radius: 10px;
  text-align: center;
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  color: #8bc34a;
  font-size: clamp(30px, 6vw, 52px);
  letter-spacing: 4px;
  text-shadow: 0 3px 0 #2c5e2c;
}

.overlay .subtitle {
  color: #c5e1a5;
  font-size: 15px;
  letter-spacing: 1px;
  margin-top: -8px;
}

.overlay button {
  font-size: 18px;
  padding: 12px 44px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #9ccc65, #689f38);
  color: #16240d;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 0 #33691e;
}

.overlay button:hover {
  background: linear-gradient(180deg, #aed581, #7cb342);
  transform: translateY(-1px);
}

.overlay button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #33691e;
}

.overlay .tip {
  color: #cfd8c3;
  font-size: 14px;
}

.overlay .btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.overlay .secondary {
  background: linear-gradient(180deg, #78909c, #546e7a);
  color: #ffffff;
  box-shadow: 0 4px 0 #37474f;
}

.overlay .secondary:hover {
  background: linear-gradient(180deg, #90a4ae, #607d8b);
}

.overlay #resultMsg {
  color: #cfd8c3;
  font-size: 16px;
}

/* ===== 关卡选择 ===== */
.overlay .level-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(560px, 92%);
  max-height: 70vh;
  overflow-y: auto;
  padding: 4px;
}

.world-title {
  color: #ffd54f;
  font-size: 14px;
  letter-spacing: 2px;
  margin-top: 10px;
  text-align: left;
  border-left: 4px solid #ffd54f;
  padding-left: 8px;
}

.level-grid .level {
  font-size: 16px;
  padding: 12px 20px;
}

.level-grid .level.cleared {
  background: linear-gradient(180deg, #aed581, #7cb342);
}

.level-grid .level.locked {
  background: #455a64;
  color: #90a4ae;
  cursor: not-allowed;
  box-shadow: 0 4px 0 #37474f;
}

.level-grid .level.locked:hover {
  background: #455a64;
  transform: none;
}

#nextBtn.hidden {
  display: none;
}

.overlay .volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cfd8c3;
  font-size: 14px;
}

.overlay .volume-row input[type="range"] {
  width: 180px;
  accent-color: #8bc34a;
}

.overlay .btn-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 220px;
}

/* ===== 手机竖屏提示 ===== */
#rotateHint {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 8, 0.95);
  color: #e8f5e9;
}

#rotateHint.hidden {
  display: none;
}

.rotate-inner {
  text-align: center;
}

.rotate-inner p {
  font-size: 20px;
  margin-top: 16px;
  letter-spacing: 2px;
}

.rotate-sub {
  font-size: 13px !important;
  color: #a5d6a7;
  margin-top: 6px !important;
  letter-spacing: 1px;
}

.rotate-icon {
  width: 54px;
  height: 90px;
  margin: 0 auto;
  border: 4px solid #8bc34a;
  border-radius: 12px;
  position: relative;
  animation: rotateHint 1.8s ease-in-out infinite;
}

.rotate-icon::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 4px;
  background: #8bc34a;
  border-radius: 2px;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
}

@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

/* ===== 移动端触控 dock ===== */
#touchDock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(20,30,18,0.92), rgba(10,16,10,0.98));
  border-top: 2px solid #33691e;
  backdrop-filter: blur(4px);
}

#touchDock.hidden {
  display: none;
}

.dock-cards {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.dock-card {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 76px;
  border: 2px solid #1b5e20;
  border-radius: 10px;
  background: linear-gradient(180deg, #2e6b2e, #1b4d1b);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 2px;
  overflow: hidden;
}

.dock-card.sel {
  border-color: #ffd54f;
  box-shadow: 0 0 0 2px #ffd54f inset;
}

.dock-card.disabled {
  opacity: 0.55;
}

.dock-icon {
  width: 56px;
  height: 50px;
  pointer-events: none;
}

.dock-name {
  font-size: 10px;
  line-height: 1.1;
  margin-top: -4px;
  pointer-events: none;
}

.dock-cost {
  position: absolute;
  right: 3px;
  top: 2px;
  font-size: 11px;
  font-weight: bold;
  color: #ffd54f;
  text-shadow: 0 1px 1px #000;
  pointer-events: none;
}

.dock-overlay {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.dock-overlay.hidden {
  display: none;
}

.dock-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 0 0 auto;
}

.dock-btn {
  flex: 1;
  min-width: 56px;
  border: 2px solid #33691e;
  border-radius: 10px;
  background: linear-gradient(180deg, #558b2f, #33691e);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  padding: 0 10px;
}

.dock-btn.sel {
  border-color: #ffd54f;
  background: linear-gradient(180deg, #827717, #5d5300);
}

.dock-btn:active {
  transform: scale(0.96);
}

/* 桌面端隐藏 dock（仅触屏设备由 JS 启用） */
@media (pointer: fine) {
  #touchDock { display: none !important; }
}
