/* ========================================
   全局样式重置
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ========================================
   页面主体样式
   ======================================== */
body {
    /* 渐变背景色 */
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    /* Flexbox居中布局 */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    /* 字体设置 */
    font-family: 'Arial', sans-serif;
    /* 隐藏溢出内容 */
    overflow: hidden;
}

/* ========================================
   游戏容器样式
   ======================================== */
#gameContainer {
    /* 相对定位，用于内部绝对定位元素 */
    position: relative;
    /* 阴影效果 */
    box-shadow: 0 25px 50px rgba(0,0,0,0.5), 0 0 100px rgba(0,0,0,0.3);
    /* 圆角边框 */
    border-radius: 25px;
    /* 隐藏溢出内容 */
    overflow: hidden;
    /* 渐变背景 */
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    /* 白色边框 */
    border: 4px solid rgba(255,255,255,0.4);
    /* 过渡动画 */
    transition: all 0.3s ease;
}

/* ========================================
   脉冲动画
   ======================================== */
@keyframes pulse {
    0%   { box-shadow: 0 0 25px rgba(0,0,0,0.4); }
    50%  { box-shadow: 0 0 50px rgba(0,0,0,0.6); }
    100% { box-shadow: 0 0 25px rgba(0,0,0,0.4); }
}

/* ========================================
   画布样式
   ======================================== */
canvas {
    /* 隐藏默认显示 */
    display: block;
    /* 十字光标 */
    cursor: crosshair;
    /* 过滤器过渡 */
    transition: filter 0.3s;
    /* 圆角边框 */
    border-radius: 20px;
    /* 内阴影和外阴影 */
    box-shadow: inset 0 0 25px rgba(0,0,0,0.15), 0 5px 15px rgba(0,0,0,0.3);
    /* 过渡动画 */
    transition: all 0.3s ease;
    /* 固定尺寸 */
    width: 1246px;
    height: 700px;
    /* 网格样式背景 */
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.1) 1px, transparent 1px);
    background-size: 40px 40px;
}

/* ========================================
   游戏UI显示区域样式
   ======================================== */
#ui {
    /* 绝对定位 */
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    /* Flexbox布局 */
    display: none;
    justify-content: space-between;
    align-items: center;
    /* 文字样式 */
    color: white;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.9);
    font-size: 12px;
    font-weight: bold;
    /* 禁用指针事件 */
    pointer-events: none;
    /* 背景透明 */
    background: transparent;
    padding: 10px 15px;
    border-radius: 0;
    backdrop-filter: none;
    border: none;
    box-shadow: none;
    /* 过渡动画 */
    transition: all 0.3s ease;
}

/* ========================================
   UI滑入动画
   ======================================== */
@keyframes uiSlideDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   UI子元素样式
   ======================================== */
#ui > div {
    background: transparent;
    padding: 5px 5px;
    border-radius: 0;
    pointer-events: none;
    transition: none;
    border: none;
    box-shadow: none;
    position: static;
    overflow: visible;
    font-size: 24px;
    margin-left: 180px;
    margin-top: -20px;
}

#ui > div:nth-child(2) {
    margin-left: 300px;
    margin-right: auto;
    text-align: center;
}

/* ========================================
   防御塔选择器样式
   ======================================== */
#towerSelector {
    /* 绝对定位 */
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    /* 隐藏 */
    display: none;
    gap: 20px;
    background: rgba(0,0,0,0.8);
    padding: 10px 10px;
    border-radius: 25px;
    backdrop-filter: blur(25px);
    animation: slideIn 0.6s ease-out;
    border: 2px solid rgba(255,255,255,0.5);
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    transition: all 0.3s ease;
}

/* ========================================
   滑入动画
   ======================================== */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ========================================
   防御塔按钮通用样式
   ======================================== */
.tower-btn {
    width: 50px;
    height: 50px;
    border: 4px solid white;
    border-radius: 20px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(0,0,0,0.5);
    transform: scale(1);
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ========================================
   防御塔按钮悬停效果
   ======================================== */
.tower-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, transparent, rgba(255,255,255,0.4), transparent);
    transform: translateX(-100%);
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

.tower-btn:hover::before {
    transform: translateX(100%);
}

.tower-btn:hover {
    transform: scale(1.3) rotate(5deg);
    box-shadow: 0 10px 35px rgba(0,0,0,0.6);
}

/* ========================================
   选中状态的防御塔按钮
   ======================================== */
.tower-btn.selected {
    border-color: #FFD700;
    box-shadow: 0 0 30px #FFD700, 0 0 60px #FFD700, 0 0 90px #FFD700;
    transform: scale(1.3) rotate(0deg);
    z-index: 10;
}

/* ========================================
   防御塔颜色样式
   ======================================== */
.tower-btn.tower1 { background: linear-gradient(135deg, #FF6B6B, #EE5A5A); }
.tower-btn.tower2 { background: linear-gradient(135deg, #4ECDC4, #44A08D); }
.tower-btn.tower3 { background: linear-gradient(135deg, #A8E6CF, #88D8B0); }
.tower-btn.tower4 { background: linear-gradient(135deg, #ADD8E6, #87CEEB); }

/* ========================================
   防御塔图标样式
   ======================================== */
.tower-icon {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 10%;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.6));
}

/* ========================================
   防御塔悬停图标效果
   ======================================== */
.tower-btn:hover .tower-icon {
    transform: scale(1.4);
}

/* ========================================
   防御塔价格标签样式
   ======================================== */
.tower-btn span {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    font-size: 14px;
    font-weight: bold;
    color: white;
    text-shadow: 2px 2px 5px rgba(0,0,0,0.9);
    pointer-events: none;
}

/* ========================================
   游戏结束界面样式
   ======================================== */
#gameOver {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.95);
    color: white;
    padding: 60px;
    border-radius: 30px;
    text-align: center;
    display: none;
    animation: fadeIn 0.8s ease-out;
    border: 3px solid rgba(255,255,255,0.4);
    box-shadow: 0 10px 30px rgba(0,0,0,0.6);
    transition: all 0.3s ease;
}

/* ========================================
   渐入动画
   ======================================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* ========================================
   游戏结束标题样式
   ======================================== */
#gameOver h2 {
    font-size: 50px;
    margin-bottom: 30px;
    text-shadow: 4px 4px 12px rgba(0,0,0,0.9);
    animation: titlePulse 3s infinite;
    letter-spacing: 2px;
    transition: all 0.3s ease;
}

/* ========================================
   标题脉冲动画
   ======================================== */
@keyframes titlePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* ========================================
   游戏结束按钮样式
   ======================================== */
#gameOver button {
    padding: 20px 50px;
    font-size: 24px;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    margin-top: 30px;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    border: 3px solid rgba(255,255,255,0.5);
    transition: all 0.3s ease;
}

#gameOver button:hover {
    background: linear-gradient(135deg, #45a049, #3d8b40);
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 12px 30px rgba(0,0,0,0.5);
    border-color: rgba(255,255,255,0.7);
}

/* ========================================
   游戏开始界面样式
   ======================================== */
#startScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    animation: fadeOut 0.6s ease-in;
    border-radius: 20px;
    transition: all 0.3s ease;
}

/* ========================================
   渐出动画
   ======================================== */
@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* ========================================
   游戏开始标题样式
   ======================================== */
#startScreen h1 {
    font-size: 64px;
    margin-bottom: 30px;
    color: #FFD700;
    text-shadow: 5px 5px 10px rgba(0,0,0,0.9), 0 0 30px #FFD700;
    animation: glow 3s infinite alternate;
    letter-spacing: 3px;
    transition: all 0.3s ease;
}

/* ========================================
   发光动画
   ======================================== */
@keyframes glow {
    from {
        text-shadow: 5px 5px 10px rgba(0,0,0,0.9), 0 0 20px #FFD700;
    }
    to {
        text-shadow: 5px 5px 10px rgba(0,0,0,0.9), 0 0 40px #FFD700;
    }
}

/* ========================================
   游戏开始说明文字样式
   ======================================== */
#startScreen p {
    font-size: 24px;
    margin-bottom: 40px;
    max-width: 500px;
    text-align: center;
    line-height: 1.8;
    animation: slideInUp 0.8s ease-out forwards;
    padding: 15px;
    border-radius: 15px;
    background: rgba(0,0,0,0.4);
    transition: all 0.3s ease;
}

/* ========================================
   滑入向上动画
   ======================================== */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   游戏开始按钮样式
   ======================================== */
#startScreen button {
    padding: 30px 70px;
    font-size: 32px;
    background: linear-gradient(135deg, #FF6B6B, #EE5A5A);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
    border: 3px solid rgba(255,255,255,0.5);
    transition: all 0.3s ease;
}

#startScreen button:hover {
    transform: scale(1.15) translateY(-5px);
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
    border-color: rgba(255,255,255,0.7);
}

/* ========================================
   游戏控制按钮区域样式
   ======================================== */
#gameControls {
    position: absolute;
    top: 5px;
    right: 125px;
    z-index: 999;
    display: none;
    gap: 10px;
}

/* ========================================
   暂停和加速按钮样式
   ======================================== */
#pauseBtn, #speedBtn {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    background: linear-gradient(135deg, #FF6B6B, #EE5A5A);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    border: 3px solid rgba(255,255,255,0.5);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    min-width: 80px;
}

/* ========================================
   加速按钮特殊样式
   ======================================== */
#speedBtn {
    margin-left: -30px;
    min-width: 110px;
}

/* ========================================
   首页按钮样式
   ======================================== */
#homeBtn {
    padding: 12px 24px;
    font-size: 16px;
    font-weight: bold;
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 8px 25px rgba(0,0,0,0.4);
    border: 3px solid rgba(255,255,255,0.5);
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    min-width: 80px;
}

#homeBtn:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 12px 35px rgba(0,0,0,0.5);
    border-color: rgba(255,255,255,0.7);
    background: linear-gradient(135deg, #5CBF60, #4CAF50);
}

#homeBtn:active {
    transform: scale(0.95);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* ========================================
   按钮悬停效果
   ======================================== */
#pauseBtn:hover, #speedBtn:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 12px 35px rgba(0,0,0,0.5);
    border-color: rgba(255,255,255,0.7);
    background: linear-gradient(135deg, #FF7B7B, #FF6A6A);
}

#pauseBtn:active, #speedBtn:active {
    transform: scale(0.95);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* ========================================
   暂停按钮激活状态
   ======================================== */
#pauseBtn.paused {
    background: linear-gradient(135deg, #4CAF50, #45a049);
}

#pauseBtn.paused:hover {
    background: linear-gradient(135deg, #5CBF60, #4CAF50);
}

/* ========================================
   加速按钮激活状态
   ======================================== */
#speedBtn.speed-active {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #333;
    text-shadow: 1px 1px 2px rgba(255,255,255,0.5);
}

#speedBtn.speed-active:hover {
    background: linear-gradient(135deg, #FFE135, #FFB800);
}

/* ========================================
   渐入渐出动画
   ======================================== */
@keyframes fadeInOut {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
    20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    80%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}

/* ========================================
   浮动向上动画
   ======================================== */
@keyframes floatUp {
    0%   { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-60px); }
}

/* ========================================
   倒计时覆盖层样式
   ======================================== */
#countdownOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: 20px;
}

#countdownNumber {
    font-size: 160px;
    font-weight: bold;
    color: #FFD700;
    text-shadow: 0 0 40px rgba(255, 215, 0, 0.8), 0 0 80px rgba(255, 215, 0, 0.4);
    animation: countdownPulse 1s ease-in-out;
    line-height: 1;
}

#countdownLabel {
    font-size: 36px;
    color: white;
    margin-top: 20px;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.9);
    letter-spacing: 4px;
    animation: countdownFade 1s ease-in-out;
}

@keyframes countdownPulse {
    0% {
        transform: scale(1.5);
        opacity: 0;
    }
    50% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
}

@keyframes countdownFade {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    50% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0.5;
        transform: translateY(-10px);
    }
}