/* SharpLab Leaderboard — Dark Theme */

:root {
    --bg: #0d1117;
    --card: #161b22;
    --border: #30363d;
    --text: #c9d1d9;
    --text-muted: #8b949e;
    --accent: #f1c40f;
    --accent-dim: #f1c40f33;
    --green: #3fb950;
    --red: #f85149;
    --hover: #21262d;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* ── Layout ─────────────────────────────────────────────────────────────── */

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px;
}

header {
    text-align: center;
    padding: 32px 0 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.5px;
}

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

/* ── Header Nav ─────────────────────────────────────────────────────────── */

.header-nav {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
}

.header-nav a {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 4px 0;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
}

.header-nav a:hover { color: var(--text); text-decoration: none; }
.header-nav a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Tabs ────────────────────────────────────────────────────────────────── */

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.tab {
    padding: 10px 20px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ── Game filter ─────────────────────────────────────────────────────────── */

.game-filter {
    margin-bottom: 16px;
}

.game-filter select {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    min-width: 200px;
}

.game-filter select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ── Table ────────────────────────────────────────────────────────────────── */

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.leaderboard-table th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.leaderboard-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.leaderboard-table tr {
    transition: background 0.1s;
}

.leaderboard-table tbody tr:hover {
    background: var(--hover);
    cursor: pointer;
}

.leaderboard-table .num {
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.85rem;
}

.rank {
    width: 40px;
    text-align: center;
    font-weight: 600;
}

.rank-1 { color: #f1c40f; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

.user-cell {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
}

.positive { color: var(--green); }
.negative { color: var(--red); }

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

/* ── Player Profile ─────────────────────────────────────────────────────── */

.profile-header {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 24px;
    padding: 24px;
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--border);
}

.profile-info h2 {
    font-size: 1.4rem;
    font-weight: 600;
}

.profile-level {
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 500;
    margin-top: 2px;
}

.xp-bar-container {
    width: 200px;
    margin-top: 6px;
}

.xp-bar-bg {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.xp-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.xp-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Stat Cards ──────────────────────────────────────────────────────────── */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

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

.stat-card .value {
    font-size: 1.3rem;
    font-weight: 600;
    font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
}

/* ── Section headers ─────────────────────────────────────────────────────── */

.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 24px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

/* ── Achievement Grid ────────────────────────────────────────────────────── */

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 8px;
    margin-bottom: 24px;
}

.achievement {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

.achievement.locked {
    opacity: 0.4;
}

.achievement.unlocked {
    border-color: var(--accent-dim);
}

.achievement .emoji {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.achievement .name {
    font-weight: 500;
}

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

/* ── Per-game table ──────────────────────────────────────────────────────── */

.game-breakdown {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    margin-bottom: 24px;
}

.game-breakdown th {
    text-align: left;
    padding: 8px 10px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}

.game-breakdown td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

/* ── Table footer ────────────────────────────────────────────────────────── */

.table-footer {
    text-align: center;
    padding: 12px 0;
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* ── Loading / Empty ─────────────────────────────────────────────────────── */

.loading, .empty {
    text-align: center;
    padding: 48px 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.back-link {
    display: inline-block;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    .container { padding: 16px 12px; }
    header h1 { font-size: 1.4rem; }
    .tabs { overflow-x: auto; }
    .tab { padding: 8px 14px; font-size: 0.85rem; white-space: nowrap; }
    .leaderboard-table { font-size: 0.8rem; }
    .leaderboard-table th, .leaderboard-table td { padding: 8px 6px; }
    .hide-mobile { display: none; }
    .profile-header { flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .achievements-grid { grid-template-columns: 1fr; }
}
