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

body {
    background: #111;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    min-height: 100dvh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    user-select: none;
}

/* ====================== SCREENS ====================== */
.screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}
.screen.hidden { display: none !important; }

/* ====================== LOBBY ====================== */
#lobby-screen {
    background: linear-gradient(135deg, #0a0a0a 0%, #1a2a1a 50%, #0a0a0a 100%);
}

.lobby-container {
    text-align: center;
    max-width: 480px;
    width: 90%;
}

.lobby-title {
    font-size: 3rem;
    font-weight: 900;
    color: #4caf50;
    text-shadow: 0 0 30px rgba(76, 175, 80, 0.4), 0 2px 0 #2a5a1a;
    letter-spacing: 4px;
    margin-bottom: 0.2em;
}

.lobby-subtitle {
    color: #888;
    font-size: 1rem;
    margin-bottom: 2em;
    letter-spacing: 2px;
}

.lobby-form {
    display: flex;
    flex-direction: column;
    gap: 1.5em;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.4em;
    text-align: left;
}

.input-group label {
    color: #aaa;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.input-group input {
    background: rgba(255,255,255,0.06);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 0.7em 1em;
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-group input:focus {
    border-color: #4caf50;
}

.lobby-options {
    display: flex;
    flex-direction: column;
    gap: 1em;
    align-items: center;
}

.btn-lobby {
    background: linear-gradient(180deg, #3a7a2a, #2a5a1a);
    color: #fff;
    border: 1px solid #4caf50;
    border-radius: 6px;
    padding: 0.7em 2em;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 1px;
    min-width: 180px;
}

.btn-lobby:hover {
    background: linear-gradient(180deg, #4a8a3a, #3a7a2a);
    border-color: #6fcf50;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.3);
}

.btn-lobby:active {
    transform: scale(0.97);
}

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

.btn-create {
    background: linear-gradient(180deg, #2a5a8a, #1a4a6a);
    border-color: #4fc3f7;
}

.btn-create:hover {
    background: linear-gradient(180deg, #3a6a9a, #2a5a8a);
    border-color: #7fd8ff;
}

.btn-solo {
    background: linear-gradient(180deg, #6a4a8a, #4a2a6a);
    border-color: #bb86fc;
    width: 100%;
}

.btn-solo:hover {
    background: linear-gradient(180deg, #7a5a9a, #6a4a8a);
    border-color: #d4aaff;
}

.btn-join {
    background: linear-gradient(180deg, #8a6a2a, #6a4a1a);
    border-color: #ffa726;
}

.btn-join:hover {
    background: linear-gradient(180deg, #9a7a3a, #8a6a2a);
    border-color: #ffb740;
}

.divider {
    color: #666;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 1em;
    width: 100%;
}

.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #333;
}

.join-group {
    display: flex;
    gap: 0.5em;
    width: 100%;
}

.join-group input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 0.7em 1em;
    color: #fff;
    font-size: 1rem;
    text-align: center;
    letter-spacing: 4px;
    font-weight: bold;
    outline: none;
    transition: border-color 0.2s;
    text-transform: uppercase;
}

.join-group input:focus {
    border-color: #ffa726;
}

.difficulty-group {
    text-align: left;
}

.difficulty-group label {
    color: #aaa;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: block;
    margin-bottom: 0.5em;
}

.difficulty-buttons {
    display: flex;
    gap: 0.5em;
}

.btn-diff {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 0.6em;
    color: #aaa;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-diff:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.btn-diff.active {
    background: rgba(76, 175, 80, 0.2);
    border-color: #4caf50;
    color: #4caf50;
    font-weight: 600;
}

/* ====================== ROOM VIEW ====================== */
.room-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8em;
    margin-bottom: 1em;
}

.room-label {
    color: #aaa;
    font-size: 0.9rem;
}

.room-code {
    font-size: 2rem;
    font-weight: 900;
    color: #4fc3f7;
    letter-spacing: 6px;
    background: rgba(79, 195, 247, 0.1);
    padding: 0.1em 0.4em;
    border-radius: 6px;
    border: 1px solid rgba(79, 195, 247, 0.3);
}

.btn-small {
    background: rgba(255,255,255,0.08);
    border: 1px solid #555;
    border-radius: 4px;
    padding: 0.3em 0.8em;
    color: #ccc;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-small:hover {
    background: rgba(255,255,255,0.15);
    border-color: #8f8;
    color: #fff;
}

.room-status {
    color: #ffa;
    font-size: 0.9rem;
    margin-bottom: 1.5em;
    min-height: 1.5em;
}

.players-list {
    display: flex;
    flex-direction: column;
    gap: 0.5em;
    margin-bottom: 1.5em;
}

.player-slot {
    display: flex;
    align-items: center;
    gap: 0.8em;
    background: rgba(255,255,255,0.04);
    border: 1px solid #333;
    border-radius: 6px;
    padding: 0.7em 1em;
    text-align: left;
}

.slot-icon {
    font-size: 1.2rem;
    color: #4caf50;
}

#slot-guest .slot-icon {
    color: #555;
}

.slot-status {
    margin-left: auto;
    font-size: 0.8rem;
    color: #888;
}

.btn-ready {
    width: 100%;
    background: linear-gradient(180deg, #4caf50, #2e7d32);
    border-color: #6fcf50;
    font-size: 1.1rem;
}

.btn-ready:hover {
    background: linear-gradient(180deg, #5abf60, #3a8a3a);
}

.ready-status {
    color: #888;
    font-size: 0.8rem;
    margin-top: 0.8em;
    min-height: 1em;
}

.lobby-error {
    color: #f44336;
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid rgba(244, 67, 54, 0.3);
    border-radius: 6px;
    padding: 0.6em 1em;
    margin-top: 1em;
    font-size: 0.9rem;
}

/* ====================== GAME SCREEN ====================== */
#game-screen {
    background: #111;
}

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

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: default;
}

#ui-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
}

#top-bar {
    position: absolute;
    top: 1.5%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid #555;
    border-radius: 6px;
    padding: 0.6% 2%;
    display: flex;
    align-items: center;
    gap: 1.5vw;
    font-size: clamp(11px, 1.5vw, 16px);
    pointer-events: none;
    white-space: nowrap;
}

#gold-display {
    color: #ffd700;
    font-weight: bold;
    font-size: clamp(12px, 1.7vw, 18px);
}

#income-display {
    color: #8f8;
    font-size: clamp(10px, 1.2vw, 13px);
}

#unit-counts {
    color: #aaa;
    font-size: clamp(10px, 1.2vw, 13px);
}

.bottom-panel {
    position: absolute;
    bottom: 5%;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.6vw;
    align-items: center;
    background: rgba(0, 0, 0, 0.75);
    border: 1px solid #555;
    border-radius: 6px;
    padding: 0.6% 1.5%;
    pointer-events: auto;
}

.panel-label {
    color: #4fc3f7;
    font-size: clamp(10px, 1.2vw, 14px);
    font-weight: bold;
    margin-right: 0.5vw;
    letter-spacing: 1px;
}

#prod-status {
    color: #ffa;
    font-size: clamp(9px, 1.2vw, 13px);
    min-width: 200px;
    text-align: left;
}

.btn-sm {
    font-size: clamp(8px, 1vw, 11px);
    padding: 2px 6px;
    margin-left: auto;
    pointer-events: auto;
    cursor: pointer;
}

#placement-info {
    position: absolute;
    top: 7%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.75);
    color: #ffa;
    padding: 0.5% 1.5%;
    border-radius: 4px;
    font-size: clamp(10px, 1.2vw, 13px);
    border: 1px solid #aa8;
    pointer-events: none;
    white-space: nowrap;
}

#minimap {
    position: absolute;
    bottom: 5%;
    right: 1%;
    border: 2px solid #555;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.8);
    pointer-events: auto;
    cursor: crosshair;
}

.btn {
    background: rgba(30, 30, 30, 0.85);
    color: #ccc;
    border: 1px solid #666;
    border-radius: 4px;
    padding: 0.5% 1.2%;
    font-size: clamp(10px, 1.2vw, 14px);
    cursor: pointer;
    pointer-events: auto;
    transition: background 0.15s, border-color 0.15s;
    font-family: inherit;
    white-space: nowrap;
    min-width: 120px;
    text-align: center;
    flex-shrink: 0;
}

.btn:hover {
    background: rgba(60, 60, 60, 0.9);
    border-color: #8f8;
    color: #fff;
}

.btn:active {
    background: rgba(40, 80, 40, 0.9);
}

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

#instructions {
    position: absolute;
    bottom: 1%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: #777;
    padding: 0.2% 1%;
    border-radius: 4px;
    font-size: clamp(9px, 1vw, 12px);
    white-space: nowrap;
    border: 1px solid #333;
    pointer-events: none;
}

/* ====================== GAME RESULT OVERLAY ====================== */
#game-result {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    pointer-events: auto;
}

#game-result.hidden { display: none !important; }

.result-content {
    text-align: center;
}

.result-content h1 {
    font-size: 3.5rem;
    font-weight: 900;
    margin-bottom: 0.3em;
    letter-spacing: 6px;
}

#result-title {
    color: #ffd700;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
}

#result-message {
    color: #ccc;
    font-size: 1.2rem;
    margin-bottom: 2em;
}

.result-content .btn-lobby {
    font-size: 1.1rem;
}

/* ====================== IN-GAME MENU ====================== */
#ingame-menu {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 90;
    pointer-events: auto;
}

#ingame-menu.hidden { display: none !important; }

.ingame-menu-content {
    display: flex;
    flex-direction: column;
    gap: 0.8em;
    align-items: center;
    min-width: 220px;
}

.ingame-menu-content .btn-lobby {
    width: 100%;
}

.btn-exit {
    background: linear-gradient(180deg, #8a3a2a, #6a2a1a) !important;
    border-color: #f44336 !important;
}

.btn-exit:hover {
    background: linear-gradient(180deg, #9a4a3a, #8a3a2a) !important;
    border-color: #ff5252 !important;
}

.btn-secondary {
    background: rgba(255,255,255,0.08) !important;
    border-color: #555 !important;
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.15) !important;
}

.hidden {
    display: none !important;
}

@media (max-width: 700px) {
    .bottom-panel {
        flex-wrap: wrap;
        justify-content: center;
        max-width: 90vw;
    }
    .panel-label {
        width: 100%;
        text-align: center;
        margin-bottom: 2px;
    }
    #instructions {
        font-size: 8px;
        padding: 1px 6px;
    }
    .lobby-title { font-size: 2rem; }
    .room-code { font-size: 1.5rem; }
}

/* ====================== TOUCH / TABLET ====================== */
@media (pointer: coarse) {
    .btn {
        min-width: 60px;
        padding: 0.8% 2%;
        font-size: clamp(12px, 2vw, 16px);
    }
    .bottom-panel {
        padding: 1% 2%;
        gap: 1vw;
    }
    #top-bar {
        padding: 1% 3%;
        gap: 2vw;
    }
    #instructions {
        font-size: clamp(8px, 1.5vw, 11px);
    }
    #minimap {
        width: 160px;
        height: 96px;
    }
}
