/* Loaded by both leaderboards: Live Play's modal (#leaderboardModal, the block at the foot of this
   file) and the in-game board (.lb-*). The .leader-board-open-button rules are the in-game button. */

.popup-item-content {
	position: relative;
}

/* Lives inline in the start/end modal footers (see js/leaderboard.js),
   not floating in the page corner.

   Deliberately declares NO `display`. This file is injected into <head> at
   runtime by addCssFiles(), so it lands after the per-game stylesheets and wins
   ties. Games that hide the button do so with `.leader-board-open-button {
   display: none }` — spelling-supporters.css (all Spelling Zone games) without
   !important — so any `display` here would silently un-hide it. A <button>
   centres its own content, so none is needed.

   The button is a bare, transparent wrapper: Leaderboardbtn.png already draws
   its own rounded background and its corners are transparent, so a background
   or radius on the button shows as a rim around them. Radius and shadow go on
   the <img> instead — the same treatment .exitbutton / .teacherbutton /
   .levelbutton get in layout_2021-7.css. */
.leader-board-open-button {
    background: none;
    border: none;
    padding: 0px;
    font-size: 24px;
    cursor: pointer;
}

/* End modal only — the start footer sizes and drop-shadows every child itself
   (src/scss/games/components/_custom-modal.scss), so this would double the shadow. */
.button-footer .leader-board-open-button img {
    display: block;
    border-radius: 15px;
    box-shadow: 5px 5px #733381;
}

/* Hug the artwork so the button box *is* the image, with no gap at any edge. */
.button-footer > .leader-board-open-button {
    min-width: unset;
    max-width: unset;
    width: auto;
    flex: 0 0 auto;
}

/* End modal only. Five buttons don't fit one phone-width row, and .button-footer
   is nowrap, so without this the flex line squeezes the Home link to zero width
   and pushes the leaderboard button off-screen. Scoped to #end-overlay because
   .button-footer is also used for in-game button rows (common/games/base/*.php). */
#end-overlay .button-footer {
    flex-wrap: wrap;
    gap: 8px;
}

/* ============================================================================================
   .lb-* — the redesigned in-game leaderboard.

   Preview at tools/leaderboard-preview.php.

   Sizing follows the end-card (src/scss/games/components/_end-card.scss): container queries off
   the sheet, one radius token, one gap token. Ranks are set apart by SIZE and COLOUR only —
   llamarollFont has a single weight, so bold renders regular by design (rule 14) — and never by
   gold/silver/bronze, which already mean the difficulty level.
   ============================================================================================ */

/* A full-cover frame with the sheet placed by flex, never px — px-placed fixed boxes render
   displaced on real iPhones inside the game iframe (L-175). Doubles as the dimmer. */
.lb-frame {
    position: fixed;
    inset: 0;
    z-index: 99;
    display: flex;
    padding: 16px;
    background: rgba(0, 0, 0, 0.55);
    overflow: auto;
    overscroll-behavior: contain;
}

.lb-sheet {
    container-type: inline-size;

    --lb-radius: clamp(10px, 3cqw, 18px);
    --lb-gap: clamp(6px, 1.8cqw, 12px);
    --lb-ink: #4a3050;
    --lb-panel: #ed9d57;
    --lb-shadow: 5px 5px #733381;

    position: relative;
    width: 100%;
    max-width: 994px;
    margin: auto;              /* centres the card, and pins the sheet down when it can't fit */
    padding: clamp(12px, 3cqw, 20px);
    border-radius: var(--lb-radius);
    background: #545454;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: var(--lb-gap);
    text-shadow: none;
}

.lb-sheet * {
    font-family: inherit;
}

.lb-close {
    position: absolute;
    top: 6px;
    right: 10px;
    z-index: 2;
    padding: 0 6px;
    border: none;
    background: none;
    color: #fff;
    font-size: clamp(22px, 5cqw, 30px);
    line-height: 1;
    cursor: pointer;
}

/* ---- Header ------------------------------------------------------------------------------ */

.lb-head {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: clamp(6px, 2cqw, 12px) 40px;
    border-radius: var(--lb-radius);
    background: #fb8d35;
    box-shadow: var(--lb-shadow);
    color: var(--lb-ink);
    text-align: center;
}

.lb-head__title {
    max-width: min(340px, 100%);
    height: auto;
}

.lb-head__game {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45em;
    font-size: clamp(1rem, 3.4cqw, 1.6rem);
    line-height: 1.15;
}

/* The game's own menu banner. Sized by HEIGHT at its natural ratio, never cropped: these are
   landscape images with the game's name drawn into them, so any square crop cuts the title. */
.lb-head__icon {
    flex: none;
    height: clamp(30px, 6cqw, 50px);
    width: auto;
    max-width: 40%;
    object-fit: contain;
    border-radius: calc(var(--lb-radius) * 0.4);
}

/* ---- Filters ----------------------------------------------------------------------------- */

/* Narrow: three centred rows stacked. Wide: time on the left, scope on the right, as the old
   board had them — the level row is hidden there, so the two ends are all that is left. */
.lb-filters {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--lb-gap);
}

.lb-filters__row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: clamp(4px, 1.4cqw, 10px);
}

.lb-pill {
    display: flex;
    align-items: center;
    gap: 0.35em;
    padding: clamp(4px, 1.4cqw, 9px) clamp(9px, 2.4cqw, 16px);
    border: none;
    border-radius: 999px;
    background: #fee9aa;
    color: var(--lb-ink);
    box-shadow: 3px 3px #733381;
    font-size: clamp(0.85rem, 2.6cqw, 1.25rem);
    line-height: 1.2;
    cursor: pointer;
}

.lb-pill.is-on {
    background: #fbca3f;
    box-shadow: inset 0 0 0 2px #733381, 3px 3px #733381;
}

.lb-pill--scope {
    background: #ee9d57;
}

/* The level pills carry the medal art itself, so the pill row and the list headings read as the
   same thing. Phone-only — above the breakpoint all three lists are on screen at once. */
.lb-pill--level img {
    width: clamp(20px, 6cqw, 28px);
    height: auto;
}

/* ---- Lists ------------------------------------------------------------------------------- */

.lb-lists {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-items: start;        /* an empty board is a short box, not a tall orange void */
    gap: var(--lb-gap);
}

.lb-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: clamp(6px, 1.6cqw, 12px);
    border-radius: var(--lb-radius);
    background: var(--lb-panel);
    box-shadow: var(--lb-shadow);
    color: var(--lb-ink);
    font-size: clamp(0.78rem, 1.9cqw, 1rem);
}

/* The medal art has "Gold Level" drawn into it, so the heading is the picture — no caption. */
.lb-list__head {
    display: flex;
    justify-content: center;
    margin: 0 0 2px;
}

.lb-list__head img {
    width: 75px;
    max-width: 100%;
    height: auto;
}

.lb-list__rows {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin: 0;
    padding: 0;
    list-style: none;
}

/* ---- Row --------------------------------------------------------------------------------- */

.lb-row {
    display: grid;
    grid-template-columns: 1.9em minmax(0, 1fr) auto;
    gap: 0.1em 0.45em;
    align-items: center;
    padding: 0.22em 0.4em;
    border-radius: calc(var(--lb-radius) * 0.6);
    animation: lb-row-in 0.3s ease-out both;
}

/* A flat tint, not odd/even striping: a :nth-child stripe is (0-2-0) and would outrank the
   medal colours below, which are plain single-class rules. */
.lb-row {
    background: rgba(255, 255, 255, 0.2);
}

.lb-row__rank {
    text-align: right;
    opacity: 0.75;
}

.lb-row__who {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.lb-row__name {
    overflow-wrap: anywhere;   /* long names wrap instead of forcing the column open */
    line-height: 1.1;
}

.lb-row__meta {
    font-size: 0.8em;
    opacity: 0.7;
    line-height: 1.1;
}

.lb-row__meta:empty {
    display: none;
}

.lb-row__points {
    justify-self: end;
    white-space: nowrap;
}

.lb-row__unit {
    font-size: 0.75em;
    opacity: 0.7;
    margin-left: 0.15em;
}

/* Rank 1 leads on size and the shimmer; 2 and 3 sit between it and the rest, and the three carry
   medal fills (Andrew, 15 Aug). No bold anywhere — llamarollFont has one weight (rule 14).
   Gradients rather than flats so they read as struck metal against the panel's orange. */
.lb-row--1 {
    font-size: 1.4em;
    background: linear-gradient(160deg, #ffe488, #f2b705);
}

.lb-row--2 {
    font-size: 1.18em;
    background: linear-gradient(160deg, #f6f8fa, #c4c9d0);
}

.lb-row--3 {
    font-size: 1.08em;
    /* The dark stop is the binding one: the ink has to clear 4.5:1 against it, which #cf8b4f
       did not (4.08:1). Guarded by tests/visual/contrast.spec.js. */
    background: linear-gradient(160deg, #f2c39b, #d99a63);
}

.lb-row--1 .lb-row__rank,
.lb-row--2 .lb-row__rank,
.lb-row--3 .lb-row__rank {
    opacity: 1;
}

/* The child looking at the board, wherever they land. The ring and the marker carry it, so a
   medal row keeps its metal — only rank 4 and below take the yellow fill. */
.lb-row--you {
    box-shadow: inset 0 0 0 2px #733381;
}

/* Cyan, not the panel's yellow — "this is you" has to read as a different kind of thing from
   the three medal fills right above it. */
.lb-row--you:not(.lb-row--1):not(.lb-row--2):not(.lb-row--3) {
    background: #c5fcff;
}

.lb-row--you .lb-row__rank::before {
    content: "\25B8";          /* ▸ — marks the row without spending a column */
    margin-right: 0.15em;
}

.lb-empty {
    padding: 0.6em 0.2em;
    text-align: center;
    opacity: 0.85;
    line-height: 1.25;
}

/* ---- Your position ----------------------------------------------------------------------- */

/* Sticks to the foot of the sheet so it survives a long list without a second scroll region.
   Same three columns as .lb-lists, so each chip sits under the board it reports on. */
.lb-you {
    position: sticky;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-items: center;
    gap: 2px var(--lb-gap);
    padding: clamp(6px, 1.8cqw, 12px);
    border-radius: var(--lb-radius);
    background: #c5fcff;       /* the "you" colour, shared with .lb-row--you */
    box-shadow: var(--lb-shadow);
    color: var(--lb-ink);
    font-size: clamp(0.85rem, 2.4cqw, 1.15rem);
}

/* Its own row above the chips — as a grid item it would eat a column and break the alignment. */
.lb-you__label {
    grid-column: 1 / -1;
    text-align: center;
    opacity: 0.7;
}

.lb-you__chip {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3em;
}

.lb-you__chip img {
    width: clamp(20px, 5cqw, 30px);
    height: auto;
}

.lb-you__rank {
    font-size: 1.25em;
}

.lb-you__of {
    font-size: 0.85em;
    opacity: 0.7;
}

.lb-you__chip--none {
    opacity: 0.65;
}

.lb-you__chip--old {
    flex-wrap: wrap;
}

.lb-you__note {
    flex-basis: 100%;
    text-align: center;
    font-size: 0.75em;
    opacity: 0.7;
}

/* ---- Loading ----------------------------------------------------------------------------- */

.lb-skeleton {
    height: 1.6em;
    margin: 3px 0;
    border-radius: calc(var(--lb-radius) * 0.6);
    background: linear-gradient(90deg, rgba(255,255,255,0.15), rgba(255,255,255,0.45), rgba(255,255,255,0.15));
    background-size: 300% 100%;
    animation: lb-sheen 1.4s linear infinite;
}

@keyframes lb-sheen {
    to { background-position: 300% 0; }
}

/* ---- Phone: one level at a time ---------------------------------------------------------- */

/* The whole mobile fix. The JS always renders all three lists and marks the selected one, so a
   pill click is an attribute swap, never a re-render. */
@container (max-width: 620px) {
    .lb-lists {
        grid-template-columns: 1fr;
    }

    .lb-list:not([data-lb-active]),
    .lb-you__chip:not([data-lb-active]) {
        display: none;
    }

    /* One board, so one column — otherwise the surviving chip sits stranded in column 1. */
    .lb-you {
        grid-template-columns: 1fr;
    }

    /* One list has the full sheet width, so the type can be bigger here than in the 3-up view. */
    .lb-list {
        font-size: clamp(0.95rem, 4cqw, 1.2rem);
    }

    .lb-list__head {
        display: none;         /* the selected pill already names the level */
    }

    .lb-sheet {
        margin-top: auto;      /* a bottom sheet, without ever positioning it in px (L-175) */
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }

    .lb-frame {
        padding: 0;
    }
}

@container (min-width: 621px) {
    .lb-filters__row--level {
        display: none;         /* all three lists are already on screen */
    }

    .lb-filters {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
    }
}

/* ---- Shimmer ----------------------------------------------------------------------------- */

/* The end-card's .ec-rainbow recipe (src/scss/games/components/_end-card.scss), duplicated rather
   than imported — this file is hand-written and must stay out of the gulp output (rule 12).
   The two selectors give (0-2-0), so body.dark-mode's span whitener can never outrank the clip.

   Darker stops than the end-card's: that one shimmers on a near-white row, this one on peach over
   #ed9d57, where the end-card's yellows and mints leave the winner's name unreadable. */
.lb-row__name.lb-shimmer,
.lb-row__name.lb-shimmer span {
    background: linear-gradient(90deg, #7b1fa2, #c2185b, #d84315, #2e7d32, #7b1fa2);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent !important;
    animation: lb-rainbow 2.4s linear infinite;
}

@keyframes lb-rainbow {
    to { background-position: 300% 0; }
}

@keyframes lb-row-in {
    from { opacity: 0; transform: translateY(3px); }
    to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .lb-row,
    .lb-skeleton,
    .lb-row__name.lb-shimmer,
    .lb-row__name.lb-shimmer span {
        animation: none;
    }
}

/* ---- Dark and plain mode ----------------------------------------------------------------- */

/* dark-mode.css reaches inside the game iframe (common/games/partials/head.php) and whitens bare
   span/li/a/small with !important — ~2:1 on these fills. Same restore-the-ink fix as the end-card
   and the Snapshot pills (L-070/L-071). Two selectors each, to clear the catch-all's specificity. */
body.dark-mode .lb-sheet {
    background: #3b3b3b;
}

body.dark-mode .lb-list,
body.dark-mode .lb-list span,
body.dark-mode .lb-list li,
body.dark-mode .lb-head,
body.dark-mode .lb-head span,
body.dark-mode .lb-you,
body.dark-mode .lb-you span {
    color: var(--lb-ink) !important;
    text-shadow: none !important;
}

/* NOT restored: the rank-1 shimmer needs color:transparent, and a restore would paint the clip. */
body.dark-mode .lb-row__name.lb-shimmer,
body.dark-mode .lb-row__name.lb-shimmer span {
    color: transparent !important;
}

/* dark-mode.css paints every <button> black with a white rim, which flattens on/off to identical
   pills. These re-state both states at a specificity it cannot reach. */
/* The label span needs naming too — the whitener hits it directly, so colour on the button alone
   is only inherited and loses. */
body.dark-mode .lb-sheet .lb-pill,
body.dark-mode .lb-sheet .lb-pill span {
    background: #fee9aa !important;
    color: var(--lb-ink) !important;
    border: none !important;
    box-shadow: 3px 3px #733381 !important;
}

body.dark-mode .lb-sheet .lb-pill span {
    background: none !important;
    box-shadow: none !important;
}

body.dark-mode .lb-sheet .lb-pill--scope {
    background: #ee9d57 !important;
}

body.dark-mode .lb-sheet .lb-pill.is-on {
    background: #fbca3f !important;
    box-shadow: inset 0 0 0 2px #733381, 3px 3px #733381 !important;
}

body.dark-mode .lb-sheet .lb-close {
    background: none !important;
    border: none !important;
    color: #fff !important;
    box-shadow: none !important;
}

/* Same treatment for plain mode — css/plain-mode.css mirrors every one of those catch-alls. */
body.plain-mode .lb-sheet {
    background: #e8e8e8;
}

body.plain-mode .lb-list,
body.plain-mode .lb-list span,
body.plain-mode .lb-list li,
body.plain-mode .lb-head,
body.plain-mode .lb-head span,
body.plain-mode .lb-you,
body.plain-mode .lb-you span {
    color: #000 !important;
    text-shadow: none !important;
}

body.plain-mode .lb-sheet .lb-pill,
body.plain-mode .lb-sheet .lb-pill span {
    background: none !important;
    color: #000 !important;
    box-shadow: none !important;
}

body.plain-mode .lb-sheet .lb-pill {
    background: #fff !important;
    border: 2px solid #000 !important;
}

body.plain-mode .lb-sheet .lb-pill.is-on {
    background: #000 !important;
}

body.plain-mode .lb-sheet .lb-pill.is-on,
body.plain-mode .lb-sheet .lb-pill.is-on span {
    color: #fff !important;
}

/* The shimmer has no meaning in plain mode — it is decoration the theme exists to remove. */
body.plain-mode .lb-row__name.lb-shimmer,
body.plain-mode .lb-row__name.lb-shimmer span {
    background: none;
    color: #000 !important;
    animation: none;
}

/* ============================================================================================
   Live Play modal — index-quests/leaderboard-modal.php + js/quest-play-live.js.

   Every colour is a token, so plain mode re-themes by swapping them. Text sits in <div>s because
   dark-mode.css / plain-mode.css repaint bare spans with !important.
   ============================================================================================ */

#leaderboardModal {
    --pl-neon: #1eff00;
    --pl-on-neon: #000;
    --pl-glow: rgba(30, 255, 0, 0.4);
    --pl-wash: rgba(30, 255, 0, 0.14);
    --pl-bg: #000;
    --pl-panel: #0a0e0a;
    --pl-row: #141b14;
    --pl-chip: #1f2b1f;
    --pl-line: #263726;
    --pl-ink: #fff;
    --pl-dim: #a3b8a0;
}

/* Wider than Bootstrap's modal-xl, which is 800px below a 1200px window — too tight for three lanes. */
@media (min-width: 576px) {
    #leaderboardModal .modal-dialog {
        max-width: min(1400px, calc(100vw - 32px));
    }
}

#leaderboardModal .modal-content {
    border: 2px solid var(--pl-neon);
    border-radius: 24px;
    background: var(--pl-bg);
    box-shadow: 0 0 26px var(--pl-glow), 0 0 90px var(--pl-wash);
}

#leaderboardModal .pl-shell {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 1.6vw, 20px);
    padding: clamp(14px, 2.2vw, 28px);
    border-radius: 22px;
    background: radial-gradient(110% 70% at 50% -15%, var(--pl-wash), transparent 65%), var(--pl-bg);
    color: var(--pl-ink);
    text-shadow: none;
}

/* ---- Header ------------------------------------------------------------------------------ */

#leaderboardModal .pl-head {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0 52px;
    text-align: center;
}

#leaderboardModal .pl-head::after {
    content: "";
    align-self: stretch;
    height: 2px;
    margin: 8px -52px 0;
    background: linear-gradient(90deg, transparent, var(--pl-neon), transparent);
}

#leaderboardModal .pl-head__logo {
    width: auto;
    height: clamp(56px, 7vw, 84px);
}

#leaderboardModal .pl-head__game {
    font-size: clamp(24px, 3vw, 38px);
    line-height: 1.15;
}

#leaderboardModal .pl-head__game:empty {
    display: none;
}

#leaderboardModal .qr-code img {
    border-radius: 15px;
}

#leaderboardModal .pl-close {
    position: absolute;
    top: 0;
    right: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--pl-line);
    border-radius: 50%;
    background: var(--pl-panel);
    color: var(--pl-ink);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

#leaderboardModal .pl-close:hover {
    border-color: var(--pl-neon);
    color: var(--pl-neon);
    box-shadow: 0 0 14px var(--pl-glow);
}

/* ---- Board ------------------------------------------------------------------------------- */

#leaderboardModal .pl-board {
    position: relative;
}

#leaderboardModal .pl-lanes {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
    gap: clamp(10px, 1.4vw, 18px);
}

#leaderboardModal .pl-lane {
    min-height: 150px;
    padding: 12px;
    border: 1px solid var(--pl-line);
    border-radius: 18px;
    background: var(--pl-panel);
}

#leaderboardModal .pl-lane__head {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}

#leaderboardModal .pl-lane__head img {
    width: 60px;
    height: auto;
}

/* Sized for a classroom projector — this board is read from the back of the room. */
#leaderboardModal .pl-list {
    position: relative;        /* rows measure offsetTop against this for the glide */
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: clamp(18px, 1.75vw, 24px);
}

#leaderboardModal .pl-empty {
    padding: 14px 6px;
    color: var(--pl-dim);
    font-size: 1.1em;
    text-align: center;
}

#leaderboardModal .pl-more {
    color: var(--pl-dim);
    font-size: 0.8em;
    text-align: center;
}

/* First load only — the live polls after it run without a loader. */
#leaderboardModal .loading-result {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: rgba(0, 0, 0, 0.6);
}

#leaderboardModal .loading-result img {
    width: 110px;
}

/* ---- Row --------------------------------------------------------------------------------- */

/* Ranks differ by size and neon only — never gold/silver/bronze, which here mean the level. */
#leaderboardModal .pl-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.45em;
    padding: 0.28em 0.55em 0.28em 0.3em;
    border: 1px solid transparent;
    border-radius: 12px;
    background: var(--pl-row);
    color: var(--pl-ink);
    line-height: 1.15;
}

#leaderboardModal .pl-row__rank {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.75em;
    height: 1.75em;
    border-radius: 50%;
    background: var(--pl-chip);
    color: var(--pl-dim);
    font-size: 0.8em;
}

#leaderboardModal .pl-row__who {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15em 0.45em;
    min-width: 0;
}

/* Grows, so the tag sits hard right on a shared line; only a name too long for its own line breaks. */
#leaderboardModal .pl-row__name {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

#leaderboardModal .pl-row__tag {
    flex: none;
    padding: 0.2em 0.6em;
    border-radius: 999px;
    background: var(--pl-neon);
    color: var(--pl-on-neon);
    font-size: 0.62em;
    white-space: nowrap;
}

#leaderboardModal .pl-row__pts {
    flex: none;
    display: flex;
    align-items: baseline;
    gap: 0.15em;
    color: var(--pl-neon);
    white-space: nowrap;
}

#leaderboardModal .pl-row__unit {
    color: var(--pl-dim);
    font-size: 0.7em;
}

#leaderboardModal .pl-row--1 {
    border-color: var(--pl-neon);
    background: linear-gradient(90deg, var(--pl-wash), transparent 85%), var(--pl-row);
    box-shadow: 0 0 16px var(--pl-wash);
    font-size: 1.18em;
}

#leaderboardModal .pl-row--1 .pl-row__rank {
    background: var(--pl-neon);
    color: var(--pl-on-neon);
}

#leaderboardModal .pl-row--2 .pl-row__rank,
#leaderboardModal .pl-row--3 .pl-row__rank {
    background: none;
    box-shadow: inset 0 0 0 2px var(--pl-neon);
    color: var(--pl-neon);
}

/* Rows the cached pre-redesign JS still emits for a few hours after a deploy. */
#leaderboardModal .top-list-user-item {
    padding: 0.2em 0.5em;
}

#leaderboardModal .top-list-user-item.selected {
    color: var(--pl-neon);
}

/* ---- Moments: what each pupil just did --------------------------------------------------- */

/* --pl-wait is set per row by appendPoints(), so every pupil gets a turn rather than all at once.
   The glow lives on ::before because the row's own transform belongs to the JS glide. */
#leaderboardModal .pl-row.is-enter {
    animation: pl-enter 0.55s cubic-bezier(0.2, 1.4, 0.4, 1) var(--pl-wait, 0s) both;
}

#leaderboardModal .pl-row.is-new,
#leaderboardModal .pl-row.is-up,
#leaderboardModal .pl-row.is-lead {
    z-index: 1;                /* a climber passes over the rows it overtakes */
    border-color: var(--pl-neon);
}

#leaderboardModal .pl-row[class*=" is-"]::before {
    content: "";
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    pointer-events: none;
    opacity: 0;
}

#leaderboardModal .pl-row.is-new::before {
    background: var(--pl-neon);
    box-shadow: 0 0 26px 4px var(--pl-neon);
    animation: pl-flash 1.1s ease-out var(--pl-wait, 0s) both;
}

/* A band of light that travels up through the row, the way the pupil just did. */
#leaderboardModal .pl-row.is-up::before {
    background: linear-gradient(0deg, transparent 30%, var(--pl-neon) 50%, transparent 70%) 0 100% / 100% 300% no-repeat;
    animation: pl-rise 1s ease-out var(--pl-wait, 0s) both;
}

#leaderboardModal .pl-row.is-score::before {
    box-shadow: inset 0 0 0 2px var(--pl-neon);
    animation: pl-flash 0.9s ease-out var(--pl-wait, 0s) both;
}

#leaderboardModal .pl-row.is-score .pl-row__pts {
    animation: pl-pulse 0.6s ease-out var(--pl-wait, 0s);
}

/* Taking the top spot: a sheen across the row, then sparks off the rank chip. */
#leaderboardModal .pl-row.is-lead::before {
    background: linear-gradient(100deg, transparent 35%, #fff 50%, transparent 65%) 150% 0 / 250% 100% no-repeat;
    box-shadow: 0 0 34px 6px var(--pl-neon);
    animation: pl-sheen 1.4s ease-out var(--pl-wait, 0s) both;
}

#leaderboardModal .pl-row.is-lead::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 1.1em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    animation: pl-sparks 0.9s ease-out calc(var(--pl-wait, 0s) + 0.25s) both;
}

#leaderboardModal .pl-row.is-lead .pl-row__name {
    background: linear-gradient(90deg, var(--pl-ink), var(--pl-neon), var(--pl-ink)) 0 0 / 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: pl-shimmer 2.4s linear infinite;
}

#leaderboardModal .pl-row[class*=" is-"] .pl-row__tag {
    animation: pl-pop 0.5s ease-out calc(var(--pl-wait, 0s) + 0.2s) both;
}

@keyframes pl-enter {
    from { opacity: 0; transform: translateY(18px) scale(0.9); }
    to   { opacity: 1; transform: none; }
}

@keyframes pl-flash {
    0%   { opacity: 0; }
    12%  { opacity: 0.85; }
    100% { opacity: 0; }
}

@keyframes pl-rise {
    0%   { opacity: 0; background-position: 0 100%; }
    15%  { opacity: 0.8; }
    100% { opacity: 0; background-position: 0 0; }
}

@keyframes pl-sheen {
    0%   { opacity: 0; background-position: 150% 0; }
    15%  { opacity: 0.9; }
    70%  { opacity: 0.6; }
    100% { opacity: 0; background-position: -50% 0; }
}

@keyframes pl-sparks {
    0% {
        opacity: 0;
        box-shadow: 0 0 var(--pl-neon), 0 0 #fff, 0 0 var(--pl-neon), 0 0 #fff,
                    0 0 var(--pl-neon), 0 0 #fff, 0 0 var(--pl-neon), 0 0 #fff;
    }
    10% { opacity: 1; }
    100% {
        opacity: 0;
        box-shadow: -46px -30px var(--pl-neon), 4px -52px #fff, 50px -28px var(--pl-neon), 72px 4px #fff,
                    44px 34px var(--pl-neon), -6px 48px #fff, -52px 26px var(--pl-neon), -70px -2px #fff;
    }
}

@keyframes pl-shimmer {
    to { background-position: 300% 0; }
}

@keyframes pl-pulse {
    40% { transform: scale(1.35); }
}

@keyframes pl-pop {
    0%   { opacity: 0; transform: scale(0.4); }
    60%  { opacity: 1; transform: scale(1.25); }
    100% { opacity: 1; transform: none; }
}

/* ---- Still to score ---------------------------------------------------------------------- */

#leaderboardModal .pl-waiting {
    padding: 14px 16px;
    border: 1px dashed var(--pl-line);
    border-radius: 18px;
    background: var(--pl-panel);
}

#leaderboardModal .pl-waiting__title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 10px;
    color: var(--pl-dim);
    font-size: clamp(16px, 1.5vw, 20px);
}

#leaderboardModal .pl-waiting__count {
    min-width: 1.9em;
    padding: 0.05em 0.5em;
    border-radius: 999px;
    background: var(--pl-chip);
    color: var(--pl-ink);
    text-align: center;
}

#leaderboardModal .pl-waiting__count:empty {
    display: none;
}

#leaderboardModal .pl-bubbles {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    font-size: clamp(16px, 1.5vw, 21px);
    line-height: 1.2;
}

#leaderboardModal .pl-bubble {
    padding: 0.3em 0.8em;
    border: 1px solid var(--pl-line);
    border-radius: 999px;
    background: var(--pl-row);
    color: var(--pl-ink);
}

/* The bubble lights up and pops as its pupil lands on the board. */
#leaderboardModal .pl-bubble.is-leaving {
    animation: pl-bubble-out 0.45s ease-in forwards;
}

@keyframes pl-bubble-out {
    35%  { transform: scale(1.15); background: var(--pl-neon); border-color: var(--pl-neon); color: var(--pl-on-neon); }
    100% { transform: scale(0); opacity: 0; }
}

/* ---- Footer ------------------------------------------------------------------------------ */

#leaderboardModal .pl-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 20px;
}

#leaderboardModal .pl-btn {
    padding: 0.45em 1.1em;
    border: 2px solid var(--pl-neon);
    border-radius: 999px;
    background: transparent;
    color: var(--pl-ink);
    font-family: inherit;
    font-size: clamp(18px, 1.7vw, 24px);
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}

#leaderboardModal .pl-btn--go,
#leaderboardModal .pl-btn:hover:not(:disabled) {
    border-color: var(--pl-neon);
    background: var(--pl-neon);
    color: var(--pl-on-neon);
}

#leaderboardModal .pl-btn:hover:not(:disabled) {
    box-shadow: 0 0 18px var(--pl-glow);
}

#leaderboardModal .pl-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

@media (max-width: 767px) {
    #leaderboardModal .pl-lanes {
        grid-template-columns: 1fr;
    }

    #leaderboardModal .pl-lane {
        min-height: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    #leaderboardModal .pl-row,
    #leaderboardModal .pl-row::before,
    #leaderboardModal .pl-row::after,
    #leaderboardModal .pl-row *,
    #leaderboardModal .pl-bubble {
        animation: none !important;
    }
}

/* ---- Plain mode -------------------------------------------------------------------------- */

/* The theme exists to remove decoration: black on white, no glow, and the leader's name solid. */
body.plain-mode #leaderboardModal {
    --pl-neon: #000;
    --pl-on-neon: #fff;
    --pl-glow: transparent;
    --pl-wash: transparent;
    --pl-bg: #fff;
    --pl-panel: #fff;
    --pl-row: #fff;
    --pl-chip: #e6e6e6;
    --pl-line: #000;
    --pl-ink: #000;
    --pl-dim: #333;
}

body.plain-mode #leaderboardModal .pl-row {
    border-color: var(--pl-line);
}

body.plain-mode #leaderboardModal .pl-row.is-lead .pl-row__name {
    background: none;
    color: var(--pl-ink);
    animation: none;
}

body.plain-mode #leaderboardModal .pl-row::before,
body.plain-mode #leaderboardModal .pl-row::after {
    display: none;
}
