:root {
    --player-color: #3498db;
    --enemy-color: #e74c3c;
    --ui-bg: rgba(255, 255, 255, 0.95);
    --gold-color: #f1c40f;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #2c3e50;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* --- 游戏主区域 --- */
#game-wrapper {
    position: relative;
    width: 95vw;
    height: 75vh; /* 略微减小高度给工具栏更多空间 */
    margin-top: 15px;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    border: 6px solid #bdc3c7;
}

#game-area {
    width: 100%;
    height: 100%;
    /* 网格背景，方便看路径 */
    background-color: #7dbc7d;
    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: 50px 50px;
    position: relative;
    cursor: default;
}

/* --- 工具栏/UI --- */
#toolbar {
    width: 95vw;
    background: var(--ui-bg);
    margin-top: 10px;
    padding: 10px 20px;
    border-radius: 15px;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* 确保小屏幕下能换行 */
}

#resource-display {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--gold-color);
    padding: 5px 10px;
    background: #34495e;
    border-radius: 10px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.3);
}

.control-menu-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    margin: 0;
    flex-wrap: wrap;
}
.menu-title {
    margin-right: 2px;
    font-weight: bold;
    color: #2c3e50;
    white-space: nowrap;
    font-size: 0.9rem;
    writing-mode: vertical-rl;
    text-orientation: upright;
}

.build-menu-inline, .unit-menu-inline {
    display: flex;
    gap: 2px;
    margin: 0;
}

.build-btn, .unit-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    background: #ecf0f1;
    border-radius: 10px;
    padding: 6px;
    transition: all 0.2s ease;
    box-shadow: 0 3px #bdc3c7;
    width: 60px; /* 适度恢复宽度 */
    text-align: center;
}

.build-btn:hover, .unit-btn:hover {
    background: #e0e6e7;
    transform: translateY(-2px);
    box-shadow: 0 6px #bdc3c7;
}

.build-btn.selected {
    background: #3498db;
    color: white;
    box-shadow: 0 2px #2980b9;
    transform: translateY(2px);
}

.build-btn.disabled, .unit-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    pointer-events: none;
}

.icon {
    font-size: 1.5rem;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.name {
    display: block; /* 恢复文字显示 */
    font-size: 0.7rem;
    font-weight: 600;
    margin-top: 3px;
}
.cost {
    font-size: 0.65rem;
    color: #27ae60;
    font-weight: bold;
    margin-top: 1px;
}

.unit-btn[data-unit="soldier"] .cost { color: #27ae60; }
.unit-btn[data-unit="tank"] .cost { color: #d35400; }
.unit-btn[data-unit="rocketcar"] .cost { color: #9b59b6; }

.control-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ctrl-btn {
    padding: 5px 10px;
    border: none;
    border-radius: 5px;
    color: white;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px rgba(0,0,0,0.2);
    transition: all 0.1s;
    font-size: 0.8rem;
    width: 100%;
}
.ctrl-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px rgba(0,0,0,0.2);
}

/* --- 游戏元素通用样式 --- */
.entity {
    position: absolute;
    border-radius: 50%;
    transition: border 0.1s;
}

/* 基地 */
.entity.base {
    width: 80px; height: 80px;
    border-radius: 15px;
    border: 5px solid white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    font-weight: bold;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
    z-index: 10;
}
.entity.base.player { background-color: var(--player-color); }
.entity.base.enemy { background-color: var(--enemy-color); }
.base .label { font-size: 0.8rem; position: absolute; bottom: -20px; color: #333; }

/* 建筑 */
.entity.building {
    border-radius: 8px;
    border: 4px solid white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    z-index: 20;
    cursor: pointer;
}
.entity.building.player { background-color: var(--player-color); }
.entity.building.enemy { background-color: var(--enemy-color); }

.entity.powerplant { width: 30px; height: 30px; font-size: 1.2rem; }
.entity.barracks { width: 40px; height: 40px; font-size: 1.5rem; }
.entity.factory { width: 50px; height: 50px; font-size: 1.8rem; }
.entity.runway { width: 60px; height: 40px; font-size: 1.5rem; border-radius: 5px; }
.entity.turret { width: 30px; height: 30px; font-size: 1.2rem; border-radius: 50%; }
.entity.antiair { width: 35px; height: 35px; font-size: 1.3rem; border-radius: 5px; }

/* 战斗单位 */
.entity.unit {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 30;
    transition: left 0.1s linear, top 0.1s linear; /* 平滑移动 */
}

.entity.unit.player { 
    background-color: var(--player-color); 
    border: 2px solid white;
}
.entity.unit.enemy { 
    background-color: var(--enemy-color); 
    border: 2px solid #c0392b;
}

/* 血条 */
.hp-bar {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 4px;
    background: #555;
    border-radius: 2px;
    overflow: hidden;
    pointer-events: none;
}
.hp-fill {
    height: 100%;
    background: #2ecc71;
    width: 100%;
}

/* 投射物 */
.projectile {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #f1c40f;
    border-radius: 50%;
    z-index: 40;
    box-shadow: 0 0 5px #f39c12;
}

/* 爆炸效果 */
.explosion {
    position: absolute;
    width: 40px;
    height: 40px;
    background: radial-gradient(circle, #f1c40f, #e74c3c, transparent);
    border-radius: 50%;
    animation: boom 0.3s ease-out forwards;
    z-index: 50;
}

@keyframes boom {
    0% { transform: scale(0.5); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* 浮动文本 */
.floating-text {
    position: absolute;
    color: white;
    font-weight: bold;
    font-size: 1rem;
    text-shadow: 1px 1px 2px black;
    pointer-events: none;
    animation: floatUp 1.5s ease-out forwards;
    z-index: 100;
}

@keyframes floatUp {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(-30px); opacity: 0; }
}

/* 弹窗 */
#game-over-modal {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    padding: 30px 50px;
    border-radius: 15px;
    text-align: center;
}

.modal-content h1 { margin-top: 0; }

.modal-content button {
    padding: 10px 25px;
    font-size: 1.2rem;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}
.modal-content button:hover {
    background: #2980b9;
}

/* 原子弹爆炸效果 */
.nuke-explosion {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, #ffeb3b 20%, #ff9800 40%, #f44336 60%, rgba(0,0,0,0) 80%);
    box-shadow: 0 0 50px #ff5722;
    animation: nuke-expand 1s ease-out forwards;
    pointer-events: none;
    z-index: 999;
}

@keyframes nuke-expand {
    0% { transform: scale(0.1); opacity: 1; }
    50% { opacity: 0.9; }
    100% { transform: scale(1.2); opacity: 0; }
}