/* =========================================
   GLOBAL LAYOUT
   ========================================= */
:root {
    --color-R: #ff5555; /* Red */
    --color-G: #55aa55; /* Green */
    --color-B: #5555ff; /* Blue */
    --color-Y: #ffaa00; /* Yellow */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #2c2f33; /* Dark Theme Background */
    text-align: center;
    margin: 0;
    padding: 20px;
    color: white;
}

h1 { color: #ffffff; margin-bottom: 20px; }

#game-container {
    max-width: 900px;
    margin: 0 auto;
    background-color: #23272a; /* Darker Container */
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    min-height: 100vh; 
    /* Dynamic height fix for mobile browsers */
    min-height: calc(var(--vh, 1vh) * 100);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* =========================================
   OPPONENT AREA (TOP)
   ========================================= */
#opponents-container {
    display: flex;
    justify-content: space-between;
    padding-bottom: 20px;
    border-bottom: 1px solid #444;
    gap: 10px;
}

.player-slot {
    background: #2c2f33;
    padding: 10px;
    border-radius: 8px;
    width: 30%;
    min-height: 80px;
    border: 2px solid #444;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.player-slot p { margin: 0 0 5px 0; font-weight: bold; color: #ddd; }
.hand-counter { font-size: 1.2em; font-weight: bold; color: #00b0ff; }

/* Highlight Active Player */
.player-slot.is-current-player {
    border-color: #ffc107;
    background-color: #3a3f44;
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.5);
}

/* =========================================
   CENTER TABLE (FIXED CENTERING)
   ========================================= */
#table-area {
    position: relative; /* Established coordinate system */
    height: 180px;      /* Fixed height defines the "Game Space" */
    width: 100%;
    margin: 20px 0;
    
    /* Flexbox centers the Discard Pile automatically */
    display: flex;
    justify-content: center;
    align-items: center;
}

#draw-pile {
    position: absolute; /* Take out of flow */
    left: 15%;          /* Lock to the left side */
    top: 50%;           /* Center vertically */
    transform: translateY(-50%); /* Correct vertical offset */
    z-index: 5;
}

#discard-pile {
    /* No position needed; Flexbox parent centers this perfectly */
    z-index: 10;
    transform: scale(1.1); /* Make active card slightly larger */
}

/* =========================================
   PLAYER HAND (BOTTOM)
   ========================================= */
#player-area {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid #444;
}

#ui-controls {
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

#player-hand-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
    min-height: 120px;
    padding: 10px;
    background: #2c2f33;
    border-radius: 10px;
}

/* =========================================
   CARD STYLES
   ========================================= */
.uno-card {
    width: 80px;
    height: 120px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    box-shadow: 2px 2px 5px rgba(0,0,0,0.4);
    user-select: none;
    position: relative;
    border: 2px solid white;
    transition: transform 0.2s, filter 0.3s;
}

.uno-card.playable {
    cursor: pointer;
    border-color: #ffff00; /* Yellow highlight hint */
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.3);
}
.uno-card.playable:hover {
    transform: translateY(-15px) scale(1.1);
    z-index: 20;
}

/* Colors */
.uno-card.R { background-color: var(--color-R); }
.uno-card.G { background-color: var(--color-G); }
.uno-card.B { background-color: var(--color-B); }
.uno-card.Y { background-color: var(--color-Y); }
.uno-card.back { background-color: #111; border-color: #555; cursor: pointer; }

/* Wild Card (4 Quadrants) */
.uno-card.BL {
    background: conic-gradient(
        var(--color-R) 0deg 90deg, 
        var(--color-G) 90deg 180deg, 
        var(--color-B) 180deg 270deg, 
        var(--color-Y) 270deg 360deg
    );
    border: 3px solid white;
}

/* Wild Color Indicators */
.chosen-R { border: 4px solid var(--color-R); }
.chosen-G { border: 4px solid var(--color-G); }
.chosen-B { border: 4px solid var(--color-B); }
.chosen-Y { border: 4px solid var(--color-Y); }

/* =========================================
   GREYSCALE LOGIC
   ========================================= */
.not-my-turn .uno-card {
    filter: grayscale(100%) brightness(0.5);
    opacity: 0.6;
    cursor: not-allowed !important;
    transform: none !important;
}

/* =========================================
   LOBBY & UTILS
   ========================================= */
#lobby-settings {
    margin: 20px auto;
    padding: 20px;
    border: 1px solid #444;
    border-radius: 8px;
    max-width: 400px;
    background: #2c2f33;
    text-align: left;
}

#lobby-settings label { display: block; margin-top: 10px; font-weight: bold; color: white; }
#lobby-settings input, #lobby-settings select { 
    width: 100%; padding: 8px; margin-top: 5px; box-sizing: border-box; 
    border-radius: 4px; border: none;
}

#lobby-action-button {
    width: 100%; margin-top: 20px; padding: 10px;
    background-color: #28a745; color: white;
    border: none; border-radius: 4px; cursor: pointer; font-size: 16px;
}
#lobby-action-button:hover:not(:disabled) { background-color: #218838; }
#lobby-action-button:disabled { background-color: #555; cursor: not-allowed; }

#status-message { 
    margin-top: 15px; font-weight: bold; 
    padding: 10px; background: #333; border-radius: 5px; 
}

/* Buttons */
#uno-button {
    background-color: #ff4500; color: white; font-weight: bold;
    border: none; padding: 10px 20px; border-radius: 5px; cursor: pointer;
}
#uno-button:disabled { background-color: #555; cursor: default; opacity: 0.5; }

/* Color Picker */
#color-picker {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: #333; padding: 20px;
    border-radius: 10px; border: 2px solid white;
    z-index: 100;
    display: none; /* JS toggles this */
}
.color-btn {
    width: 60px; height: 60px; margin: 5px;
    border: 2px solid white; cursor: pointer; border-radius: 50%;
}

/* =========================================
   MOBILE RESPONSIVENESS
   ========================================= */
@media screen and (max-width: 768px) {
    
    body { padding: 5px; }
    
    #game-container {
        width: 100%; margin: 0; padding: 10px 5px;
    }

    /* Opponent Area */
    #opponents-container {
        gap: 5px;
    }
    .player-slot {
        padding: 5px;
        font-size: 0.8rem;
        min-height: 60px;
    }
    
    /* Table Area Fixes for Mobile */
    #table-area {
        height: 140px; /* Slightly shorter for mobile */
    }
    #draw-pile {
        left: 5%; /* Move closer to edge on small screens */
    }

    /* Smaller Cards for Mobile */
    .uno-card {
        width: 50px; height: 80px;
        font-size: 18px; border-width: 1px;
    }
    
    /* Ensure teammate cards in top slots don't break layout */
    .player-slot .uno-card {
        width: 30px; height: 50px; /* Tiny cards for teammates */
        font-size: 10px;
    }

    #player-hand-container {
        gap: 5px; padding: 10px;
    }
    
    .action-buttons {
        flex-direction: column; gap: 10px;
    }
    .action-buttons button { width: 100%; margin: 0; }
}