* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; }
body {
  background: #070b0e;
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", sans-serif;
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  touch-action: manipulation;
}

#app-container {
  position: relative;
  width: 100%;
  max-width: 760px;
  height: 100%;
  max-height: 900px;
  background: #122418;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 12px 40px rgba(0,0,0,0.85);
  overflow: hidden;
}

/* 顶部导航与状态栏 */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.45);
  border-bottom: 1px solid rgba(255,255,255,0.1);
  z-index: 20;
  flex-shrink: 0;
}
.bar-left, .bar-right { display: flex; gap: 8px; align-items: center; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.speed-btn {
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid #ffd600;
  background: rgba(255, 214, 0, 0.15);
  color: #ffd600;
  font-weight: 800;
  cursor: pointer;
}
.hud-stats { display: flex; gap: 8px; }
.stat-pill {
  background: rgba(0,0,0,0.5);
  padding: 5px 10px;
  border-radius: 14px;
  font-size: 13px;
  border: 1px solid rgba(255,255,255,0.12);
}
.stat-pill strong { color: #ffd600; margin-left: 3px; }

/* 核心球场舞台自适应 */
#stage-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 8px;
  gap: 8px;
  overflow: hidden;
}
#canvas-box {
  position: relative;
  aspect-ratio: 12 / 7;
  width: 100%;
  max-width: 720px;
  max-height: 100%;
  background: #1e5a2c;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  margin: auto 0;
}
canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

/* 建塔/升级弹出菜单 (支持自动 2x2 折行与紧凑排版) */
.tile-menu {
  position: absolute;
  background: rgba(12, 20, 16, 0.96);
  border: 1.5px solid #69f0ae;
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,0.85);
  max-width: 168px;
  pointer-events: auto;
}
.tower-opt {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  padding: 6px 4px;
  color: #fff;
  font-size: 11px;
  text-align: center;
  cursor: pointer;
  width: 72px;
  flex-shrink: 0;
  box-sizing: border-box;
}
.tower-opt:hover { background: rgba(105, 240, 174, 0.2); }
.tower-opt.disabled { opacity: 0.4; cursor: not-allowed; }
.tower-opt .price { color: #ffd600; font-weight: bold; display: block; margin-top: 2px; }

/* 底部战术提示栏 */
.tactical-bar {
  width: 100%;
  max-width: 720px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0,0,0,0.4);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 12px;
  color: #cfd8dc;
  gap: 10px;
  flex-shrink: 0;
}
.panic-btn {
  background: linear-gradient(135deg, #ff9100, #ff3d00);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
}

/* 弹窗遮罩 */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 10, 0.94);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 40;
}
.hidden { display: none !important; }
.modal-card {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 18px;
  padding: 20px;
  width: 100%;
  max-width: 440px;
  text-align: center;
}
.subtitle { font-size: 13px; color: #90a4ae; margin: 6px 0 14px 0; }

/* 选关卡片与双徽章 */
.level-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.lvl-btn {
  position: relative;
  background: rgba(255,255,255,0.08);
  border: 1.5px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 10px 4px;
  color: #fff;
  cursor: pointer;
  transition: all 0.15s;
}
.lvl-btn:active { transform: scale(0.95); }
.lvl-btn .num { font-size: 17px; font-weight: 900; color: #69f0ae; }
.lvl-btn .name { font-size: 11px; color: #cfd8dc; margin-top: 3px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.lvl-btn.locked {
  opacity: 0.42;
  filter: grayscale(0.85);
  cursor: not-allowed;
  border-color: rgba(255,255,255,0.1);
}
.lvl-btn.perfect {
  border: 1.5px solid #ffd600;
  box-shadow: 0 0 14px rgba(255, 214, 0, 0.45);
  background: rgba(255, 214, 0, 0.08);
}
.lvl-btn .badges {
  margin-top: 5px;
  font-size: 12px;
  display: flex;
  justify-content: center;
  gap: 5px;
}
.badge-dim { opacity: 0.22; filter: grayscale(1); }

.btn-group { display: flex; flex-direction: column; gap: 8px; align-items: center; margin-top: 14px; }
.btn {
  width: 100%; max-width: 260px; padding: 11px;
  border-radius: 25px; border: none; font-weight: 800; font-size: 14px; cursor: pointer; color: #fff;
}
.btn-primary { background: linear-gradient(135deg, #00e676, #00b0ff); color: #000; }
.btn-ad { background: linear-gradient(135deg, #ff9100, #ff3d00); }
.btn-sub { background: rgba(255,255,255,0.15); }

/* 广告槽位 */
.ad-top-indicator {
  width: 300px; display: flex; justify-content: space-between;
  background: rgba(255,255,255,0.1); padding: 6px 14px; border-radius: 16px;
  font-size: 12px; color: #ffd600; margin-bottom: 10px;
}
.banner-300x250-box {
  width: 300px; height: 250px; background: #0d131a;
  border: 1px solid rgba(255,255,255,0.2); border-radius: 10px;
  display: flex; justify-content: center; align-items: center; overflow: hidden; margin-bottom: 12px;
}
#bottom-ad-bar {
  width: 100%; height: 54px; background: #080c10;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex; justify-content: center; align-items: center; flex-shrink: 0;
}

/* ==========================================================================
   移动端横屏 (Landscape) 专属响应式优化
   ========================================================================== */
@media (orientation: landscape) and (max-height: 520px) {
  #app-container {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    box-shadow: none;
  }
  .top-bar {
    padding: 4px 10px;
  }
  .icon-btn {
    width: 28px; height: 28px;
    font-size: 13px;
  }
  .speed-btn {
    padding: 3px 8px;
    font-size: 11px;
  }
  .stat-pill {
    padding: 3px 8px;
    font-size: 11px;
  }
  #stage-wrap {
    padding: 2px 6px;
    gap: 4px;
  }
  #canvas-box {
    width: auto;
    height: 100%;
    max-width: 100%;
    aspect-ratio: 12 / 7;
  }
  .tactical-bar {
    padding: 2px 8px;
    font-size: 11px;
  }
  .panic-btn {
    padding: 3px 8px;
    font-size: 10px;
  }
  #bottom-ad-bar {
    height: 50px;
  }
  .modal-card {
    padding: 10px 16px;
    max-height: 94vh;
    overflow-y: auto;
  }
  .modal-card h2 { font-size: 17px; }
  .subtitle { font-size: 11px; margin: 3px 0 8px 0; }
  .level-grid { gap: 6px; }
  .lvl-btn { padding: 5px 2px; }
  .lvl-btn .num { font-size: 14px; }
  .lvl-btn .name { font-size: 10px; }
  .btn-group { margin-top: 8px; gap: 6px; }
  .btn { padding: 7px 12px; font-size: 12px; }
  .banner-300x250-box {
    width: 260px; height: 180px;
    margin-bottom: 6px;
  }
}