/* General Styles */
:root {
    --player-color: #3498db;
    --computer1-color: #e74c3c;
    --computer2-color: #2ecc71;
    --bg-color: #f5f5f5;
    --card-bg: white;
    --card-back: #34495e;
    --text-color: #333;
    --border-color: #ddd;
    --animation-duration: 0.5s; /* Default, will be overridden by JS */
    --keep-btn-color: #27ae60;
    --discard-btn-color: #e74c3c;
}

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

body {
    font-family: 'Arial', sans-serif;
    background-color: #e0f7fa; /* Changed to light blue to confirm changes are applied */
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

#game-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Button Styles */
.btn {
    background-color: var(--player-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.btn:hover {
    opacity: 0.9;
}

.btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

#keep-card-btn {
    background-color: var(--keep-btn-color);
}

#discard-card-btn {
    background-color: var(--discard-btn-color);
}

/* Screen Styles */
.screen {
    display: none;
    width: 100%;
    height: 100%;
    justify-content: center;
    align-items: flex-start;
    padding-top: 10px;
    overflow-y: auto;
}

.screen.active {
    display: flex;
}

/* Welcome Screen */
.welcome-content {
    text-align: center;
    max-width: 500px;
    padding: 40px;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

.welcome-content h1 {
    color: var(--player-color);
    margin-bottom: 20px;
}

.player-input {
    margin: 30px 0 15px;
}

.player-input label {
    display: block;
    margin-bottom: 10px;
}

.player-input input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    font-size: 16px;
}

/* Game Settings */
.game-settings {
    margin-bottom: 20px;
}

.setting {
    margin-bottom: 10px;
    text-align: left;
}

.setting label {
    display: block;
    margin-bottom: 5px;
}

.setting select {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: white;
}

/* Game Layout */
.game-layout {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    gap: 20px;
    flex: 1;
}

.left-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 40px);
}

.right-panel {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    max-height: calc(100vh - 40px);
}

/* Current Turn Indicator */
.current-turn-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--player-color);
    color: white;
    text-align: center;
    padding: 5px;
    font-weight: bold;
    z-index: 90;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Game Screen */
.game-info {
    padding: 10px;
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin-top: 30px; /* Add space for the turn indicator */
}

.player-info {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Opponent Area */
.opponents-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.opponent {
    padding: 15px 15px 25px;
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    text-align: center;
}

#computer1 h3 {
    color: var(--computer1-color);
}

#computer2 h3 {
    color: var(--computer2-color);
}

.mini-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin: 10px 0;
}

.mini-card {
    width: 100%;
    aspect-ratio: 2/3;
    border-radius: 3px;
    background-color: var(--card-back);
    position: relative;
}

.mini-card.revealed {
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: white;
}

/* Card Piles */
.card-piles {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin: 20px 0;
    padding: 20px;
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.pile {
    text-align: center;
}

.pile .card {
    width: 120px;
    height: 180px;
    margin: 0 auto 10px;
}

/* Player Area */
.player-area {
    padding: 20px 20px 30px;
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.player-area h3 {
    color: var(--player-color);
    text-align: center;
    margin-bottom: 15px;
}

.player-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 15px;
}

.score {
    text-align: center;
    font-weight: bold;
    font-size: 18px;
}

.live-score {
    text-align: center;
    margin-top: 5px;
    font-size: 16px;
    color: #666;
}

/* Card Selection Area */
.card-selection-area {
    position: fixed;
    top: 30px;
    right: 20px;
    background-color: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    z-index: 100;
    max-width: 180px;
    width: auto;
}

.card-selection-area .card {
    width: 100px;
    height: 150px;
    margin: 0 auto 10px;
}

.card-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Card Styles */
.card {
    width: 100%;
    aspect-ratio: 2/3;
    perspective: 1000px;
    cursor: pointer;
    position: relative;
}

.card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform var(--animation-duration);
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.card.flipped .card-inner {
    transform: rotateY(180deg);
}

.card-front, .card-back {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    border-radius: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    font-weight: bold;
}

.card-front {
    transform: rotateY(180deg);
}

.card-back {
    background-color: var(--card-back);
}

.card.empty .card-inner {
    background-color: #f0f0f0;
    border: 2px dashed #ccc;
}

.card.back .card-inner {
    background-color: var(--card-back);
}

/* Card Values and Colors */
.card-m2 { background-color: #1abc9c; color: white; } /* Dark Turquoise */
.card-m1 { background-color: #48c9b0; color: white; } /* Light Turquoise */
.card-0 { background-color: #95a5a6; color: white; } /* Gray */
.card-1 { background-color: #58d68d; color: white; } /* Light Green */
.card-2 { background-color: #2ecc71; color: white; } /* Green */
.card-3 { background-color: #2d9b58; color: white; } /* Olive Green */
.card-4 { background-color: #f1c40f; color: black; } /* Yellow */
.card-5 { background-color: #f39c12; color: white; } /* Orange */
.card-6 { background-color: #e67e22; color: white; } /* Coral */
.card-7 { background-color: #e74c3c; color: white; } /* Light Red */
.card-8 { background-color: #cb4335; color: white; } /* Red */
.card-9 { background-color: #a93226; color: white; } /* Dark Red */
.card-10 { background-color: #8e44ad; color: white; } /* Purple */
.card-11 { background-color: #9b59b6; color: white; } /* Magenta */
.card-12 { background-color: #d98cb3; color: white; } /* Pink */

/* Round End Screen */
.round-results {
    background-color: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 800px;
    width: 90%;
}

.round-results h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--player-color);
}

.results-container, .total-scores, .final-scores {
    margin-bottom: 30px;
}

.total-scores h3, .final-scores h3 {
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
}

.completed-first {
    position: relative;
}

.completed-first::after {
    content: "★";
    color: gold;
    margin-left: 10px;
}

.doubled-score {
    color: var(--discard-btn-color);
    font-weight: bold;
}

.doubled-score::after {
    content: " (doubled)";
    font-size: 80%;
}

.final-cards-display {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    margin-top: 20px;
    margin-bottom: 30px;
}

.player-final-cards {
    text-align: center;
    padding: 15px;
    background-color: rgba(0,0,0,0.05);
    border-radius: 10px;
}

.player-final-cards h4 {
    margin-bottom: 10px;
    color: var(--player-color);
}

.player-final-cards.computer1 h4 {
    color: var(--computer1-color);
}

.player-final-cards.computer2 h4 {
    color: var(--computer2-color);
}

.final-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
}

.final-card {
    width: 50px;
    height: 75px;
    border-radius: 3px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: white;
    font-size: 16px;
}

#next-round-btn, #new-game-btn {
    display: block;
    margin: 0 auto;
}

/* Game End Screen */
.game-results {
    background-color: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 800px;
    width: 90%;
}

#winner-announcement {
    text-align: center;
    font-size: 24px;
    margin: 20px 0;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 5px;
}

.winner-name {
    font-weight: bold;
    color: var(--player-color);
}

/* Message Container */
#message-container {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 20px;
    border-radius: 5px;
    z-index: 200;
}

/* Round Scoreboard */
.round-scoreboard {
    background-color: white;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    padding: 15px;
    overflow-x: auto;
}

.round-scoreboard h3 {
    text-align: center;
    margin-bottom: 10px;
    color: var(--player-color);
}

#round-scoreboard-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 300px;
}

#round-scoreboard-table th,
#round-scoreboard-table td {
    padding: 8px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
}

#round-scoreboard-table th {
    background-color: #f8f9fa;
}

#round-scoreboard-table th:first-child {
    text-align: left;
}

#round-scoreboard-table tr:last-child {
    font-weight: bold;
    background-color: #f8f9fa;
}

.hidden {
    display: none !important;
}

/* Card Animation */
@keyframes cardDraw {
    0% { transform: translateY(-50px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

@keyframes cardMove {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes cardDiscard {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { transform: translate(100px, 50px) scale(0.8); opacity: 0; }
}

.card-animated {
    animation: cardDraw var(--animation-duration) ease-out;
}

.card-moved {
    animation: cardMove var(--animation-duration) ease-in-out;
}

.card-discarded {
    animation: cardDiscard var(--animation-duration) ease-in-out;
}

/* Thinking Animation */
.thinking-indicator {
    display: flex;
    gap: 8px;
}

.thinking-dot {
    width: 12px;
    height: 12px;
    background-color: white;
    border-radius: 50%;
    animation: thinking 1.4s infinite ease-in-out;
}

.thinking-dot:nth-child(1) {
    animation-delay: 0s;
}

.thinking-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes thinking {
    0%, 100% { transform: scale(0.6); opacity: 0.5; }
    50% { transform: scale(1); opacity: 1; }
}

/* Leaderboard Styles */
.leaderboard-content {
    background-color: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 800px;
    width: 90%;
}

.leaderboard-content h2 {
    text-align: center;
    margin-bottom: 20px;
    color: var(--player-color);
}

.leaderboard-table-container {
    margin-bottom: 30px;
    max-height: 400px;
    overflow-y: auto;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

#leaderboard-table th,
#leaderboard-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

#leaderboard-table th {
    background-color: #f8f9fa;
    position: sticky;
    top: 0;
}

#back-to-game-btn {
    display: block;
    margin: 0 auto;
}

/* Responsive Styles */
@media (max-width: 768px) {
    .game-layout {
        flex-direction: column;
    }
    
    .right-panel {
        order: 1;
    }
    
    .left-panel {
        order: 2;
    }
    
    .pile .card {
        width: 80px;
        height: 120px;
    }
    
    .card-selection-area {
        max-width: 150px;
    }
    
    .card-selection-area .card {
        width: 70px;
        height: 105px;
    }
    
    .final-cards-display {
        flex-direction: column;
    }
}

/* Column match animations */
.column-match-highlight {
    animation: highlight-pulse 0.5s ease-in-out;
}

.column-fade-out {
    animation: fade-out 0.5s ease-in-out forwards;
    pointer-events: none;
}

@keyframes highlight-pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 rgba(255, 215, 0, 0); }
    50% { transform: scale(1.05); box-shadow: 0 0 15px rgba(255, 215, 0, 0.8); }
    100% { transform: scale(1); box-shadow: 0 0 0 rgba(255, 215, 0, 0); }
}

@keyframes fade-out {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.8); }
}

/* Placeholder cards to maintain grid structure */
.card.placeholder,
.mini-card.placeholder {
    visibility: hidden;
    pointer-events: none;
}

/* Player and Computer Cards Grid Layouts */
.player-cards, .mini-cards {
    display: grid;
    gap: 10px;
    width: 100%;
    grid-auto-flow: dense;
    margin: 0 auto 20px;
    max-width: 600px;
}

/* Specific styling for player cards */
.player-cards {
    grid-template-rows: repeat(3, 1fr);
    min-height: 350px;
}

/* Specific styling for computer cards */
.mini-cards {
    grid-template-rows: repeat(3, 1fr);
    min-height: 200px;
    gap: 5px;
}

/* Make sure cards stay in their assigned positions and keep consistent size */
.card, .mini-card {
    width: 100%;
    height: 100%;
    aspect-ratio: 2/3;
    margin: 0;
    transition: all 0.3s ease-in-out;
    justify-self: center;
}

/* Ensure cards maintain fixed dimensions */
.card {
    min-width: 80px;
    max-width: 120px;
}

.mini-card {
    min-width: 50px;
    max-width: 80px;
}

/* Ensure parent containers don't expand/contract too much */
.player-area, .opponent {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

/* Column match highlight animation */
@keyframes highlight-column {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
    }
    50% { 
        opacity: 0.8; 
        transform: scale(1.05);
        box-shadow: 0 0 15px gold;
    }
}

/* Apply animation to columns being removed */
.column-being-removed {
    animation: highlight-column 0.5s ease-in-out 3;
}

/* Responsive adjustments for card sizing */
@media (max-width: 768px) {
    .card {
        min-width: 70px;
    }
    
    .mini-card {
        min-width: 45px;
    }
}

/* Remove duplicated rules */

/* Card highlight for clickable cards */
.clickable-highlight {
    box-shadow: 0 0 15px var(--player-color);
    transform: scale(1.05);
    z-index: 10;
    position: relative;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 5px var(--player-color); }
    50% { box-shadow: 0 0 20px var(--player-color); }
    100% { box-shadow: 0 0 5px var(--player-color); }
}

/* Column match animations */ 