flowchart TD
    A["HyprTile Launcher / hyprtile.c"] --> F1["F1 gedrückt"]

    F1 -->|"wenn nicht im Filtermodus"| Next["background_next(win_w, win_h)"]
    F1 -. "Filtermodus aktiv" .-> Blocked["F1 bewusst deaktiviert\nFilter, Page-Wechsel, Ctrl-Edit aus"]

    Next --> Shutdown["background_shutdown()\naktuelles Plugin cleanup"]
    Shutdown --> Advance["current_index + 1\nbei Ende zurück auf 0"]
    Advance --> Start["start_plugin(next, width, height)"]
    Start --> MouseCenter["background_set_mouse(win_w/2, win_h/2)"]
    MouseCenter --> Log["Log: Switched background plugin"]

    Config["config.json / load_config"] --> BgKey["background"]
    Config --> BgVideo["background_video"]
    BgKey --> Init["background_init(preferred_id, win_w, win_h)"]
    BgVideo --> VideoFile["background_video_file"]

    Init --> FindPlugin["find_plugin_index(id)"]
    FindPlugin -->|"gefunden"| Start
    FindPlugin -->|"unbekannt"| Fallback["Fallback: none"]

    subgraph Interface["BackgroundPlugin Interface"]
        I1["id / name"]
        I2["init(width,height)"]
        I3["resize(width,height)"]
        I4["update()"]
        I5["set_mouse(x,y)"]
        I6["render()"]
        I7["shutdown()"]
    end

    Start --> Interface

    subgraph Runtime["Render-/Update-Pipeline"]
        UpdateLoop["Main Loop"] --> BgUpdate["background_update()"]
        MouseMove["Mouse Motion"] --> BgMouse["background_set_mouse(x,y)"]
        Resize["Window Resize"] --> BgResize["background_resize(w,h)"]
        RenderPage["render_page()"] --> GLFlush1["SDL_FlushRenderer"]
        GLFlush1 --> BgRender["background_render()"]
        BgRender --> Glass["glass_overlay_render()"]
        Glass --> Scanlines["scanline_overlay_render()"]
        Scanlines --> GLFlush2["SDL_FlushRenderer"]
        GLFlush2 --> Tiles["SDL Tiles / Text / Overlays"]
    end

    Interface --> Runtime

    subgraph Registered["Aktuell registrierter F1-Zyklus"]
        None["none\nNo-op Background"]
        Starfield["starfield\nSterne + Nebel + Maus-Parallax"]
        VideoRender["videorender\nVideo-Background über background_video"]
        Dolphin["cosmic_dolphin_portal\nregistriertes GL/Portal Plugin"]
    end

    Advance --> None
    Liberation --> Starfield
    VideoRender --> Dolphin
    Dolphin --> None

    subgraph StarfieldFeatures["starfield Features"]
        SF1["OpenGL VAO/VBO/IBO"]
        SF2["dynamische Star-Quads"]
        SF3["Nebel-Discs / driftende Nebulas"]
        SF4["Maus-Parallax\nCenter verschiebt sich mit Maus"]
        SF5["Resize resetet Sterne + Nebel"]
        SF6["Time-based Animation"]
    end

    Starfield --> StarfieldFeatures

    subgraph VideoFeatures["videorender Features"]
        VF1["liest background_video_file"]
        VF2["nur bei gesetztem lesbarem Pfad"]
        VF3["Video als GL-Background"]
        VF4["läuft vor Tiles und Overlays"]
    end

    VideoRender --> VideoFeatures
    BgVideo --> VideoFeatures

    subgraph OptionalAudio["Im Codebestand vorhandene audioreaktive Kandidaten"]
        EQ["equalizer\nAudio Equalizer"]
    end

    subgraph EqualizerFeatures["equalizer Features"]
        EQ1["audio_analyzer_start()"]
        EQ2["32 Audio-Bänder: uBands[32]"]
        EQ3["Peaks + Glättung"]
        EQ4["Emphasis Modes:\nflat / balanced / smile / treble / vocal"]
        EQ5["Maus-Uniform iMouse"]
        EQ6["idle bars wenn Analyzer fehlt"]
    end

    EQ --> EqualizerFeatures

    OptionalAudio -. "in gefundenem manager nicht in plugins[] gelistet" .-> Registered
