.theme-toggle {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.theme-toggle__track {
  --toggle-bg: rgba(255, 255, 255, 0.78);
  --toggle-border: rgba(125, 145, 170, 0.2);
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  width: 92px;
  height: 52px;
  padding: 6px 10px;
  border: 1px solid var(--toggle-border);
  border-radius: 999px;
  background: var(--toggle-bg);
  box-shadow: 0 16px 34px rgba(63, 82, 108, 0.12);
  backdrop-filter: blur(14px);
  transition:
    background-color 0.28s ease,
    border-color 0.28s ease,
    box-shadow 0.28s ease,
    transform 0.28s ease;
}

.theme-toggle:hover .theme-toggle__track,
.theme-toggle:focus-visible .theme-toggle__track {
  transform: translateY(-1px);
  box-shadow: 0 18px 36px rgba(63, 82, 108, 0.16);
}

.theme-toggle:focus-visible {
  outline: none;
}

.theme-toggle:focus-visible .theme-toggle__track {
  box-shadow:
    0 0 0 4px rgba(107, 144, 184, 0.16),
    0 18px 36px rgba(63, 82, 108, 0.16);
}

.theme-toggle__icon {
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  font-size: 0.95rem;
  line-height: 1;
  color: #6a7688;
  transition:
    opacity 0.28s ease,
    transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    color 0.28s ease;
}

.theme-toggle__thumb {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffffff 0%, #edf2f9 100%);
  box-shadow:
    0 10px 18px rgba(56, 72, 95, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition:
    transform 0.38s cubic-bezier(0.22, 1, 0.36, 1),
    background 0.28s ease,
    box-shadow 0.28s ease;
}

html[data-theme="dark"] .theme-toggle__track {
  --toggle-bg: rgba(19, 28, 39, 0.82);
  --toggle-border: rgba(145, 170, 204, 0.18);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] .theme-toggle__thumb {
  transform: translateX(40px);
  background: linear-gradient(180deg, #dce6f3 0%, #bac9da 100%);
  box-shadow:
    0 10px 18px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

html[data-theme="dark"] .theme-toggle__icon--sun {
  opacity: 0.45;
  transform: rotate(-35deg) scale(0.9);
  color: #9eacc0;
}

html[data-theme="dark"] .theme-toggle__icon--moon {
  opacity: 1;
  transform: rotate(0deg) scale(1.06);
  color: #e9f1ff;
}

html:not([data-theme="dark"]) .theme-toggle__icon--sun {
  opacity: 1;
  transform: rotate(0deg) scale(1.06);
  color: #5f6d80;
}

html:not([data-theme="dark"]) .theme-toggle__icon--moon {
  opacity: 0.45;
  transform: rotate(35deg) scale(0.9);
  color: #9aa8bb;
}

.theme-toggle.is-animating .theme-toggle__track {
  animation: toggle-pop 0.42s ease;
}

@keyframes toggle-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

@media (max-width: 920px) {
  .theme-toggle {
    top: 16px;
    right: 16px;
  }
}

@media (max-width: 640px) {
  .theme-toggle {
    top: 12px;
    right: 12px;
  }

  .theme-toggle__track {
    width: 84px;
    height: 48px;
  }

  .theme-toggle__thumb {
    width: 36px;
    height: 36px;
  }

  html[data-theme="dark"] .theme-toggle__thumb {
    transform: translateX(34px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle__track,
  .theme-toggle__icon,
  .theme-toggle__thumb,
  .theme-toggle.is-animating .theme-toggle__track {
    transition: none;
    animation: none;
  }
}
