* {
  box-sizing: border-box;
}

body {
  display: grid;
  min-height: 100vh;
  margin: 0;
  padding: 2rem;
  place-items: center;
  font-family: Arial, sans-serif;
  background-color: #f4f4f4;
  color: #222;
}

main {
  width: min(700px, 100%);
}

h1,
p {
  text-align: center;
}

.animation-track {
  width: 100%;
  margin-top: 2rem;
  padding: 1rem;
  overflow: hidden;
  border: 3px solid #333;
  border-radius: 0.75rem;
  background-color: #fff;
}

.animated-box {
  display: grid;
  width: 100px;
  height: 100px;
  place-items: center;
  border-radius: 0.5rem;
  background-color: #4f46e5;
  color: #fff;
  font-weight: bold;
  animation: move-and-change 3s ease-in-out infinite;
}

@keyframes move-and-change {
  from {
    transform: translateX(0);
    background-color: #4f46e5;
  }

  to {
    transform: translateX(calc(min(700px, 100vw - 4rem) - 138px));
    background-color: #e11d48;
  }
}

/* If the user requests reduced motion, this standard fix makes animations finish almost instantly instead of repeatedly moving, while !important ensures it overrides component animation settings. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
