/* Custom properties */
:root {
  --earth-size: 2.3625rem;
  --luna-moon-size: 0.675rem;
}

/* Media queries */
@media (max-width: 480px) {
  :root {
    --earth-size: .75rem;
    --earth-moon-size: 0.21rem;
  }

  .sun {
    width: 4rem;
    height: 4rem;
  }
}

@media (max-width: 768px) {
  :root {
    --earth-size: 1.5rem;
    --luna-moon-size: 0.42rem;
  }

  .sun {
    width: 6rem;
    height: 6rem;
  }
}

@media (max-width: 1024px) {
  :root {
    --earth-size: 2rem;
    --luna-moon-size: 0.56rem;
  }

  .sun {
    width: 8rem;
    height: 8rem;
  }
}

/* Keyframes */
@keyframes orbit {
  0% {
    transform: rotate(var(--rotation))
      translateX(var(--distance))
      translateY(-50%)
      rotate(calc(-1 * var(--rotation)));
  }
  100% {
    transform: rotate(calc(var(--rotation) + 360deg))
      translateX(var(--distance))
      translateY(-50%)
      rotate(calc(-1 * var(--rotation) - 360deg));
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes glowing {
  0% {
    box-shadow: 0 0 5px #f39c12, 0 0 10px #f39c12, 0 0 15px #f39c12, 0 0 20px #f39c12;
  }
  50% {
    box-shadow: 0 0 10px #f39c12, 0 0 20px #f39c12, 0 0 30px #f39c12, 0 0 40px #f39c12;
  }
  100% {
    box-shadow: 0 0 5px #f39c12, 0 0 10px #f39c12, 0 0 15px #f39c12, 0 0 20px #f39c12;
  }
}

@keyframes twinkling {
  0% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.7;
  }
}

html, body {
  font-family: 'Arial', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
  background-color: #000;
  color: #fff;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.solar-system {
  position: relative;
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

.sun {
  position: absolute;
  background-color: #f39c12;
  width: 10rem;
  height: 10rem;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  z-index: 4;
  animation-name: rotate, glowing;
  animation-duration: 2400s, 3s;
  animation-iteration-count: infinite, infinite;
  animation-timing-function: linear, ease-in-out;
}

.sun::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(243, 156, 18, 0.7), rgba(243, 156, 18, 0.2) 70%);
  z-index: -1;
  animation: glowing 3s infinite ease-in-out;
}

.planet, .moon {
  position: absolute;
  opacity: 0;
  border-radius: 50%;
  animation-name: orbit;
  animation-duration: var(--duration);
  animation-iteration-count: infinite;
  transform: rotate(var(--rotation)) translateX(calc(-50% + var(--distance)em)) translateY(-50%);
  transform-style: preserve-3d;
  animation-timing-function: cubic-bezier(0.3, 1, 0.4, 0.8);
  transition: transform 0.5s ease;
}

.planet {
  z-index: 5;
}

.planet:before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  z-index: 1;
}

.planet.mars::before, .planet.earth::before, .planet.venus::before {
  top: -150%;
  left: -150%;
  width: 400%;
  height: 400%;
}

.planet.mercury::before {
  top: -350%;
  left: -350%;
  width: 800%;
  height: 800%;
}

.planet:hover {
  z-index: 15;
}

.planet:hover::before, .planet.clicked::before {
  content: attr(data-label);
  position: absolute;
  background-color: transparent;
  transition: all 0.3s ease-in-out;
}

.planet-label {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.8rem;
  white-space: nowrap;
  text-align: center;
  pointer-events: none;
  user-select: none;
  opacity: 0;
  transition: opacity 0.3s;
  background-color: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 4px 8px;
  border-radius: 5px;
  text-shadow: 0 0 2px #000;
  margin-top: 5px;
}

.rotation-counter {
  position: absolute;
  top: -15px;
  left: -15px;
  width: 30px;
  height: 30px;
  background-color: rgba(255, 255, 255, 0);
  border-radius: 50%;
  text-align: center;
  line-height: 30px;
  font-size: 12px;
  font-weight: bold;
  pointer-events: none;
  user-select: none;
}

.planet:hover > .planet-label, .planet.clicked > .planet-label {
  opacity: 1;
}

.moon {
  background-color: #ccc;
  z-index: 4;
}

.mercury {
  background-color: #c8c8c8;
  width: calc(var(--earth-size) * 0.383);
  height: calc(var(--earth-size) * 0.383);
  --distance: 4rem;
  --duration: 88s;
  --rotation: 320deg;
}

.venus {
  background-color: #f1c40f;
  width: calc(var(--earth-size) * 0.949);
  height: calc(var(--earth-size) * 0.949);
  --distance: 7rem;
  --duration: 225s;
  --rotation: 10deg;
}

.earth {
  background-color: #3498db;
  width: var(--earth-size);
  height: var(--earth-size);
  --distance: 10rem;
  --duration: 365s;
  --rotation: 40deg;
}

.mars {
  background-color: #e74c3c;
  width: calc(var(--earth-size) * 0.57);
  height: calc(var(--earth-size) * 0.57);
  --distance: 12.5rem;
  --duration: 687s;
  --rotation: 60deg;
}

.jupiter {
  background-color: #f1c40f;
  width: calc(var(--earth-size) * 2);
  height: calc(var(--earth-size) * 2);
  --distance: 15rem;
  --duration: 4300s;
  --rotation: 80deg;
}

.saturn {
  background-color: #e67e22;
  width: calc(var(--earth-size) * 1.714);
  height: calc(var(--earth-size) * 1.714);
  position: relative;
  --distance: 17.5rem;
  --duration: 10750s;
  --rotation: 100deg;
}

.saturn::before {
  content: '';
  position: absolute;
  width: 9%;
  height: 94%;
  transform: rotate(60deg);
  top: -8%;
  left: 40%;
  background-color: #e67e22;
  z-index: 3;
}

.saturn::after {
  content: '';
  position: absolute;
  width: 150%;
  height: 30%;
  border-radius: 50%;
  border: 2px solid #f1c40f;
  box-sizing: border-box;
  transform: rotate(-30deg) scale(1.2);
  top: 40%;
  left: -25%;
  z-index: 0;
}

.uranus {
  background-color: #5da6e1;
  width: calc(var(--earth-size) * 1.556);
  height: calc(var(--earth-size) * 1.556);
  --distance: 20rem;
  --duration: 30600s;
  --rotation: 120deg;
}

.neptune {
  background-color: #4a6f8d;
  width: calc(var(--earth-size) * 1.556);
  height: calc(var(--earth-size) * 1.556);
  --distance: 22.5rem;
  --duration: 60225s;
  --rotation: 140deg;
}

/* Earth */
.moon-luna {
  width: var(--luna-moon-size);
  height: var(--luna-moon-size);
  --distance: 1rem;
  --duration: 27s;
  --rotation: 0deg;
}

/* Mars */
.moon-phobos,
.moon-deimos {
  width: calc(var(--luna-moon-size) * 0.5);
  height: calc(var(--luna-moon-size) * 0.5);
}

.moon-phobos {
  --distance: 0.5rem;
  --duration: 8s;
  --rotation: 0deg;
}

.moon-deimos {
  --distance: 0.75rem;
  --duration: 30s;
  --rotation: 45deg;
}

/* Jupiter */
.moon-io,
.moon-europa,
.moon-ganymede,
.moon-callisto {
  width: calc(var(--luna-moon-size) * 0.666);
  height: calc(var(--luna-moon-size) * 0.666);
}

.moon-io {
  --distance: 1.5rem;
  --duration: 42s;
  --rotation: 0deg;
}

.moon-europa {
  --distance: 2rem;
  --duration: 85s;
  --rotation: 30deg;
}

.moon-ganymede {
  --distance: 2.5rem;
  --duration: 172s;
  --rotation: 60deg;
}

.moon-callisto {
  --distance: 3rem;
  --duration: 400s;
  --rotation: 90deg;
}

/* Saturn */
.moon-titan {
  width: calc(var(--luna-moon-size) * 1.333);
  height: calc(var(--luna-moon-size) * 1.333);
  --distance: 1.75rem;
  --duration: 382s;
  --rotation: 0deg;
}

/* Uranus */
.moon-titania,
.moon-oberon {
  width: var(--luna-moon-size);
  height: var(--luna-moon-size);
}

.moon-titania {
  --distance: 1.25rem;
  --duration: 42s;
  --rotation: 0deg;
}

.moon-oberon {
  --distance: 1.75rem;
  --duration: 65s;
  --rotation: 45deg;
}

/* Neptune */
.moon-triton {
  width: var(--luna-moon-size);
  height: var(--luna-moon-size);
  --distance: 1.25rem;
  --duration: 141s;
  --rotation: 0deg;
}

.star {
  position: absolute;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 1s ease;
  opacity: 0.8;
  z-index: 1;
  animation: twinkling 1.5s infinite;
  transition: opacity 0.25s ease-in-out;
}

.star:nth-of-type(1) {
  animation-delay: 4s;
}

.star:nth-of-type(2) {
  animation-delay: 2s;
}

.star:nth-of-type(3) {
  animation-delay: 7s;
}