:root {
    --bg: #0b0e1a;
    --bg-dark: #060812;
    --accent: #00ff9d;
    --accent2: #00d4ff;
    --accent3: #7c9eff;
    --text: #e0f0ff;
    --text-dim: #a3bffa;
    --card: rgba(20, 25, 45, 0.65);
    --glow: 0 0 20px;
    --glow-intense: 0 0 40px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --header-height: 70px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background: linear-gradient(145deg, var(--bg-dark) 0%, var(--bg) 100%);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* Desktop Layout (≥1025px) */
@media (min-width: 1025px) {
    body {
        padding: 0;
    }
}

/* Mobile Layout (≤1024px) */
@media (max-width: 1024px) {
    body {
        padding: 0.75rem;
    }
}

/* Custom Scrollbar - hidden on mobile for better UX */
@media (min-width: 768px) {
    ::-webkit-scrollbar {
        width: 8px;
    }

    ::-webkit-scrollbar-track {
        background: var(--bg-dark);
    }

    ::-webkit-scrollbar-thumb {
        background: linear-gradient(var(--accent), var(--accent2));
        border-radius: 4px;
    }
}

/* Desktop Navbar - Only visible on large screens */
.navbar-desktop {
    position: fixed;
    inset: 0 0 auto 0;
    padding: 0.9rem 5vw;
    background: rgba(8, 12, 30, 0.98);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 255, 157, 0.16);
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

@media (max-width: 1024px) {
    .navbar-desktop {
        display: none;
    }
}

.logo {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.4rem, 5vw, 1.8rem);
    font-weight: 800;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-decoration: none;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: clamp(1rem, 3vw, 1.8rem);
    align-items: center;
}

.nav-links a {
    color: var(--text-dim);
    text-decoration: none;
    font-weight: 500;
    font-size: clamp(0.8rem, 3vw, 0.95rem);
    transition: all 0.22s;
    padding: 0.3rem 0.5rem;
    white-space: nowrap;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--accent);
    text-shadow: 0 0 12px var(--accent);
}

.btn-small {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #0b1121 !important;
    padding: 0.4rem 1rem;
    border-radius: 50vmax;
    font-weight: 700;
    font-size: 0.85rem;
    box-shadow: var(--glow) rgba(0, 255, 157, 0.45);
}

/* Sidebar Toggle Button - Only visible on mobile (≤1024px) */
.sidebar-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1100;
    background: var(--card);
    border: 1px solid var(--accent2);
    color: var(--accent2);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    box-shadow: var(--glow) var(--accent2);
}

@media (max-width: 1024px) {
    .sidebar-toggle {
        display: flex;
    }
}

/* Sidebar Navigation - Only visible on mobile (≤1024px) */
.admin-sidebar {
    display: none;
}

@media (max-width: 1024px) {
    .admin-sidebar {
        display: block;
        position: fixed;
        top: 1rem;
        left: 1rem;
        transform: translateX(-120%);
        opacity: 0;
        width: 260px;
        background: rgba(8, 12, 24, 0.98);
        backdrop-filter: blur(16px);
        border: 1px solid var(--accent2);
        border-radius: 2rem;
        padding: 1.5rem 0.8rem;
        transition: transform 0.3s, opacity 0.2s;
        z-index: 2000;
        box-shadow: var(--glow-intense) var(--accent2);
    }

    .admin-sidebar.open {
        transform: translateX(0);
        opacity: 1;
    }
}

.admin-sidebar .sidebar-logo {
    font-family: 'Orbitron', monospace;
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(90deg, var(--accent2), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 0.5rem 1.2rem 0.5rem;
    border-bottom: 1px solid var(--accent2);
    margin-bottom: 1.2rem;
}

.admin-sidebar .sidebar-logo i {
    color: var(--accent2);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem 1rem;
    color: var(--text-dim);
    text-decoration: none;
    font-weight: 500;
    border-radius: 2rem;
    transition: 0.2s;
    font-size: 0.95rem;
}

.sidebar-nav a i {
    width: 1.5rem;
    font-size: 1.2rem;
    color: var(--accent2);
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(0, 212, 255, 0.15);
    color: var(--accent2);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid rgba(0, 255, 157, 0.1);
    margin-top: 1.5rem;
}

.sidebar-footer .signup-link {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #0b1121;
    padding: 0.7rem 1rem;
    border-radius: 2rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 700;
    text-decoration: none;
}

.sidebar-footer .logout-link {
    background: linear-gradient(90deg, rgba(225, 62, 62, 0.81), red);
    color: #0b1121;
    padding: 0.7rem 1rem;
    border-radius: 2rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-weight: 700;
    text-decoration: none;
}

/* Main Content Container */
.main-container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Desktop padding for navbar */
@media (min-width: 1025px) {
    .main-container {
        padding-top: 80px;
    }
}

/* Mobile adjustments */
@media (max-width: 1024px) {
    .main-container {
        padding-top: 0.5rem;
    }
}

.back-home {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-dim);
    text-decoration: none;
    margin: 1rem 0 0.5rem;
    font-size: 0.9rem;
    transition: all 0.3s;
    padding: 0.5rem 0;
}

@media (max-width: 1024px) {
    .back-home {
        margin-left: 3.5rem;
        margin-top: 0.5rem;
    }
}

@media (min-width: 1025px) {
    .back-home {
        margin-left: 5vw;
    }
}

.back-home:hover {
    color: var(--accent);
    transform: translateX(-5px);
}

/* Leaderboard Header */
.leaderboard-header {
    padding: 10px 5vw 10px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.leaderboard-header h1 {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.8rem, 8vw, 2.5rem);
    font-weight: 900;
    margin-bottom: 0.3rem;
    line-height: 1.1;
}

.gradient-text {
    background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent3));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.leaderboard-subtitle {
    color: var(--text-dim);
    font-size: clamp(0.8rem, 3vw, 1rem);
    margin-bottom: 1rem;
}

/* Stats Bar - Responsive Grid */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: clamp(0.5rem, 2vw, 1rem);
    background: var(--card);
    border-radius: 1rem;
    padding: clamp(0.8rem, 3vw, 1.2rem);
    border: 1px solid rgba(0, 255, 157, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    margin: 1rem 0;
    width: 100%;
}

@media (max-width: 400px) {
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.8rem;
    }
}

.stat-block {
    text-align: center;
}

.stat-block .stat-value {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1rem, 4vw, 1.4rem);
    color: var(--accent);
    text-shadow: 0 0 10px currentColor;
    line-height: 1.2;
}

.stat-block .stat-label {
    font-size: clamp(0.65rem, 2.5vw, 0.75rem);
    color: var(--text-dim);
    text-transform: uppercase;
    white-space: nowrap;
}

@media (max-width: 350px) {
    .stat-block .stat-label {
        white-space: normal;
        font-size: 0.6rem;
    }
}

/* Your Rank Card - Mobile Optimized */
.your-rank {
    background: linear-gradient(135deg, rgba(0, 255, 157, 0.15), rgba(0, 212, 255, 0.15));
    border-radius: 1rem;
    padding: 1rem;
    margin: 1.5rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    border: 1px solid var(--accent);
    box-shadow: 0 0 20px rgba(0, 255, 157, 0.2);
    width: 100%;
}

.your-rank-info {
    display: flex;
    align-items: center;
    gap: clamp(0.8rem, 4vw, 1.5rem);
    flex-wrap: wrap;
}

@media (max-width: 600px) {
    .your-rank-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.8rem;
        width: 100%;
    }
}

.your-rank-label {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.your-rank-value {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.4rem, 6vw, 1.8rem);
    font-weight: 900;
    color: var(--accent);
}

.your-rank-detail {
    display: flex;
    align-items: center;
    gap: clamp(0.8rem, 3vw, 2rem);
    flex-wrap: wrap;
}

.rank-badge {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.4rem 0.8rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

@media (max-width: 400px) {
    .rank-badge {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
    }
}

/* Filter Bar - Mobile First */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    margin: 1rem 0;
    width: 100%;
}

@media (max-width: 700px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

.filter-tabs {
    display: flex;
    gap: 0.3rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.3rem;
    border-radius: 2rem;
    border: 1px solid rgba(0, 255, 157, 0.2);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    white-space: nowrap;
    width: 100%;
}

.filter-tabs::-webkit-scrollbar {
    display: none;
}

.filter-tab {
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-dim);
    white-space: nowrap;
    flex: 0 0 auto;
}

@media (max-width: 400px) {
    .filter-tab {
        padding: 0.4rem 0.8rem;
        font-size: 0.75rem;
    }
}

.filter-tab.active {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #0b1121;
    box-shadow: var(--glow) rgba(0, 255, 157, 0.3);
}

.filter-search {
    display: flex;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.3rem 0.3rem 0.3rem 1rem;
    border-radius: 2rem;
    border: 1px solid rgba(0, 255, 157, 0.2);
    flex: 1;
    min-width: 200px;
}

@media (max-width: 700px) {
    .filter-search {
        width: 100%;
    }
}

.filter-search input {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    min-width: 0;
    width: 100%;
    outline: none;
}

.filter-search input::placeholder {
    color: var(--text-dim);
    opacity: 0.5;
}

.filter-search button {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border: none;
    color: #0b1121;
    padding: 0.5rem 1.2rem;
    border-radius: 2rem;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
}

@media (max-width: 400px) {
    .filter-search button {
        padding: 0.4rem 0.8rem;
        font-size: 0.75rem;
    }
}

/* Main Leaderboard Container */
.leaderboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 5vw 40px;
    width: 100%;
}

/* Leaderboard Table - Fully Responsive */
.leaderboard-table {
    background: var(--card);
    border-radius: 1rem;
    border: 1px solid rgba(0, 255, 157, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow: hidden;
    margin-bottom: 2rem;
    width: 100%;
}

.table-header {
    display: grid;
    padding: 0.8rem 1rem;
    background: rgba(0, 255, 157, 0.1);
    border-bottom: 2px solid rgba(0, 255, 157, 0.3);
    font-family: 'Orbitron', monospace;
    font-size: 0.8rem;
    color: var(--accent2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    gap: 0.5rem;
}

.table-row {
    display: grid;
    padding: 0.8rem 1rem;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s;
    font-size: 0.9rem;
    gap: 0.5rem;
}

/* Responsive Grid Columns */
@media (min-width: 1024px) {

    .table-header,
    .table-row {
        grid-template-columns: 80px 100px 1fr 120px 100px 80px;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {

    .table-header,
    .table-row {
        grid-template-columns: 70px 80px 1fr 100px 80px 70px;
        font-size: 0.85rem;
    }
}

@media (min-width: 560px) and (max-width: 767px) {

    .table-header,
    .table-row {
        grid-template-columns: 60px 70px 1fr 90px 70px 60px;
        font-size: 0.8rem;
        gap: 0.3rem;
        padding: 0.7rem 0.8rem;
    }
}

@media (min-width: 400px) and (max-width: 559px) {

    .table-header,
    .table-row {
        grid-template-columns: 50px 60px 1fr 80px 60px 50px;
        font-size: 0.75rem;
        gap: 0.2rem;
        padding: 0.6rem 0.5rem;
    }

    .bricks-col {
        display: none;
    }

    .table-header div:nth-child(5),
    .table-row div:nth-child(5) {
        display: none;
    }
}

@media (max-width: 399px) {

    .table-header,
    .table-row {
        grid-template-columns: 40px 50px 1fr 70px 40px;
        font-size: 0.7rem;
        gap: 0.2rem;
        padding: 0.6rem 0.4rem;
    }

    .bricks-col,
    .table-header div:nth-child(5),
    .table-row div:nth-child(5) {
        display: none;
    }

    .trend-col span {
        display: none;
    }

    .trend-col i {
        margin: 0;
    }
}

@media (max-width: 320px) {

    .table-header,
    .table-row {
        grid-template-columns: 35px 40px 1fr 60px 30px;
        font-size: 0.65rem;
        padding: 0.5rem 0.3rem;
    }

    .player-level {
        display: none;
    }
}

.table-row:hover {
    background: rgba(0, 255, 157, 0.05);
    transform: scale(1.002);
}

.table-row.top-three {
    background: rgba(255, 215, 0, 0.05);
    border-left: 3px solid gold;
}

.rank-col {
    font-family: 'Orbitron', monospace;
    font-weight: 700;
}

.rank-1 {
    color: gold;
    text-shadow: 0 0 10px gold;
}

.rank-2 {
    color: silver;
    text-shadow: 0 0 10px silver;
}

.rank-3 {
    color: #cd7f32;
    text-shadow: 0 0 10px #cd7f32;
}

.country-col {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.country-col .fi {
    font-size: 1.2rem;
}

@media (max-width: 400px) {
    .country-col .fi {
        font-size: 1rem;
    }
}

.player-col {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.player-avatar {
    width: clamp(24px, 5vw, 32px);
    height: clamp(24px, 5vw, 32px);
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #0b1121;
    font-size: clamp(0.7rem, 3vw, 0.9rem);
    flex-shrink: 0;
}

.player-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

@media (max-width: 480px) {
    .player-name {
        max-width: 80px;
    }
}

@media (max-width: 320px) {
    .player-name {
        max-width: 60px;
    }
}

.player-level {
    font-size: 0.7rem;
    color: var(--accent3);
    background: rgba(124, 158, 255, 0.15);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    white-space: nowrap;
}

.score-col {
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    color: var(--accent2);
    white-space: nowrap;
}

.bricks-col {
    color: var(--text-dim);
    font-size: 0.85rem;
    white-space: nowrap;
}

.trend-col {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    justify-content: center;
}

.trend-up {
    color: var(--accent);
}

.trend-down {
    color: #ff4d4d;
}

.trend-neutral {
    color: var(--text-dim);
}

/* Pagination - Mobile Optimized */
.pagination {
    display: flex;
    justify-content: center;
    gap: 0.3rem;
    margin: 2rem 0;
    flex-wrap: wrap;
}

.page-btn {
    width: clamp(35px, 10vw, 40px);
    height: clamp(35px, 10vw, 40px);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--card);
    border: 1px solid rgba(0, 255, 157, 0.2);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    -webkit-tap-highlight-color: transparent;
}

.page-btn:active {
    transform: scale(0.95);
}

.page-btn:hover,
.page-btn.active {
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    color: #0b1121;
    border-color: transparent;
}

@media (max-width: 480px) {
    .page-btn {
        width: 32px;
        height: 32px;
        font-size: 0.8rem;
    }
}

/* Country Ranking - Responsive Grid */
.country-ranking {
    background: var(--card);
    border-radius: 1rem;
    padding: 1.2rem;
    border: 1px solid rgba(0, 255, 157, 0.15);
    margin-top: 2rem;
    width: 100%;
}

.country-ranking h3 {
    font-family: 'Orbitron', monospace;
    font-size: clamp(1.1rem, 5vw, 1.3rem);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.country-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.8rem;
}

@media (max-width: 480px) {
    .country-grid {
        grid-template-columns: 1fr;
    }
}

.country-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.8rem;
}

.country-rank {
    font-family: 'Orbitron', monospace;
    font-size: 1rem;
    min-width: 30px;
    color: var(--accent);
}

.country-flag {
    font-size: 1.2rem;
}

.country-name {
    flex: 1;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.country-score {
    font-family: 'Orbitron', monospace;
    color: var(--accent2);
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
}

/* Update Badges */
.update-badges {
    margin: 2rem 0;
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    justify-content: center;
}

.update-badge {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .update-badge {
        font-size: 0.7rem;
        padding: 0.4rem 0.8rem;
    }
}

/* Footer */
footer {
    padding: 2rem 5vw 1.5rem;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    color: var(--text-dim);
    border-top: 1px solid rgba(0, 255, 157, 0.1);
    font-size: 0.8rem;
    margin-top: 2rem;
    width: 100%;
    padding-bottom: calc(1.5rem + var(--safe-bottom));
}

.footer-developer {
    font-family: 'Orbitron', monospace;
    font-size: 0.9rem;
    color: #8ab4ff;
}

footer a {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.8rem;
}

footer a:hover {
    color: var(--accent);
}

@media (max-width: 930px) {
    footer {
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    footer p {
        margin-top: 0.8rem;
    }

    .footer-developer {
        margin-top: 0.5rem;
        text-align: center;
    }
}

/* Touch-friendly improvements */
.filter-tab,
.page-btn,
.btn-small,
.back-home,
.filter-search button {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.filter-tab:active,
.page-btn:active,
.btn-small:active {
    opacity: 0.8;
    transform: scale(0.97);
}

/* Prevent text overflow */
* {
    word-break: break-word;
}

/* Safe area for notched phones */
@supports (padding: max(0px)) {
    .navbar-desktop {
        padding-left: max(5vw, env(safe-area-inset-left));
        padding-right: max(5vw, env(safe-area-inset-right));
    }

    .leaderboard-container {
        padding-left: max(5vw, env(safe-area-inset-left));
        padding-right: max(5vw, env(safe-area-inset-right));
    }
}

/* Disable body scroll when sidebar open on mobile */
body.sidebar-open {
    overflow: hidden;
}