from manim import *

class EpicAdvertisingReportCard(ThreeDScene):
    def construct(self):
        # Set up 3D camera
        self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)
        
        # Title creation with 3D depth
        title = Text("ADVERTISING", font="Impact", font_size=96, color=BLUE)
        title.set_shade_in_3d(True)
        
        subtitle = Text("REPORT CARD", font="Impact", font_size=96, color=RED)
        subtitle.set_shade_in_3d(True)
        subtitle.next_to(title, DOWN, buff=0.3)
        
        # Create epic entrance - explode in from the z-axis
        title.shift(OUT * 20)
        subtitle.shift(OUT * 20)
        
        # Animate title flying in with rotation
        self.play(
            title.animate.shift(IN * 20).rotate(2 * PI, axis=UP),
            run_time=1.5,
            rate_func=rush_into
        )
        
        self.play(
            subtitle.animate.shift(IN * 20).rotate(-2 * PI, axis=UP),
            run_time=1.5,
            rate_func=rush_into
        )
        
        self.wait(0.5)
        
        # Create rotating 3D "EPIC" text
        epic_text = Text("E P I C", font="Impact", font_size=144, color=GOLD)
        epic_text.set_shade_in_3d(True)
        epic_text.shift(OUT * 2)
        
        # Camera rotation around the text
        self.play(Create(epic_text))
        self.move_camera(phi=60 * DEGREES, theta=-90 * DEGREES, run_time=2)
        
        # Spin the epic text
        self.play(
            Rotate(epic_text, angle=4 * PI, axis=OUT),
            run_time=2
        )
        
        # Scale pulse effect
        self.play(
            epic_text.animate.scale(1.5),
            rate_func=there_and_back,
            run_time=1
        )
        
        # Fade out epic, bring back title
        self.play(FadeOut(epic_text))
        self.move_camera(phi=75 * DEGREES, theta=-45 * DEGREES, run_time=1)
        
        # Create rating bars in 3D space
        bars = VGroup()
        labels = ["IMPACT", "CLARITY", "ROI", "CREATIVITY", "STRATEGY"]
        colors = [RED, BLUE, GREEN, YELLOW, PURPLE]
        ratings = [0.95, 0.88, 0.92, 0.97, 0.90]
        
        for i, (label, color, rating) in enumerate(zip(labels, colors, ratings)):
            bar_bg = Rectangle(width=6, height=0.4, color=GRAY, fill_opacity=0.3)
            bar_bg.set_shade_in_3d(True)
            
            bar_fill = Rectangle(width=6 * rating, height=0.4, color=color, fill_opacity=0.8)
            bar_fill.set_shade_in_3d(True)
            bar_fill.align_to(bar_bg, LEFT)
            
            label_text = Text(label, font_size=24, color=WHITE)
            label_text.set_shade_in_3d(True)
            label_text.next_to(bar_bg, LEFT, buff=0.3)
            
            rating_text = Text(f"{int(rating*100)}%", font_size=28, color=color, weight=BOLD)
            rating_text.set_shade_in_3d(True)
            rating_text.next_to(bar_bg, RIGHT, buff=0.3)
            
            bar_group = VGroup(label_text, bar_bg, bar_fill, rating_text)
            bar_group.shift(DOWN * (i * 0.7) + OUT * (i * 0.2))
            bars.add(bar_group)
        
        bars.shift(DOWN * 0.5)
        
        # Clear previous
        self.play(
            FadeOut(title),
            FadeOut(subtitle)
        )
        
        # Animate bars flying in from different angles
        for i, bar_group in enumerate(bars):
            bar_group.shift(LEFT * 15)
            self.play(
                bar_group.animate.shift(RIGHT * 15),
                run_time=0.5
            )
        
        self.wait(1)
        
        # Camera orbit around the bars
        self.begin_ambient_camera_rotation(rate=0.2)
        self.wait(3)
        self.stop_ambient_camera_rotation()
        
        # Final zoom and text
        final_text = Text("EXCELLENCE\nDELIVERED", font="Impact", font_size=72, color=GOLD)
        final_text.set_shade_in_3d(True)
        final_text.shift(UP * 2.5)
        
        self.play(
            FadeIn(final_text, shift=OUT * 3),
            bars.animate.shift(DOWN * 1),
            run_time=1.5
        )
        
        # Epic finale - everything scales up
        everything = VGroup(bars, final_text)
        self.play(everything.animate.scale(1.3), run_time=1.5)
        self.move_camera(phi=65 * DEGREES, run_time=1)
        
        self.wait(2)
