:root {
    --mpl-blue: #4576ba;
    --mpl-red: #ed1b24;
    --mpl-green: #8cc542;
    --mpl-yellow: #fedc01;
    --mpl-black: #1A1A1A;
    --bg-main: #f8fafc;
    --card-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

body {
    background: var(--bg-main);
    color: var(--mpl-black);
    font-family: 'Outfit', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
}

/* UI LAYOUT */
#game-ui {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 95%;
    max-width: 1500px;
    background: white;
    padding: 15px 20px;
    border-radius: 24px;
    box-shadow: var(--card-shadow);
    margin-bottom: 20px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    transition: border-top 0.3s ease;
}

#players-list {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    width: 100%;
    justify-content: center;
    padding-bottom: 5px;
    scrollbar-width: none;
}

#players-list::-webkit-scrollbar {
    display: none;
}

.player-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 15px;
    border-radius: 16px;
    transition: all 0.3s;
    min-width: 90px;
    border: 2px solid transparent;
}

.player-item.active {
    background: rgba(0, 85, 164, 0.08);
    border-color: var(--mpl-blue);
    transform: scale(1.05);
}

.player-name {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: #64748b;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.player-cards {
    font-size: 28px;
    font-weight: 800;
    color: var(--mpl-black);
}

.stat-box {
    text-align: center;
    flex: 1;
}

.stat-box h3 {
    margin: 0 0 5px 0;
    font-size: 13px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.stat-box div {
    font-size: 32px;
    font-weight: 800;
    color: var(--mpl-black);
}

/* TURNS & FEEDBACK */
#turn-indicator {
    flex: 2;
    text-align: center;
}

#turn-msg {
    font-size: 16px;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 99px;
    transition: 0.3s;
}

.player-turn {
    color: var(--mpl-blue);
    background: rgba(0, 85, 164, 0.1);
}

.cpu-turn {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

/* THE GAME CONTAINER */
#game-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 50px;
    width: 100%;
    max-width: 800px;
    padding: 20px;
}

/* THE DRAW PILE (55x85 Ratio) */
#draw-pile {
    width: 170px;
    height: 262px;
    border: 8px solid white;
    border-radius: 25px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: -6px 6px 0px #cbd5e1, -12px 12px 0px #e2e8f0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    background-image: url('Back.png');
    background-size: cover;
    background-position: center;
}

#draw-pile:hover {
    transform: translateY(-8px) rotate(-1deg);
    box-shadow: -8px 8px 0px #94a3b8, -16px 16px 0px #cbd5e1;
}

.draw-required {
    animation: pulseGlow 1.5s infinite alternate;
    border-color: var(--mpl-yellow) !important;
    box-shadow: 0 0 20px var(--mpl-yellow);
}

@keyframes pulseGlow {
    from {
        transform: scale(1);
        box-shadow: 0 0 10px var(--mpl-yellow);
    }

    to {
        transform: scale(1.05);
        box-shadow: 0 0 30px var(--mpl-yellow);
    }
}

#draw-pile img {
    display: none;
    /* Replaced by background-image */
}

.draw-label {
    position: absolute;
    bottom: 15px;
    color: white;
    font-weight: 800;
    font-size: 11px;
    letter-spacing: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    z-index: 2;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 8px;
    border-radius: 4px;
}

/* AUTHENTIC CARD BACK */
.card-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-image: url('Back.png');
    background-size: cover;
    background-position: center;
}

/* THE CARD FRONT (55x85 Ratio) */
#table {
    width: 240px;
    height: 320px;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
}

.card {
    width: 195px;
    height: 300px;
    border-radius: 12px;
    border: 3px solid #eee;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    background: #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    transition: transform 0.6s;
    transform-style: preserve-3d;
    overflow: hidden;
}

/* Premium Card Accents - The Dashed Lines */
.card::before,
.card::after {
    content: "";
    position: absolute;
    width: 90%;
    border-top: 1.5px dashed #ccc;
    z-index: 1;
    left: 5%;
}

.card::before {
    top: 40%;
}

.card::after {
    top: 75%;
}

.letter-text {
    font-size: 200px;
    font-weight: 500;
    z-index: 2;
    position: relative;
    line-height: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.card-id {
    position: absolute;
    top: 10px;
    left: 12px;
    font-size: 18px;
    color: #333;
    font-weight: 800;
}

.card-logo {
    display: none;
    /* Removed corner logo as per image */
}

.action-label {
    position: absolute;
    bottom: 12px;
    right: 15px;
    font-size: 32px;
    font-weight: 800;
}

.plus-two {
    color: black;
    font-family: 'Outfit', sans-serif;
}

.blue-text {
    color: var(--mpl-blue);
    text-transform: lowercase;
}

.red-text {
    color: var(--mpl-red);
    text-transform: uppercase;
}

.green-text {
    color: var(--mpl-green);
    text-transform: uppercase;
}

.yellow-text {
    color: var(--mpl-yellow);
    text-transform: lowercase;
}

.black-text {
    color: var(--mpl-black);
}

/* Wild Card Layout Update */
.wild-card-face {
    width: 100%;
    height: 100%;

    border: 10px solid white;
    box-shadow: -6px 6px 0px #cbd5e1, -12px 12px 0px #e2e8f0;
    background-image: url('Wild Card.png');
    background-size: cover;
    background-position: center;
    border-radius: 10px;
}

/* Fix: Hide dash lines on Wild Cards */
.card:has(.wild-card-face)::before,
.card:has(.wild-card-face)::after {
    display: none;
}

/* WILD CARD FRONT */
.wild-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.wild-logo {
    width: 30px !important;
    height: auto;
    opacity: 1 !important;
}

.wild-text-label {
    font-size: 18px;
    font-weight: 800;
    color: #1a1a1a;
    text-transform: uppercase;
}

/* SCREENS & BUTTONS */
#victory-screen {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.98);
    z-index: 100;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    backdrop-filter: blur(10px);
}

.controls {
    margin-top: 40px;
}

button {
    padding: 18px 45px;
    font-size: 20px;
    cursor: pointer;
    border-radius: 16px;
    border: none;
    font-weight: 800;
    background: var(--mpl-blue);
    color: white;
    box-shadow: 0 10px 20px rgba(0, 85, 164, 0.2);
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

button:hover {
    transform: translateY(-4px);
    box-shadow: 0 15px 30px rgba(0, 85, 164, 0.3);
    background: #004481;
}

button:active {
    transform: translateY(-1px);
}

/* CONFETTI & ANIMATIONS */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    animation: fall 4s linear forwards;
    border-radius: 2px;
}

@keyframes fall {
    0% {
        transform: translateY(-10vh) rotate(0);
        opacity: 1;
    }

    100% {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

@keyframes playCard {
    0% {
        transform: scale(0.6) translateY(100px) rotate(-10deg);
        opacity: 0;
    }

    100% {
        transform: scale(1) translateY(0) rotate(0);
        opacity: 1;
    }
}

.animate-card {
    animation: playCard 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* MOBILE OPTIMIZATION */
@media (max-width: 600px) {
    #game-ui {
        width: 95%;
        padding: 15px;
    }

    .stat-box div {
        font-size: 24px;
    }

    #game-container {
        flex-direction: column-reverse;
        gap: 30px;
    }

    #draw-pile {
        width: 140px;
        height: 216px;
    }

    .card {
        width: 160px;
        height: 246px;
    }

    .letter-text {
        font-size: 80px;
    }
}

/* --- PLAYER HAND SYSTEM --- */
#player-hand {
    display: flex;
    justify-content: flex-start;
    gap: 15px;
    width: 100%;
    max-width: 1600px;
    padding: 20px 40px;
    min-height: 220px;
    overflow-x: auto;
    scroll-behavior: smooth;
    margin-top: 20px;
    align-items: flex-end;
    scrollbar-width: thin;
    scrollbar-color: var(--mpl-blue) rgba(0,0,0,0.05);
}

#player-hand::-webkit-scrollbar {
    height: 8px;
    display: block; /* Show scrollbar for better feedback */
}

#player-hand::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 10px;
}

#player-hand::-webkit-scrollbar-thumb {
    background: var(--mpl-blue);
    border-radius: 10px;
}


/* --- CARD STYLING --- */

.hand-card {
    width: 100px;
    height: 154px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
    transform: translateY(20px);
}

.hand-card:hover {
    transform: translateY(-30px) scale(1.1);
    z-index: 100;
    cursor: pointer;
}

.hand-card .card {
    width: 100%;
    height: 100%;
    border-width: 2px;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    /* Let clicks pass to the hand-card container */
}

.hand-card .letter-text {
    font-size: 100px;
}

.hand-card .card-id {
    font-size: 10px;
    top: 8px;
    left: 10px;
}

.hand-card .card-logo {
    width: 15px;
    top: 8px;
    right: 10px;
}

.hand-card .action-label {
    font-size: 12px;
    bottom: 10px;
}

.hand-card .card-inner-border {
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    border-radius: 5px;
}

@media (max-width: 600px) {
    #player-hand {
        gap: 10px;
        padding: 10px;
    }

    .hand-card {
        width: 80px;
        height: 123px;
    }

    .hand-card .letter-text {
        font-size: 40px;
    }

    .hand-card .card-id {
        font-size: 10px;
        top: 5px;
        left: 8px;
    }

    .hand-card .action-label {
        font-size: 14px;
        bottom: 5px;
        right: 8px;
    }
}

/* --- UNO RULES & VISUALS --- */
.unplayable {
    opacity: 0.6;
    filter: grayscale(20%);
    cursor: not-allowed !important;
    pointer-events: none;
}

.playable {
    transform: translateY(-15px);
    box-shadow: 0 0 25px rgba(0, 85, 164, 0.5);
    border: 3px solid var(--mpl-blue);
    border-radius: 12px;
    z-index: 50;
    /* Ensure playable cards are on top of unplayable ones */
    animation: playablePulse 2s infinite alternate;
}

@keyframes playablePulse {
    from {
        box-shadow: 0 0 10px rgba(0, 85, 164, 0.3);
    }

    to {
        box-shadow: 0 0 30px rgba(0, 85, 164, 0.6);
    }
}

.playable:hover {
    transform: translateY(-40px) scale(1.15);
    z-index: 101;
}

.unplayable-reason {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    white-space: nowrap;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    z-index: 5;
}

#color-picker {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 200;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
}

#color-picker h2 {
    color: white;
    margin-bottom: 30px;
    font-size: 32px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.color-row {
    display: flex;
    gap: 20px;
}

.color-btn {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 6px solid white;
    cursor: pointer;
    transition: transform 0.3s;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.color-btn:hover {
    transform: scale(1.2) rotate(10deg);
}

.btn-blue {
    background: var(--mpl-blue);
}

.btn-red {
    background: var(--mpl-red);
}

.btn-green {
    background: var(--mpl-green);
}

.btn-yellow {
    background: var(--mpl-yellow);
}

/* Notification Toast */
#game-toast {
    position: fixed;
    top: 50px;
    left: 50%;
    color: white;
    transform: translateX(-50%);
    background: var(--mpl-blue);
    padding: 15px 40px;
    border-radius: 99px;
    font-weight: 800;
    font-size: 22px;
    z-index: 999;
    transition: 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    box-shadow: 0 15px 35px rgba(0, 85, 164, 0.4);
    letter-spacing: 1px;
    pointer-events: none;
    border: 2px solid white;
}

.toast-show {
    opacity: 1;
    top: 80px;
}

.toast-hide {
    opacity: 0;
    top: 50px;
}

/* LOGIN & WAITING */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-main);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

#login-overlay input {
    padding: 18px 25px;
    font-size: 20px;
    border-radius: 16px;
    border: 2px solid #e2e8f0;
    margin-bottom: 25px;
    width: 100%;
    max-width: 320px;
    font-family: 'Outfit', sans-serif;
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: all 0.3s;
}

#login-overlay input:focus {
    outline: none;
    border-color: var(--mpl-blue);
    box-shadow: 0 0 0 4px rgba(0, 85, 164, 0.1);
}

#waiting-msg {
    font-size: 24px;
    font-weight: 800;
    color: var(--mpl-blue);
    animation: pulseMsg 1.5s infinite;
    text-transform: uppercase;
}

@keyframes pulseMsg {
    0% {
        opacity: 0.5;
        transform: scale(0.98);
    }

    50% {
        opacity: 1;
        transform: scale(1.02);
    }

    100% {
        opacity: 0.5;
        transform: scale(0.98);
    }
}