:root {
    --red: #f55040;
    --blue: #0072c4;
    --green: #419c3b;
    --yellow: #f8c922;
    --dark: #222;
    --primary-gradient: linear-gradient(135deg, #ff4e50 0%, #f9d423 100%);
    --shadow-lg: 0 15px 35px rgba(0, 0, 0, 0.5);
}

body {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    color: white;
    touch-action: manipulation;
    overflow: hidden;
    height: 100vh;
    transition: background 0.5s ease;
}

/* Themes */
body.theme-green {
    background: radial-gradient(circle at center, #2e5a32 0%, #0d1a0f 100%);
}
body.theme-blue {
    background: radial-gradient(circle at center, #1b3b6f 0%, #06101e 100%);
}
body.theme-red {
    background: radial-gradient(circle at center, #6f1b1b 0%, #1e0606 100%);
}
body.theme-dark {
    background: radial-gradient(circle at center, #2b2b2b 0%, #0a0a0a 100%);
}

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    box-sizing: border-box;
    position: relative;
}

.hidden { display: none !important; }

/* Buttons */
.btn {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    padding: 14px 24px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.btn:active {
    transform: translateY(1px) scale(0.98);
}

.btn-primary {
    background: var(--red);
    color: white;
}
.btn-primary:hover {
    background: #e03e2e;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(5px);
}
.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.25);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 8px;
}

.btn-cancel {
    background: #555;
    color: #eee;
    margin-top: 15px;
}

.btn-icon-only {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    font-size: 1.3rem;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}
.btn-icon-only:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* Main Menu */
#main-menu {
    justify-content: center;
    background: rgba(0,0,0,0.4);
    width: 100%;
}

.menu-card {
    background: rgba(20, 20, 20, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 40px 30px;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    width: 90%;
    max-width: 380px;
    animation: fadeIn 0.4s ease-out;
}

.logo-container {
    margin-bottom: 30px;
}

.game-logo {
    margin: 0;
    font-size: 4rem;
    font-weight: 800;
    line-height: 1;
    background: linear-gradient(45deg, var(--red), var(--yellow), var(--green), var(--blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
}

.sub-logo {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 4px;
    color: var(--yellow);
    display: block;
    margin-top: 5px;
}

.menu-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

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

.input-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #bbb;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group input {
    width: 100%;
    box-sizing: border-box;
    font-size: 1.1rem;
    padding: 14px 16px;
    background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    color: white;
    font-family: 'Poppins', sans-serif;
    outline: none;
    transition: border-color 0.2s, background 0.2s;
}

.input-group input:focus {
    border-color: var(--yellow);
    background: rgba(255,255,255,0.15);
}

/* Waiting Room */
#waiting-room {
    justify-content: center;
    background: rgba(0,0,0,0.6);
    width: 100%;
}

.waiting-card {
    background: rgba(20, 20, 20, 0.9);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 40px 30px;
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    width: 90%;
    max-width: 360px;
}

.waiting-card h2 {
    margin-top: 0;
    color: white;
    font-size: 1.6rem;
}

.spinner-container {
    margin: 30px 0;
    display: flex;
    justify-content: center;
}

.cards-loader {
    display: flex;
    gap: 8px;
}

.mini-card {
    width: 28px;
    height: 42px;
    border-radius: 5px;
    border: 2px solid white;
    animation: cardPulse 1.2s infinite ease-in-out alternate;
}
.mini-card.red { background: var(--red); animation-delay: 0s; }
.mini-card.blue { background: var(--blue); animation-delay: 0.2s; }
.mini-card.green { background: var(--green); animation-delay: 0.4s; }
.mini-card.yellow { background: var(--yellow); animation-delay: 0.6s; }

@keyframes cardPulse {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(-15px) scale(1.15); }
}

.players-badge {
    display: inline-block;
    background: rgba(248, 201, 34, 0.2);
    border: 1px solid var(--yellow);
    color: var(--yellow);
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 600;
    margin: 15px 0;
}

/* Header Bar inside Game */
#header-bar {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    box-sizing: border-box;
    z-index: 10;
}

#status {
    background: rgba(0,0,0,0.5);
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-size: 0.95rem;
    border: 1px solid rgba(255,255,255,0.15);
}

/* Game Styles */
#game {
    justify-content: space-between;
    padding: 10px 0;
}

#opponents {
    display: flex;
    gap: 20px;
    overflow-x: hidden;
    width: 100%;
    padding: 10px 20px;
    box-sizing: border-box;
    min-height: 90px;
}
#opponents::before, #opponents::after {
    content: '';
    margin: auto;
}

.opponent {
    padding: 10px;
    text-align: center;
    flex: 1 1 0;
    min-width: 0;
    transition: transform 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.opponent .opp-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    color: white;
    transition: color 0.3s, text-shadow 0.3s;
}

.opp-hand {
    display: flex;
    padding-bottom: 1rem;
}

.opp-hand .card {
    margin-right: -25px; 
    box-shadow: 2px 5px 10px rgba(0,0,0,0.4) !important;
    pointer-events: none;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.opp-hand .card.hovered {
    transform: translateY(20px) scale(1.1);
    z-index: 999 !important;
}

.card-back {
    background: #111;
    border-color: #eee;
    color: var(--red);
    cursor: default;
}
.card-back .card-content {
    color: var(--red);
    transform: rotate(-15deg);
    text-shadow: 1px 1px 0 #000;
    font-weight: 900;
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.opponent.current-turn .opp-name {
    color: var(--yellow);
    text-shadow: 0 0 10px var(--yellow), 1px 1px 3px black;
    font-size: 1.1rem;
}

.opponent.current-turn {
    transform: scale(1.1) translateY(5px);
}

/* Table Area */
#table {
    display: flex;
    gap: 30px;
    margin: auto 0;
    align-items: center;
    justify-content: center;
    width: 100%;
}

#discard {
    position: relative;
    width: 75px;
    height: 115px;
}

#discard .card {
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
}

/* Cards */
.card {
    width: 75px;
    height: 115px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    font-weight: 800;
    box-shadow: 2px 5px 10px rgba(0,0,0,0.4);
    cursor: pointer;
    border: 5px solid white;
    user-select: none;
    position: relative;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
}

.card:hover {
    transform: translateY(-15px);
}

.card-played {
    animation: dropCard 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes dropCard {
    0% {
        transform: translate(var(--start-x, 0px), var(--start-y, -200px)) scale(1.5) rotate(calc(var(--end-rot, 0deg) - 45deg));
        opacity: 0.2;
        box-shadow: 20px 30px 40px rgba(0,0,0,0.6);
    }
    100% {
        transform: translate(0, 0) scale(1) rotate(var(--end-rot, 0deg));
        opacity: 1;
        box-shadow: 2px 5px 10px rgba(0,0,0,0.4);
    }
}

.card::before {
    content: '';
    position: absolute;
    width: 85%;
    height: 75%;
    background: white;
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    transform: rotate(-25deg);
    z-index: 0;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
}

.card-content {
    position: relative;
    z-index: 1;
    transform: rotate(-10deg);
}

/* Card Colors */
.card.red { background: var(--red); color: var(--red); }
.card.blue { background: var(--blue); color: var(--blue); }
.card.green { background: var(--green); color: var(--green); }
.card.yellow { background: var(--yellow); color: var(--yellow); }
.card.wild { background: var(--dark); color: white; }
.card.wild::before { background: linear-gradient(45deg, var(--red) 25%, var(--blue) 25% 50%, var(--green) 50% 75%, var(--yellow) 75%); }

#my-hand-container {
    width: 100%;
    overflow-x: hidden;
    padding: 30px 8px 20px;
    justify-items: center;
}

#my-hand {
    display: flex;
    margin: 0 auto;
    width: 100vw;
    justify-content: center;
    flex-wrap: wrap;
}

#my-hand .card {
    margin-right: -25px;
}
#my-hand .card:last-child {
    margin-right: 0;
}

#my-hand .card:hover {
    transform: translateY(-25px) scale(1.1);
    z-index: 999 !important;
}

#my-hand .card.playable {
    transform: translateY(-12px);
    box-shadow: 0 8px 20px rgba(255,255,255,0.3);
    z-index: 999;
}

#color-picker {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.95);
    padding: 20px;
    border-radius: 15px;
    text-align: center;
    z-index: 100;
    color: #333;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

#color-picker h3 {
    margin-top: 0;
    font-weight: 800;
}

.color-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.color-btns button {
    width: 70px;
    height: 70px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

.color-btns button:hover {
    transform: scale(1.1);
}

/* UNO Button */
#uno-btn {
    position: fixed;
    bottom: 160px;
    left: 50%;
    transform: translateX(-50%);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--red);
    border: 4px solid white;
    color: white;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    z-index: 500;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    animation: unoPulse 0.6s ease-in-out infinite alternate;
}

.uno-text {
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 1px;
}

.uno-countdown {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1;
}

@keyframes unoPulse {
    0% { transform: translateX(-50%) scale(1); box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
    100% { transform: translateX(-50%) scale(1.1); box-shadow: 0 4px 30px rgba(245, 80, 64, 0.7); }
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background: #1e1e24;
    color: white;
    border-radius: 20px;
    padding: 25px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255,255,255,0.1);
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 10px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.close-btn {
    background: none;
    border: none;
    color: #aaa;
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
}
.close-btn:hover { color: white; }

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.setting-item.vertical {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
}

.setting-item label {
    font-weight: 600;
    font-size: 0.95rem;
}

.theme-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
}

.theme-btn {
    padding: 10px;
    border-radius: 8px;
    border: 2px solid transparent;
    color: white;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    transition: transform 0.2s, border-color 0.2s;
}

.theme-btn:hover { transform: scale(1.05); }

.theme-btn.active {
    border-color: var(--yellow);
    box-shadow: 0 0 10px var(--yellow);
}

.theme-green { background: #2e5a32; }
.theme-blue { background: #1b3b6f; }
.theme-red { background: #6f1b1b; }
.theme-dark { background: #333; }

.modal-footer {
    margin-top: 25px;
    display: flex;
    justify-content: flex-end;
}

/* Switch Toggle */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #444;
    transition: .3s;
    border-radius: 26px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--green); }
input:checked + .slider:before { transform: translateX(24px); }

/* Range Slider */
input[type=range] {
    accent-color: var(--yellow);
    cursor: pointer;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

::-webkit-scrollbar {
    display: none;
}

#light-player {
    visibility: hidden;
    position: fixed;
    bottom: 0;
    width: 100vw;
    height: 50vh;
    background: linear-gradient(0deg, rgba(0, 148, 207, 0.5) 0%, rgba(255, 255, 255, 0) 100%);
    animation: pulse-light 2s ease-in-out infinite alternate;
    pointer-events: none;
}

@keyframes pulse-light {
    0% {
        opacity: 0.4;
        transform: scaleY(1);
    }
    100% {
        opacity: 1;
        transform: scaleY(1.05);
    }
}