/* Side Leaderboard - Desktop Game Integration */

/* Side Leaderboard Container */
.side-leaderboard {
    position: fixed;
    top: 104px; /* Start below navbar (64px) + moving title (40px) */
    right: 0;
    height: calc(100vh - 104px); /* Account for navbar + moving title height */
    z-index: 200;
    pointer-events: none; /* Allow clicks to pass through when collapsed */
}

/* Collapsed Toggle Button */
.side-leaderboard-toggle {
    position: absolute;
    top: 10%;
    right: 0;
    width: 50px;
    height: 80px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-right: none;
    border-top-left-radius: 12px;
    border-bottom-left-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    pointer-events: auto;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
}

.side-leaderboard-toggle:hover {
    background: var(--hover-bg);
    transform: translateX(-2px);
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.15);
}

.side-leaderboard-toggle .toggle-icon,
.side-leaderboard-toggle .arrow-icon {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    transition: color 0.2s ease;
}

.side-leaderboard-toggle:hover .toggle-icon,
.side-leaderboard-toggle:hover .arrow-icon {
    color: var(--text-primary);
}

/* Expanded Panel */
.side-leaderboard-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 380px;
    height: 100%; /* Use 100% of container height (which is already calc(100vh - 64px)) */
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Panel States */
.side-leaderboard.expanded .side-leaderboard-panel {
    transform: translateX(0);
}

.side-leaderboard.expanded .side-leaderboard-toggle {
    display: none;
}

/* Adjust main content when expanded */
.game-main {
    transition: transform 0.3s ease;
}

.game-main.side-panel-open {
    transform: translateX(-190px);
}

/* Close Button in Period Selector */
.side-panel-close {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.side-panel-close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.side-panel-close svg {
    width: 16px;
    height: 16px;
    color: rgba(255, 255, 255, 0.9);
}

.side-panel-close:hover svg {
    color: var(--white);
}

/* Period Selector with Close Button */
.side-period-selector {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary-500), var(--secondary-500), var(--primary-600), var(--secondary-600));
    background-size: 400% 400%;
    animation: gradientShift 120s ease-in-out infinite;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.side-period-pills {
    display: flex;
    gap: 0.375rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 50px;
    padding: 0.25rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    flex: 1;
}

.side-period-pill {
    background: transparent;
    color: rgba(255, 255, 255, 0.8);
    border: none;
    padding: 0.375rem 0.75rem;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
    flex: 1;
    text-align: center;
}

.side-period-pill:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 1);
    transform: translateY(-1px);
}

.side-period-pill.active {
    background: var(--white);
    color: var(--primary-600);
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    25% {
        background-position: 100% 50%;
    }
    50% {
        background-position: 100% 100%;
    }
    75% {
        background-position: 50% 0%;
    }
    100% {
        background-position: 0% 50%;
    }
}

/* Leaderboard Content */
.side-leaderboard-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, 
        rgba(212, 165, 116, 0.05) 0%,
        rgba(139, 108, 78, 0.03) 50%,
        var(--background) 100%
    );
}

/* Loading State */
.side-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--text-secondary);
    flex: 1;
}

.side-loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--neutral-200);
    border-top: 2px solid var(--primary-600);
    border-radius: 50%;
    animation: sideSpinLoader 1s linear infinite;
    margin-bottom: 0.75rem;
}

@keyframes sideSpinLoader {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.side-loading p {
    margin: 0;
    font-size: 0.875rem;
}

/* Leaderboard Entries */
.side-leaderboard-entries {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0;
    margin: 0.75rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.side-leaderboard-entries::-webkit-scrollbar {
    width: 6px;
}

.side-leaderboard-entries::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.side-leaderboard-entries::-webkit-scrollbar-thumb {
    background: rgba(212, 165, 116, 0.4);
    border-radius: 3px;
}

.side-leaderboard-entries::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 165, 116, 0.6);
}

/* Individual Entry */
.side-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    transition: background 0.2s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    position: relative;
    gap: 0.75rem;
}

.side-entry:hover {
    background: rgba(255, 255, 255, 0.1);
}

.side-entry.top-3 {
    background: rgba(255, 255, 255, 0.15);
    border-left: 4px solid rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
}

.side-entry.top-3:hover {
    background: rgba(255, 255, 255, 0.2);
}

.side-entry.current-user {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 193, 7, 0.1));
    backdrop-filter: blur(10px);
    border-left: 4px solid transparent;
}

.side-entry.current-user:hover {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 193, 7, 0.15));
}

.side-entry.current-game {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.12), rgba(5, 150, 105, 0.08));
    backdrop-filter: blur(10px);
    animation: currentGamePulse 2s ease-in-out infinite;
    border-left: 4px solid transparent;
}

.side-entry.current-game:hover {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.18), rgba(5, 150, 105, 0.12));
}

.side-entry.current-game.personal-best {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 193, 7, 0.1));
    animation: personalBestPulse 1.5s ease-in-out infinite;
    border-left: 4px solid transparent;
}

.side-entry.current-game.personal-best:hover {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 193, 7, 0.15));
}

@keyframes personalBestPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.4);
    }
    50% {
        box-shadow: 0 0 0 6px rgba(255, 215, 0, 0.1);
    }
}

@keyframes currentGamePulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.3);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.1);
    }
}

/* Entry Rank */
.side-entry-rank {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary-600);
    text-align: center;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.side-entry:hover .side-entry-rank {
    background: rgba(255, 255, 255, 0.4);
}

.side-entry.top-3 .side-entry-rank {
    font-size: 0.85rem;
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.4);
}

.side-entry-rank.rank-1 {
    color: #FFD700;
    background: rgba(255, 215, 0, 0.2);
}

.side-entry-rank.rank-2 {
    color: #C0C0C0;
    background: rgba(192, 192, 192, 0.2);
}

.side-entry-rank.rank-3 {
    color: #CD7F32;
    background: rgba(205, 127, 50, 0.2);
}

/* Entry Left Section (Rank + Name) */
.side-entry-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

/* Entry Info */
.side-entry-info {
    flex: 1;
    min-width: 0;
}

.side-entry-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.side-entry-score {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
    font-weight: 400;
    white-space: nowrap;
    flex-shrink: 0;
    text-align: right;
}

.side-entry-score .score-number {
    font-weight: 700;
    color: var(--primary-600);
}

/* Adjust for mobile moving title height */
@media (max-width: 768px) {
    .side-leaderboard {
        top: 96px; /* Start below navbar (64px) + moving title mobile (32px) */
        height: calc(100vh - 96px); /* Account for navbar + mobile moving title height */
    }
}

/* Hide on mobile */
@media (max-width: 1024px) {
    .side-leaderboard {
        display: none !important;
    }
}

/* Responsive adjustments for smaller desktops */
@media (min-width: 1025px) and (max-width: 1280px) {
    .side-leaderboard-panel {
        width: 340px;
    }
    
    .game-main.side-panel-open {
        transform: translateX(-170px);
    }
    
    .side-period-selector {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }
    
    .side-period-pills {
        gap: 0.25rem;
        padding: 0.2rem;
    }
    
    .side-period-pill {
        padding: 0.3rem 0.6rem;
        font-size: 0.7rem;
    }
    
    .side-panel-close {
        width: 32px;
        height: 32px;
        padding: 0.375rem;
    }
    
    .side-panel-close svg {
        width: 14px;
        height: 14px;
    }
}

/* Large desktop optimizations */
@media (min-width: 1400px) {
    .side-leaderboard-panel {
        width: 400px;
    }
    
    .game-main.side-panel-open {
        transform: translateX(-200px);
    }
}
