/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0a0a0b;
    --bg-secondary: #111113;
    --bg-tertiary: #1a1a1d;
    --bg-hover: #222225;
    --bg-card: #151517;
    --border: #2a2a2e;
    --border-light: #333338;
    --text-primary: #e8e8ed;
    --text-secondary: #8e8e93;
    --text-tertiary: #636366;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-dim: rgba(99, 102, 241, 0.15);
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --gold: #fbbf24;
    --silver: #9ca3af;
    --bronze: #d97706;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ===== Navbar ===== */
#navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: rgba(10, 10, 11, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
    white-space: nowrap;
}

.brand-icon {
    width: 22px;
    height: 22px;
    color: var(--accent);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.nav-link.active {
    color: var(--accent);
    background: var(--accent-dim);
}

.nav-link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: all 0.2s ease;
}

.mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 90;
}

/* ===== Main Content ===== */
#content {
    max-width: 680px;
    margin: 0 auto;
    padding: 72px 16px 32px;
    min-height: 100vh;
}

/* ===== Login Page ===== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 100px);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 32px;
}

.login-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 32px;
}

.login-brand svg {
    width: 32px;
    height: 32px;
    color: var(--accent);
}

.login-brand span {
    font-size: 1.5rem;
    font-weight: 700;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
}

.form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
    padding: 12px 20px;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-small {
    padding: 6px 14px;
    font-size: 0.82rem;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-light);
}

.login-error {
    color: var(--danger);
    font-size: 0.85rem;
    text-align: center;
    margin-top: 12px;
    display: none;
}

/* ===== Post Composer ===== */
.composer {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 8px;
}

.composer-inner {
    display: flex;
    gap: 12px;
}

.composer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
}

.composer-body {
    flex: 1;
    min-width: 0;
}

.composer-textarea {
    width: 100%;
    min-height: 60px;
    max-height: 200px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    outline: none;
}

.composer-textarea::placeholder {
    color: var(--text-tertiary);
}

.composer-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.btn-post {
    background: var(--accent);
    color: white;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}

.btn-post:hover {
    background: var(--accent-hover);
}

.btn-post:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== Feed Posts ===== */
.feed-section {
    margin-top: 4px;
}

.post {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 8px;
    transition: background 0.15s ease;
}

.post:hover {
    background: var(--bg-card);
}

.post-header {
    display: flex;
    gap: 12px;
}

.post-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: white;
    flex-shrink: 0;
}

.post-meta {
    flex: 1;
    min-width: 0;
}

.post-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.post-username {
    color: var(--text-tertiary);
    font-size: 0.85rem;
}

.post-time {
    color: var(--text-tertiary);
    font-size: 0.82rem;
}

.post-dot {
    margin: 0 4px;
}

.post-content {
    margin-top: 8px;
    padding-left: 52px;
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.post-actions {
    display: flex;
    gap: 24px;
    margin-top: 12px;
    padding-left: 52px;
}

.post-action {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 0.82rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 20px;
    transition: all 0.15s ease;
    font-family: inherit;
}

.post-action svg {
    width: 16px;
    height: 16px;
}

.post-action:hover {
    color: var(--danger);
    background: rgba(248, 113, 113, 0.1);
}

.post-action.liked {
    color: var(--danger);
}

.post-action.liked svg {
    fill: var(--danger);
}

.post-action.delete-action:hover {
    color: var(--text-secondary);
    background: var(--bg-hover);
}

.empty-feed {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-tertiary);
}

.empty-feed svg {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-feed p {
    font-size: 1rem;
    margin-bottom: 4px;
}

.empty-feed small {
    font-size: 0.85rem;
}

/* ===== Leaderboards Grid ===== */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 4px;
}

.games-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.game-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    color: inherit;
}

.game-card:hover {
    background: var(--bg-card);
    border-color: var(--border-light);
    transform: translateY(-1px);
    color: inherit;
}

.game-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: var(--accent-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.game-info {
    flex: 1;
    min-width: 0;
}

.game-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.game-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.game-tag {
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.game-arrow {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.game-arrow svg {
    width: 18px;
    height: 18px;
}

/* ===== Single Leaderboard ===== */
.lb-header {
    margin-bottom: 20px;
}

.lb-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 12px;
    transition: color 0.15s ease;
}

.lb-back:hover {
    color: var(--accent);
}

.lb-back svg {
    width: 16px;
    height: 16px;
}

.lb-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.lb-title {
    font-size: 1.3rem;
    font-weight: 700;
}

.lb-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--accent-dim);
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent);
}

.lb-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.lb-meta a {
    font-size: 0.82rem;
}

.lb-table {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.lb-row {
    display: grid;
    grid-template-columns: 48px 1fr auto auto;
    align-items: center;
    padding: 12px 16px;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s ease;
}

.lb-row:last-child {
    border-bottom: none;
}

.lb-row:hover {
    background: var(--bg-hover);
}

.lb-row-head {
    background: var(--bg-tertiary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    padding: 10px 16px;
}

.lb-row-head:hover {
    background: var(--bg-tertiary);
}

.lb-rank {
    font-weight: 700;
    font-size: 0.95rem;
    text-align: center;
}

.lb-rank.gold { color: var(--gold); }
.lb-rank.silver { color: var(--silver); }
.lb-rank.bronze { color: var(--bronze); }

.lb-player {
    min-width: 0;
}

.lb-player-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-player-name a {
    color: var(--text-primary);
}

.lb-player-name a:hover {
    color: var(--accent);
}

.lb-player-country {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    margin-top: 1px;
}

.lb-time {
    font-weight: 600;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    color: var(--success);
}

.lb-links {
    display: flex;
    gap: 8px;
    align-items: center;
}

.lb-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    transition: all 0.15s ease;
}

.lb-link:hover {
    background: var(--accent-dim);
    color: var(--accent);
}

.lb-link svg {
    width: 14px;
    height: 14px;
}

/* ===== Profile Page ===== */
.profile-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.profile-banner {
    height: 120px;
    background: linear-gradient(135deg, var(--accent), #a855f7, #ec4899);
}

.profile-content {
    padding: 0 24px 24px;
}

.profile-avatar-wrap {
    margin-top: -40px;
    margin-bottom: 16px;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 2rem;
    color: white;
    border: 4px solid var(--bg-secondary);
}

.profile-name {
    font-size: 1.3rem;
    font-weight: 700;
}

.profile-handle {
    color: var(--text-tertiary);
    font-size: 0.9rem;
}

.profile-bio {
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
}

.profile-stats {
    display: flex;
    gap: 24px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.profile-stat strong {
    font-weight: 700;
}

.profile-stat span {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.profile-joined {
    margin-top: 8px;
    color: var(--text-tertiary);
    font-size: 0.82rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.profile-joined svg {
    width: 14px;
    height: 14px;
}

/* Bio Edit */
.bio-edit-section {
    margin-top: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
}

.bio-edit-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.bio-textarea {
    width: 100%;
    min-height: 80px;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
}

.bio-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

.bio-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.bio-saved {
    color: var(--success);
    font-size: 0.85rem;
    margin-right: auto;
    display: none;
    align-items: center;
    gap: 4px;
}

.profile-posts-section {
    margin-top: 20px;
}

.profile-posts-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

/* ===== Country Flags ===== */
.country-flag {
    display: inline-block;
    width: 18px;
    height: 13px;
    margin-right: 4px;
    vertical-align: middle;
    border-radius: 2px;
    background-size: cover;
    background-position: center;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .nav-links {
        position: fixed;
        top: 56px;
        right: -260px;
        width: 260px;
        height: calc(100vh - 56px);
        background: var(--bg-secondary);
        border-left: 1px solid var(--border);
        flex-direction: column;
        padding: 16px;
        gap: 4px;
        transition: right 0.25s ease;
        z-index: 95;
    }

    .nav-links.open {
        right: 0;
    }

    .mobile-overlay.open {
        display: block;
    }

    .hamburger {
        display: flex;
    }

    .hamburger.open span:nth-child(1) {
        transform: rotate(45deg) translate(5px, 5px);
    }
    .hamburger.open span:nth-child(2) {
        opacity: 0;
    }
    .hamburger.open span:nth-child(3) {
        transform: rotate(-45deg) translate(5px, -5px);
    }

    #content {
        padding: 68px 12px 24px;
    }

    .lb-row {
        grid-template-columns: 40px 1fr auto;
        gap: 8px;
        padding: 10px 12px;
    }

    .lb-links {
        display: none;
    }

    .lb-player-name {
        font-size: 0.85rem;
    }

    .lb-time {
        font-size: 0.85rem;
    }

    .profile-banner {
        height: 90px;
    }

    .profile-content {
        padding: 0 16px 16px;
    }

    .login-card {
        padding: 32px 20px;
    }

    .post-content {
        padding-left: 0;
        margin-top: 10px;
    }

    .post-actions {
        padding-left: 0;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .games-grid {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 1025px) {
    .games-grid {
        grid-template-columns: 1fr 1fr;
    }

    #content {
        max-width: 900px;
    }

    /* Wider leaderboard table */
    .lb-row {
        grid-template-columns: 52px 1fr 120px 100px;
    }
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.2s ease;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ===== Tooltip for mobile run links ===== */
.lb-player-name-link {
    display: block;
}

@media (max-width: 768px) {
    .lb-row {
        cursor: pointer;
    }
}
