body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: #333;
    color: white;
    overflow: hidden; /* Prevents scrollbars from canvas */
}

canvas {
    display: block;
}

#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    z-index: 10;
}

#unit-selection, #team-selection, #controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

#unit-selection {
    flex-grow: 1;
}

.unit-card {
    padding: 8px 12px;
    border: 2px solid #555;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease-in-out;
}

.unit-card img {
    width: 40px;
    height: 40px;
    pointer-events: none;
}

.unit-card.selected {
    border-color: #f0c400;
    background-color: rgba(240, 196, 0, 0.2);
    transform: scale(1.05);
}

#team-switch-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    transition: background-color 0.3s;
    width: 100px;
}

#controls button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    color: white;
    cursor: pointer;
    background-color: #4CAF50;
}

#controls button#reset-btn {
    background-color: #f44336;
}

#controls button:disabled {
    background-color: #555;
    cursor: not-allowed;
}

.blue-team-bg {
    background-color: #2196F3;
}

.red-team-bg {
    background-color: #E53935;
}

.red-team-border.selected {
     border-color: #E53935;
     background-color: rgba(229, 57, 53, 0.2);
}

.blue-team-border.selected {
     border-color: #2196F3;
     background-color: rgba(33, 150, 243, 0.2);
}

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1000;
}

.spinner {
    border: 8px solid #f3f3f3;
    border-top: 8px solid #3498db;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#winner-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 40px 80px;
    border-radius: 20px;
    background-color: rgba(0, 0, 0, 0.75);
    font-size: 4em;
    font-weight: bold;
    text-align: center;
    z-index: 20;
}
.hidden {
    display: none !important;
}

/* Make unit names readable on smaller screens */
.unit-card span {
    font-size: 0.8rem;
    white-space: nowrap;
}

/* Override for longer names that might not fit */
.unit-card[data-unit="viking_bear_rider"] span,
.unit-card[data-unit="war_machine"] span {
    font-size: 0.7rem;
}

.white-text {
    color: #ffffff;
}
.blue-text {
    color: #2196F3;
}
.red-text {
    color: #E53935;
}

@media (max-width: 800px) {
    #ui-container {
        overflow-x: auto;
        justify-content: flex-start;
        gap: 20px;
    }

    #unit-selection {
        flex-shrink: 0; /* Prevents this container from shrinking */
    }

    #team-selection {
        flex-shrink: 0;
    }

    #controls {
        flex-shrink: 0;
    }

    /* Hide scrollbar for a cleaner look, but still allow scrolling */
    #ui-container::-webkit-scrollbar {
        display: none;
    }
    #ui-container {
        -ms-overflow-style: none;  /* IE and Edge */
        scrollbar-width: none;  /* Firefox */
    }
}