/* Custom styles - Game UI with dark theme */

/* Make the canvas container fill the viewport */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none; /* Prevent browser handling of touch gestures */
    background-color: #222;
    color: #fff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Canvas container styles */
#canvas-container {
    width: 100%;
    height: 100%;
    display: none; /* Initially hidden, shown after loading */
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    cursor: grab; /* Indicate the map can be dragged */
}

#canvas-container:active {
    cursor: grabbing; /* Change cursor when dragging */
}

/* Loading indicator */
#loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    text-align: center;
}

/* WebGL error message */
#webgl-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 20;
    text-align: center;
    display: none;
    max-width: 600px;
    padding: 20px;
}

/* Game UI Container */
.ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to the canvas */
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Align content to bottom */
}

/* AI Resources Display - horizontal top bar */
.ai-resources-display {
    width: 100%;
    background-color: rgba(15, 15, 25, 0.9); /* Match player's background */
    padding: 3px 150px 3px 10px; /* Adjusted right padding for top-right link */
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(100, 100, 180, 0.3); /* Match player's border */
    pointer-events: auto;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 15;
}

.ai-resources-header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.ai-resources-title {
    color: #ff6666;
    font-weight: bold;
    font-size: 0.8rem;
    margin-right: 8px;
}

.ai-resources-total {
    background-color: rgba(40, 40, 60, 0.8); /* Match player's background */
    padding: 2px 5px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 3px;
    font-weight: bold;
    font-size: 0.7rem;
    white-space: nowrap;
}

.ai-resources-total i {
    color: #ffcc00; /* Match player's coin color */
}

.ai-resources-bar {
    flex: 1;
    min-width: 50px;
    height: 10px;
    background-color: rgba(20, 20, 30, 0.7); /* Match player's background */
    border-radius: 5px;
    margin: 0 10px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(60, 60, 90, 0.6); /* Match player's border */
}

/* AI Resources progress bar */
.ai-resources-progress {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3); /* Match player's shadow */
    display: block;
    position: relative;
}

/* Add shine effect to the AI progress bar */
.ai-resources-progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, 
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    animation: shine 1.5s infinite;
    display: none;
}

/* Show shine effect when AI resources are near max */
.ai-resources-progress[style*="width: 9"]::after, 
.ai-resources-progress[style*="width: 100%"]::after {
    display: block;
}

.ai-state-indicator {
    background-color: rgba(40, 40, 60, 0.8); /* Match player's background */
    padding: 2px 5px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: bold;
    margin-left: 10px;
    color: #fff; /* Match player's text color */
}

.ai-resource-counts-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-shrink: 0;
}

/* Unit Selection Panel - compact bottom bar */
.unit-panel {
    position: relative;
    width: 100%;
    background-color: rgba(10, 10, 20, 0.8);
    pointer-events: auto;
    border-top: 1px solid rgba(120, 120, 200, 0.4);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: visible; /* Always show all content */
}

/* Resources Display - horizontal top bar */
.resources-display {
    width: 100%;
    background-color: rgba(15, 15, 25, 0.9);
    padding: 3px 10px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(100, 100, 180, 0.3);
}

.resources-header {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.resources-title {
    display: none; /* Hidden title */
}

.resources-total {
    background-color: rgba(40, 40, 60, 0.8);
    padding: 2px 5px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 3px;
    font-weight: bold;
    font-size: 0.7rem;
    white-space: nowrap; /* Prevent wrapping */
}

.resources-total i {
    color: #ffcc00;
}

.resources-bar {
    flex: 1;
    min-width: 50px;
    height: 10px;
    background-color: rgba(20, 20, 30, 0.7);
    border-radius: 5px;
    margin: 0 10px;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(60, 60, 90, 0.6);
    display: block; /* Show the bar */
}

/* Resources progress bar */
.resources-progress {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
    display: block;
    position: relative;
}

/* Add shine effect to the progress bar */
.resources-progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, 
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.3) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    animation: shine 1.5s infinite;
    display: none; /* Only show when resources are near max */
}

/* Shine animation */
@keyframes shine {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Show shine effect when resources are near max */
.resources-progress[style*="width: 9"]::after, 
.resources-progress[style*="width: 100%"]::after {
    display: block;
}

/* Resource counts container and section */
.resource-counts-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex-shrink: 0;
}

.resource-counts {
    display: flex;
    gap: 5px;
    flex-shrink: 0;
}

.resource-count {
    display: flex;
    align-items: center;
    background-color: rgba(30, 30, 50, 0.7);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.65rem;
}

.resource-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 2px;
}

/* Resource icon colors */
.black-resource .resource-icon {
    background-color: #222222; /* Black - visible but not too dark */
    border: 1px solid #fff; /* Add white border */
}

.green-resource .resource-icon {
    background-color: #22cc22;
}

.red-resource .resource-icon {
    background-color: #cc2222;
}

.blue-resource .resource-icon {
    background-color: #2222cc;
}

.white-resource .resource-icon {
    background-color: #ffffff;
}

/* Resource count text colors for better visibility */
.black-resource {
    color: #fff; /* Keep text white for visibility */
}

.white-resource {
    color: #fff; /* Keep text white */
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

/* Game controls layout */
.game-controls-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    padding: 10px;
    background-color: rgba(20, 20, 30, 0.9);
}

/* Units container - removed extra container */
.units-container {
    display: none; /* Hide the container */
}

/* Unit buttons layout */
.unit-buttons {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap; /* Prevent wrapping */
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 10px;
    width: 100%;
    overflow-x: auto; /* Allow horizontal scrolling if needed */
    margin: 0 auto;
}

/* Workers and Units Containers */
.workers-container, .units-container {
    background-color: rgba(15, 15, 25, 0.9);
    border-radius: 6px;
    padding: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(100, 100, 180, 0.3);
    width: 49%; /* Almost half, with gap between */
    display: flex;
    flex-direction: column;
    overflow: visible; /* Always show all content */
}

/* Headers for workers and units sections */
.workers-header, .units-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 3px;
    margin-bottom: 3px;
    border-bottom: 1px solid rgba(100, 100, 180, 0.3);
}

.workers-title {
    font-weight: bold;
    font-size: 0.75rem;
    color: #fff;
}

.units-title {
    display: none; /* Hidden title */
}

.workers-idle {
    background-color: rgba(40, 40, 60, 0.8);
    padding: 2px 6px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #cccc22;
    margin-left: auto; /* Push to right */
}

.workers-idle i {
    color: #cccc22;
    font-size: 0.7rem;
}

/* Workers section */
.workers-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: visible; /* No scrolling, always show all content */
}

.worker-group {
    background-color: rgba(30, 30, 40, 0.8);
    border-radius: 4px;
    padding: 3px 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3px; /* Ensure spacing between worker groups */
}

/* Worker group colors */
.black-group {
    border-left: 3px solid #222222; /* Black - visible but not too dark */
    box-shadow: -1px 0 0 #fff; /* Add white outline to the left border */
}

.green-group {
    border-left: 3px solid #22cc22;
}

.red-group {
    border-left: 3px solid #cc2222;
}

.blue-group {
    border-left: 3px solid #2222cc;
}

.white-group {
    border-left: 3px solid #ffffff;
}

/* Worker labels for better visibility */
.black-group .worker-label {
    color: #fff; /* Keep text white */
}

.white-group .worker-label {
    color: #fff;
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

.worker-label {
    font-size: 0.7rem;
    font-weight: bold;
    color: #fff; /* Ensure all worker labels are white */
}

.worker-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.worker-count-display {
    background-color: rgba(40, 40, 60, 0.9);
    padding: 1px 6px;
    border-radius: 3px;
    min-width: 20px;
    text-align: center;
    font-weight: bold;
    font-size: 0.7rem;
}

.worker-btn {
    background-color: rgba(60, 60, 80, 0.8);
    color: white;
    border: none;
    border-radius: 3px;
    width: 20px;
    height: 20px;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.worker-btn:hover {
    background-color: rgba(80, 80, 100, 0.9);
    transform: translateY(-1px);
}

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

/* Unit selection */
.unit-btn {
    background-color: rgba(40, 40, 60, 0.8);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 4px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    text-align: left;
    flex: 0 0 auto; /* Don't grow or shrink */
    width: calc((100% - 50px) / 6); /* Distribute space evenly among 6 cards */
    max-width: 150px; /* Maximum card width */
    min-width: 90px; /* Minimum card width */
}

.unit-btn:hover {
    background-color: rgba(60, 60, 90, 0.9);
    transform: translateY(-1px);
}

.unit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.unit-icon {
    background-color: rgba(30, 30, 50, 0.8);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 5px;
    flex-shrink: 0;
}

.unit-icon i {
    font-size: 0.8rem;
    color: #ffcc00;
}

.unit-details {
    display: flex;
    flex-direction: column;
}

.unit-name {
    font-weight: bold;
    font-size: 0.7rem;
    margin-bottom: 1px;
}

.unit-cost {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 0.65rem;
    color: #ffcc00;
}

/* Action Bar */
.action-bar {
    position: absolute;
    bottom: 20px;
    right: 20px;
    pointer-events: auto;
}

/* Pause Button */
.pause-button {
    position: absolute;
    top: 40px; /* Adjusted to account for AI resources bar */
    right: 10px;
    pointer-events: auto;
    z-index: 30;
    display: flex;
    align-items: center;
}

.header-timer {
    background-color: rgba(40, 40, 60, 0.8);
    color: white;
    border-radius: 20px;
    padding: 5px 15px;
    margin-right: 10px;
    font-size: 1rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    font-weight: bold;
    user-select: none;
}

.pause-btn {
    background-color: rgba(40, 40, 60, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.pause-btn:hover {
    background-color: rgba(60, 60, 90, 0.9);
    transform: scale(1.1);
}

.pause-btn i {
    font-size: 1.2rem;
}

/* Game Menu */
.game-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 100;
    pointer-events: auto;
}

.menu-content {
    background-color: rgba(20, 20, 35, 0.95);
    border-radius: 12px;
    padding: 20px;
    width: 280px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(120, 120, 200, 0.4);
}

.menu-content h2 {
    margin-bottom: 15px;
    color: white;
    font-size: 1.5rem;
}

.game-timer {
    background-color: rgba(30, 30, 50, 0.8);
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 20px;
    color: white;
    font-size: 1.1rem;
    text-align: center;
}

.menu-btn {
    background-color: rgba(40, 40, 60, 0.8);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 10px 15px;
    margin: 8px 0;
    width: 100%;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.menu-btn:hover {
    background-color: rgba(60, 60, 90, 0.9);
    transform: translateY(-2px);
}

.menu-btn i {
    margin-right: 8px;
    font-size: 1rem;
}

/* Unit Info Panel */
.unit-info {
    position: absolute;
    top: 60px;
    right: 10px;
    background-color: rgba(10, 10, 20, 0.8);
    border-radius: 6px;
    padding: 8px;
    width: 150px;
    pointer-events: auto;
    border: 1px solid rgba(120, 120, 200, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    display: none; /* Hidden by default, shown when unit selected */
}

.unit-info h4 {
    font-size: 0.9rem;
    margin-bottom: 5px;
    border-bottom: 1px solid rgba(120, 120, 200, 0.4);
    padding-bottom: 3px;
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-gap: 5px;
}

.stats div {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 0.75rem;
}

/* Mobile-specific adjustments */
@media (max-width: 576px) {
    .unit-panel {
        /* No max-height to ensure all content is visible */
        height: auto;
        overflow: visible;
    }
    
    .resources-display {
        flex-wrap: nowrap; /* Force single line */
    }
    
    .resources-bar {
        min-width: 30px; /* Even smaller minimum width on mobile */
    }
    
    .resource-counts {
        gap: 2px; /* Smaller gap between resource counts */
    }
    
    .game-controls-container {
        flex-direction: row; /* Keep horizontal layout on mobile */
        height: auto; /* Auto height to fit content */
        min-height: unset; /* Remove min-height */
        overflow: visible; /* Always show all content */
    }
    
    .worker-group {
        white-space: nowrap; /* Prevent wrapping */
    }
    
    .worker-label {
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 45px; /* Limit label width */
    }
}
