/* ============================================================
   RUST KINGDOMS - Stylesheet
   ============================================================ */

/* === RESET & BASE === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-dark: #0a0a12;
    --bg-panel: #1a1a2e;
    --bg-button: #2a2a4e;
    --bg-hover: #3a3a5e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent-gold: #ffd700;
    --accent-green: #4ade80;
    --accent-red: #f87171;
    --accent-blue: #60a5fa;
    --border-color: #3a3a5e;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
}

/* === MAIN LAYOUT === */
#game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* === HEADER === */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(180deg, var(--bg-panel), var(--bg-dark));
    border-bottom: 2px solid var(--border-color);
    z-index: 100;
}

.resources {
    display: flex;
    gap: 20px;
}

.resource {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--bg-button);
    border-radius: 6px;
    font-weight: 600;
}

.resource-icon {
    font-size: 1.2em;
}

.resource-value {
    min-width: 50px;
}

.game-info {
    display: flex;
    align-items: center;
    gap: 20px;
}

#culture-display {
    padding: 6px 12px;
    background: var(--bg-button);
    border-radius: 6px;
    font-weight: 600;
}

#game-time {
    font-family: monospace;
    font-size: 1.2em;
    color: var(--accent-gold);
}

/* === GAME AREA === */
#game-area {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

/* === MINIMAP === */
#minimap-container {
    position: absolute;
    bottom: 80px;
    right: 16px;
    background: var(--bg-panel);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    z-index: 50;
}

#minimap {
    display: block;
    border-radius: 4px;
    cursor: pointer;
}

/* === SELECTION PANEL === */
#selection-panel {
    position: absolute;
    bottom: 80px;
    left: 16px;
    width: 320px;
    background: var(--bg-panel);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    z-index: 50;
}

#selection-panel.hidden {
    display: none;
}

.entity-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.entity-icon {
    font-size: 2.5em;
}

.entity-name {
    font-size: 1.2em;
    font-weight: 700;
}

.entity-type {
    color: var(--text-secondary);
    font-size: 0.9em;
}

/* Stat Bars */
.stat-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.stat-bar-label {
    width: 60px;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.stat-bar-bg {
    flex: 1;
    height: 12px;
    background: #333;
    border-radius: 6px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    transition: width 0.3s ease;
}

.stat-bar-fill.hp {
    background: linear-gradient(90deg, #22c55e, #4ade80);
}

.stat-bar-fill.morale {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.stat-bar-fill.loyalty {
    background: linear-gradient(90deg, #eab308, #facc15);
}

.stat-bar-fill.training {
    background: linear-gradient(90deg, #8b5cf6, #a78bfa);
}

.stat-bar-value {
    width: 70px;
    text-align: right;
    font-size: 0.85em;
    font-family: monospace;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 12px 0;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    background: var(--bg-button);
    border-radius: 6px;
}

.stat-icon {
    font-size: 1.2em;
    margin-bottom: 4px;
}

/* Stat Row */
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-top: 1px solid var(--border-color);
}

.status-idle { color: var(--accent-green); }
.status-moving { color: var(--accent-blue); }
.status-attacking { color: var(--accent-red); }
.status-fleeing { color: #fbbf24; }

/* Action Buttons */
#action-buttons {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-btn {
    padding: 10px 16px;
    background: var(--bg-button);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.95em;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-gold);
}

.action-section {
    margin-top: 8px;
}

.action-title {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.train-buttons {
    display: flex;
    gap: 6px;
}

.train-btn {
    width: 44px;
    height: 44px;
    font-size: 1.5em;
    background: var(--bg-button);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.train-btn:hover:not(.disabled) {
    background: var(--bg-hover);
    border-color: var(--accent-gold);
    transform: scale(1.1);
}

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

.tax-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.tax-controls button {
    padding: 6px 12px;
    background: var(--bg-button);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85em;
}

.tax-controls button:hover {
    background: var(--bg-hover);
}

/* Multi Selection */
.multi-selection {
    text-align: center;
}

.selection-count {
    font-size: 1.3em;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--accent-gold);
}

.unit-groups {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.unit-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    background: var(--bg-button);
    border-radius: 6px;
}

.unit-group-icon {
    font-size: 1.5em;
}

.unit-group-count {
    font-weight: 700;
}

.unit-group-hp {
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* === FOOTER === */
#footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(0deg, var(--bg-panel), var(--bg-dark));
    border-top: 2px solid var(--border-color);
    z-index: 100;
}

/* Build Buttons */
.build-buttons {
    display: flex;
    gap: 8px;
}

.build-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 14px;
    background: var(--bg-button);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 70px;
}

.build-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-gold);
    transform: translateY(-2px);
}

.build-btn.active {
    background: var(--accent-gold);
    color: #000;
    border-color: var(--accent-gold);
}

.build-btn .icon {
    font-size: 1.8em;
    margin-bottom: 2px;
}

.build-btn .label {
    font-size: 0.75em;
}

.build-btn .cost {
    font-size: 0.7em;
    color: var(--text-secondary);
}

.build-btn.active .cost {
    color: #333;
}

/* Control Buttons */
.control-buttons {
    display: flex;
    gap: 8px;
}

.control-btn {
    padding: 10px 14px;
    background: var(--bg-button);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.2em;
    transition: all 0.2s;
}

.control-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-blue);
}

.speed-btn.active {
    background: var(--accent-blue);
    color: #000;
}

/* === DIPLOMACY PANEL === */
#diplomacy-panel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 400px;
    max-height: 80vh;
    background: var(--bg-panel);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    z-index: 200;
    overflow: hidden;
}

#diplomacy-panel.hidden {
    display: none;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-button);
    border-bottom: 2px solid var(--border-color);
}

.panel-header h2 {
    margin: 0;
    font-size: 1.3em;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5em;
    cursor: pointer;
    padding: 4px 8px;
}

.close-btn:hover {
    color: var(--accent-red);
}

#diplomacy-content {
    padding: 16px;
    max-height: 60vh;
    overflow-y: auto;
}

.diplomacy-kingdom {
    padding: 12px;
    margin-bottom: 12px;
    background: var(--bg-button);
    border-radius: 8px;
}

.kingdom-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.kingdom-icon {
    font-size: 1.8em;
}

.kingdom-name {
    flex: 1;
    font-weight: 600;
}

.kingdom-relation {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.85em;
}

.kingdom-relation.neutral {
    background: #666;
}

.kingdom-relation.peace {
    background: #22c55e;
    color: #000;
}

.kingdom-relation.war {
    background: #ef4444;
}

.diplomacy-actions {
    display: flex;
    gap: 8px;
}

.diplomacy-actions button {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.9em;
}

.diplomacy-actions button:hover {
    background: var(--bg-hover);
}

/* === TOOLTIP === */
#tooltip {
    position: fixed;
    padding: 10px 14px;
    background: var(--bg-dark);
    border: 2px solid var(--accent-gold);
    border-radius: 8px;
    z-index: 1000;
    pointer-events: none;
    max-width: 250px;
}

#tooltip.hidden {
    display: none;
}

.tooltip-title {
    font-weight: 700;
    font-size: 1.1em;
    margin-bottom: 6px;
}

.tooltip-cost {
    color: var(--accent-gold);
    margin-bottom: 6px;
}

.tooltip-desc {
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* === TOASTS === */
#toast-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 24px;
    background: var(--bg-panel);
    border: 2px solid var(--accent-gold);
    border-radius: 8px;
    color: var(--text-primary);
    font-weight: 500;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* === START SCREEN === */
#start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0a12 0%, #1a1a3e 50%, #0a0a12 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

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

.logo {
    max-width: 300px;
    margin-bottom: 10px;
}

.game-title {
    font-size: 3em;
    font-weight: 900;
    color: var(--accent-gold);
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
    margin-bottom: 10px;
}

.game-subtitle {
    font-size: 1.2em;
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.start-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 400px;
    max-width: 90%;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-group label {
    font-size: 0.9em;
    color: var(--text-secondary);
}

.option-group select {
    padding: 12px 16px;
    background: var(--bg-button);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1em;
    cursor: pointer;
}

.option-group select:focus {
    outline: none;
    border-color: var(--accent-gold);
}

#start-btn {
    padding: 16px 32px;
    background: linear-gradient(135deg, var(--accent-gold), #b8860b);
    border: none;
    border-radius: 8px;
    color: #000;
    font-size: 1.3em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 20px;
}

#start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
}

.start-tips {
    margin-top: 30px;
    padding: 20px;
    background: var(--bg-panel);
    border-radius: 8px;
    max-width: 500px;
}

.start-tips h3 {
    margin-bottom: 10px;
    color: var(--accent-gold);
}

.start-tips ul {
    list-style: none;
    text-align: left;
}

.start-tips li {
    padding: 4px 0;
    color: var(--text-secondary);
}

.start-tips li::before {
    content: "→ ";
    color: var(--accent-gold);
}

/* === GAME OVER === */
#game-over {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

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

#game-over-title {
    font-size: 4em;
    font-weight: 900;
    margin-bottom: 20px;
}

#game-over-title.victory {
    color: var(--accent-gold);
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
}

#game-over-title.defeat {
    color: var(--accent-red);
    text-shadow: 0 0 30px rgba(239, 68, 68, 0.5);
}

#game-over-reason {
    font-size: 1.5em;
    color: var(--text-secondary);
    margin-bottom: 30px;
}

#game-over-time {
    font-size: 1.2em;
    margin-bottom: 20px;
}

#game-over-stats {
    display: flex;
    gap: 30px;
    margin-bottom: 40px;
}

#game-over-stats div {
    padding: 10px 20px;
    background: var(--bg-panel);
    border-radius: 8px;
}

#restart-btn {
    padding: 16px 40px;
    background: var(--accent-gold);
    border: none;
    border-radius: 8px;
    color: #000;
    font-size: 1.2em;
    font-weight: 700;
    cursor: pointer;
}

#restart-btn:hover {
    transform: scale(1.05);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .resources {
        gap: 10px;
    }
    
    .resource {
        padding: 4px 8px;
        font-size: 0.9em;
    }
    
    #selection-panel {
        width: calc(100% - 32px);
        left: 16px;
        bottom: 70px;
    }
    
    #minimap-container {
        width: 120px;
        height: 120px;
    }
    
    #minimap {
        width: 100%;
        height: 100%;
    }
    
    .build-btn {
        padding: 6px 10px;
        min-width: 55px;
    }
    
    .build-btn .icon {
        font-size: 1.4em;
    }
    
    .build-btn .label {
        display: none;
    }
    
    .game-title {
        font-size: 2em;
    }
    
    .start-options {
        width: 90%;
    }
}

/* === ANIMATIONS === */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 10px rgba(255, 215, 0, 0.3); }
    50% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.6); }
}

.build-btn.active {
    animation: pulse 1s infinite;
}

#start-btn {
    animation: glow 2s infinite;
}
