/* ===============================================================
   Leaderboard, drawn by static/js/leaderboard.js:
     #lb-preview                     compact ranking on the project page
     #lb-stats, #lb-podium, #lb-table  the full page at leaderboard/
   Uses the tokens and shared components in site.css.
   =============================================================== */

/* --- Shared pieces ------------------------------------------------ */
.lb-rank { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; font: 700 14px 'Google Sans', sans-serif; color: var(--muted); }
.lb-rank.is-top { color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45); }
.lb-rank.is-1 { background: linear-gradient(145deg, #e6b422, #c8900f); }
.lb-rank.is-2 { background: linear-gradient(145deg, #b4b8bd, #8e949b); }
.lb-rank.is-3 { background: linear-gradient(145deg, #d49a6a, #ad6e3e); }
.lb-policy { display: flex; align-items: center; gap: 12px; min-width: 0; }
.lb-logo { flex: none; width: 40px; height: 40px; padding: 7px; border-radius: 12px; background: #fff; box-shadow: 0 0 0 1px var(--line); object-fit: contain; }
.lb-logo.is-blank { display: inline-flex; align-items: center; justify-content: center; font-weight: 600; color: var(--muted); }
.lb-who { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.lb-name { font: 600 1rem 'Google Sans', sans-serif; color: var(--ink); white-space: nowrap; }
.lb-org { margin-top: 2px; overflow: hidden; font-size: 0.78rem; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.lb-mark { margin-left: 1px; font-size: 0.7em; color: var(--muted); cursor: help; }
/* 95% CI whisker drawn over a bar track */
.lb-ci { position: absolute; top: 50%; height: 10px; margin-top: -5px; border: solid rgba(17, 19, 23, 0.45); border-width: 0 1.2px; background: linear-gradient(rgba(17, 19, 23, 0.45), rgba(17, 19, 23, 0.45)) center / 100% 1.2px no-repeat; }

/* --- Project-page preview: rows race in when site.js adds .is-in --- */
.lb-mini { margin-top: 40px; padding: 8px 28px; border-radius: 28px; background: var(--card); box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.lb-mini:empty { min-height: 470px; }
.lb-mini-row {
  display: grid; grid-template-columns: 28px minmax(190px, 230px) 1fr 70px; align-items: center; gap: 16px; padding: 15px 0;
  opacity: 0; transform: translateY(12px); transition: opacity 0.6s ease var(--d), transform 0.8s cubic-bezier(.2, .9, .3, 1.2) var(--d);
}
.lb-mini-row + .lb-mini-row { border-top: 1px solid var(--line); }
.lb-mini.is-in .lb-mini-row { opacity: 1; transform: none; }
.lb-mini-track { position: relative; height: 10px; border-radius: 5px; background: var(--soft); }
.lb-mini-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 5px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 50%, transparent), var(--c)); transition: width 1.6s cubic-bezier(.2, .8, .2, 1) calc(var(--d) + 0.25s); }
.lb-mini.is-in .lb-mini-fill { width: var(--v); }
.lb-mini-fill::after { content: ''; position: absolute; right: -1px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 28%, transparent); }
.lb-mini .lb-ci { opacity: 0; transition: opacity 0.6s ease calc(var(--d) + 1.4s); }
.lb-mini.is-in .lb-ci { opacity: 1; }
.lb-mini-val { font: 700 1.08rem 'Google Sans', sans-serif; color: var(--ink); text-align: right; }
.lb-mini-val small { margin-left: 1px; font-weight: 400; font-size: 0.75em; color: var(--muted); }
.lb-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px 24px; margin-top: 18px; font-size: 0.86rem; color: var(--muted); }
.lb-foot .btn { background: var(--ink); color: #fff; }
.lb-foot .btn:hover { background: var(--accent); }
@media (max-width: 640px) {
  .lb-mini { padding: 6px 16px; }
  .lb-mini-row { grid-template-columns: 26px 1fr 58px; gap: 10px; }
  .lb-mini-track { grid-column: 2 / 4; grid-row: 2; }
  .lb-logo { width: 34px; height: 34px; }
}

/* ===============================================================
   leaderboard/ page
   =============================================================== */

/* --- Hero: the shared scene hero (site.css), shorter, stats in the slab - */
.hero.is-short { height: 84vh; height: 84svh; min-height: 620px; }
.hero.is-short .slab { width: min(640px, calc(100vw - 56px)); }
.lb-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 24px; min-height: 64px; margin-top: 26px; padding-top: 22px; border-top: 1px solid rgba(255, 255, 255, 0.16); }
.lb-stat b { display: block; font: 700 2rem/1 'Google Sans', sans-serif; letter-spacing: -0.03em; color: #fff; font-variant-numeric: tabular-nums; }
.lb-stat span { display: block; margin-top: 6px; font-size: 0.8rem; color: rgba(255, 255, 255, 0.66); }
.hero-cue { position: absolute; z-index: 4; right: max(28px, calc(50vw - 660px)); bottom: 48px; display: inline-flex; align-items: center; gap: 12px; height: 54px; padding: 0 8px 0 22px; border-radius: 999px; color: #fff; font: 500 15px 'Google Sans', sans-serif; }
.hero-cue i { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: #fff; color: var(--ink); }
.hero-cue i svg { width: 18px; height: 18px; animation: cue 1.8s ease-in-out infinite; }
@keyframes cue { 50% { transform: translateY(3px); } }
@media (max-width: 900px) {
  .lb-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; }
  .lb-stat b { font-size: 1.6rem; }
  .hero-cue { display: none; }
}

/* --- Podium: top three on the light body, laid out 2 · 1 · 3 ------- */
.lb-podium { display: grid; grid-template-columns: repeat(3, 1fr); align-items: end; gap: 20px; min-height: 380px; margin-top: 40px; font-variant-numeric: tabular-nums; }
.lb-podium-card {
  position: relative; overflow: hidden; padding: 26px 26px 22px; border-radius: 30px; background: var(--card); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(26px); transition: opacity 0.8s ease, transform 0.9s cubic-bezier(.2, .9, .3, 1.15), box-shadow 0.4s;
}
.lb-podium.is-in .lb-podium-card { opacity: 1; transform: none; }
.lb-podium-card:hover { box-shadow: 0 0 0 1px var(--line), 0 40px 70px -40px color-mix(in srgb, var(--c) 55%, transparent); }
/* Policy colour: a wash from the top corner and a bar along the top edge. */
.lb-podium-card::before { content: ''; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(110% 70% at 100% 0%, color-mix(in srgb, var(--t) 75%, transparent), transparent 62%); }
.lb-podium-card::after { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--c); }
.lb-podium-card > * { position: relative; }
.lb-podium-card.is-1 { order: 2; padding: 34px 30px 28px; transition-delay: 0.05s; box-shadow: 0 0 0 1px var(--line), 0 50px 90px -45px color-mix(in srgb, var(--c) 60%, transparent); }
.lb-podium-card.is-2 { order: 1; transition-delay: 0.2s; }
.lb-podium-card.is-3 { order: 3; transition-delay: 0.35s; }
.lb-podium-top { display: flex; align-items: center; justify-content: space-between; }
.lb-podium-top .lb-logo { width: 48px; height: 48px; padding: 8px; border-radius: 14px; }
.lb-medal { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; font: 700 18px 'Google Sans', sans-serif; color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 6px 16px -6px rgba(0, 0, 0, 0.35); }
.is-1 .lb-medal { width: 52px; height: 52px; font-size: 21px; background: linear-gradient(145deg, #f0c53a, #c8900f); }
.is-2 .lb-medal { background: linear-gradient(145deg, #c3c7cc, #8e949b); }
.is-3 .lb-medal { background: linear-gradient(145deg, #dca777, #ad6e3e); }
.lb-podium-name { margin-top: 20px; font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.is-1 .lb-podium-name { font-size: 1.65rem; }
.lb-podium-org { margin: 2px 0 0; font-size: 0.86rem; color: var(--muted); }
.lb-podium-big { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 2px; margin: 18px 0 0; font: 700 3rem/1 'Google Sans', sans-serif; letter-spacing: -0.045em; color: var(--ink); }
.is-1 .lb-podium-big { font-size: 3.9rem; }
.lb-podium-big small { font-size: 0.45em; letter-spacing: 0; color: var(--muted); }
.lb-podium-big span { flex-basis: 100%; margin-top: 8px; font: 400 0.82rem 'Noto Sans', sans-serif; letter-spacing: 0; color: var(--muted); }
.lb-podium-bar { position: relative; height: 10px; margin-top: 16px; border-radius: 5px; background: var(--soft); }
.lb-podium-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 50%, transparent), var(--c)); }
.lb-podium.is-in .lb-podium-fill { animation: lb-grow 1.4s cubic-bezier(.2, .8, .2, 1) 0.5s both; }
.lb-podium:not(.is-in) .lb-podium-fill { width: 0 !important; }
.lb-podium-facts { display: grid; grid-template-columns: 1fr 1fr auto; align-items: start; gap: 10px; margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--line); }
.lb-podium-facts dt { font-size: 0.74rem; color: var(--muted); }
.lb-podium-facts dd { margin: 3px 0 0; font: 600 1.08rem 'Google Sans', sans-serif; color: var(--ink); }
.lb-podium-facts .is-ring { text-align: center; }
.lb-podium-facts .is-ring dd { display: flex; justify-content: center; margin-top: 1px; }
.lb-podium-facts .lb-ring { width: 30px; height: 30px; }
@media (max-width: 900px) {
  .lb-podium { grid-template-columns: 1fr; min-height: 0; gap: 14px; }
  .lb-podium-card.is-1, .lb-podium-card.is-2, .lb-podium-card.is-3 { order: 0; padding: 22px; }
  .is-1 .lb-podium-big { font-size: 3.2rem; }
}

/* --- Sortable table ------------------------------------------------- */
.lb-table-card { margin-top: 36px; padding: 6px 26px 12px; border-radius: 28px; background: var(--card); box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.lb-table:empty { min-height: 420px; }
.lb-row {
  display: grid; grid-template-columns: 2rem minmax(11rem, 1.25fr) 1fr 1fr 3.6rem 5rem;
  grid-template-areas: "rank policy sr ms solved succ";
  align-items: center; column-gap: 18px; padding: 14px 10px; margin: 0 -10px; border-radius: 16px;
  transition: background 0.2s;
}
.lb-row:not(.lb-head) { animation: lb-in 0.6s cubic-bezier(.2, .9, .3, 1.1) both; }
.lb-row:nth-child(2) { animation-delay: 0.04s; } .lb-row:nth-child(3) { animation-delay: 0.08s; } .lb-row:nth-child(4) { animation-delay: 0.12s; }
.lb-row:nth-child(5) { animation-delay: 0.16s; } .lb-row:nth-child(6) { animation-delay: 0.2s; } .lb-row:nth-child(7) { animation-delay: 0.24s; }
@keyframes lb-in { from { opacity: 0; transform: translateY(8px); } }
.lb-row + .lb-row:not(:hover) { box-shadow: 0 -1px 0 var(--line); }
.lb-row:not(.lb-head):hover { background: var(--bg); }
.lb-c-rank { grid-area: rank; display: flex; justify-content: center; }
.lb-c-policy { grid-area: policy; min-width: 0; }
.lb-c-sr { grid-area: sr; } .lb-c-ms { grid-area: ms; }
.lb-c-solved { grid-area: solved; display: flex; justify-content: center; }
.lb-c-succ { grid-area: succ; text-align: right; font: 600 1rem 'Google Sans', sans-serif; color: var(--ink-2); }
.lb-of { font-weight: 400; color: var(--muted); }

.lb-head { padding-top: 16px; padding-bottom: 12px; }
.lb-head > span { font: 700 11px 'Google Sans', sans-serif; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.lb-head .lb-c-sr, .lb-head .lb-c-ms { padding-left: 3.9rem; }
.lb-sort { display: inline-flex; align-items: center; gap: 4px; margin: -4px -8px; padding: 4px 8px; border: 0; border-radius: 999px; background: none; cursor: pointer; font: inherit; letter-spacing: inherit; text-transform: inherit; color: inherit; transition: background 0.2s, color 0.2s; }
.lb-sort:hover { color: var(--ink); background: var(--soft); }
.lb-sort.is-on { color: #fff; background: var(--ink); }
.lb-arrow { font-size: 0.9em; opacity: 0; }
.lb-sort:hover .lb-arrow { opacity: 0.4; }
.lb-sort.is-on .lb-arrow { opacity: 1; }

.lb-meter { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lb-num { flex: none; width: 3.4rem; text-align: right; font: 600 0.98rem 'Google Sans', sans-serif; color: var(--ink); }
.lb-track { position: relative; flex: 1; height: 8px; border-radius: 4px; background: var(--soft); }
.lb-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; animation: lb-grow 1.2s cubic-bezier(.2, .8, .2, 1) 0.15s both; }
@keyframes lb-grow { from { width: 0; } }
.lb-ring { display: block; width: 38px; height: 38px; }
.lb-ring circle { fill: none; stroke-width: 3.2; }
.lb-ring text { font: 600 8px 'Google Sans', sans-serif; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }

.lb-table-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; margin-top: 6px; padding: 14px 0 6px; border-top: 1px solid var(--line); font-size: 0.84rem; color: var(--muted); }
.lb-legend { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.lb-legend > span { display: inline-flex; align-items: center; gap: 8px; }
.lb-key-bar { width: 18px; height: 8px; border-radius: 4px; background: var(--ink-2); }
.lb-key-ci { width: 14px; height: 8px; border: solid rgba(17, 19, 23, 0.45); border-width: 0 1.2px; background: linear-gradient(rgba(17, 19, 23, 0.45), rgba(17, 19, 23, 0.45)) center / 100% 1.2px no-repeat; }
.lb-notes { display: flex; flex-direction: column; gap: 3px; }
.lb-caption { margin: 14px 4px 0; font-size: 0.86rem; color: var(--muted); }

@media (max-width: 760px) {
  .lb-table-card { padding: 4px 14px 10px; }
  .lb-row { grid-template-columns: 1.7rem 1fr 1fr 2.6rem; grid-template-areas: "rank policy policy solved" ". sr ms solved"; row-gap: 10px; column-gap: 10px; }
  .lb-c-succ { display: none; }
  .lb-head .lb-c-sr, .lb-head .lb-c-ms { padding-left: 0; }
  .lb-num { width: 2.9rem; font-size: 0.86rem; }
  .lb-ring { width: 32px; height: 32px; }
}
@media (max-width: 520px) {
  .lb-row { grid-template-columns: 1.7rem 1fr 2.6rem; grid-template-areas: "rank policy solved" ". sr solved" ". ms solved"; }
}

/* --- Protocol ------------------------------------------------------- */
.lb-protocol { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 36px; }
.lb-protocol-item { padding: 22px; border-radius: 26px; background: var(--card); box-shadow: var(--shadow); transition: transform 0.5s cubic-bezier(.2, .9, .3, 1.2); }
.lb-protocol-item:hover { transform: translateY(-4px); }
.lb-protocol-item svg { width: 38px; height: 38px; padding: 9px; border-radius: 12px; background: rgba(15, 118, 110, 0.1); color: var(--accent); }
.lb-protocol-item h3 { margin-top: 16px; font-size: 1.08rem; letter-spacing: -0.01em; }
.lb-protocol-item p { margin: 8px 0 0; font-size: 0.92rem; line-height: 1.6; }
@media (max-width: 980px) { .lb-protocol { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .lb-protocol { grid-template-columns: 1fr; } }

@media (prefers-reduced-motion: reduce) {
  .lb-mini-row, .lb-mini .lb-ci, .lb-podium-card { opacity: 1 !important; transform: none !important; }
  .lb-mini-fill { width: var(--v) !important; }
}
