I understand that に can be used to mark the agent of an intransitive verb, but I often see it being used with adjectives instead. For example, in the sentence:
私にはできる
As for me, I can do it.
に here marks the agent of the verb. The same thing can be said about 私にはわかる. However, there are cases where に are followed by adjectives, which, although I intuitively understand the meaning, do not understand the grammar behind them.
私には金が必要です。
As for me, I need money.
寝るには早すぎる。
It's too early to sleep.
電車に詳しいです。
to know a lot about trains.
体にいいです。
It's good for your body.
子供に怖い×
Scary to children. (apparently incorrect.)
What is the function of に(は) here? In what situations can this be used?
Edit: I found a related question, and this linked one, but the first one seems to have conflicts about in which situations you can do this and the second question only uses に to mark the agent of intransitive/potential verbs. This question also asks something very similar, but the answer doesn't really address why 「子供に怖い」would be wrong.