.rb {
  --rb-year-h: 1.05rem;
  --rb-gap: 0.7rem;
  --rb-dot: 0.72rem;
  /* centre of the dot row = year row + gap + half a dot */
  --rb-axis: calc(var(--rb-year-h) + var(--rb-gap) + (var(--rb-dot) / 2));
  margin: 0;
  padding: clamp(1.15rem, 2.5vw, 1.75rem);
  border: 1px solid var(--route);
  background: var(--atlas-sheet);
}

.rb-route {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.rb-route::before {
  position: absolute;
  top: calc(var(--rb-axis) - 1px);
  right: 0;
  left: 0;
  height: 2px;
  background: var(--route);
  content: "";
  transform: scaleX(0);
  transform-origin: left;
  animation: rb-route-reveal 900ms cubic-bezier(0.22, 1, 0.36, 1) 120ms forwards;
}

.rb-stop {
  position: relative;
  z-index: 1;
  display: grid;
  /* year / dot / label row A / label row B — odd stops label on A, even on
     B, so two neighbouring labels never share a baseline and can each take
     nearly two columns of width. */
  grid-template-rows: var(--rb-year-h) var(--rb-dot) 1lh 1lh;
  justify-items: center;
  row-gap: var(--rb-gap);
  min-width: 0;
  color: var(--carbon-soft);
  font-family: var(--font-mono);
  opacity: 0;
  text-align: center;
  animation: rb-stop-reveal 360ms ease-out forwards;
}

/* the dot is a real grid row, so the label can never collide with it */
.rb-stop::before {
  width: var(--rb-dot);
  height: var(--rb-dot);
  border: 2px solid var(--atlas-sheet);
  border-radius: 50%;
  background: var(--route);
  box-shadow: 0 0 0 1px var(--route);
  content: "";
  grid-row: 2;
}

.rb-stop:nth-child(1) { animation-delay: 280ms; }
.rb-stop:nth-child(2) { animation-delay: 390ms; }
.rb-stop:nth-child(3) { animation-delay: 500ms; }
.rb-stop:nth-child(4) { animation-delay: 610ms; }
.rb-stop:nth-child(5) { animation-delay: 720ms; }
.rb-stop:nth-child(6) { animation-delay: 830ms; }
.rb-stop:nth-child(7) { animation-delay: 940ms; }

.rb-stop:last-child::before {
  background: var(--schism);
  box-shadow: 0 0 0 1px var(--schism);
  animation: rb-now-pulse 2.4s ease-out 1.3s infinite;
}

.rb-year {
  grid-row: 1;
  align-self: end;
  color: var(--carbon);
  font-size: clamp(0.6rem, 1vw, 0.72rem);
  font-weight: 700;
  line-height: 1;
}

.rb-event {
  grid-row: 3;
  font-size: clamp(0.52rem, 0.85vw, 0.64rem);
  letter-spacing: 0.04em;
  line-height: 1.3;
  white-space: nowrap;
}

.rb-stop:nth-child(even) .rb-event {
  grid-row: 4;
  color: color-mix(in srgb, var(--carbon-soft) 78%, var(--atlas-sheet));
}

.rb-label {
  margin-top: 1.6rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--hairline);
  color: var(--carbon-soft);
  font-family: var(--font-mono);
  font-size: 0.61rem;
  letter-spacing: 0.07em;
  line-height: 1.55;
  text-transform: uppercase;
}

@keyframes rb-route-reveal {
  to { transform: scaleX(1); }
}

@keyframes rb-stop-reveal {
  to { opacity: 1; }
}

@keyframes rb-now-pulse {
  0%   { box-shadow: 0 0 0 1px var(--schism), 0 0 0 0 color-mix(in srgb, var(--schism) 45%, transparent); }
  70%  { box-shadow: 0 0 0 1px var(--schism), 0 0 0 0.6rem color-mix(in srgb, var(--schism) 0%, transparent); }
  100% { box-shadow: 0 0 0 1px var(--schism), 0 0 0 0 color-mix(in srgb, var(--schism) 0%, transparent); }
}

@media (max-width: 640px) {
  .rb {
    padding-right: 0.65rem;
    padding-left: 0.65rem;
  }

  .rb-stop {
    grid-template-rows: var(--rb-year-h) var(--rb-dot) 4.6rem;
  }

  /* not enough width for seven horizontal labels: run them down the page */
  .rb-event,
  .rb-stop:nth-child(even) .rb-event {
    grid-row: 3;
    color: var(--carbon-soft);
    writing-mode: vertical-rl;
    text-orientation: mixed;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rb-route::before,
  .rb-stop,
  .rb-stop:last-child::before {
    animation: none;
  }

  .rb-route::before {
    transform: scaleX(1);
  }

  .rb-stop {
    opacity: 1;
  }
}
