#top-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 18px;
  width: 100%;
  margin: 0;
  padding: 6px 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: #126fd2 linear-gradient(to right, #126fd2, #773adc);
  color: #fff;
  font-size: 14px;
}

#top-bar a {
  color: #fff;
  text-decoration: none;
}

#top-bar a:hover {
  text-decoration: underline;
}

#top-bar a:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 4px;
  border-radius: 2px;
}

.theme-toggle-wrapper {
  position: relative;
  display: inline-block;
  flex-shrink: 0;
  width: 50px;
  height: 26px;
  margin-left: 4px;
  margin-right: 2px;
}

#theme-toggle {
  position: absolute;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.6);
  border-radius: 26px;
  background: rgba(255, 255, 255, 0.2);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.toggle-slider::before {
  position: absolute;
  top: 50%;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  content: "";
  transform: translateY(-50%);
  transition: transform 0.3s ease;
}

#theme-toggle:hover + .toggle-slider {
  border-color: rgba(255, 255, 255, 0.9);
}

#theme-toggle:focus-visible + .toggle-slider {
  outline: 2px solid #fff;
  outline-offset: 4px;
}

#theme-toggle:checked + .toggle-slider {
  border-color: #773adc;
  background: rgba(117, 58, 220, 0.8);
}

#theme-toggle:checked + .toggle-slider::before {
  transform: translate(24px, -50%);
}

#theme-toggle:disabled {
  cursor: not-allowed;
}

#theme-toggle:disabled + .toggle-slider {
  opacity: 0.5;
}

@media (max-width: 420px) {
  #top-bar {
    gap: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toggle-slider,
  .toggle-slider::before {
    transition: none;
  }
}
