/**
 * Leaderboard Styles
 */

/* Page Base */
body.leaderboard-page {
    background: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
}

.leaderboard-app {
    max-width: 960px;
    margin: 0 auto;
    /* This page lives inside dashboard-shell — `.ds-content > .ds-main`
       already offsets the fixed topbar. The old
       `padding-top: calc(var(--header-height) + var(--space-md))` was a
       legacy STANDALONE-page rule that double-counted the header height,
       which was the "too much space above the title". Symmetric content
       padding only — the shell owns the topbar offset. */
    padding: var(--space-2xl) var(--space-lg);
    padding-bottom: calc(var(--space-2xl) + env(safe-area-inset-bottom, 0px));
}

/* Page Title */
.lb-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    letter-spacing: -0.02em;
    margin-bottom: var(--space-lg);
}

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

.lb-main-tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 3px;
    border: 1px solid var(--border-subtle);
}

.lb-tab {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

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

.lb-tab--active {
    background: var(--accent);
    color: #fff;
    box-shadow: var(--shadow-sm);
    font-weight: var(--font-weight-semibold);
}

/* ── Period Sub-Tabs ────────────────────────────────────────────── */

.lb-period-tabs {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.lb-period {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-2xl);
    background: transparent;
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.lb-period:hover {
    border-color: var(--border-medium);
    color: var(--text-secondary);
}

.lb-period--active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ── Sort Headers ───────────────────────────────────────────────── */

.lb-sort-row {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-subtle);
}

.lb-sort {
    padding: 0.25rem 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-tertiary);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.lb-sort:hover {
    color: var(--text-secondary);
}

.lb-sort--active {
    color: var(--accent);
    font-weight: var(--font-weight-semibold);
}

/* ── Leaderboard List ───────────────────────────────────────────── */

.lb-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

/* ── Row ────────────────────────────────────────────────────────── */

.lb-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--duration-fast) var(--ease-out);
}

.lb-row:hover {
    border-color: var(--border-medium);
}

.lb-row--me {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
}

/* Rank */
.lb-rank {
    width: 36px;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-tertiary);
    text-align: center;
    flex-shrink: 0;
}

.lb-rank--top {
    color: var(--accent-warning);
    font-weight: var(--font-weight-bold);
}

/* Avatar */
.lb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: #fff;
    flex-shrink: 0;
    background-position: center;
}

.lb-avatar--gym {
    border-radius: var(--radius-md);
    background: var(--accent);
}

/* Name */
.lb-name {
    flex: 1;
    min-width: 0;
}

.lb-name-text {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-gym-label {
    font-size: var(--font-size-xs);
    color: var(--text-tertiary);
    margin-top: 1px;
}

/* Stat */
.lb-stat--primary {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
    align-self: flex-start;
    padding-top: 2px;
}

/* ── Direction A redesign (Duolingo-league): medals, XP bar, you-row,
      climb line, ghost rows ─────────────────────────────────────── */

/* Top-3 podium rows get a faint elevated tint + thicker presence */
.lb-row--podium {
    background: var(--bg-elevated, rgba(255, 255, 255, 0.03));
}
.lb-row { align-items: flex-start; }  /* let the XP bar + climb line stack under the name */

/* Medal disc for ranks 1-3 */
.lb-rank--medal {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #1a1a1a;
    line-height: 1;
    gap: 0;
}
.lb-rank--medal .lb-rank__num { font-size: 12px; font-weight: var(--font-weight-bold); }
.lb-rank--medal svg { margin-bottom: -1px; }
.lb-rank--gold   { background: linear-gradient(145deg, #ffd86b, #f5b301); }
.lb-rank--silver { background: linear-gradient(145deg, #e8e8ee, #b9bcc6); }
.lb-rank--bronze { background: linear-gradient(145deg, #e6a877, #c17d49); }
/* Subtle shimmer on the #1 (gold) medal only — never on every row */
@media (prefers-reduced-motion: no-preference) {
    .lb-rank--gold {
        background-size: 200% 200%;
        animation: lbGoldShimmer 4s ease-in-out infinite;
    }
}
@keyframes lbGoldShimmer {
    0%, 100% { background-position: 0% 50%; }
    50%      { background-position: 100% 50%; }
}

/* Name row (name + YOU pill) */
.lb-name-row { display: flex; align-items: center; gap: 8px; }
.lb-you-pill {
    font-size: 10px;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.04em;
    color: var(--text-on-accent, #fff);
    background: var(--accent);
    border-radius: 999px;
    padding: 1px 7px;
    flex-shrink: 0;
}
/* Greg-subscriber badge (Coaches board) — marks a real full Greg subscriber.
   Theme-aware --accent-success (NOT -bright; passes WCAG in both themes). */
.lb-greg-badge {
    font-size: 10px;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.02em;
    color: var(--text-on-accent, #fff);
    background: var(--accent-success);
    border-radius: 999px;
    padding: 1px 7px;
    flex-shrink: 0;
    white-space: nowrap;
}

/* XP bar — scaled to the leader so gaps are visible */
.lb-bar {
    height: 5px;
    border-radius: 999px;
    background: var(--border-subtle);
    margin-top: 6px;
    overflow: hidden;
}
.lb-bar__fill {
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width var(--duration-slow, 0.6s) var(--ease-out);
}
.lb-row--podium .lb-rank--gold ~ * .lb-bar__fill,
.lb-row:first-child .lb-bar__fill { background: var(--accent-warning, #f5b301); }

/* Climb sub-line on the signed-in coach's own row */
.lb-climb {
    font-size: var(--font-size-xs);
    color: var(--accent);
    margin-top: 5px;
    font-weight: var(--font-weight-medium);
}
.lb-climb--leader { color: var(--accent-success); }

/* Ghost "open spot" rows — make a thin board feel like a starting race */
.lb-row--ghost {
    border-style: dashed;
    background: transparent;
    opacity: 0.65;
    pointer-events: none;
}
.lb-avatar--ghost {
    width: 36px; height: 36px; border-radius: 50%;
    border: 1px dashed var(--border-medium);
    background: transparent;
    flex-shrink: 0;
}
.lb-name-text--ghost {
    color: var(--text-tertiary);
    font-style: italic;
    font-weight: var(--font-weight-regular, 400);
}

/* ── Sticky "Your Row" ──────────────────────────────────────────── */

.lb-sticky {
    position: sticky;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: 0.75rem 1rem;
    background: var(--bg-elevated);
    border-top: 2px solid var(--accent);
    margin-top: var(--space-sm);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.lb-sticky-rank {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: var(--accent);
    width: 36px;
    text-align: center;
}

.lb-sticky-name {
    flex: 1;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

.lb-sticky-stat {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

/* ── Empty State ────────────────────────────────────────────────── */

.lb-empty {
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
    padding: var(--space-2xl);
    text-align: center;
    background: var(--bg-card);
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-md);
}

/* Motivational zero-state (always-show empty board → the hook). */
.lb-empty--cta {
    border-style: solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
}
.lb-empty__prize {
    color: var(--text-primary);
    font-size: var(--font-size-lg);
    font-weight: 700;
    line-height: 1.3;
}
.lb-empty__sub {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    margin: 0;
    max-width: 36ch;
}
.lb-empty__you {
    color: var(--text-tertiary);
    font-size: var(--font-size-sm);
    font-variant-numeric: tabular-nums;
}
.lb-empty__cta {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: var(--font-size-sm);
    text-decoration: none;
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-md);
}
.lb-empty__cta:hover { filter: brightness(1.08); }
.lb-empty__cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

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

@media (max-width: 600px) {
    .leaderboard-app {
        /* Same fix as desktop — no header-height double-count inside the
           dashboard-shell (the shell offsets the topbar). */
        padding: var(--space-lg) var(--space-md);
    }

    .lb-title {
        font-size: var(--font-size-xl);
    }

    .lb-row {
        gap: var(--space-sm);
        padding: 0.625rem 0.75rem;
    }

    .lb-rank {
        width: 28px;
        font-size: var(--font-size-xs);
    }

    .lb-avatar {
        width: 32px;
        height: 32px;
    }

}

/* ── Dashboard Teaser Card ──────────────────────────────────────── */

/* Personal-Rank Strip (XP economy unit 9) — replaces the legacy
   #leaderboardTeaser top-5 list. YOU-centric strip on the student
   dashboard showing "#N this week · +M XP to overtake #N-1". */
#personalRankStrip {
    margin-top: 2.5rem;
    margin-bottom: 2rem;
}

.rank-strip-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.rank-strip-head {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
}

.rank-strip-rank {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    line-height: 1;
}

.rank-strip-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rank-strip-period {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-transform: capitalize;
}

.rank-strip-score {
    font-size: var(--font-size-sm);
    color: var(--text-tertiary);
}

.rank-strip-climb {
    background: var(--accent-success-light);
    color: var(--accent-success);
    border-radius: var(--radius-md);
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    align-self: flex-start;
}

.rank-strip-top {
    color: var(--accent-success);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

.rank-strip-empty {
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rank-strip-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
    align-self: flex-start;
}

.rank-strip-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.rank-strip-cta {
    display: block;
    text-align: center;
    color: var(--accent);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    text-decoration: none;
    margin-top: var(--space-xs);
    transition: color var(--duration-fast) var(--ease-out);
}

.rank-strip-cta:hover {
    color: var(--accent-hover);
}

/* Admin-only "Mark as test" affordance (per-row, leaderboard.js). The
   button only renders for users whose `roles[]` includes 'admin' AND
   is NOT the signed-in user's own row. Compact × glyph; tooltip carries
   the affordance ("Mark <name> as a test account (admin only)"). On
   click it POSTs /api/leaderboard/admin/mark-test/{uid} and optimistically
   removes the row. */
.lb-mark-test {
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
    width: 24px;
    height: 24px;
    line-height: 1;
    font-size: 16px;
    font-weight: var(--font-weight-medium);
    margin-left: var(--space-xs);
    cursor: pointer;
    flex-shrink: 0;
    transition: color var(--duration-fast) var(--ease-out),
                border-color var(--duration-fast) var(--ease-out),
                background var(--duration-fast) var(--ease-out);
}

.lb-mark-test:hover {
    color: var(--accent-danger, #ef4444);
    border-color: var(--accent-danger, #ef4444);
    background: var(--accent-danger-light, rgba(239, 68, 68, 0.12));
}

.lb-mark-test:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* Performance: skip rendering off-screen rows */
.lb-row {
    content-visibility: auto;
    contain-intrinsic-size: auto 56px;
}
