/* tower-defense.css */

.td-body {
  background-color: var(--bg);
  touch-action: none; /* 防止双指缩放 */
  overflow: hidden; /* 游戏全屏体验，防止外层滚动 */
}

.td-main {
  height: 100vh;
  padding: 100px 24px 24px 24px;
  box-sizing: border-box;
  position: relative;
}

.td-workspace {
  display: flex;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  height: calc(100vh - 124px);
}

.game-container {
  flex-grow: 1;
  background: var(--glass-strong);
  backdrop-filter: blur(24px);
  border: 1px solid var(--soft-line);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  box-shadow: 0 12px 40px rgba(0,0,0,0.15);
}

/* 核心等比例拉伸机制 */
.game-container canvas {
  transform-origin: center center;
  image-rendering: pixelated; /* 强制像素抗锯齿关闭，保留像素风 */
  max-width: none !important;
  max-height: none !important;
  width: auto !important;
  height: auto !important;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

.control-panel {
  width: 320px;
  background: var(--glass);
  border: 1px solid var(--soft-line);
  border-radius: 16px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.04);
  overflow-y: auto;
  flex-shrink: 0;
}

.panel-header h2 {
  margin: 0 0 12px 0;
  font-size: 24px;
  color: var(--ink);
}

.stats-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.stat-badge {
  background: #fff;
  border: 1px solid var(--soft-line);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.tower-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tower-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 2px solid transparent;
  padding: 12px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.03);
  transition: all 0.2s;
  text-align: left;
}

.tower-card:hover {
  transform: translateY(-2px);
  border-color: rgba(44, 90, 242, 0.3);
}

.tower-card.selected {
  border-color: #2c5af2;
  background: #f0f4ff;
}

.tower-icon {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  flex-shrink: 0;
}

.tower-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tower-info strong {
  font-size: 15px;
  color: var(--ink);
}

.tower-info span {
  font-size: 12px;
  color: var(--muted);
}

.tower-info .cost {
  color: #e67e22;
  font-weight: bold;
}

.action-menu {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.primary-button {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: var(--ink);
  color: #fff;
  font-weight: bold;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.2s;
  min-height: 48px; /* Touch target size */
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--soft-line);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.ghost-button:hover {
  background: var(--hover-bg);
  color: var(--text-color);
}

.hidden {
  display: none !important;
}

.highlight {
  background: linear-gradient(135deg, #2c5af2, #688af7);
  box-shadow: 0 4px 15px rgba(44, 90, 242, 0.3);
}

.highlight:hover {
  transform: translateY(-2px);
}

.hidden {
  display: none !important;
}

.upgrade-panel {
  background: #fff;
  padding: 16px;
  border-radius: 12px;
  border: 1px dashed var(--soft-line);
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.upgrade-info {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
}

/* 覆盖层：选关与结束 */
.overlay-screen {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(250, 247, 240, 0.9);
  backdrop-filter: blur(10px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay-screen.active {
  opacity: 1;
  pointer-events: auto;
}

.level-dialog, .game-over-dialog {
  background: #fff;
  padding: 40px;
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.1);
  text-align: center;
  width: min(90%, 500px);
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 24px;
}

.level-btn {
  padding: 16px;
  border-radius: 16px;
  border: 2px solid var(--soft-line);
  background: transparent;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.level-btn:hover:not(:disabled) {
  border-color: #2c5af2;
  color: #2c5af2;
  background: rgba(44, 90, 242, 0.05);
}

.level-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f5f5f5;
}

/* 开发者控制台日志 */
.dev-console {
  max-height: 100px;
  overflow-y: auto;
  font-family: monospace;
  font-size: 10px;
  background: #2b2b2b;
  color: #a9b7c6;
  padding: 8px;
  border-radius: 6px;
  margin-top: 8px;
  display: none;
}
.dev-console.active { display: block; }

@media (max-width: 900px) {
  .td-body {
    overflow: auto; /* 允许移动端原生滚动 */
    touch-action: auto;
  }

  .td-body .site-header {
    position: relative;
    top: 0;
    transform: none;
    left: 0;
    width: auto;
    margin: 12px;
    z-index: 100;
  }

  .td-main {
    height: auto; /* 解除 100vh 限制 */
    min-height: 100vh;
    padding: 12px; /* 恢复正常留白，因为 header 已经是 relative 不会遮挡了 */
  }
  
  .td-workspace {
    flex-direction: column;
    gap: 12px;
    height: auto;
    min-height: calc(100dvh - 100px);
  }

  .game-container {
    flex-grow: 0;
    min-height: 0;
    width: 100%;
    aspect-ratio: 4 / 3;
  }

  .control-panel {
    width: 100%;
    max-height: none; /* 移除抽屉高度限制，让它可以自然向下滚动 */
    border-radius: 20px;
    padding: 16px;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  }

  .tower-cards {
    flex-direction: row;
    overflow-x: auto;
  }
  
  .tower-card {
    min-width: 140px;
    flex-shrink: 0;
  }
}

/* 资金不足时的置灰效果 */
.disabled-card {
  opacity: 0.4 !important;
  filter: grayscale(100%) !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}

.disabled-card:hover {
  transform: none !important;
  border-color: transparent !important;
}
