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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    user-select: none;
    -webkit-user-select: none;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}
.screen.active {
    display: flex;
    flex-direction: column;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: transform 0.1s, filter 0.1s;
}
.btn:active {
    transform: scale(0.95);
}
.btn-primary {
    background: linear-gradient(135deg, #0f3460, #16213e);
    color: #fff;
    padding: 14px 40px;
    font-size: 18px;
    border: 2px solid #0f3460;
}
.btn-primary:hover {
    filter: brightness(1.2);
}
.btn-secondary {
    background: #16213e;
    color: #a0a0c0;
    padding: 12px 32px;
    font-size: 16px;
    border: 1px solid #2a2a4a;
}
.btn-secondary:hover {
    background: #1f2b47;
}
.btn-small {
    padding: 6px 14px;
    font-size: 13px;
    background: #16213e;
    color: #c0c0e0;
    border: 1px solid #2a2a4a;
}
.btn-tiny {
    padding: 4px 10px;
    font-size: 12px;
    background: #16213e;
    color: #c0c0e0;
    border: 1px solid #2a2a4a;
}
.btn-accent {
    background: #e94560;
    color: #fff;
    border-color: #e94560;
}
.btn-accent:hover {
    filter: brightness(1.1);
}
.btn-danger {
    background: #c62828;
    color: #fff;
    border-color: #c62828;
}

/* Main Menu */
.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 16px;
}
.game-title {
    font-size: 52px;
    font-weight: 800;
    background: linear-gradient(135deg, #ff6b35, #f7c948);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    margin-bottom: 4px;
}
.game-subtitle {
    font-size: 18px;
    color: #8888aa;
    margin-bottom: 20px;
}

/* Help Screen */
.help-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    height: 100%;
    overflow-y: auto;
}
.help-content {
    max-width: 600px;
    text-align: left;
    margin: 20px 0;
    line-height: 1.8;
}
.help-content h3 {
    color: #f7c948;
    margin-top: 16px;
    margin-bottom: 6px;
}
.tower-help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 20px;
    font-size: 14px;
}

/* Level Select */
.level-select-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 12px;
}
.level-select-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 0;
    flex-shrink: 0;
}
.level-select-header h2 {
    flex: 1;
    text-align: center;
    font-size: 22px;
}
.total-stars {
    color: #f7c948;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}
.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    overflow-y: auto;
    padding: 8px;
    flex: 1;
    align-content: start;
}
.level-btn {
    aspect-ratio: 1.4;
    border: 2px solid #2a2a4a;
    border-radius: 10px;
    background: #16213e;
    color: #e0e0e0;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-family: inherit;
    transition: transform 0.1s, border-color 0.2s;
    min-height: 60px;
}
.level-btn:hover {
    border-color: #0f3460;
    transform: scale(1.03);
}
.level-btn.locked {
    opacity: 0.4;
    cursor: not-allowed;
}
.level-btn.locked:hover {
    transform: none;
    border-color: #2a2a4a;
}
.level-btn .level-num {
    font-size: 18px;
    font-weight: 700;
}
.level-btn .level-stars {
    font-size: 12px;
    color: #f7c948;
    letter-spacing: 2px;
}
.level-btn .level-lock {
    font-size: 16px;
    opacity: 0.5;
}

/* Game Screen */
#gameScreen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #0d1117;
}

/* HUD Top */
.hud-top {
    width: 100%;
    max-width: 840px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: #16213e;
    border-bottom: 1px solid #2a2a4a;
    flex-shrink: 0;
    z-index: 5;
}
.hud-left, .hud-center, .hud-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.hud-item {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}
.gold-display {
    color: #ffd700;
}
.lives-display {
    color: #ff6b6b;
}

/* Canvas */
.canvas-container {
    position: relative;
    flex-shrink: 0;
}
#gameCanvas {
    display: block;
    background: #2d5a27;
    border: 2px solid #2a2a4a;
}

/* Wave Overlay */
.wave-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    pointer-events: none;
    z-index: 3;
}
.wave-text {
    margin-top: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 20px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    font-weight: 600;
    pointer-events: all;
}

/* Tower Panel */
.tower-panel {
    display: flex;
    gap: 4px;
    padding: 4px 8px;
    background: #16213e;
    border-top: 1px solid #2a2a4a;
    max-width: 840px;
    width: 100%;
    overflow-x: auto;
    flex-shrink: 0;
    z-index: 5;
    justify-content: center;
}
.tower-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    min-width: 56px;
    border: 2px solid transparent;
    transition: border-color 0.15s, background 0.15s;
    flex-shrink: 0;
}
.tower-btn:hover {
    background: rgba(255,255,255,0.05);
}
.tower-btn.selected {
    border-color: #e94560;
    background: rgba(233, 69, 96, 0.15);
}
.tower-btn.disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.tower-icon {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: #fff;
    font-weight: 700;
}
.tower-btn span {
    font-size: 10px;
    white-space: nowrap;
}
.tower-cost {
    color: #ffd700;
    font-weight: 600;
}

/* Items Panel */
.items-panel {
    display: flex;
    gap: 6px;
    padding: 4px 8px;
    background: #121a2e;
    max-width: 840px;
    width: 100%;
    justify-content: center;
    flex-shrink: 0;
    z-index: 5;
}
.item-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid #2a2a4a;
    background: #16213e;
    transition: background 0.15s;
    font-size: 11px;
}
.item-btn:hover {
    background: #1f2b47;
}
.item-icon {
    font-size: 14px;
}
.item-name {
    font-size: 11px;
    color: #aaa;
}
.item-count {
    background: #e94560;
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
}

/* Tower Info Popup */
.tower-info {
    position: absolute;
    background: #1a1a2e;
    border: 2px solid #0f3460;
    border-radius: 10px;
    padding: 10px 14px;
    min-width: 160px;
    z-index: 20;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.tower-info-name {
    font-size: 15px;
    font-weight: 700;
    color: #f7c948;
    margin-bottom: 6px;
}
.tower-info-stats {
    font-size: 12px;
    line-height: 1.6;
    color: #bbb;
    margin-bottom: 8px;
}
.tower-info-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.overlay-content {
    background: #1a1a2e;
    border: 2px solid #0f3460;
    border-radius: 16px;
    padding: 30px 40px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 260px;
}
.overlay-content h2 {
    font-size: 28px;
    margin-bottom: 8px;
}
.overlay-content.victory h2 {
    color: #f7c948;
}
.overlay-content.defeat h2 {
    color: #e94560;
}
.stars-display {
    font-size: 40px;
    letter-spacing: 8px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: #0d1117;
}
::-webkit-scrollbar-thumb {
    background: #2a2a4a;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 860px) {
    .tower-panel {
        justify-content: flex-start;
    }
    .game-title {
        font-size: 36px;
    }
    .level-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 6px;
    }
}
@media (max-height: 700px) {
    .hud-top {
        padding: 2px 8px;
    }
    .tower-panel {
        padding: 2px 4px;
    }
    .items-panel {
        padding: 2px 4px;
    }
    .hud-item {
        font-size: 12px;
    }
}
