The mythology of the moon emphasizes especially those periods when it disappears—the three days of darkness in the lunar cycle and eclipses. Both are usually interpreted as the result of battles between some monster who devours or slays the moon and who subsequently regurgitates or revives it. The interregnum is interpreted as an evil period necessitating strict taboos against beginning any new or creative period (e.g., planting or sexual intercourse). In primitive hunting cultures the moon is frequently regarded as male and, particularly in regard to women, is understood as a preeminently evil or dangerous figure. In agricultural traditions the moon is usually regarded as female and is the benevolent ruler of the cyclical vegetative process.
The Torah revolutionized the mental framework of "civilized" mankind:
(16) God made the two great lights, the greater light to dominate the day and the lesser light to dominate the night, and the stars. (17) And God set them in the expanse of the sky to shine upon the earth, (18) to dominate the day and the night, and to separate light from darkness. And God saw that this was good.
(ב) ה' אֲדֹנֵ֗ינוּ מָֽה־אַדִּ֣יר שִׁ֭מְךָ בְּכָל־הָאָ֑רֶץ אֲשֶׁ֥ר תְּנָ֥ה ה֝וֹדְךָ֗ עַל־הַשָּׁמָֽיִם׃ ... (ד) כִּֽי־אֶרְאֶ֣ה שָׁ֭מֶיךָ מַעֲשֵׂ֣י אֶצְבְּעֹתֶ֑יךָ יָרֵ֥חַ וְ֝כוֹכָבִ֗ים אֲשֶׁ֣ר כּוֹנָֽנְתָּה׃
O LORD, our Lord, How majestic is Your name throughout the earth, You who have covered the heavens with Your splendor! ...When I behold Your heavens, the work of Your fingers, the moon and stars that You set in place.
(ה) לְעֹשֵׂ֣ה הַ֭שָּׁמַיִם בִּתְבוּנָ֑ה כִּ֖י לְעוֹלָ֣ם חַסְדּֽוֹ׃...(ז) לְ֭עֹשֵׂה אוֹרִ֣ים גְּדֹלִ֑ים כִּ֖י לְעוֹלָ֣ם חַסְדּֽוֹ׃ (ח) אֶת־הַ֭שֶּׁמֶשׁ לְמֶמְשֶׁ֣לֶת בַּיּ֑וֹם כִּ֖י לְעוֹלָ֣ם חַסְדּֽוֹ׃ (ט) אֶת־הַיָּרֵ֣חַ וְ֭כוֹכָבִים לְמֶמְשְׁל֣וֹת בַּלָּ֑יְלָה כִּ֖י לְעוֹלָ֣ם חַסְדּֽוֹ׃
(5) Who made the heavens with wisdom, His steadfast love is eternal...(7) Who made the great lights, His steadfast love is eternal; (8) the sun to dominate the day, His steadfast love is eternal; (9) the moon and the stars to dominate the night, His steadfast love is eternal;
Midrash about the moon...R Shimon b Pazi, 3rd C Palestine, Tiberias. The theme of the "shrunken moon" permeates the KL liturgy:
רבי שמעון בן פזי רמי כתיב (בראשית א, טז) ויעש אלקים את שני המאורות הגדולים וכתיב את המאור הגדול ואת המאור הקטן אמרה ירח לפני הקב"ה רבש"ע אפשר לשני מלכים שישתמשו בכתר אחד אמר לה לכי ומעטי את עצמך אמרה לפניו רבש"ע הואיל ואמרתי לפניך דבר הגון אמעיט את עצמי אמר לה לכי ומשול ביום ובלילה אמרה ליה מאי רבותיה דשרגא בטיהרא מאי אהני אמר לה זיל לימנו בך ישראל ימים ושנים אמרה ליה יומא נמי אי אפשר דלא מנו ביה תקופותא דכתיב (בראשית א, יד) והיו לאותות ולמועדים ולימים ושנים זיל ליקרו צדיקי בשמיך (עמוס ז, ב) יעקב הקטן שמואל הקטן (שמואל א יז, יד) דוד הקטן חזייה דלא קא מיתבא דעתה אמר הקב"ה הביאו כפרה עלי שמיעטתי את הירח והיינו דאמר ר"ש בן לקיש מה נשתנה שעיר של ראש חדש שנאמר בו (במדבר כח, יא) לה' אמר הקב"ה שעיר זה יהא כפרה על שמיעטתי את הירח
Talmud Yerushalmi Berachot, Ch9 halacha 2:

The main source for kiddush levana, T Bavli:
וא"ר אחא בר חנינא אמר רב אסי אמר רבי יוחנן עד כמה מברכין על החדש עד שתתמלא פגימתה...
... וא"ר אחא בר חנינא א"ר אסי א"ר יוחנן כל המברך על החדש בזמנו כאילו מקבל פני שכינה כתיב הכא (שמות יב, ב) החדש הזה וכתיב התם (שמות טו, ב) זה אלי ואנוהו תנא דבי רבי ישמעאל אילמלא (לא) זכו ישראל אלא להקביל פני אביהן שבשמים כל חדש וחדש דיים אמר אביי הלכך נימרינהו מעומד מרימר ומר זוטרא מכתפי (אהדדי) ומברכי א"ל רב אחא לרב אשי במערבא מברכי ברוך מחדש חדשים אמר ליה האי נשי דידן נמי מברכי אלא כדרב יהודה דאמר רב יהודה ברוך [וכו'] אשר במאמרו ברא שחקים וברוח פיו כל צבאם חוק וזמן נתן להם שלא ישנו את תפקידם ששים ושמחים לעשות רצון קונם פועלי אמת שפעולתן אמת וללבנה אמר שתתחדש עטרת תפארת לעמוסי בטן שהן עתידין להתחדש כמותה ולפאר ליוצרם על שם כבוד מלכותו ברוך אתה ה' מחדש חדשים.
And Rabbi Aḥa bar Ḥanina says that Rabbi Asi says that Rabbi Yoḥanan says: With regard to anyone who blesses the new month in its proper time, it is as if he greets the Face of the Divine Presence. Alluding to this, it is written here concerning the sanctification of the new month: “This month shall be for you the beginning of months” (Exodus 12:2), and it is written there, where the Jewish people encountered the Divine Presence at the splitting of the sea: “This is my God and I will glorify Him” (Exodus 15:2). The term “this” is employed in both verses. The school of Rabbi Yishmael taught: If the Jewish people merited to greet the Face of their Father in Heaven only one time each and every month, it would suffice for them, since in the blessing of the moon there is an aspect of greeting the Divine Presence. Abaye said: Therefore, we will say the blessing while standing, in honor of the Divine Presence. The Gemara relates: Mareimar and Mar Zutra would lean on one another’s shoulders and recite the blessing. Rav Aḥa said to Rav Ashi: In the West, Eretz Yisrael, they recite the following blessing on the moon: Blessed is He Who renews the months. Rav Ashi said to him: Our women also recite that blessing, meaning that this is an abridged version for the unlettered. Rather, the full version of the blessing is the version of Rav Yehuda. As Rav Yehuda says: Blessed are You, Lord our God, King of the Universe, Who by His word created the heavens, and by the breath of his mouth all their hosts. He set for them a law and a time, that they should not deviate from their task. And they are joyous and glad to perform the will of their Owner; they are workers of truth whose work is truth. And to the moon He said that it should renew itself as a crown of beauty for those He carried from the womb, as they are destined to be renewed like it, and to praise their Creator for the name of His glorious kingdom. Blessed are You the Lord, Who renews the months.
Aruch HaShulchan explains the intertextual allusions in the bracha:
וזה שאומר: "במאמרו ברא שחקים, וברוח פיו כל צבאם" – מפני שכן אמר דוד: "בדבר ד' שמים נעשו, וברוח פיו כל צבאם". ואומר: "חוק וזמן נתן להם, שלא ישנו את תפקידם". ה"זמן" הוא כל ימי עולם, והם שית אלפי שנין, ששים ושמחים לעשות רצון קונם, כדכתיב: "ישיש כגבור לרוץ אורח". ואומר לשון "ששון ושמחה", כמו שלשון זה מעותד על ישראל, שנאמר: "ששון ושמחה ימצא בה, תודה וקול זמרה"."פועלי אמת שפעולתן אמת" – כן הוא גירסת רש"י, ועל חמה ולבנה קאי, שאין משנים תפקידם. והתוספות גורסים "פועל אמת שפעולתו אמת", ואקדוש ברוך הוא קאי, שבאמת ובדין מיעט הלבנה. "וללבנה אמר שתתחדש..." – זהו לעתיד לבוא, תתחדש לגמרי. ולעת עתה – תתחדש בכל חודש. והיא סימן לישראל שהם "עמוסי בטן", שכן אמר הנביא: "העמוסים מני בטן". כלומר: עמוסי התלאות. ומסיים "ברוך... מחדש חודשים".
Masechet Soferim, probably 8th century CE, Palestine. A non-canonical Talmudic treatise dealing especially with the rules relating to the preparation of the holy books, as well as with the regulations for the reading of the Torah, and belongs to the "Masechtot Ketanot." Adds in lots of extras beyond the Bavli:
(א) ואין מברכין על הירח אלא במוצאי שבת כשהוא מבושם ובכלים נאים ותולה עיניו כנגדה ומיישר את רגליו ומברך אשר במאמרו ברא שחקים וברוח פיו כל צבאם חוק וזמן נתן להם שלא ישנו את תפקידם פועלי אמת שפעולתו אמת וללבנה אמר שתתחדש באור יקר ועטרת תפארת לעמוסי בטן שהם עתידים להתחדש כמותה לפאר יוצרם על כבוד מלכותו בא"י מקדש ראשי חדשים:
(ב) ואומר ג"פ סימן טוב סימן טוב [תהיה] לכל ישראל ברוך יוצרך ברוך עושך ברוך קונך ברוך בוראך ורוקד ג׳ רקידות כנגדה ואומר ג"פ כשם שאני רוקד כנגדך ואיני נוגע ביך כך אם ירקדו אחרים כנגדי [להזיקני] לא יגעו בי תפול עליהם אימתה ופחד ולמפרע אמן אמן סלה הללויה ואומר לחבירו ג"פ שלום וילך לביתו בלב טוב והדא היא לכל מפסיקין לראשי חדשים:
Rambam places birchat levana in the section of berachot when one sees natural wonders, after the rainbows. No additions to the core text from the Talmud Bavli. Context is similar to T Yerushalmi:
הָרוֹאֶה לְבָנָה בְּחִדּוּשָׁהּ מְבָרֵךְ בָּרוּךְ אַתָּה יְיָ׳ אֱלֹקֵינוּ מֶלֶךְ הָעוֹלָם אֲשֶׁר בְּמַאֲמָרוֹ בָּרָא שְׁחָקִים וּבְרוּחַ פִּיו כָּל צְבָאָם חֹק וּזְמַן נָתַן לָהֶם שֶׁלֹּא יְשַׁנּוּ אֶת תַּפְקִידָם שָׂשִׂים וּשְׂמֵחִים לַעֲשׂוֹת רְצוֹן קוֹנֵיהֶם פּוֹעֲלֵי אֱמֶת וּפְעֻלָּתָם צֶדֶק וְלַלְּבָנָה אָמַר שֶׁתִּתְחַדֵּשׁ עֲטָרָה תִּפְאֶרֶת לַעֲמוּסֵי בָטֶן שֶׁהֵם עֲתִידִין לְהִתְחַדֵּשׁ כְּמוֹתָהּ וּלְפָאֵר לְיוֹצְרָם עַל כְּבוֹד מַלְכוּתוֹ וְעַל כָּל מַה שֶּׁבָּרָא בָּרוּךְ אַתָּה יְיָ׳ מְחַדֵּשׁ הֶחֳדָשִׁים:
(יז) וְצָרִיךְ לְבָרֵךְ בְּרָכָה זוֹ מְעֻמָּד. שֶׁכָּל הַמְבָרֵךְ עַל הַחֹדֶשׁ בִּזְמַנּוֹ כְּאִלּוּ הִקְבִּיל פְּנֵי הַשְּׁכִינָה. אִם לֹא בֵּרֵךְ עָלֶיהָ בַּלַּיִל הָרִאשׁוֹן מְבָרֵךְ עָלֶיהָ עַד שִׁשָּׁה עָשָׂר יוֹם בַּחֹדֶשׁ עַד שֶׁתִּמָּלֵא פְּגִימָתָהּ:
(16) At sight of a rainbow, one says the blessing "Blessed art Thou, O Lord our God, King of the Universe, Who rememberest the Covenant, art faithful to Thy Covenant and keepest Thy promise." At sight of the new moon, one says, "Blessed art Thou, O Lord our God, King of the Universe, by Whose word the heavens were created, and by the breath of Whose mouth all their hosts. A statute and season Thou didst assign unto them, that they should not change their appointed charge. They are glad and rejoice to do the will of their Master—faithful workers whose work is faithful. And the moon He bade renew herself as a crown of glory unto those that have been upborne by Him from the womb, who, in the time to come, will themselves be renewed like her, to honor their Creator for His glorious sovereignty's sake and for all that He has created. Blessed art Thou, O Lord, Who renewest the months."
(17) This blessing is said standing; For everyone who says the blessing for the new moon at the appointed time is regarded as if he had received the Divine Presence. If one has not said the blessing the first night, (of the new moon) he may do so up to the sixteenth of the month, when it is full moon.
The Tur essentially paraphrases Ms. Soferim, but with some changes. Must have had different manuscript:
... גרסי' במסכת סופרים אין מברכין על הירח אלא במ"ש כשהוא מבושם ובגדיו נאים ותולה עיניו כנגדה ומיישר רגליו ומברך ואומר ג"פ סי' טוב תהיה לכל ישראל ברוך בוראך ברוך יוצרך ברוך מקדשך ורוקד ג"פ כנגדה ואומר בכל פעם כשם שאני רוקד כנגדך ואיני יכול ליגע בך כך אם ירקדו אחרים כנגדי להזיקני לא יגעו בי ואומר תפול עליהם אימתה ופחד בגדול זרועך ידמו כאבן ולמפרע כאבן ידמו זרועך בגדול ופחד אימתה עליהם תפול ואומר כן ג"פ אמן ואמן הללויה ואומר לחבירו ג"פ שלום עליך וילך לביתו בלב טוב וי"א בזה הסדר ברוך יוצרך ברוך עושך ברוך קונך ברוך בוראך וסימן יעקב והיא רמז לו:
Shulchan aruch only keeps "siman tov" and "baruch yotzrech"...leaves out the rest (like Rambam.) Rema adds back in all of the extras from Ms. Soferim and the Tur:
ותולה עיניו ומיישר רגליו ומברך (מעומד) (טור) ואומר שלשה פעמים סימן טוב תהיה לכל ישראל ברוך יוצרך וכו': הגה ורוקד ג' פעמים כנגדה ואומר כשם שאני רוקד כו' ואומר תפול עליהם וגו' ולמפרע כאבן ידמו כו' ג' פעמים ואומר לחבירו ג"פ שלום עליך (הג"ה החדשות) ומשיב הוי כשואל (טור) ונוהגין לומר דוד מלך ישראל חי וקים שמלכותו נמשל ללבנה ועתיד להתחדש כמותה וכנסת ישראל תחזור להתדבק בבעלה שהוא הקב"ה דוגמת הלבנה המתחדשת עם החמה שנאמר שמש ומגן ה' ולכן עושין שמחות ורקודין בקדוש החדש דוגמת שמחת נשואין: (בחיי פרשת וישב וד"ע):
Looking at the moon while reciting kiddush levana:
ותולה וכו' ואומר וכו' - כתב בשיורי כנה"ג דמשמע לכאורה דעד גמר כל הסדר תולה עיניו בה וכן נהוג עלמא אבל שמע משם ספר חרדים שהחמיר בזה מאד מלהסתכל בלבנה ולא התיר להסתכל בה אלא עד שסיים הברכה והמ"א בשם של"ה החמיר עוד יותר דאפילו בשעת הברכה אין לו להסתכל בה אלא רואה אותה פעם אחת כשירצה לברך ואח"כ לא יסתכל בה:
"Keshem sheani roked" and the forward-backward "incantantation":
(יד) (יד) ורוקד וכו' - וכתבו האחרונים דיזהר מאוד שלא יכרע ברכיו לרקוד דלא יהא נראה ככורע ללבנה אלא יסמוך על אצבעות רגליו וירקוד:
Otzar HaChayim. R. Chaim Yehuda Ehrenreich, 1935.


The incantation was the most prominent element in Jewish magic...The incantation comprised several ingredients, all more or less constant: an appeal to ancient masters of magic, such as the statement that a certain charm for intelligence was "performed by our teacher Moses on behalf of Joshua"; citations from or allusions to Biblical passages; the invocation of angels; the enunciation of holy names; and finally the specific request or command...A familiar characteristic of magic is the injunction to do things in reverse, to walk backward, to put one's clothing on backward, to throw things behind one's back. The same principle applies in incantations, and Talmudic and medieval Jewish charms amply illustrate its operation. Biblical quotations were often recited both forward and backward, mystical names were reversed; sometimes the words were actually written backward as they were to be uttered, so that it requires considerable mental agility not to be taken in by the unnatural rendering. Phrases that are capable of being read alike in either direction were especially highly prized. The purpose was to capitalize the mystery of the bizarre and unfamiliar, and the power that is associated with the ability to reverse the natural order of things.
Why is "Aleinu" added?
Rav Yisrael Chaim Friedman of Rachov (1922). He was one of the important talmidim of the Yitav Lev (Satmar). He died in an accident that occurred while he was assuring the kashrus of cheese. There was a sudden cloud burst of heavy rain, which resulted in a sudden flash flood in which Rabbi Friedman drowned. [The Internet]

"Segula"-you won't die in that upcoming month:
... כתב אור חדש מעשה באחד שפגעו עכו''ם בלילה ורצו להרגו וביקש שיניחו לו לעשות מצוה אחד קודם מותו והלבנה היתה בחידושה וקדשה בכוונה גדולה ונעשה לו נס כשדילג ג''פ כמנהג ונשאו הרוח וניצול מהם גם שמעתי שמי שיקדש הלבנה מיום שקדשה שוב לא ידאוג שימות באותו חודש מאותו יום ואילך ע''כ:
"Segula"-A dentist's mightmare:
One time the Senior Rabbanit Kanievsky, Rabbi Yaakov Yisrael’s wife got a toothache. Rabbi Yaakov Yisrael said the appropriate verses during Kidush Levana and the toothache went away immediately. [the internet]


Women and Kiddush Levana
(א) (א) הרואה וכו' - ונשים פטורות מלקדש הלבנה דהוי מ"ע שהזמן גרמא ואף דכל מ"ע שהזמן גרמא נוהגות הנשים שמקיימות ומברכות עליהן מ"מ מצוה זו אין צריכין לקיימה משום דהם גרמו פגם הלבנה.
מרימר ומר זוטרא מכתפי (אהדדי) ומברכי א"ל רב אחא לרב אשי במערבא מברכי ברוך מחדש חדשים אמר ליה האי נשי דידן נמי מברכי
The Gemara relates: Mareimar and Mar Zutra would lean on one another’s shoulders and recite the blessing. Rav Aḥa said to Rav Ashi: In the West, Eretz Yisrael, they recite the following blessing on the moon: Blessed is He Who renews the months. Rav Ashi said to him: Our women also recite that blessing, meaning that this is an abridged version for the unlettered.
סעיף א' הרואה לבנה בחידושה וכו'. נ"ב עיין במג"א סק"א שכתב דברכת הלבנה הוי מ"ע שהז"ג ונשים פטורות וכתב כן בשם השל"ה הקדוש. ולדעתי זה היא תמוה מאד ואין לו ענין כלל למ"ע שהז"ג דכלל זה לא נאמר רק במצוה דגוף המצוה שייכא תמיד בכל ענין וככל זמן כגון במצה או סוכה ולולב וכדומה דמצוה זו אפשר להתקיים בחשוון כמו בתשרי ואייר כמו בניסן ואעפ"כ אמרה התורה שבימים הללו חייב ומכאן ואילך פטור מוכח דהוי מ"ע שהז"ג ולכך נשים פטורות אבל בלבנה אטו הוה לה מניעה מכח הזמן זה הוי המניעה מגוף המצוה שלא שייכא אז דממ"נ אם כבר בירך פעם אחת על ראייתה לא שייך ברכה עוד ב"פ כיון שכבר בירך פ"א לו יהא דהוי פרי חדש אם בירך עליו בשעת ראיה או אכילה א"צ לברך אח"כ עוד ומכל מקום כשמתחדש בשנה החדשה פרי חדש מברכין שנית ואטו יחשב בזה זמן גרמא זה ודאי אינו דאין המניעה מכח הזמן ואף אם לא ברכו עליו בחודש הזה מכל מקום לא שייך עוד ברכה מכח דמתחלת להתקטן אחר כך וא"כ הוי מניעת הברכה שאין כאן גוף הדבר לברד עליו והוה המניעה מכח הדבר שאין כאן לברך עליו ולא מכח הזמן דאטו בפירי דלא שכיח רק בקיץ לא תהיה האשה מברכת על אכילתה או ראייתה שהחיינו כיון דהוי זמן גרמא שבחורף ליתנהו להנך פירות זה ודאי אינו. כך הלבנה בכל חדש כמו הפירי בכל שנה ולכך כיון דאין מניעה זו מכח גוף הזמן רק מכח הלבנה דבשעת הידוש מברכין ובשעת חסרונה אין מברכין ואין המניעה מכח הזמן רק מגוף הלבנה והוי ממש הלבנה חודש בחדשה כפירי של שנה ואין זה מ"ע שהזמן גרמא כנלפע"ד ברור ורבנן לא דקו בהאי מלתא במחילה מכבודם הרמה ודו"ק:
What are some "big picture" take aways?
(ב) ובפשוטו הטעם מה שמברכין על הלבנה יותר מעל כל הכוכבים, והיא קטנה כמעט מכל הכוכבים (זולת כוכב) – מפני שהיא קרובה לארץ יותר מכל הכוכבים, שאינה רחוקה מן הארץ רק בערך מ"ג אלף פרסה. ובה נראית לנו בחוש גדולתו של הקדוש ברוך הוא, בכל לילה ולילה מהילוכה המורגש, והקיפה את הארץ בכל חודש....וישראל המונים ללבנה – נמשלו ללבנה: כשם שהלבנה אין לה אור מעצמותה, רק תאיר מאור השמש, כמו כן ישראל אין להם שום אור זולת אורו של הקדוש ברוך הוא, הזורח לנו באמצעות התורה הקדושה, כמו שנאמר: "שמש ומגן ד' אלקים".וכשם שהלבנה תחשך ותאיר, כמו כן ישראל, כמו שאנו אומרים בברכתה: "וללבנה אמר שתתחדש עטרת תפארת לעמוסי בטן, שהם עתידים להתחדש כמותה". וכשם שהלבנה אף בימי חסרונה, שעל הארץ נראתה חשך – מכל מקום תאיר אל עבר פניה במרומים כידוע, כמו כן ישראל. ומכל אלו הטעמים קבלו ישראל מצוה זו בשמחה.

הַמְחַדֵּשׁ בְּטוּבו בְּכָל יום תָּמִיד מַעֲשה בְרֵאשִׁית. כָּאָמוּר לְעשה אורִים גְּדלִים. כִּי לְעולָם חַסְדּו. אור חָדָשׁ עַל צִיּון תָּאִיר וְנִזְכֶּה כֻלָּנוּ מְהֵרָה לְאורו. בָּרוּךְ אַתָּה ה', יוצֵר הַמְּאורות.
Rav Soloveitchick, as recorded by R. Hershel Schachter in B'ikve Hatzon, 1997. The darkness and smallness of the moon is a metaphorical and poetic representation of the existential problem of evil in the world. Why do bad things happen to good people? Why do good things happen to bad people? Doesn't this mock the idea of a God that is in control of the universe?

Did the rabbis really believe that the moon used to be a star like the sun? Did they really believe that God was a sinner; that He wronged the moon and needed atonement? No. The story must be a symbol. It needs decoding.
Judaism is a messianic religion. It believes that the best is yet to come. In the end of days, “the light of the moon shall be as the light of the sun” (Isaiah 30:26). In the meantime, the world is less than perfect. It had to be. A perfect world would need no improvement. But a world without the possibility of improvement would be a world without the possibility of human growth; a world without the possibility of human partnership with God. We could certainly enjoy life in such a world, but we couldn’t be a part of improving and building it...Accordingly, a perfect God has to create a world that falls short. This is symbolised by God’s diminishing the moon. Rabbi Soloveitchick explains: “The creator of the world diminished the image and stature of creation in order to leave something for man, the work of His hands, to do, in order to adorn man with the crown of [co-]creator and maker.”...The ultimate perfection of reality will come about through our efforts. Rosh Chodesh [and kiddush levana] celebrates this fact.