.theme-toggle-container {
  position: static;
  padding: 0;
}

.theme-switch {
  position: relative;
  display: inline-flex;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.theme-switch.is-rippling .theme-switch__track {
  animation: themeTrackSlosh 0.52s cubic-bezier(0.33, 1, 0.38, 1);
}

@keyframes themeTrackSlosh {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.05) rotate(-1.5deg); }
  55% { transform: scale(0.97) rotate(1deg); }
  80% { transform: scale(1.02) rotate(-0.5deg); }
}

.theme-switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}

.theme-switch__track {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 68px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius, 2px);
  background: color-mix(in srgb, var(--bg) 60%, transparent);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.3s ease;
}

.theme-switch__track::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent, var(--accent-soft), transparent);
  transform: translateX(-100%);
  transition: transform 0.5s ease;
}

.theme-switch__track:hover::before {
  transform: translateX(100%);
}

.theme-switch__track:hover {
  border-color: var(--accent);
  box-shadow: 0 0 16px var(--accent-glow);
}

.theme-switch__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  color: var(--muted);
  transition: color 0.3s ease, opacity 0.3s ease;
  z-index: 1;
}

.theme-switch__icon svg {
  width: 12px;
  height: 12px;
}

.theme-switch__droplet {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(
    circle,
    color-mix(in srgb, var(--accent) 42%, transparent) 0%,
    color-mix(in srgb, var(--accent) 14%, transparent) 38%,
    transparent 72%
  );
  transform: scale(0);
  animation: themeSwitchDroplet 0.56s cubic-bezier(0.33, 1, 0.38, 1) forwards;
}

@keyframes themeSwitchDroplet {
  0% {
    transform: scale(0);
    opacity: 0.9;
  }
  45% {
    opacity: 0.55;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

.theme-switch__thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius, 2px);
  border: 1px solid var(--line-hover, var(--line));
  background: var(--text);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--text) 20%, transparent);
  transition: left 0.38s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  z-index: 2;
}

.theme-switch.is-rippling .theme-switch__thumb {
  transition-duration: 0.48s;
  transition-timing-function: cubic-bezier(0.33, 1, 0.38, 1);
}

.theme-switch input:checked + .theme-switch__track .theme-switch__thumb {
  left: calc(100% - 28px);
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.theme-switch input:not(:checked) + .theme-switch__track .theme-switch__icon--moon {
  color: var(--text);
  opacity: 1;
}

.theme-switch input:checked + .theme-switch__track .theme-switch__icon--sun {
  color: var(--text);
  opacity: 1;
}

.theme-switch input:focus-visible + .theme-switch__track {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .theme-switch.is-rippling .theme-switch__track {
    animation: none;
  }

  .theme-switch__droplet {
    display: none;
  }
}

@media (max-width: 768px) {
  .theme-switch__track {
    width: 60px;
    height: 30px;
    padding: 0 7px;
  }

  .theme-switch__thumb {
    width: 20px;
    height: 20px;
    top: 4px;
    left: 4px;
  }

  .theme-switch input:checked + .theme-switch__track .theme-switch__thumb {
    left: calc(100% - 24px);
  }
}