* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: radial-gradient(circle at top, #1b1f3b, #0c0f1f 70%);
    color: #f8fafc;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.game-container {
    width: 100%;
    max-width: 1100px;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.back-link {
    color: #cbd5f5;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.08);
    padding: 10px 18px;
    border-radius: 10px;
}

h1 {
    font-size: 2.4rem;
}

.hud {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.08);
    padding: 8px 14px;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
}

.toggle input {
    display: none;
}

.slider {
    width: 42px;
    height: 22px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.4);
    position: relative;
    transition: background 0.2s ease;
}

.slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #f8fafc;
    transition: transform 0.2s ease;
}

.toggle input:checked + .slider {
    background: rgba(99, 102, 241, 0.8);
}

.toggle input:checked + .slider::after {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.9rem;
    color: #e2e8f0;
}

.hud-item {
    background: rgba(255, 255, 255, 0.08);
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 600;
}

.btn {
    border: none;
    border-radius: 10px;
    padding: 12px 20px;
    font-weight: 600;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    cursor: pointer;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: linear-gradient(135deg, #0ea5e9, #38bdf8);
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.9rem;
    width: 100%;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #f97316);
}

.game-layout {
    display: grid;
    grid-template-columns: 1fr 240px;
    gap: 20px;
}

.game-area {
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    overflow: hidden;
}

#game-canvas {
    width: 100%;
    height: 600px;
    display: block;
    background: #0f172a;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.panel {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 16px;
}

.panel h3 {
    margin-bottom: 12px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tower-btn {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    cursor: pointer;
}

.tower-btn.active {
    border-color: #a5b4fc;
    background: rgba(99, 102, 241, 0.3);
}

.tower-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tower-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.selected-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.upgrade-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.upgrade-card {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 12px;
    text-align: left;
}

.upgrade-card h4 {
    margin-bottom: 8px;
}

.upgrade-card p {
    font-size: 0.9rem;
    color: #cbd5f5;
    margin-bottom: 10px;
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#upgrade-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    max-width: 360px;
}

.overlay-content.overlay-wide {
    max-width: 900px;
    max-height: 80vh;
    overflow-y: auto;
}

.track-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    margin: 20px 0;
    max-height: 500px;
    overflow-y: auto;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

.track-card {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
    border: 2px solid rgba(148, 163, 184, 0.3);
    border-radius: 10px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    position: relative;
}

.track-card svg {
    width: 100%;
    height: 80px;
    margin-bottom: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
}

.track-card h3 {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.track-card .difficulty {
    font-size: 0.8rem;
    margin: 4px 0;
    color: #fbbf24;
}

.track-card .description {
    font-size: 0.75rem;
    color: #cbd5f5;
    line-height: 1.3;
}

.track-card:hover:not(.locked) {
    transform: scale(1.05);
    border-color: rgba(148, 163, 184, 0.6);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(139, 92, 246, 0.2));
}

.track-card.selected {
    border-color: #a5b4fc;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(139, 92, 246, 0.4));
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
}

.track-card.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.track-card.locked::after {
    content: '🔒';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 32px;
    opacity: 0.6;
}

.controls {
    list-style: none;
    margin: 20px 0;
    text-align: left;
}

.controls li {
    margin: 8px 0;
}

.final-score {
    margin: 20px 0;
    font-size: 1.2rem;
}



@media (max-width: 900px) {
    .game-layout {
        grid-template-columns: 1fr;
    }

    .hud {
        flex-wrap: wrap;
    }

    .track-selection {
        grid-template-columns: 1fr;
    }
}
