body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; /* Modern font */
    overflow: hidden; /* Prevent scrollbars */
    background-color: #102a1a; /* Dark background for the page */
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(ellipse at center, #2a5a3a 0%, #1a472a 70%); /* Gradient green felt */
    display: grid;
    grid-template-areas:
        "ai-left ai-top ai-right"
        "played-center played-center played-center"
        "message-area message-area message-area"
        "human-hand human-hand human-hand"
        "controls controls controls";
    grid-template-rows: 180px 1fr auto auto auto; /* More height for top row */
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    padding: 20px;
    box-sizing: border-box;
}

/* Assign grid areas */
#ai-top-hand { grid-area: ai-left; } /* Player 2 (Diep) on the left */
#ai-left-hand { grid-area: ai-top; } /* Player 3 (Paul) in the middle */
#ai-right-hand { grid-area: ai-right; } /* Player 4 (Van) on the right */
#played-cards { grid-area: played-center; }
#message-banner { grid-area: message-area; }
#human-hand { grid-area: human-hand; }
#rules-section { 
    grid-area: rules;
    position: static;
    width: auto;
    background-color: rgba(0, 0, 0, 0.3);
    color: #f0f0f0;
    border-radius: 10px;
    padding: 15px;
    max-height: none;
    overflow-y: auto;
    z-index: auto;
}
#controls {
    grid-area: controls;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    padding: 10px 0;
}

/* General hand styling */
.ai-hand, .player-hand {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

/* Unified AI Hand Styles */
#ai-top-hand,
#ai-left-hand,
#ai-right-hand {
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10px;
}

#played-cards {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 150px;
    border: 1px dashed rgba(255,255,255,0.3);
    padding: 10px;
    flex-wrap: wrap;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
}

#message-banner {
    background-color: rgba(0, 0, 0, 0.5);
    color: #FFD700;
    padding: 10px 20px;
    text-align: center;
    font-weight: bold;
    border-radius: 20px;
    margin: 0 auto;
    width: fit-content;
    max-width: 80%;
    align-self: center;
    border: 1px solid rgba(255, 215, 0, 0.5);
}

#human-hand {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding-bottom: 20px;
}

#rules-section button {
    width: 100%;
    margin-bottom: 10px;
}

#rules-section h3, #rules-section h4 {
    color: #FFD700;
    border-bottom: 1px solid rgba(255, 215, 0, 0.5);
    padding-bottom: 5px;
    margin-top: 0;
}

#rules-section ul {
    list-style-type: none;
    padding-left: 0;
}

#rules-section li {
    margin-bottom: 8px;
    padding-left: 15px;
    position: relative;
}

#rules-section li::before {
    content: '▶';
    position: absolute;
    left: 0;
    color: #FFD700;
    font-size: 0.8em;
}

button {
    padding: 12px 25px;
    font-size: 16px;
    cursor: pointer;
    background-color: #c0983c;
    color: #1a1a1a;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}

button:hover {
    background-color: #d4b35a;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
    transform: translateY(-2px);
}

/* Card Styling */
.card {
    width: 70px;
    height: 100px;
    border: 1px solid #111;
    border-radius: 8px;
    background-color: #f0f0f0;
    box-shadow: 3px 3px 8px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
    position: relative;
    cursor: pointer;
    padding: 5px;
    box-sizing: border-box;
    transition: transform 0.2s ease-out, border 0.2s ease-out, box-shadow 0.2s ease-out;
}

.card .rank-top-left {
    align-self: flex-start;
    font-size: 1em;
}

.card .suit-center {
    font-size: 2em;
}

.card .rank-bottom-right {
    align-self: flex-end;
    transform: rotate(180deg);
    font-size: 1em;
}

#human-hand .card {
    margin-right: 5px;
    margin-left: 0;
}

#human-hand .card:last-child {
    margin-right: 0;
}

.card.selected {
    transform: translateY(-25px);
    border: 2px solid #3498db;
    box-shadow: 0 0 15px #3498db;
}

.card.suggested {
    border: 2px solid #f1c40f;
    box-shadow: 0 0 15px #f1c40f;
}

.ai-card-back, .human-card-back {
    background-image: url('assets/vietnam_flag_card_back.png');
    background-size: cover;
    background-color: #8B0000;
    color: transparent;
    border: 1px solid #550000;
}

/* AI hand stacking */
.ai-hand .card {
    position: absolute;
    top: 0;
    left: 0;
}

#ai-top-hand .card,
#ai-left-hand .card,
#ai-right-hand .card {
    transform: translateX(calc(var(--card-index) * 5px));
}

/* Winner Display */
#winner-display {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 3em;
    z-index: 200;
}

#winner-name {
    margin-bottom: 20px;
    text-shadow: 2px 2px 8px rgba(0,0,0,0.7);
}

#confetti-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

.confetti-card {
    position: absolute;
    width: 50px;
    height: 70px;
    background-color: #fff;
    border-radius: 5px;
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
    animation: fall linear infinite;
    opacity: 0;
}

@keyframes fall {
    0% {
        transform: translateY(-100px) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    100% {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

/* Player Info and Currency Display */
.player-info {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 1em;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

/* Unified AI Player Info */
#ai-top-hand .player-info,
#ai-left-hand .player-info,
#ai-right-hand .player-info {
    top: 110px; /* Position below the 100px high cards */
    left: 50%;
    transform: translateX(-50%);
    flex-direction: column;
    gap: 4px;
}

#human-hand .player-info {
    top: 110px; /* Position below the card stack */
    left: 50%;
    transform: translateX(-50%);
    flex-direction: column;
    gap: 4px;
}

.player-name {
    font-weight: bold;
    color: #fff;
}

.player-currency {
    color: #FFD700;
    font-weight: bold;
}

/* Active Player Highlight */
.player-info.active {
    border-color: #FFD700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.7);
}

.player-info.active .player-name {
    color: #FFD700;
}

#top-right-buttons {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column; /* Stack buttons vertically */
    gap: 10px;
    z-index: 100; /* Ensure it's on top */
}