:root {
    --bg-color: #1a1c23;
    --panel-bg: rgba(255, 255, 255, 0.05);
    --panel-border: rgba(255, 255, 255, 0.1);
    --accent-primary: #4ade80;
    /* Green */
    --accent-secondary: #60a5fa;
    /* Blue */
    --accent-danger: #f87171;
    /* Red */
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --font-family: 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image: radial-gradient(circle at 50% 50%, #2d3748 0%, #1a202c 100%);
}

.app-container {
    width: 100%;
    max-width: 1200px;
    height: 95vh;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.game-header h1 {
    font-weight: 800;
    background: linear-gradient(to right, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 1.8rem;
}

.stats-bar {
    display: flex;
    gap: 2rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 8px;
}

.game-area {
    display: flex;
    gap: 1rem;
    flex: 1;
    min-height: 0;
    /* Prevent overflow */
}

.canvas-wrapper {
    flex: 1;
    position: relative;
    background: #2f3e46;
    /* Map background placeholder */
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--panel-border);
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    background-color: #354f52;
    /* Grass color */
    cursor: crosshair;
    touch-action: none;
}

#game-over-screen,
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    gap: 1rem;
}

.hidden {
    display: none !important;
}

h2 {
    font-size: 3rem;
    color: var(--text-primary);
}

button {
    padding: 0.8rem 2rem;
    font-size: 1.2rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent-primary), #22c55e);
    color: #064e3b;
    transition: transform 0.1s, filter 0.2s;
}

button:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(0);
}

.controls-panel {
    width: 300px;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.controls-panel h2 {
    font-size: 1.5rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.tower-selection {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    overflow-y: auto;
}

.tower-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.tower-card:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-primary);
    transform: translateX(5px);
}

.tower-card.selected {
    background: rgba(74, 222, 128, 0.2);
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.3);
}

.tower-card.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
    pointer-events: none;
}

.tower-icon {
    font-size: 2.5rem;
}

.tower-info h3 {
    font-size: 1.1rem;
    margin-bottom: 0.2rem;
}

.cost {
    color: var(--accent-secondary);
    font-weight: 700;
}

.desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.game-controls {
    margin-top: auto;
}

#next-wave-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-secondary), #3b82f6);
    color: white;
}

@media (max-width: 900px) {
    body {
        height: 100vh;
        height: 100dvh;
        /* Use dynamic viewport height if available */
        overflow: hidden;
        padding: 0;
        align-items: flex-start;
    }

    .app-container {
        height: 100%;
        max-height: 100%;
        padding: 0.25rem;
        /* Minimal padding */
        gap: 0.25rem;
    }

    .game-header {
        flex-direction: row;
        flex-wrap: nowrap;
        /* Prevent wrapping if possible */
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.5rem;
        flex-shrink: 0;
        min-height: 50px;
    }

    .game-header h1 {
        font-size: 1rem;
        width: auto;
        text-align: left;
        margin-bottom: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .stats-bar {
        width: auto;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    .stat-item {
        font-size: 0.8rem;
        padding: 0.2rem 0.4rem;
    }

    .game-area {
        flex-direction: column;
        overflow: hidden;
    }

    .canvas-wrapper {
        order: 1;
        width: 100%;
        flex: 1;
        min-height: 0;
        background: #1a202c;
        /* Match bg to hide letterboxing slightly better */
        border: none;
        /* Remove border to save space */
        border-radius: 8px;
    }

    canvas {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .controls-panel {
        order: 2;
        width: 100%;
        flex-shrink: 0;
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem;
        height: auto;
        max-height: 120px;
        /* Slightly smaller max height */
        background: rgba(0, 0, 0, 0.3);
        /* More transparent */
        backdrop-filter: blur(5px);
    }

    .controls-panel h2 {
        display: none;
    }

    .tower-selection {
        flex-direction: row;
        overflow-x: auto;
        padding-bottom: 0;
        gap: 0.5rem;
        height: 100%;
        align-items: center;
        justify-content: flex-start;
        /* Align left */
    }

    .tower-card {
        min-width: 70px;
        /* Larger touch target */
        width: 70px;
        height: 100%;
        flex-direction: column;
        justify-content: center;
        padding: 0.2rem;
        gap: 0.2rem;
    }

    .tower-icon {
        font-size: 1.8rem;
        /* Larger icon */
    }

    .tower-info {
        display: none;
    }

    /* Add cost overlay for mobile */
    .tower-card::after {
        content: attr(data-cost);
        font-size: 0.8rem;
        font-weight: bold;
        color: var(--accent-secondary);
    }

    .game-controls {
        margin-top: 0;
        min-width: 90px;
    }

    #next-wave-btn {
        padding: 0.4rem;
        font-size: 0.8rem;
        white-space: normal;
        line-height: 1.1;
        height: 100%;
        /* Fill height */
        display: flex;
        align-items: center;
        justify-content: center;
    }
}