/* The leaderboards page (/leaderboards): sample standings until the
   ranked API lands — a podium for the top three, a ladder below. */

.leaderboards .board {
  padding-block: var(--space-4) var(--space-5);
  text-align: center;

  .head .eyebrow {
    margin: 0 0 var(--space-2);
    color: var(--color-accent);
    font-size: var(--size-eyebrow);
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
  }

  .head .title {
    margin: 0;
    /* Off the scale on purpose: "LEADERBOARDS" is one twelve-letter word,
       and --size-display floors too high to keep it on a single line on a
       narrow screen. Tracks the viewport the whole way down instead. */
    font-size: clamp(1.25rem, 5.5vw, 4.5rem);
  }

  .head .season {
    margin: var(--space-2) 0 0;
    color: var(--color-muted);
    font-size: var(--size-small);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  /* --- the season picker --- */
  /* A <details> disclosure, not a native <select>, so the whole thing -- the
     plaque and the open list -- is ours to paint on every platform. */
  .seasons {
    position: relative;
    z-index: 5;
    display: inline-block;
    margin-top: var(--space-3);
    text-align: left;
  }

  /* The summary is a warm plaque, kin to the podium steps: a gold glow off the
     top edge over the night surface, a gilded rim, the buttons' gloss line. */
  .seasons summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    min-width: 10rem;
    padding: 0.6rem 1.1rem;
    border: 1px solid color-mix(in srgb, var(--gold-500) 32%, var(--color-rule));
    border-radius: var(--radius);
    background:
      radial-gradient(
        130% 150% at 50% -30%,
        color-mix(in srgb, var(--gold-500) 13%, transparent),
        transparent 62%
      ),
      var(--color-elevated);
    box-shadow:
      inset 0 1px 0 color-mix(in srgb, var(--gold-400) 22%, transparent),
      0 8px 22px color-mix(in srgb, var(--night-950) 55%, transparent);
    color: var(--color-text);
    font-size: var(--size-small);
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    list-style: none;
    cursor: pointer;
    transition:
      border-color var(--transition),
      box-shadow var(--transition),
      color var(--transition);
  }

  /* Drop the platform's own disclosure triangle; the caret below replaces it. */
  .seasons summary::-webkit-details-marker {
    display: none;
  }

  .seasons summary:hover {
    border-color: color-mix(in srgb, var(--color-accent) 60%, var(--color-rule));
    color: var(--color-accent-strong);
  }

  .seasons summary:focus-visible {
    outline: none;
    border-color: var(--color-accent);
    box-shadow:
      inset 0 1px 0 color-mix(in srgb, var(--gold-400) 30%, transparent),
      0 0 0 3px color-mix(in srgb, var(--color-accent) 22%, transparent);
  }

  .seasons .caret {
    flex: none;
    width: 0;
    height: 0;
    border-inline: 0.32rem solid transparent;
    border-top: 0.4rem solid var(--color-accent);
    transition:
      transform var(--transition),
      border-top-color var(--transition);
  }

  .seasons summary:hover .caret {
    border-top-color: var(--color-accent-strong);
  }

  /* The caret flips to point up while the menu is open. */
  .seasons[open] .caret {
    transform: rotate(180deg);
  }

  /* The open list: a gilded card of options, cut from the same cloth as the
     podium steps, floated below the plaque. */
  .seasons .options {
    position: absolute;
    left: 0;
    top: calc(100% + 0.5rem);
    min-width: 100%;
    margin: 0;
    padding: 0.4rem;
    list-style: none;
    border: 1px solid color-mix(in srgb, var(--gold-500) 30%, var(--color-rule));
    border-radius: 12px;
    background:
      radial-gradient(
        120% 80% at 50% 0%,
        color-mix(in srgb, var(--gold-500) 10%, transparent),
        transparent 60%
      ),
      var(--color-elevated);
    box-shadow: 0 18px 40px color-mix(in srgb, var(--night-950) 60%, transparent);
  }

  /* The plaque's padding, less the menu's own, so an option's label lands in
     the summary label's column and its bead in the caret's -- one straight
     edge down the left, one down the right. */
  .seasons .option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text);
    font: inherit;
    font-size: var(--size-small);
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
    text-align: left;
    cursor: pointer;
    transition:
      background-color var(--transition),
      color var(--transition);
  }

  /* A gold bead marks the chosen season; the empty slot holds the column. */
  .seasons .option::after {
    content: '';
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: transparent;
    transition: background-color var(--transition);
  }

  .seasons .option:hover {
    background-color: color-mix(in srgb, var(--gold-500) 12%, transparent);
    color: var(--color-accent-strong);
  }

  .seasons .option[aria-current='true'] {
    color: var(--color-accent);
  }

  .seasons .option[aria-current='true']::after {
    background: var(--color-accent);
    box-shadow: 0 0 8px color-mix(in srgb, var(--color-accent) 55%, transparent);
  }

  /* Only the chosen season is shown; the rest wait in the DOM. */
  .season-panel[hidden] {
    display: none;
  }

  /* --- the podium: second, first, third --- */
  .podium {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 16rem));
    justify-content: center;
    align-items: end;
    gap: var(--space-3);
    margin: var(--space-4) 0 0;
    padding: 0;
    list-style: none;
  }

  .step {
    position: relative;
    display: grid;
    justify-items: center;
    padding: var(--space-3) var(--space-2) var(--space-2);
    border: 1px solid var(--color-rule);
    border-radius: 14px;
    background:
      radial-gradient(
        120% 90% at 50% 0%,
        color-mix(in srgb, var(--step-metal) 14%, transparent),
        transparent 60%
      ),
      var(--color-elevated);
    box-shadow: 0 18px 40px color-mix(in srgb, var(--night-950) 55%, transparent);
  }

  /* Each place carries its metal; the champion stands a step higher. */
  .step.place-1 {
    --step-metal: var(--gold-400);
    order: 2;
    padding-block: var(--space-4) var(--space-3);
    border-color: color-mix(in srgb, var(--gold-400) 55%, var(--color-rule));
  }

  .step.place-2 {
    --step-metal: #c9ccd4; /* silver */
    order: 1;
  }

  .step.place-3 {
    --step-metal: #cd8a52; /* bronze */
    order: 3;
  }

  /* A trophy in the step's metal instead of a bare 1/2/3 (the number stays
     for screen readers). */
  .step .rank {
    position: absolute;
    top: -1.1rem;
    display: grid;
    place-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--step-metal);
    box-shadow: 0 4px 14px color-mix(in srgb, var(--night-950) 60%, transparent);
  }

  .step .rank svg {
    width: 1.3rem;
    height: 1.3rem;
    fill: var(--night-950);
  }

  .step .avatar {
    width: min(9rem, 60%);
    height: auto;
    border-radius: 50%;
    border: 3px solid var(--step-metal);
    box-shadow: 0 0 24px color-mix(in srgb, var(--step-metal) 35%, transparent);
  }

  .step.place-1 .avatar {
    width: min(11rem, 68%);
  }

  .step .merchant {
    margin-top: var(--space-2);
    font-family: var(--font-display);
    font-size: var(--size-h3);
    line-height: var(--leading-tight);
  }

  .step .hero {
    margin-top: 0.25rem;
    color: var(--color-muted);
    font-size: var(--size-small);
  }

  .step .score {
    margin-top: var(--space-2);
    color: var(--color-muted);
    font-size: var(--size-small);

    strong {
      color: var(--color-accent);
      font-size: 1.35em;
      font-weight: 600;
      margin-right: 0.35rem;
    }
  }

  /* --- the ladder below the podium --- */
  /* The four columns have a floor of about 400px between them, which a phone
     does not have. The table keeps its shape and this box does the scrolling,
     so the score stays reachable instead of being cut off the right edge. */
  .ladder-scroll {
    width: min(52rem, 100%);
    margin: var(--space-4) auto 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;

    &:focus-visible {
      outline: 2px solid var(--color-accent);
      outline-offset: 4px;
      border-radius: var(--radius);
    }
  }

  .ladder {
    width: 100%;
    min-width: 26rem;
    border-collapse: collapse;
    text-align: left;
  }

  .ladder th {
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--color-rule);
    color: var(--color-muted);
    font-size: var(--size-eyebrow);
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }

  .ladder td {
    padding: 0.7rem 0.9rem;
    border-bottom: 0.5px solid var(--color-rule);
  }

  .ladder tbody tr {
    transition: background-color var(--transition);
  }

  .ladder tbody tr:hover {
    background-color: color-mix(in srgb, var(--gold-500) 7%, transparent);
  }

  /* The standing is the point of the row, so it sits a step above the names
     beside it -- which means moving with the body size, not against it. */
  .ladder .rank {
    width: 3rem;
    color: var(--color-accent);
    font-size: var(--size-lead);
  }

  .ladder td.merchant {
    font-weight: 600;
  }

  .ladder td.hero {
    color: var(--color-muted);

    img {
      width: 2rem;
      height: 2rem;
      margin-right: 0.6rem;
      border-radius: 50%;
      border: 1px solid var(--color-rule);
      vertical-align: middle;
    }
  }

  .ladder th.score,
  .ladder td.score {
    text-align: right;
  }

  /* The score is the headline metric, so it carries the accent. */
  .ladder td.score {
    color: var(--color-accent);
  }

  .lead {
    max-width: 52ch;
    margin: var(--space-4) auto 0;
    color: var(--color-muted);
    font-size: var(--size-body);
  }

  .more {
    margin: var(--space-3) 0 0;
    color: var(--color-muted);
    font-size: var(--size-small);
  }

  @media (max-width: 48rem) {
    /* The podium stacks champion-first; the ladder tightens its padding. */
    .podium {
      grid-template-columns: minmax(0, 20rem);
    }

    .step.place-1 {
      order: 1;
    }

    .step.place-2 {
      order: 2;
    }

    .step.place-3 {
      order: 3;
    }

    .ladder th,
    .ladder td {
      padding-inline: 0.5rem;
    }
  }
}
