.ranker {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  align-items: center;
  width: 100%;
}

.ranker-stage {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  align-items: center;
  justify-content: center;
  min-height: clamp(10rem, 26vw, 16rem);
}

.ranker-meta {
  margin: 0;
  display: flex;
  gap: var(--space-3);
  align-items: baseline;
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--c-ink-muted);
}

.ranker-meta .count {
  color: var(--c-ink);
}

.ranker-meta .steps {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-transform: none;
  font-weight: 400;
}

/* The bar answers the question every participant asks: how much longer is this
   going to take? Merge sort's step count is known exactly, so it can be honest. */
.ranker-bar {
  width: 100%;
  max-width: 30rem;
  height: 6px;
  border-radius: 999px;
  background: var(--c-line);
  overflow: hidden;
}

.ranker-bar-fill {
  height: 100%;
  background: var(--c-ink-muted);
  transform-origin: left center;
  transition: transform 220ms ease;
}

.ranker-question {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--c-ink);
  text-align: center;
}

/* --- The pair ------------------------------------------------------------ */

.matchup {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  width: 100%;
}

@media (max-width: 44rem) {
  .matchup {
    grid-template-columns: 1fr;
  }
}

.option {
  font: inherit;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-3);
  min-height: clamp(6.5rem, 15vw, 10rem);
  padding: var(--space-6);
  cursor: pointer;
  text-align: left;

  background: var(--hue-tint);
  color: var(--c-ink);
  border: 2px solid transparent;
  border-radius: var(--radius);
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.option:hover {
  border-color: var(--hue);
  transform: translateY(-2px);
  box-shadow: var(--shadow-raised);
}

.option:active {
  transform: translateY(0);
}

.option-name {
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.25;
  text-wrap: balance;
}

.option-key {
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: var(--hue);
  color: var(--c-ink-inverse);
  font-size: var(--text-sm);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --- The ranking --------------------------------------------------------- */

.ranker-result {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  align-items: center;
}

.result-label {
  margin: 0;
  font-size: var(--text-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--c-ink-muted);
}

.ranking {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 34rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  counter-reset: rank;
}

.rank {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--hue-tint);
  color: var(--c-ink);
  border-left: 4px solid var(--hue);
  animation: rank-in 380ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

/* The list settles from the top down, so the eye reads the winner first. */
.rank:nth-child(1) {
  animation-delay: 0ms;
}
.rank:nth-child(2) {
  animation-delay: 55ms;
}
.rank:nth-child(3) {
  animation-delay: 110ms;
}
.rank:nth-child(4) {
  animation-delay: 165ms;
}
.rank:nth-child(5) {
  animation-delay: 220ms;
}
.rank:nth-child(n + 6) {
  animation-delay: 275ms;
}

@keyframes rank-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.rank-number {
  display: grid;
  place-items: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--hue);
  color: var(--c-ink-inverse);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rank-name {
  font-weight: 600;
  text-wrap: balance;
}

/* The top priority is the point of the whole exercise: let it carry weight. */
.rank:first-child .rank-name {
  font-size: var(--text-lg);
  font-weight: 700;
}

/* --- Setup --------------------------------------------------------------- */

.ranker-options {
  width: 100%;
  max-width: 28rem;
}

.ranker-options textarea {
  font: inherit;
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--c-ink);
  background: var(--c-paper);
  border: 1px solid var(--c-line);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  width: 100%;
  resize: vertical;
  min-height: 8rem;
}

.option-chip {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  min-height: 36px;
  border-radius: 999px;
  background: var(--hue-tint);
  color: var(--c-ink);
  font-weight: 600;
}

.ranker-hint {
  margin: 0;
  color: var(--c-ink-muted);
  font-size: var(--text-sm);
  text-align: center;
}

.ranker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: center;
  align-items: center;
}

/* --- Fullscreen ---------------------------------------------------------- */

.toy.is-fullscreen .ranker {
  justify-content: center;
  height: 100%;
}

.toy.is-fullscreen .option-name {
  font-size: var(--text-xl);
}

.toy.is-fullscreen .ranker-options {
  opacity: 0;
  transition: opacity 200ms ease;
}

.toy.is-fullscreen .ranker-options:focus-within,
.toy.is-fullscreen:hover .ranker-options {
  opacity: 1;
}
