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

:root {
    --sand-light: #E8C47C;
    --sand-main: #D4A574;
    --sand-dark: #CC7832;
    --spice: #FF6B35;
    --atreides: #4A90D9;
    --harkonnen: #C23B22;
    --rock: #5C4033;
    --bg-dark: #0a0500;
    --bg-panel: #1a0a00;
    --border: #5c4033;
}

body {
    background: var(--bg-dark);
    color: var(--sand-main);
    font-family: 'VT323', monospace;
    min-height: 100vh;
    overflow: hidden;
}

#game-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Title Screen */
#title-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center bottom, #2a1500 0%, #0a0500 70%);
    z-index: 100;
    overflow: hidden;
}

#title-screen.hidden {
    display: none;
}

.title-content {
    text-align: center;
    position: relative;
    z-index: 2;
}

.dune-logo {
    margin-bottom: 2rem;
}

.game-title {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(2rem, 8vw, 5rem);
    color: var(--spice);
    text-shadow: 
        0 0 30px var(--spice),
        0 0 60px var(--sand-dark),
        6px 6px 0 #2a1000;
    letter-spacing: 0.15em;
    animation: titlePulse 3s ease-in-out infinite;
}

.title-ornament {
    width: 300px;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--spice), transparent);
    margin: 1rem auto;
}

.subtitle {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.5rem, 2vw, 0.9rem);
    color: var(--sand-light);
    letter-spacing: 0.4em;
    text-shadow: 2px 2px 0 var(--bg-dark);
}

@keyframes titlePulse {
    0%, 100% { 
        text-shadow: 0 0 30px var(--spice), 0 0 60px var(--sand-dark), 6px 6px 0 #2a1000;
        transform: scale(1);
    }
    50% { 
        text-shadow: 0 0 50px var(--spice), 0 0 100px var(--sand-dark), 6px 6px 0 #2a1000;
        transform: scale(1.02);
    }
}

.sand-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='20' cy='30' r='1' fill='%23D4A574' opacity='0.3'/%3E%3Ccircle cx='60' cy='70' r='1.5' fill='%23E8C47C' opacity='0.2'/%3E%3Ccircle cx='80' cy='20' r='1' fill='%23CC7832' opacity='0.3'/%3E%3C/svg%3E");
    animation: dustDrift 20s linear infinite;
    pointer-events: none;
}

@keyframes dustDrift {
    from { transform: translateX(0) translateY(0); }
    to { transform: translateX(-50px) translateY(50px); }
}

.faction-select {
    margin-top: 2.5rem;
}

.faction-select h3 {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(0.5rem, 2vw, 0.75rem);
    color: var(--sand-light);
    margin-bottom: 1.5rem;
    letter-spacing: 0.3em;
}

.faction-buttons {
    display: flex;
    gap: 2rem;
    justify-content: center;
    flex-wrap: wrap;
}

.faction-btn {
    background: linear-gradient(180deg, rgba(42,21,0,0.9) 0%, rgba(26,10,0,0.95) 100%);
    border: 3px solid var(--border);
    padding: 1.5rem 2rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.7rem;
    transition: all 0.3s ease;
    min-width: 180px;
    position: relative;
    overflow: hidden;
}

.faction-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    transition: left 0.5s ease;
}

.faction-btn:hover::before {
    left: 100%;
}

.faction-btn:hover {
    transform: translateY(-5px) scale(1.02);
}

.faction-btn.atreides:hover {
    border-color: var(--atreides);
    box-shadow: 0 15px 40px rgba(74,144,217,0.4), inset 0 0 30px rgba(74,144,217,0.1);
}

.faction-btn.harkonnen:hover {
    border-color: var(--harkonnen);
    box-shadow: 0 15px 40px rgba(194,59,34,0.4), inset 0 0 30px rgba(194,59,34,0.1);
}

.faction-emblem {
    font-size: 3rem;
    filter: drop-shadow(0 0 10px currentColor);
}

.faction-btn.atreides .faction-emblem { color: var(--atreides); }
.faction-btn.harkonnen .faction-emblem { color: var(--harkonnen); }

.faction-name {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    color: #fff;
}

.faction-motto {
    font-size: 1rem;
    color: #888;
    font-style: italic;
}

.controls-preview {
    margin-top: 2rem;
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: #666;
}

.loading-status {
    margin-top: 2rem;
    font-size: 1.2rem;
    color: var(--spice);
    min-height: 1.5rem;
}

/* Game Screen */
#game-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#game-screen.hidden {
    display: none;
}

/* Header Bar */
#header-bar {
    height: 55px;
    background: linear-gradient(180deg, #2a1500 0%, var(--bg-panel) 100%);
    border-bottom: 2px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1.5rem;
}

.resources {
    display: flex;
    gap: 1rem;
}

.resource {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 1.3rem;
    padding: 0.3rem 0.7rem;
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border);
    border-radius: 3px;
}

.resource.warning {
    border-color: #ff4444;
    animation: powerWarning 0.5s ease-in-out infinite alternate;
}

@keyframes powerWarning {
    from { background: rgba(255,0,0,0.1); }
    to { background: rgba(255,0,0,0.3); }
}

.resource .icon {
    font-size: 1.1rem;
}

#faction-display {
    flex: 1;
    text-align: center;
}

.atreides-badge {
    color: var(--atreides);
    font-family: 'Press Start 2P', cursive;
    font-size: 0.65rem;
    text-shadow: 0 0 10px var(--atreides);
}

.harkonnen-badge {
    color: var(--harkonnen);
    font-family: 'Press Start 2P', cursive;
    font-size: 0.65rem;
    text-shadow: 0 0 10px var(--harkonnen);
}

.wave-display {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.9rem;
    color: var(--sand-light);
}

#minimap-container {
    border: 2px solid var(--border);
    background: var(--bg-dark);
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

#minimap {
    display: block;
}

/* Main Area */
#main-area {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

#game-canvas {
    flex: 1;
    background: var(--bg-panel);
    cursor: crosshair;
    image-rendering: pixelated;
}

/* Command Panel */
#command-panel {
    width: 200px;
    background: linear-gradient(180deg, var(--bg-panel) 0%, #2a1500 100%);
    border-left: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.5rem;
    overflow-y: auto;
}

#selection-info {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border);
    padding: 0.6rem;
    border-radius: 4px;
}

#selection-portrait {
    width: 64px;
    height: 64px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border);
}

#selection-portrait canvas {
    image-rendering: pixelated;
}

.empty-portrait {
    font-size: 2rem;
    color: #444;
}

#selection-details {
    text-align: center;
    margin-top: 0.5rem;
}

#selection-name {
    font-size: 1.1rem;
    color: #fff;
    font-weight: bold;
}

#selection-health {
    font-size: 0.9rem;
    color: #44ff44;
    margin-top: 0.3rem;
}

.health-bar-container {
    width: 100%;
    height: 8px;
    background: #222;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.3rem;
}

.health-bar {
    height: 100%;
    background: linear-gradient(180deg, #44ff44, #22aa22);
    transition: width 0.2s ease;
}

#selection-stats {
    font-size: 0.85rem;
    color: #aaa;
    margin-top: 0.3rem;
}

#action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

#action-buttons button,
.produce-btn {
    flex: 1 1 45%;
    background: linear-gradient(180deg, #3a2000 0%, #2a1500 100%);
    border: 1px solid var(--border);
    color: var(--sand-main);
    padding: 0.5rem;
    font-family: 'VT323', monospace;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 3px;
}

#action-buttons button:hover,
.produce-btn:hover {
    background: linear-gradient(180deg, #4a3000 0%, #3a2000 100%);
    border-color: var(--spice);
    transform: translateY(-1px);
}

.produce-btn .cost {
    font-size: 0.8rem;
    color: #ffd700;
}

#build-menu {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 4px;
}

#build-menu h4,
#production-queue h4 {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.5rem;
    color: var(--spice);
    margin-bottom: 0.6rem;
    text-align: center;
    letter-spacing: 0.1em;
}

.build-btn {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: linear-gradient(180deg, #3a2000 0%, #2a1500 100%);
    border: 1px solid var(--border);
    color: var(--sand-main);
    padding: 0.4rem 0.5rem;
    margin-bottom: 0.3rem;
    font-family: 'VT323', monospace;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    border-radius: 3px;
}

.build-btn:hover:not(.locked):not(:disabled) {
    background: linear-gradient(180deg, #4a3000 0%, #3a2000 100%);
    border-color: var(--spice);
}

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

.build-btn.expensive {
    color: #ff6666;
}

.build-info {
    display: flex;
    justify-content: space-between;
    margin-top: 0.2rem;
}

.build-cost {
    color: #ffd700;
    font-size: 0.85rem;
}

.build-power {
    font-size: 0.85rem;
}

.build-power.positive { color: #44ff44; }
.build-power.negative { color: #ff6666; }

#production-queue {
    background: rgba(0,0,0,0.4);
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 4px;
    min-height: 60px;
}

.queue-item {
    background: rgba(0,0,0,0.3);
    padding: 0.3rem 0.5rem;
    margin-bottom: 0.2rem;
    border-radius: 2px;
    font-size: 0.9rem;
}

.progress-bar {
    height: 4px;
    background: #333;
    border-radius: 2px;
    margin-top: 0.2rem;
    overflow: hidden;
}

.progress-bar div {
    height: 100%;
    background: linear-gradient(90deg, var(--atreides), #66aaff);
    transition: width 0.2s ease;
}

/* Status Bar */
#status-bar {
    height: 45px;
    background: linear-gradient(180deg, var(--bg-panel) 0%, #2a1500 100%);
    border-top: 2px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    gap: 1.5rem;
    font-size: 0.95rem;
}

#selected-units {
    display: flex;
    gap: 0.4rem;
}

#game-messages {
    flex: 1;
    overflow: hidden;
}

.message {
    color: var(--spice);
    animation: messageFade 0.3s ease;
}

@keyframes messageFade {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

#controls-hint {
    color: #555;
    font-size: 0.85rem;
}

/* Sandworm Warning */
#sandworm-warning {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(139, 69, 19, 0.95);
    border: 3px solid #ff6600;
    padding: 1rem 2rem;
    z-index: 1000;
    animation: warningPulse 0.3s ease-in-out infinite alternate;
    border-radius: 4px;
}

#sandworm-warning.hidden {
    display: none;
}

.warning-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.warning-icon {
    font-size: 2rem;
    animation: wormWiggle 0.2s ease-in-out infinite alternate;
}

@keyframes wormWiggle {
    from { transform: rotate(-5deg); }
    to { transform: rotate(5deg); }
}

.warning-text {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    color: #fff;
}

@keyframes warningPulse {
    from { box-shadow: 0 0 20px rgba(255, 102, 0, 0.5); }
    to { box-shadow: 0 0 40px rgba(255, 102, 0, 0.8); }
}

/* Game Over Screen */
#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.92);
    z-index: 200;
}

#game-over-screen.hidden {
    display: none;
}

.game-over-content {
    text-align: center;
    padding: 2rem;
}

#game-over-title {
    font-family: 'Press Start 2P', cursive;
    font-size: clamp(2rem, 6vw, 4rem);
    margin-bottom: 0.5rem;
    text-shadow: 0 0 40px currentColor;
    animation: victoryGlow 1s ease-in-out infinite alternate;
}

@keyframes victoryGlow {
    from { filter: brightness(1); }
    to { filter: brightness(1.3); }
}

.game-over-subtitle {
    font-size: 1.3rem;
    color: #aaa;
    margin-bottom: 2rem;
}

#game-stats {
    font-size: 1.3rem;
    margin-bottom: 2rem;
    text-align: left;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    border-bottom: 1px solid #333;
}

#play-again-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 1rem;
    padding: 1rem 2.5rem;
    background: linear-gradient(180deg, var(--spice) 0%, #cc5500 100%);
    border: none;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 4px;
}

#play-again-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 40px rgba(255,107,53,0.6);
}

/* Footer */
footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 0.4rem 1rem;
    background: rgba(26,10,0,0.95);
    border-top: 1px solid #3a2000;
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-size: 0.85rem;
    z-index: 50;
}

footer a {
    color: var(--spice);
    text-decoration: none;
    transition: color 0.2s ease;
}

footer a:hover {
    color: var(--sand-light);
    text-decoration: underline;
}

footer span {
    color: #555;
}

/* Responsive */
@media (max-width: 900px) {
    #command-panel {
        width: 160px;
    }
    
    #minimap-container {
        display: none;
    }
    
    .resources {
        gap: 0.5rem;
    }
    
    .resource {
        padding: 0.2rem 0.4rem;
        font-size: 1rem;
    }
    
    .controls-preview {
        display: none;
    }
}

@media (max-width: 600px) {
    #command-panel {
        position: absolute;
        right: 0;
        top: 55px;
        bottom: 45px;
        width: 140px;
        opacity: 0.95;
    }
    
    #header-bar {
        padding: 0 0.5rem;
    }
    
    .wave-display {
        display: none;
    }
    
    #controls-hint {
        display: none;
    }
}