:root {
    --bg-color: #0b0d17;
    --surface-color: #15192b;
    --primary-color: #7000ff;
    --secondary-color: #00d4ff;
    --text-color: #ffffff;
    --text-muted: #8f9bb3;
    --card-width: 60px;
    --card-height: 84px;
    --radius: 12px;
    --font-main: 'Outfit', sans-serif;
    --glass-bg: rgba(21, 25, 43, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow-lg: 0 10px 30px -5px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(112, 0, 255, 0.15) 0%, transparent 20%),
        radial-gradient(circle at 90% 80%, rgba(0, 212, 255, 0.15) 0%, transparent 20%);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Lobby & Auth Screen */
#lobby-screen, #auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    padding: 1rem;
}

.lobby-container {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    padding: 3rem;
    border-radius: 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.lobby-header {
    text-align: center;
    margin-bottom: 1rem;
}

.lobby-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.lobby-header p {
    color: var(--text-muted);
    font-size: 1rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-left: 0.5rem;
}

.input-group input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 12px;
    color: white;
    font-family: var(--font-main);
    font-size: 1rem;
    transition: all 0.2s;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(0, 0, 0, 0.3);
    box-shadow: 0 0 0 4px rgba(112, 0, 255, 0.1);
}

.lobby-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.full-width {
    width: 100%;
}

/* Game Container */
#game-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    margin-bottom: 1rem;
}

.status {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.status.online {
    color: #00ff88;
}

.status.offline {
    color: #ff4444;
}

.status.error {
    color: #ff4444;
}

/* Game Board */
#game-table {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    perspective: 1000px;
}

/* Opponent Area */
.opponent-area {
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.opponent-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.5s ease;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--surface-color), #2a2f45);
    border: 2px solid var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--text-muted);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    margin-bottom: 0.5rem;
    z-index: 2;
}

/* Center Table */
.center-table {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3rem;
    position: relative;
}

.card-slot {
    width: var(--card-width);
    height: var(--card-height);
    border: 2px dashed var(--glass-border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Active Highlight for Turn Phase */
@keyframes active-draw-pulse {
    0% {
        box-shadow: 0 0 8px rgba(0, 255, 136, 0.4);
        border-color: #00ff88;
    }
    50% {
        box-shadow: 0 0 22px rgba(0, 255, 136, 0.9);
        border-color: #00ff88;
        transform: scale(1.04);
    }
    100% {
        box-shadow: 0 0 8px rgba(0, 255, 136, 0.4);
        border-color: #00ff88;
    }
}
.active-draw-target {
    animation: active-draw-pulse 2s infinite ease-in-out;
    cursor: pointer !important;
}

/* Cards */
.card {
    width: var(--card-width);
    height: var(--card-height);
    background: linear-gradient(135deg, #ffffff 0%, #f4f6f8 100%);
    color: #111111;
    border-radius: var(--radius);
    position: relative;
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1), box-shadow 0.3s ease, border-color 0.3s ease;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 800;
    user-select: none;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
    border: 1.5px solid rgba(255, 255, 255, 0.85);
    will-change: transform;
}

.card.back {
    background: linear-gradient(135deg, #1b203a 0%, #0c0f1d 100%);
    border: 1.5px solid rgba(0, 212, 255, 0.35);
    box-shadow: 0 5px 12px rgba(0, 212, 255, 0.12);
}

.card.back::after {
    content: '✦';
    font-size: 1.6rem;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    opacity: 0.95;
    filter: drop-shadow(0 0 5px rgba(0, 212, 255, 0.6));
}

.card.selected {
    transform: translateY(-22px) scale(1.12) !important;
    box-shadow: 0 0 0 3px var(--secondary-color), 0 12px 24px rgba(0, 212, 255, 0.45);
    z-index: 100;
    border-color: var(--secondary-color) !important;
}

@keyframes gold-shimmer {
    0% {
        box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
        border-color: #ffd700;
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 1), 0 0 0 1px #ffd700;
        border-color: #ffea00;
    }
    100% {
        box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
        border-color: #ffd700;
    }
}
.card.wild {
    border: 2px solid #ffd700 !important;
    animation: gold-shimmer 2.5s infinite ease-in-out;
}

/* Hand Area */
.hand-area {
    height: 140px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding-bottom: 1rem;
}

.hand-area .card:hover {
    transform: translateY(-15px);
    z-index: 10;
}

/* Controls */
#controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--glass-bg);
    border-top: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

.btn {
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-family: var(--font-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn.primary {
    background: linear-gradient(135deg, var(--primary-color), #5000cc);
    color: white;
    box-shadow: 0 4px 15px rgba(112, 0, 255, 0.3);
}

.btn.primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(112, 0, 255, 0.5);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: white;
}

.btn.secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

#btn-discard {
    color: #ff6b6b;
    border-color: rgba(255, 107, 107, 0.3);
}

#btn-discard:hover:not(:disabled) {
    background: rgba(255, 107, 107, 0.1);
    border-color: #ff6b6b;
}

/* Melds */
.melds-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.player-melds-container {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.meld-group {
    display: flex;
    transition: transform 0.2s;
}

.meld-group:hover {
    transform: scale(1.05);
}

.card.small {
    width: 36px;
    height: 50px;
    font-size: 0.7rem;
    margin-right: -10px;
    border-radius: 6px;
}

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

/* Scoreboard */
#scoreboard {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--glass-bg);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.score-item {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--secondary-color);
}

/* Responsive */
@media (max-width: 768px) {
    .lobby-container {
        padding: 2rem;
        width: 90%;
    }

    #game-table {
        transform: scale(0.9);
    }

    .card {
        width: 50px;
        height: 70px;
    }
}

/* Reconnection Toast */
.reconnect-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: rgba(21, 25, 43, 0.85);
    border: 1px solid rgba(255, 68, 68, 0.4);
    color: #ff6b6b;
    padding: 1rem 2rem;
    border-radius: 50px;
    font-weight: 600;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 15px rgba(255, 68, 68, 0.2);
    z-index: 10000;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    pointer-events: none;
    font-family: var(--font-main);
}
.reconnect-toast.visible {
    transform: translateX(-50%) translateY(0);
}
.reconnect-toast .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 107, 107, 0.2);
    border-top-color: #ff6b6b;
    border-radius: 50%;
    animation: toast-spin 1s infinite linear;
}
@keyframes toast-spin {
    to { transform: rotate(360deg); }
}

/* Dynamic Turn Indicators & Labels */
.avatar.active-turn {
    border-color: var(--secondary-color) !important;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.6) !important;
    color: var(--secondary-color) !important;
}
.player-name-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 2px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Dual Column Dashboard Layout */
.lobby-layout {
    display: flex;
    gap: 2rem;
    width: 100%;
    max-width: 1100px;
    height: 90vh;
    max-height: 750px;
    padding: 1rem;
}

.lobby-sidebar {
    flex: 0 0 360px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
}

.lobby-browser {
    flex: 1;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.profile-card, .create-lobby-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 1.5rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.create-lobby-card h3 {
    font-size: 1.2rem;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 700;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: 2px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.25rem;
    color: white;
    box-shadow: 0 4px 10px rgba(0, 212, 255, 0.3);
}

.profile-user-info h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
}

.member-since {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.profile-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.stat-box {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--secondary-color);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.profile-score-stats {
    font-size: 0.85rem;
    color: var(--text-muted);
    border-top: 1px solid var(--glass-border);
    padding-top: 0.75rem;
    display: flex;
    justify-content: space-between;
}

.browser-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.browser-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.lobby-list-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.15);
}

.lobby-grid-header {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1.2fr;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.lobby-grid-rows {
    flex: 1;
    overflow-y: auto;
}

.lobby-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1.2fr;
    padding: 1rem;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.95rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.lobby-row:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.lobby-row .room-name {
    color: white;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lobby-row .players {
    color: var(--text-muted);
}

.lobby-row .room-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.room-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.room-status.playing::before {
    background: var(--secondary-color);
}

.room-status.waiting::before {
    background: #00ff88;
}

.lobby-row .access {
    font-size: 1.1rem;
}

.no-lobbies {
    padding: 3rem;
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
}

.sidebar-footer {
    margin-top: auto;
}

/* In-game header small layout adjust */
#header #btn-leave-lobby {
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    border-radius: 8px;
    margin-left: auto;
}

@media (max-width: 900px) {
    .lobby-layout {
        flex-direction: column;
        height: auto;
        max-height: none;
    }
    .lobby-sidebar {
        flex: auto;
        width: 100%;
    }
    .lobby-browser {
        width: 100%;
        min-height: 400px;
    }
}