/* Leaderboards specific styles */

/* Prevent FOUC and animation flash on page load */
.page-loading * {
    animation-play-state: paused !important;
    transition: none !important;
}

.page-loading .animate-pulse,
.page-loading .animate-gradient-text,
.page-loading .animate-coin-float,
.page-loading .animate-coin-float-delayed {
    animation: none !important;
}

/* Prevent layout shifts during loading */
.page-loading .leaderboard-section {
    visibility: hidden;
}

.page-loaded .leaderboard-section {
    visibility: visible;
}

/* Ensure smooth transitions for all interactive elements */
.page-loaded .leaderboard-tab,
.page-loaded .player-card,
.page-loaded .stats-card {
    transition: all 0.3s ease;
}

/* Promo sections - initially hidden to prevent flash */
.promo-section {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.page-loaded .promo-section {
    opacity: 1;
    transform: translateY(0);
}

/* Staggered animation for multiple promo sections */
.page-loaded .promo-section:nth-child(1) {
    transition-delay: 0.1s;
}

.page-loaded .promo-section:nth-child(2) {
    transition-delay: 0.2s;
}

/* Ensure animations only start after page is loaded */
@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.page-loaded .animate-pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.page-loaded .animate-gradient-text {
    animation: gradientShift 4s ease infinite;
}

.page-loaded .animate-coin-float {
    animation: coinFloat 3s ease-in-out infinite;
}

.page-loaded .animate-coin-float-delayed {
    animation: coinFloat 3s ease-in-out infinite;
    animation-delay: 1.5s;
}

/* Fallback for users without JavaScript */
.no-js .promo-section,
html:not(.js-enabled) .promo-section {
    opacity: 1 !important;
    transform: none !important;
}

.no-js .leaderboard-section,
html:not(.js-enabled) .leaderboard-section {
    visibility: visible !important;
}

.leaderboard-tab {
    position: relative;
    overflow: hidden;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    background: rgba(31, 41, 55, 0.5);
    border: 1px solid rgba(75, 85, 99, 0.3);
    color: rgb(209, 213, 219);
    transition: all 0.3s ease;
    font-size: 0.875rem;
    white-space: nowrap;
}

/* Add spacing between icon and text for larger screens */
.leaderboard-tab i {
    margin-right: 0.5rem;
}

/* Desktop and tablet view - show full text */
@media (min-width: 801px) {
    .hidden.md\:inline {
        display: inline !important;
    }

    .md\:hidden {
        display: none !important;
    }
}

.leaderboard-tab:hover {
    background: rgba(4, 150, 255, 0.2);
    border-color: rgba(4, 150, 255, 0.5);
    color: white;
}

.leaderboard-tab::before {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    transition: left 0.5s;
}

.leaderboard-tab:hover::before {
    left: 100%;
}

.leaderboard-tab.active {
    background: linear-gradient(135deg, rgba(4, 150, 255, 0.2), rgba(255, 107, 107, 0.2));
    border-color: rgba(4, 150, 255, 0.5);
    color: white;
    box-shadow: 0 4px 15px rgba(4, 150, 255, 0.2);
}

/* Fix horizontal scroll by ensuring tab container doesn't overflow */
.leaderboard-tabs-container {
    overflow-x: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
}

.leaderboard-tabs-wrapper {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem;
    justify-content: center;
    width: 100%;
    min-width: 0;
}

/* On mobile, make tabs scroll horizontally */
@media (max-width: 800px) {
    .leaderboard-tabs-wrapper {
        justify-content: flex-start;
        padding: 0 0.5rem;
        min-width: auto;
        width: 100%;
    }
}

@media (max-width: 500px) {
    .leaderboard-tabs-wrapper {
        gap: 0.25rem;
        padding: 0 0.25rem;
        min-width: auto;
        width: 100%;
        flex-wrap: nowrap;
    }
}

.leaderboard-tabs-container::-webkit-scrollbar {
    height: 4px;
}

.leaderboard-tabs-container::-webkit-scrollbar-track {
    background: rgba(55, 65, 81, 0.3);
    border-radius: 2px;
}

.leaderboard-tabs-container::-webkit-scrollbar-thumb {
    background: rgba(4, 150, 255, 0.5);
    border-radius: 2px;
}

/* Prevent page-wide horizontal scroll */
.leaderboard-section {
    display: none;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    overflow-x: hidden;
}

.leaderboard-section.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.leaderboard-content {
    overflow-x: hidden;
}

/* Ensure main content doesn't cause horizontal scroll */
.main-content {
    overflow-x: hidden;
}

/* Animated gradient background for stats cards */
@keyframes stats-glow {
    0%,
    100% {
        box-shadow: 0 0 20px rgba(4, 150, 255, 0.2);
    }
    50% {
        box-shadow: 0 0 30px rgba(4, 150, 255, 0.4), 0 0 40px rgba(255, 107, 107, 0.2);
    }
}

.stats-card:hover {
    animation: stats-glow 2s ease-in-out infinite;
}

/* Player card hover effects */
.player-card {
    transition: all 0.3s ease;
}

.player-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

/* Rank badge animations */
@keyframes crown-shine {
    0%,
    100% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(-5deg) scale(1.1);
    }
}

.rank-crown:hover {
    animation: crown-shine 0.6s ease-in-out;
}

/* Loading states */
.leaderboard-loading {
    opacity: 0.7;
    pointer-events: none;
}

.leaderboard-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 4px solid rgba(4, 150, 255, 0.2);
    border-top: 4px solid #0496ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile optimizations */
@media (max-width: 800px) {
    .leaderboard-tab {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
        white-space: nowrap;
    }

    /* Remove horizontal spacing and keep icons inline on medium mobile */
    .leaderboard-tab i {
        margin-right: 0.25rem;
    }

    /* On mobile 800px, keep horizontal layout but make tabs more touch-friendly */
    .leaderboard-tabs-wrapper {
        gap: 0.375rem;
        padding: 0 0.5rem;
        justify-content: flex-start;
        overflow-x: auto;
    }

    .stats-card {
        padding: 1rem;
    }

    .player-card {
        padding: 1rem;
    }

    .player-card .rank-badge {
        width: 2rem;
        height: 2rem;
    }

    .player-card .avatar {
        width: 3rem;
        height: 3rem;
    }

    .player-card .score {
        font-size: 1.5rem;
    }
}

/* Extra small screens - prevent horizontal scroll */
@media (max-width: 500px) {
    /* Global viewport constraint */
    * {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Hide long text, show short text for md breakpoint */
    .md\:hidden {
        /* display: inline !important; */
    }

    .hidden.md\:inline {
        display: none !important;
    } /* Ensure body doesn't cause horizontal overflow */
    body {
        overflow-x: hidden;
        max-width: 100%;
        width: 100%;
    }

    /* Force container to not overflow */
    .main-content,
    .container {
        max-width: 100%;
        overflow-x: hidden;
        width: 100%;
    }

    /* Ensure leaderboard tabs container doesn't exceed viewport */
    .leaderboard-tabs-container {
        max-width: 100%;
        width: 100%;
        overflow: visible;
    }

    .leaderboard-tabs-wrapper {
        max-width: 100%;
        width: auto;
        flex-wrap: nowrap;
        overflow-x: auto;
    }

    /* Force all tab buttons to be flexible */
    .leaderboard-tab {
        flex-shrink: 1;
        min-width: 0;
        max-width: none;
    }

    /* Ensure text doesn't break layout */
    .leaderboard-tab span {
        display: inline-block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Reduce padding on very small screens */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    /* Make tabs mobile-friendly and touch-optimized */
    .leaderboard-tab {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
        white-space: nowrap;
        min-width: auto;
        flex: 1;
        max-width: none;
        text-align: center;
        border-radius: 0.375rem;
    }

    /* Make tab text appropriately sized for mobile */
    .leaderboard-tab span {
        font-size: 0.75rem;
        white-space: nowrap;
        display: block;
        margin-top: 0.125rem;
    }

    /* Make icons more prominent on mobile */
    .leaderboard-tab i {
        font-size: 1rem;
        display: block;
        margin-bottom: 0.125rem;
        margin-right: 0;
    }

    /* Stack tabs in a more mobile-friendly way */
    .leaderboard-tabs-wrapper {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        padding: 0 0.5rem;
        width: 100%;
        max-width: 100%;
    }

    /* Make the last two tabs span the remaining space */
    .leaderboard-tab:nth-child(4) {
        grid-column: 1 / 3;
    }

    .leaderboard-tab:nth-child(5) {
        grid-column: 3 / 4;
    }

    /* Ensure tab icons don't break layout */
    .leaderboard-tab i {
        margin-right: 0.25rem;
        font-size: 0.75rem;
    }

    /* Reduce stats card padding */
    .stats-card {
        padding: 0.75rem;
    }

    /* Make sure stats grid doesn't overflow */
    .stats-grid {
        gap: 0.5rem;
    }

    /* Reduce spacing in player cards */
    .player-card {
        padding: 0.75rem;
    }

    /* Make sure long usernames don't cause overflow */
    .player-card h3,
    .player-card p {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Reduce title size on very small screens */
    .leaderboard-section h2 {
        font-size: 1.5rem;
    }

    /* Add word-break for any potential long text */
    .leaderboard-section {
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Ensure page header doesn't overflow */
    .text-4xl {
        font-size: 1.875rem;
    }

    /* Make sure the stats grid adjusts properly */
    .grid-cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    /* Ensure rounded elements don't cause overflow */
    .rounded-3xl,
    .rounded-2xl {
        border-radius: 1rem;
    }
}

/* Responsive grid for stats */
@media (max-width: 800px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-grid .stat-card:last-child {
        grid-column: span 2;
        max-width: 50%;
        margin: 0 auto;
    }
}

/* Smooth transitions for section switching */
.leaderboard-section {
    display: none;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.leaderboard-section.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

/* Custom scrollbar for leaderboard content */
.leaderboard-content::-webkit-scrollbar {
    width: 8px;
}

.leaderboard-content::-webkit-scrollbar-track {
    background: rgba(55, 65, 81, 0.3);
    border-radius: 4px;
}

.leaderboard-content::-webkit-scrollbar-thumb {
    background: rgba(4, 150, 255, 0.5);
    border-radius: 4px;
}

.leaderboard-content::-webkit-scrollbar-thumb:hover {
    background: rgba(4, 150, 255, 0.7);
}

/* Promo Section Styles */
.page-loaded .promo-section {
    margin-top: 4rem;
    margin-bottom: 3rem;
}

/* Coin animation styles */
@keyframes coinFloat {
    0%,
    100% {
        transform: translateY(0px) rotate(0deg);
    }
    50% {
        transform: translateY(-10px) rotate(180deg);
    }
}

.animate-coin-float {
    animation: coinFloat 3s ease-in-out infinite;
}

/* Delayed animations for floating coins */
.animate-coin-float-delayed {
    animation: coinFloat 3s ease-in-out infinite;
    animation-delay: 1.5s;
}

/* Gradient text animation */
@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.animate-gradient-text {
    background-size: 200% 200%;
    animation: gradientShift 4s ease infinite;
}

/* Responsive adjustments for promo sections */
@media (max-width: 640px) {
    .page-loaded .promo-section {
        margin-top: 2rem;
        margin-bottom: 2rem;
    }

    .promo-section h2 {
        font-size: 1.5rem !important;
        line-height: 1.3;
    }

    .promo-section p {
        font-size: 0.9rem;
        line-height: 1.5;
    }

    /* Stack buttons vertically on mobile */
    .promo-buttons {
        flex-direction: column;
        gap: 1rem;
    }

    .promo-buttons a {
        width: 100%;
        text-align: center;
    }
}

/* Coin earning promo specific styles */
.coin-promo-features {
    gap: 0.75rem;
}

.coin-promo-features .feature-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: rgb(209, 213, 219);
    font-size: 0.9rem;
}

.coin-promo-features .feature-icon {
    color: rgb(251, 191, 36);
    font-size: 1rem;
    flex-shrink: 0;
}

@media (max-width: 640px) {
    .coin-promo-features {
        gap: 0.5rem;
    }

    .coin-promo-features .feature-item {
        font-size: 0.85rem;
        gap: 0.5rem;
    }
}
