/* ==========================================================================
   Surface: public leaderboard (/leaderboard, leaderboard.html + leaderboard.js)
   --------------------------------------------------------------------------
   Standalone document: loads tokens, base, components, brand and this file.
   Owns: .lb-* (nav bar, hero + period tabs, podium, ranked list, claim CTA,
   footer). Tokens only, no !important.
   r181 (unslop): the chrome is the quiet canvas, hairlines and three text roles;
   the colour lives in the avatars and the badge medals. One accent: the #1 place.
   Every address is the signature (.nv-address: mono, the host dim, the name
   bright). Medals hold still at rest and play on the row or card in hover/focus.
   ========================================================================== */

@layer surfaces {
  .lb-body {
    position: relative;
    min-height: 100dvh;
    overflow-x: hidden;
  }

  /* ---- Nav ------------------------------------------------------------------------- */
  /* The sticky band is the canvas, so text scrolling under it never shows around the bar. */
  .lb-nav {
    position: sticky;
    top: 0;
    z-index: var(--nv-z-header);
    padding: max(var(--nv-space-3), env(safe-area-inset-top, 0px)) var(--nv-gutter) 0;
    background: var(--nv-bg);
  }

  .lb-nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-3);
    max-width: 1120px;
    min-height: 60px;
    margin: 0 auto;
    padding: var(--nv-space-2) var(--nv-space-2) var(--nv-space-2) var(--nv-space-5);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-bg);
  }

  .lb-logo {
    display: inline-flex;
    flex: none;
    border-radius: var(--nv-r-sm);
  }

  .lb-logo img {
    width: auto;
    height: 28px;
  }

  .lb-nav-actions {
    display: flex;
    align-items: center;
    gap: var(--nv-space-2);
  }

  .lb-nav-actions > a {
    white-space: nowrap;
  }

  .lb-logo picture {
    display: contents;
  }

  /* ---- Hero -------------------------------------------------------------------------- */
  .lb-main {
    position: relative;
    z-index: 1;
    max-width: calc(1120px + 2 * var(--nv-gutter));
    margin: 0 auto;
    padding: 0 var(--nv-gutter) var(--nv-space-16);
  }

  .lb-hero {
    display: grid;
    justify-items: center;
    gap: var(--nv-space-4);
    padding: var(--nv-space-16) 0 var(--nv-space-12);
    text-align: center;
  }

  /* How often the board refreshes: quiet meta above the title, not a badge. */
  .lb-live {
    margin: 0;
    color: var(--nv-text-3);
    font-size: var(--nv-fs-13);
  }

  .lb-hero h1 {
    max-width: 18ch;
    color: var(--nv-text);
    font-size: clamp(40px, 5vw, 56px);
    line-height: 1.08;
    letter-spacing: -.02em;
  }

  .lb-lead {
    max-width: 52ch;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-16);
    line-height: var(--nv-lh-body);
  }

  .lb-tabs {
    margin-top: var(--nv-space-2);
  }

  .lb-tabs > button {
    min-height: 40px;
    padding: var(--nv-space-1) var(--nv-space-5);
    font-size: var(--nv-fs-14);
  }

  /* ---- Podium ------------------------------------------------------------------------ */
  .lb-podium {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: end;
    gap: var(--nv-space-4);
    max-width: 940px;
    margin: var(--nv-space-6) auto var(--nv-space-10);
  }

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

  .lb-podium-card {
    position: relative;
    display: grid;
    justify-items: center;
    align-content: start;
    gap: var(--nv-space-2);
    min-width: 0;
    padding: var(--nv-space-10) var(--nv-space-4) var(--nv-space-6);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-surface-1);
    color: var(--nv-text);
    text-align: center;
    text-decoration: none;
    transition: border-color var(--nv-dur-1) var(--nv-ease), background-color var(--nv-dur-1) var(--nv-ease);
  }

  a.lb-podium-card:hover {
    border-color: var(--nv-line-strong);
    background: color-mix(in srgb, var(--nv-surface-1), var(--nv-surface-2));
    color: var(--nv-text);
    text-decoration: none;
  }

  .lb-podium-card.is-rank-1 {
    order: 2;
    min-height: 352px;
    padding-top: var(--nv-space-12);
  }

  .lb-podium-card.is-rank-2 {
    order: 1;
    min-height: 312px;
  }

  .lb-podium-card.is-rank-3 {
    order: 3;
    min-height: 292px;
  }

  /* Place number on the top edge (a canvas ring cuts it out of the card). #1 is the one accent. */
  .lb-place {
    position: absolute;
    top: -20px;
    left: 50%;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--nv-line-strong);
    border-radius: 50%;
    background: var(--nv-surface-3);
    color: var(--nv-text);
    font-family: var(--nv-font-mono);
    font-size: var(--nv-fs-16);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
    transform: translateX(-50%);
    box-shadow: 0 0 0 4px var(--nv-bg);
  }

  .lb-place b {
    font-weight: inherit;
  }

  .lb-place svg {
    position: absolute;
    top: -24px;
    width: 20px;
    height: 20px;
    color: var(--nv-accent-text);
  }

  .is-rank-1 .lb-place {
    border-color: transparent;
    background: var(--nv-accent);
    color: var(--nv-on-accent);
  }

  .lb-avatar {
    flex: none;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 50%;
    background: var(--nv-surface-3);
    color: var(--nv-text-2);
    font-weight: var(--nv-fw-medium);
    line-height: 1;
  }

  .lb-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .lb-avatar-xl {
    width: 88px;
    height: 88px;
    margin-bottom: var(--nv-space-2);
    font-size: 32px;
    box-shadow: 0 0 0 4px var(--nv-surface-1), 0 0 0 5px var(--nv-line-strong);
  }

  .is-rank-1 .lb-avatar-xl {
    width: 108px;
    height: 108px;
    font-size: 40px;
  }

  .lb-avatar-md {
    width: 40px;
    height: 40px;
    font-size: var(--nv-fs-16);
  }

  .lb-name {
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-1);
    min-width: 0;
    max-width: 100%;
  }

  .lb-name b {
    overflow: hidden;
    font-weight: var(--nv-fw-medium);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lb-podium-card .lb-name {
    font-size: var(--nv-fs-18);
  }

  .is-rank-1 .lb-name {
    font-size: var(--nv-fs-22);
    letter-spacing: var(--nv-tracking-tight);
  }

  /* Premium: the product's Premium line icon in the accent ink (the one Premium colour). */
  .lb-pro {
    flex: none;
    display: inline-grid;
    color: var(--nv-premium);
  }

  .lb-pro svg {
    width: 16px;
    height: 16px;
  }

  /* The address (signature). When space runs out the host gives way first, the name stays. */
  .lb-address {
    display: inline-flex;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    font-size: var(--nv-fs-12);
    line-height: 16px;
  }

  .lb-address .nv-address-host {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .lb-address .nv-address-name {
    flex: 0 0 auto;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .lb-medals {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--nv-space-1);
    min-height: 24px;
  }

  /* Medals are the colour on this page, but a board of them never moves at once: at rest they hold
     still, and the row or card under the pointer (or in keyboard focus) plays its sweep once. */
  .lb-medals .nb-medal::after,
  .lb-medals .nb-medal svg,
  .lb-medals .nb-fx,
  .lb-medals .nb-fx::before,
  .lb-medals .nb-fx::after {
    animation: none;
  }

  @media (prefers-reduced-motion: no-preference) {
    :is(a.lb-row, a.lb-podium-card):is(:hover, :focus-visible) .lb-medals .nb-medal::after {
      animation: nbSweepOnce 900ms var(--nv-ease) both;
    }
  }

  .lb-views {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--nv-space-2);
    color: var(--nv-text);
    font-family: var(--nv-font-figure);
    font-variant-numeric: tabular-nums;
  }

  .lb-views svg {
    width: 16px;
    height: 16px;
    color: var(--nv-text-3);
  }

  .lb-views b {
    font-weight: var(--nv-fw-medium);
  }

  .lb-podium-card .lb-views {
    margin-top: var(--nv-space-2);
    font-size: var(--nv-fs-16);
  }

  .lb-podium-card.is-skeleton {
    gap: var(--nv-space-3);
  }

  .lb-skel-avatar {
    width: 88px;
    height: 88px;
  }

  .lb-skel-short {
    width: 50%;
  }

  .lb-skel-rank {
    width: 20px;
  }

  /* ---- Ranked list ------------------------------------------------------------------- */
  .lb-board {
    max-width: 940px;
    margin: 0 auto;
  }

  .lb-list-head,
  .lb-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr) 176px 112px 16px;
    align-items: center;
    gap: var(--nv-space-3);
  }

  .lb-list-head {
    padding: 0 var(--nv-space-5) var(--nv-space-2);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    font-weight: var(--nv-fw-medium);
  }

  .lb-list-head > span:nth-child(2) {
    grid-column: 2;
  }

  .lb-head-views {
    text-align: right;
  }

  .lb-list {
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-lg);
    background: var(--nv-surface-1);
    list-style: none;
  }

  .lb-list > li + li {
    border-top: 1px solid var(--nv-line-soft);
  }

  .lb-row {
    min-height: 64px;
    padding: var(--nv-space-3) var(--nv-space-5);
    color: var(--nv-text);
    text-decoration: none;
    transition: background-color var(--nv-dur-1) var(--nv-ease);
  }

  a.lb-row:hover {
    background: color-mix(in srgb, var(--nv-surface-1), var(--nv-surface-2));
    color: var(--nv-text);
    text-decoration: none;
  }

  a.lb-row:focus-visible {
    outline-offset: -4px;
  }

  .lb-rank {
    color: var(--nv-text-3);
    font-family: var(--nv-font-mono);
    font-size: var(--nv-fs-14);
    font-weight: var(--nv-fw-medium);
    font-variant-numeric: tabular-nums;
  }

  .lb-person {
    display: flex;
    align-items: center;
    gap: var(--nv-space-3);
    min-width: 0;
  }

  .lb-who {
    display: grid;
    gap: var(--nv-space-1);
    min-width: 0;
  }

  .lb-row .lb-name {
    font-size: var(--nv-fs-14);
  }

  .lb-row .lb-medals {
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow: hidden;
  }

  .lb-row .lb-views {
    font-size: var(--nv-fs-14);
  }

  .lb-go {
    display: grid;
    color: var(--nv-text-3);
    transition: color var(--nv-dur-1) var(--nv-ease);
  }

  .lb-go svg {
    width: 16px;
    height: 16px;
  }

  a.lb-row:hover .lb-go {
    color: var(--nv-text);
  }

  .lb-row.is-skeleton {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .lb-row.is-skeleton .lb-who {
    flex: 1;
    gap: var(--nv-space-2);
  }

  .lb-updated {
    margin-top: var(--nv-space-4);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-12);
    text-align: center;
  }

  .lb-updated time {
    font-family: var(--nv-font-mono);
    font-variant-numeric: tabular-nums;
  }

  .lb-empty {
    max-width: 640px;
    margin: 0 auto;
  }

  /* ---- Claim CTA ----------------------------------------------------------------------- */
  .lb-cta {
    display: grid;
    justify-items: center;
    gap: var(--nv-space-6);
    max-width: 940px;
    margin: var(--nv-space-20) auto 0;
    padding: var(--nv-space-12) var(--nv-space-6);
    border: 1px solid var(--nv-line);
    border-radius: var(--nv-r-xl);
    background: var(--nv-surface-1);
    text-align: center;
  }

  .lb-cta-mark {
    width: 40px;
    height: 40px;
    margin: 0 auto var(--nv-space-4);
  }

  .lb-cta h2 {
    font-size: clamp(28px, 3.4vw, 36px);
    letter-spacing: var(--nv-tracking-tight);
  }

  .lb-cta-copy p {
    max-width: 48ch;
    margin: var(--nv-space-2) auto 0;
    color: var(--nv-text-2);
    font-size: var(--nv-fs-16);
    line-height: var(--nv-lh-body);
  }

  .lb-claim {
    display: grid;
    gap: var(--nv-space-2);
    width: min(100%, 560px);
  }

  .lb-claim-row {
    display: flex;
    gap: var(--nv-space-2);
  }

  .lb-claim-field {
    flex: 1;
    min-width: 0;
  }

  .lb-claim-field input {
    font-size: var(--nv-fs-16);
  }

  .lb-claim-status {
    color: var(--nv-text-3);
    font-size: var(--nv-fs-13);
  }

  .lb-claim-status[data-state="ok"] { color: var(--nv-success); }
  .lb-claim-status[data-state="error"] { color: var(--nv-danger); }
  .lb-claim-status[data-state="checking"] { color: var(--nv-text-2); }
  .lb-claim-status[data-state="paid"] { color: var(--nv-accent-text); }

  /* ---- Footer ------------------------------------------------------------------------- */
  .lb-footer {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--nv-space-3) var(--nv-space-6);
    max-width: calc(1120px + 2 * var(--nv-gutter));
    margin: 0 auto;
    padding: var(--nv-space-8) var(--nv-gutter) var(--nv-space-10);
    color: var(--nv-text-3);
    font-size: var(--nv-fs-13);
  }

  .lb-footer-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--nv-space-2);
  }

  .lb-footer-brand .nova-mark-mono {
    color: var(--nv-accent);
    font-size: 16px;
  }

  .lb-footer nav {
    display: flex;
    flex-wrap: wrap;
    gap: var(--nv-space-5);
  }

  .lb-footer a {
    color: var(--nv-text-2);
  }

  .lb-footer a:hover {
    color: var(--nv-text);
  }

  /* ---- Responsive ---------------------------------------------------------------------- */
  @media (max-width: 860px) {
    .lb-list-head,
    .lb-row {
      grid-template-columns: 32px minmax(0, 1fr) 96px 16px;
    }

    .lb-row .lb-medals,
    .lb-head-badges {
      display: none;
    }
  }

  /* Phones: compact and calm (r160 rhythm kept, on the 4px grid). */
  @media (max-width: 640px) {
    .lb-nav {
      padding-top: max(var(--nv-space-2), env(safe-area-inset-top, 0px));
    }

    .lb-nav-inner {
      min-height: 52px;
      padding: var(--nv-space-1) var(--nv-space-1) var(--nv-space-1) var(--nv-space-3);
    }

    .lb-logo img {
      height: 24px;
    }

    .lb-login {
      display: none;
    }

    .lb-hero {
      gap: var(--nv-space-2);
      padding: var(--nv-space-7) 0 var(--nv-space-5);
    }

    .lb-hero h1 {
      font-size: clamp(28px, 8.4vw, 32px);
      letter-spacing: var(--nv-tracking-tight);
    }

    .lb-lead {
      font-size: var(--nv-fs-14);
    }

    .lb-tabs > button {
      padding-inline: var(--nv-space-4);
    }

    .lb-podium {
      grid-template-columns: repeat(2, minmax(0, 1fr));
      gap: var(--nv-space-7) var(--nv-space-3);
      margin: var(--nv-space-6) auto;
    }

    .lb-podium[data-count="1"] {
      grid-template-columns: minmax(0, 1fr);
    }

    .lb-podium-card {
      gap: var(--nv-space-2);
    }

    .lb-podium-card.is-rank-1 {
      grid-column: 1 / -1;
      order: 0;
      min-height: 0;
      padding: var(--nv-space-7) var(--nv-space-4) var(--nv-space-4);
    }

    .lb-podium-card.is-rank-2,
    .lb-podium-card.is-rank-3 {
      min-height: 0;
      padding: var(--nv-space-8) var(--nv-space-3) var(--nv-space-4);
    }

    .lb-podium-card.is-rank-2 { order: 1; }
    .lb-podium-card.is-rank-3 { order: 2; }

    .lb-place {
      top: -16px;
      width: 32px;
      height: 32px;
      font-size: var(--nv-fs-14);
    }

    .lb-place svg {
      top: -20px;
      width: 16px;
      height: 16px;
    }

    .is-rank-1 .lb-avatar-xl {
      width: 76px;
      height: 76px;
      font-size: 28px;
    }

    .is-rank-2 .lb-avatar-xl,
    .is-rank-3 .lb-avatar-xl {
      width: 64px;
      height: 64px;
      font-size: 24px;
    }

    .is-rank-2 .lb-name,
    .is-rank-3 .lb-name {
      font-size: var(--nv-fs-16);
    }

    .is-rank-2 .lb-medals,
    .is-rank-3 .lb-medals {
      display: none;
    }

    /* #2 and #3 are half-width cards: the slug alone tells them apart («/kiravolt», as on discover), so the
       host never breaks mid-word («nova-link.l…»). */
    .is-rank-2 .lb-host,
    .is-rank-3 .lb-host {
      display: none;
    }

    .lb-list-head {
      display: none;
    }

    .lb-list-head,
    .lb-row {
      grid-template-columns: 24px minmax(0, 1fr) auto;
      padding-inline: var(--nv-space-4);
    }

    .lb-row {
      min-height: 56px;
      padding-block: var(--nv-space-2);
    }

    .lb-go {
      display: none;
    }

    .lb-cta {
      gap: var(--nv-space-4);
      margin-top: var(--nv-space-8);
      padding: var(--nv-space-6) var(--nv-space-4);
      border-radius: var(--nv-r-lg);
    }

    .lb-cta-mark {
      width: 32px;
      height: 32px;
      margin-bottom: var(--nv-space-3);
    }

    .lb-cta h2 {
      font-size: var(--nv-fs-28);
    }

    .lb-cta-copy p {
      font-size: var(--nv-fs-14);
    }

    .lb-claim-row {
      flex-direction: column;
    }

    .lb-claim-row .primary {
      width: 100%;
    }

    .lb-footer {
      justify-content: center;
      text-align: center;
    }
  }

  /* The <picture> swaps the lockup for the mark here. */
  @media (max-width: 420px) {
    .lb-logo img {
      height: 28px;
    }
  }

  /* r180: on the narrowest phones the language name stays whole («Русский», not «Русск») next to
     «Создать страницу». */
  @media (max-width: 360px) {
    .lb-nav-inner {
      gap: var(--nv-space-1);
      padding-left: var(--nv-space-2);
    }

    .lb-nav-actions {
      gap: var(--nv-space-1);
    }

    .lb-nav-actions > a {
      --btn-px: 8px;
      font-size: var(--nv-fs-13);
    }

    .lb-nav .nova-language-select {
      padding-inline: 8px 26px;
    }

    .lb-nav .nova-language-switcher.is-select::after {
      right: 10px;
    }
  }

  /* r180: touch targets: header buttons (landscape too), period tabs, footer links (a taller touch
     area, same look; 13px centres a 44px target on the 18px line). */
  @media (pointer: coarse) {
    .lb-nav-actions > a {
      --btn-h: var(--nv-hit);
    }

    .lb-tabs > button {
      min-height: var(--nv-hit);
    }

    .lb-footer a {
      padding-block: 13px;
      margin-block: -13px;
    }

    /* The logo link keeps its look and gets a 44px hit area around it (as on the landing). */
    .lb-logo {
      position: relative;
    }

    .lb-logo::after {
      content: "";
      position: absolute;
      inset: -10px;
    }
  }
}
