/* Leaderboard (/leaderboard): week banner, game tabs, podium, ranked list with the student's own row pinned.
   Also the avatar (.lb-av) that the student page uses. Tokens only (base.css); motion: transform and opacity. */

.lb { max-width: 760px; margin: 0 auto; display: grid; gap: var(--space-4); }

/* ---------- Week banner: dark console in both themes ---------- */
.lb-hero {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 20px 18px;
    border: 2px solid color-mix(in srgb, var(--primary) 45%, transparent);
    border-radius: var(--radius-lg);
    background:
        radial-gradient(18rem 12rem at 10% 110%, color-mix(in srgb, var(--primary) 35%, transparent), transparent 70%),
        radial-gradient(14rem 10rem at 95% -20%, color-mix(in srgb, var(--amber) 22%, transparent), transparent 70%),
        var(--console);
    color: var(--on-console);
    box-shadow: var(--glow), 0 4px 0 var(--primary-edge);
}
.lb-hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: radial-gradient(color-mix(in srgb, var(--on-console) 10%, transparent) 1.2px, transparent 1.4px);
    background-size: 18px 18px;
    pointer-events: none;
}
.lb-hero-copy { position: relative; min-width: 0; display: grid; justify-items: start; gap: 6px; }
.lb-title { margin: 0; font-size: var(--fs-2xl); line-height: 1.15; color: var(--on-console); }
.lb-countdown { margin: 0; font-family: var(--font-title); font-size: var(--fs-md); color: var(--amber); }
.lb-hero-mascot { position: relative; width: 88px; height: auto; margin-inline-start: auto; }

.lb-week { list-style: none; display: flex; gap: 5px; margin: 4px 0 0; padding: 0; }
.lb-week li {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    border: 2px solid color-mix(in srgb, var(--on-console) 22%, transparent);
    color: var(--on-console-muted);
    font-family: var(--font-title);
    font-size: .85rem;
    line-height: 1;
}
.lb-week .is-past { background: color-mix(in srgb, var(--primary) 30%, transparent); border-color: transparent; color: var(--on-console); }
.lb-week .is-today {
    background: var(--amber);
    border-color: var(--amber);
    color: var(--navy);
    box-shadow: 0 3px 0 var(--accent-edge);
    animation: lb-today 1.6s var(--ease-out) infinite;
}
@keyframes lb-today { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* ---------- Tabs: a segmented game switch ---------- */
.lb-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 6px;
    border-radius: 20px;
    background: var(--surface-3);
    box-shadow: inset 0 2px 4px color-mix(in srgb, var(--navy) 18%, transparent);
}
.lb-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 6px 12px;
    border-radius: 15px;
    color: var(--text-muted);
    font-family: var(--font-title);
    font-size: 1.05rem;
    text-decoration: none;
    transition: transform .12s var(--ease-out);
}
.lb-tab:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.lb-tab:active { transform: translateY(2px); }
.lb-tab.active {
    background: var(--primary);
    color: var(--on-primary);
    box-shadow: 0 4px 0 var(--primary-edge);
    transform: translateY(-2px);
}
.lb-tab.active:active { transform: translateY(2px); box-shadow: 0 0 0 var(--primary-edge); }

/* ---------- Avatar: first letter in a coloured circle ---------- */
.lb-av {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-family: var(--font-title);
    font-size: 1.15rem;
    line-height: 1;
    box-shadow: inset 0 -3px 0 color-mix(in srgb, var(--navy) 22%, transparent);
}
.lb-av-0 { background: var(--primary); color: var(--on-primary); }
.lb-av-1 { background: var(--accent); color: var(--on-accent); }
.lb-av-2 { background: var(--console-2); color: var(--on-console); }
.lb-av-3 { background: var(--bronze); color: var(--navy); }
.lb-av-4 { background: var(--silver); color: var(--navy); }
.lb-av-lg { width: 56px; height: 56px; font-size: 1.5rem; }
.lb-av-xl { width: 76px; height: 76px; font-size: 2.1rem; }

/* ---------- Podium: 2nd, 1st, 3rd (RTL: 2nd on the right) ---------- */
.lb-podium {
    list-style: none;
    display: grid;
    grid-template-columns: 1fr 1.15fr 1fr;
    align-items: end;
    gap: 8px;
    margin: 0;
    padding: 30px 0 0;
}
.lb-step { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; }
/* Fixed columns, so the 1st stays in the middle when the week has only one or two players. */
.lb-step { grid-row: 1; }
.lb-step-1 { grid-column: 2; }
.lb-step-2 { grid-column: 1; }
.lb-step-3 { grid-column: 3; }
.lb-step-who {
    position: relative;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    animation: lb-who-in .5s var(--ease-spring) both;
}
.lb-step-1 .lb-step-who { animation-delay: .55s; }
.lb-step-2 .lb-step-who { animation-delay: .4s; }
.lb-step-3 .lb-step-who { animation-delay: .3s; }
.lb-step .lb-av { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--silver); }
.lb-step-1 .lb-av { width: 68px; height: 68px; font-size: 1.8rem; box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--gold), var(--glow-accent); }
.lb-step-3 .lb-av { box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--bronze); }
.lb-step.is-me .lb-av { outline: 3px dashed var(--primary); outline-offset: 7px; }
.lb-step-name {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
}
.lb-crown {
    position: absolute;
    top: -30px;
    left: calc(50% - 22px);
    fill: var(--gold);
    filter: drop-shadow(0 3px 0 var(--accent-edge));
    transform-origin: 50% 100%;
    animation: lb-crown 2.4s ease-in-out 1s infinite;
}
.lb-crown circle { fill: var(--gold); }
.lb-crown-band { fill: none; stroke: var(--accent-edge); stroke-width: 3; stroke-linecap: round; }
@keyframes lb-crown { 0%, 100% { transform: rotate(-6deg) translateY(0); } 50% { transform: rotate(6deg) translateY(-3px); } }

.lb-step-block {
    position: relative;
    overflow: hidden;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    padding-top: 10px;
    border-radius: 16px 16px 8px 8px;
    color: var(--navy);
    box-shadow: inset 0 -6px 0 color-mix(in srgb, var(--navy) 18%, transparent), 0 4px 0 var(--edge);
    transform-origin: 50% 100%;
    animation: lb-rise .6s var(--ease-spring) both;
}
.lb-step-1 .lb-step-block { height: 128px; background: linear-gradient(170deg, var(--gold), var(--accent-edge)); animation-delay: .3s; }
.lb-step-2 .lb-step-block { height: 100px; background: linear-gradient(170deg, var(--silver), color-mix(in srgb, var(--silver) 70%, var(--navy))); animation-delay: .15s; }
.lb-step-3 .lb-step-block { height: 80px; background: linear-gradient(170deg, var(--bronze), color-mix(in srgb, var(--bronze) 75%, var(--navy))); }
.lb-step-1 .lb-step-block::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, transparent 35%, color-mix(in srgb, var(--surface) 55%, transparent) 50%, transparent 65%);
    transform: translateX(120%);
    animation: lb-shine 3.6s ease-in-out 1.4s infinite;
}
.lb-step-rank { font-size: 2.1rem; line-height: 1; }
.lb-step-1 .lb-step-rank { font-size: 2.6rem; }
.lb-step-points { font-size: var(--fs-sm); font-weight: 500; }
.lb-step-points b { font-size: 1.1rem; }
@keyframes lb-rise { from { opacity: 0; transform: scaleY(.15); } }
@keyframes lb-who-in { from { opacity: 0; transform: translateY(14px) scale(.85); } }
@keyframes lb-shine { 0%, 60% { transform: translateX(120%); } 100% { transform: translateX(-120%); } }

/* ---------- Ranked list ---------- */
.lb-list { list-style: none; display: grid; gap: 8px; margin: 0; padding: 0; }
.lb-row {
    display: grid;
    grid-template-columns: 2.4rem 40px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    min-height: 60px;
    padding: 8px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: 0 3px 0 var(--edge);
    animation: lb-row-in .4s var(--ease-out) both;
}
.lb-row:nth-child(2) { animation-delay: .05s; }
.lb-row:nth-child(3) { animation-delay: .1s; }
.lb-row:nth-child(4) { animation-delay: .15s; }
.lb-row:nth-child(5) { animation-delay: .2s; }
.lb-row:nth-child(n + 6) { animation-delay: .25s; }
.lb-rank {
    display: grid;
    place-items: center;
    height: 2.4rem;
    border-radius: 12px;
    background: var(--surface-2);
    box-shadow: inset 0 0 0 2px var(--border);
    font-size: 1.1rem;
    color: var(--text-muted);
}
.lb-name { min-width: 0; display: flex; align-items: center; gap: 6px; font-weight: 500; }
.lb-name bdi { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-you { flex: none; }
.lb-points { font-family: var(--font-title); color: var(--accent-text); white-space: nowrap; }
.lb-points b { font-size: 1.2rem; }
@keyframes lb-row-in { from { opacity: 0; transform: translateY(10px); } }

.lb-row.is-me {
    border-color: var(--accent);
    background: radial-gradient(80% 140% at 100% 50%, color-mix(in srgb, var(--accent) 30%, var(--surface)), var(--surface) 75%);
    box-shadow: var(--glow-accent), 0 3px 0 var(--accent-edge);
}
.lb-row.is-me .lb-rank { background: var(--amber); box-shadow: 0 2px 0 var(--accent-edge); color: var(--navy); }
/* The top 10 get a turquoise tint; the student's own row slides in after the list. */
.lb-row.is-top:not(.is-me) {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
    background: linear-gradient(270deg, color-mix(in srgb, var(--primary) 10%, var(--surface)), var(--surface) 60%);
}
.lb-row.is-top:not(.is-me) .lb-rank { color: var(--link); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 45%, var(--border)); }
.lb-row.is-me { animation: lb-me-in .6s var(--ease-spring) .45s both; }
@keyframes lb-me-in { from { opacity: 0; transform: translateX(-48px) scale(.94); } }
.lb-all { margin-top: -4px; }
/* Outside the top list: the student's own row stays in view above the tab bar while the list scrolls. */
.lb-row.is-pinned {
    position: sticky;
    bottom: calc(var(--tabbar-h) + 10px + env(safe-area-inset-bottom));
    z-index: 5;
}
@media (min-width: 900px) {
    .lb-row.is-pinned { bottom: 12px; }
}
.lb-gap { display: flex; justify-content: center; gap: 6px; padding: 2px 0; }
.lb-gap span { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }

/* ---------- Empty states and notes ---------- */
.lb-empty { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }
.lb-empty > div { flex: 1 1 220px; }
.lb-empty-title { margin: 0 0 .4em; font-family: var(--font-title); font-size: var(--fs-md); }
.lb-nudge { margin: 0; }
.lb-rules { margin: 0; text-align: center; }

@media (min-width: 600px) {
    .lb-hero { padding: 26px 28px; }
    .lb-hero-mascot { width: 120px; }
    .lb-week li { width: 36px; height: 36px; }
    .lb-podium { gap: 16px; padding-inline: 24px; }
    .lb-step-1 .lb-step-block { height: 150px; }
    .lb-step-2 .lb-step-block { height: 116px; }
    .lb-step-3 .lb-step-block { height: 92px; }
}
